Kotlin fundamentals.

We have learned to think about programming. Now we apply these ideas in a real language. This course uses Kotlin. Today we meet Kotlin and understand why it is a good choice for learning and for real applications.

Kotlin is a programming language created by JetBrains and first released in 2016.

It is a general-purpose language. You can build many kinds of software with it. Mobile apps. Server applications. Desktop programs. Web frontends.

Kotlin is modern. It was designed recently, learning from decades of language design experience. It avoids many problems found in older languages.

Kotlin is practical. It was built to solve real problems, not as an academic exercise. It is used by millions of developers in production systems.

Today, Kotlin is the preferred language for Android development. Google officially recommends it. But Kotlin is more than an Android language. It works everywhere.

Kotlin is statically typed. This means every value has a type, and the type is known at compile time.

When you write code, the compiler checks that types match. If you have a function that expects a number, and you pass a string, the compiler rejects it. Before your code runs.

Static typing catches errors early. The compiler is like a first reviewer. It finds mistakes before users encounter them.

Static typing enables tooling. Because types are known, the IDE can offer autocomplete. It knows what methods are available on each value. It can find all usages of a function.

Some languages are dynamically typed. Types are checked at runtime. This is flexible but delays error detection. Kotlin chooses static typing for safety and clarity.

Kotlin compiles to Java bytecode and runs on the Java Virtual Machine.

The JVM is mature and battle-tested. It runs on servers, on desktops, on phones. It manages memory. It optimizes code as it runs. It provides a vast ecosystem of libraries.

Because Kotlin runs on the JVM, it can use any Java library. Decades of Java libraries are available. You do not start from zero.

Kotlin is also interoperable with Java. Kotlin code can call Java code. Java code can call Kotlin code. You can mix both in the same project.

This is practical. Many companies have existing Java code. They can adopt Kotlin gradually, file by file. No need to rewrite everything.

Kotlin is not limited to the JVM.

Kotlin Native compiles to machine code. It runs without a virtual machine. This enables iOS apps, embedded systems, and command-line tools.

Kotlin JS compiles to JavaScript. It runs in browsers. You can share code between a Kotlin backend and a Kotlin frontend.

Kotlin Multiplatform lets you share business logic across platforms. Write once, use on Android, iOS, web, and desktop.

The language is the same. The platform differs. This flexibility makes Kotlin valuable beyond any single ecosystem.

Kotlin was designed with safety in mind.

Null safety is built into the type system. Types are non-nullable by default. If a value might be absent, you must declare it explicitly. The compiler enforces null checks.

This eliminates the most common source of crashes. The null pointer exception. In Kotlin, you cannot accidentally use a null value without checking.

Kotlin also favors immutability. The recommended way to declare variables uses val, which cannot be reassigned. Mutable variables exist but require conscious choice.

Smart casts reduce repetitive code. When you check a type, the compiler remembers. You do not need to cast again.

These features make code safer without being annoying. Safety is the default. Danger requires explicit choice.

Kotlin reduces boilerplate.

Type inference means you often do not need to write types. The compiler figures them out. You write less, the compiler understands more.

Data classes generate equals, hashCode, toString, and copy methods automatically. One line replaces dozens.

Default and named arguments reduce the need for overloaded functions. One function handles many cases.

String templates let you embed expressions in strings directly. No awkward concatenation.

Kotlin removes the ceremony found in older languages. The code you write is the code that matters.

A Kotlin file ends with the extension dot kt.

The file contains functions, classes, and other declarations. There is no required wrapper class like in Java.

The entry point is the main function. When the program runs, main executes.

A simple program: fun main opening brace, println "Hello, Kotlin!", closing brace.

That is a complete program. No boilerplate. No ceremony. The code does what it says.

Functions are declared with fun. Classes are declared with class. Values with val. Variables with var. The syntax is clean and readable.

Kotlin has a philosophy.

Pragmatic over dogmatic. Kotlin does not enforce a single paradigm. It supports object-oriented programming. It supports functional programming. Use what works.

Safe over sorry. The defaults prevent common mistakes. You can bypass safety when needed, but you must be explicit.

Concise over verbose. Reduce noise. Express ideas directly. Let the compiler handle the rest.

Interoperable over isolated. Work with existing code. Work with existing tools. Integration is not an afterthought.

This philosophy makes Kotlin productive. It helps you write correct code quickly.

Let us summarize.

Kotlin is a modern, statically typed language.

It runs on the JVM and can use all Java libraries.

It also compiles to native code and JavaScript.

Safety is built in: null safety, immutability by default.

Syntax is concise: type inference, data classes, smart casts.

The philosophy is pragmatic, safe, and interoperable.

Kotlin is an excellent choice for learning and for building real applications.