...

/

Understanding Kotlin Code Structure

Understanding Kotlin Code Structure

Understand the basic code structure and coding conventions of Kotlin, and get hands-on practice with a simple project.

Unlike Java, there’s no strong relationship between the file name and class name in Kotlin. We can put as many public classes in our file as we want, as long as the classes are related to one another and the file doesn’t grow too long to read.

Naming conventions

As a convention, if our file contains a single class, we name our file the same as our class. If our file contains more than one class, then the filename should describe the common purpose of those classes. We use Camel case when naming our files, as per the Kotlin coding convention. The main file in our Kotlin project should usually be named Main.kt.

Packages

A package is a collection of files and classes that all share a similar purpose or domain. Packages are a convenient way to have all our classes and functions under the same namespace, and often in the same folder. ...