Packages

Packages help us split code into namespaces. Normally when you have related files or classes, you want a way to organize so as to avoid name collisions. If say two developers are working on a project, and one names his file Student.kt and another the same, then we can have name collisions. Packages helps avoid this collision as placing the same files in different namespaces/packages helps prevent this collision.

package com.tutorialsloop.myproject

fun calculate(){}

class Spacecraft{}

The package name can be used to give us a Fully Qualified Name(FQN) for contents such as:

  • Class
  • Function.
  • Object
  • Interface.

In the above example, the fully qualified name for calculate is com.tutorialsloop.myproject.calculate while that for Spacecraft is com.tutorialsloop.myproject.Spacecraft.