What You Need to Know

This book assumes that you have some amount of existing programming experience in an object-oriented programming language. To help explain certain Kotlin syntax, the book will draw parallels to Java, JavaScript, and Ruby, three popular programming languages. While you do not need experience in any of those, you will need to know the basics of object-oriented programming.

The following sections outline the sorts of prior experience that you need to have in order to make the best use of this book.

Data Types and Expressions

Nearly every programming language has the concept of data types: strings, numbers, booleans, and so on. The exact roster of data types varies by language, as do some of the details of how those data types are implemented. But, you should be comfortable in thinking about how strings, numbers, and similar types of data flow through our programming.

Often, these pieces of data are used in calculations, forming parts of expressions to derive new data. That could be mathematical expressions, such as 2 + 2. That could be expressions tied to other data types, such as string concatenation (e.g., "foo" + "bar"). The details of what expressions are possible and their syntax varies a bit by programming language, but all languages can do this sort of thing.

Objects and Classes

Kotlin is a class-based object-oriented language. Quoting Wikipedia:

The most popular and developed model of OOP is a class-based model, as opposed to an object-based model. In this model, objects are entities that combine state (i.e. data), behavior (i.e. procedures, or methods) and identity (unique existence among all other objects). The structure and behavior of an object are defined by a class, which is a definition, or blueprint, of all objects of a specific type. An object must be explicitly created based on a class and an object thus created is considered to be an instance of that class.

Java and Ruby are class-based object-oriented languages, where we use the class keyword to begin the description of a class. JavaScript originally was not a class-based language, though recent updates have pulled it much closer to its class-based counterparts.

Methods or Functions

In a class-based object-oriented language, we need to tell the class what its behaviors are. A Box class might have open() and close() behaviors, for example.

In Java and Ruby, those behaviors would be implemented in the form of “methods”. In Kotlin and JavaScript, those behaviors are called “functions”.

Fields, Properties, and Variables

Similarly, in a class-based object-oriented language, we need to tell the class what data it has to work on. A Box class might have:

The term for this varies widely:

Also, our methods or functions will have temporary holding spots for bits of data. The input is usually referred to as “parameters” or “arguments”, so a seal() function might accept a parameter indicating how the box should be sealed (with tape, with staples, with welds, etc.). The working data inside the function is usually called “variables”, so a seal() function might use the length, width, and height properties to calculate how much tape is needed to seal the box, holding that calculated value in a variable.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.