Java Essentials · Ay 1

Introduction to Java & the JVM

Goal: understand what Java is, how a Java program runs, and write and run your first program. Duration: 90 min · You need: a laptop with internet

1. Why Java?

Java is one of the most used programming languages in the world. Banks (Kapital Bank, ABB, PASHA), payment systems, airlines, e-commerce and big companies like Google, Amazon and Netflix run huge backend systems on Java.

Java is:

  • Object-oriented: we model the real world with objects (a Customer, an Order, a Payment).
  • Strongly typed: the compiler checks types before the program runs, so many bugs are caught early.
  • Platform independent: the same compiled program runs on Windows, macOS and Linux.
  • Huge ecosystem: Spring Boot, Hibernate, Kafka clients, thousands of libraries.

2. JDK, JRE and JVM

Term What it is Who needs it
JVM (Java Virtual Machine) Runs compiled Java bytecode Every machine that runs Java
JRE (Java Runtime Environment) JVM + standard libraries Users who only run programs
JDK (Java Development Kit) JRE + compiler (javac) + tools Developers (us)

How a Java program runs:

Hello.java  --javac-->  Hello.class (bytecode)  --java (JVM)-->  runs on any OS

This is the famous "write once, run anywhere": you compile once to bytecode; the JVM on each operating system translates it to machine code.

3. Step by step: install your tools

Step 1: Install JDK 21

  1. Open https://adoptium.net and download Temurin 21 (LTS) for your OS.
  2. Install with default settings.
  3. Open a terminal (Windows: cmd, macOS: Terminal) and check:
java -version
javac -version

You should see 21.x.x. If you see "command not found", restart the terminal or re-install with "Add to PATH" checked.

Step 2: Install IntelliJ IDEA

  1. Download IntelliJ IDEA Community Edition (free) from jetbrains.com.
  2. Install and open it.
  3. New Project → Language: Java → Build system: IntelliJ → JDK: 21 → Create.

4. Your first program

Create a class Hello inside src:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}

Click the green ▶ next to main. You should see Hello, Java! in the console.

Line by line

Code Meaning
public class Hello A class named Hello. The file must be called Hello.java.
public static void main(String[] args) The entry point: the JVM starts here.
System.out.println(...) Prints text and moves to a new line.
; Every statement ends with a semicolon.
{ } Curly braces group code into blocks.

Run it from the terminal too

javac Hello.java   # compile → creates Hello.class
java Hello         # run (no .class extension!)

5. print vs println, comments

System.out.print("Hello ");    // no new line
System.out.println("world");   // new line after
System.out.println();          // empty line

// single-line comment
/* multi-line
   comment */

6. Common mistakes

  • ❌ File name differs from class name (hello.java vs class Hello). Java is case-sensitive.
  • ❌ Missing semicolon ;. Read the compiler error: it shows the line number.
  • ❌ Writing system.out.println: it must be System with a capital S.
  • ❌ Running java Hello.class: run java Hello.

7. Exercises (in class)

  1. Print your name, city and favourite food on three lines.
  2. Print the same three values on one line using print.
  3. Print this shape:
  *
 ***
*****
  1. Break the program on purpose (remove a ;, rename the class) and read the error messages.

8. Homework

Write a program AboutMe that prints a small "business card":

==========================
  Name:  Anar Alizada
  Goal:  Java Backend Developer
  Start: 2026
==========================

9. Self-check

  1. What is the difference between the JDK and the JVM?
  2. What does javac produce?
  3. Why can a compiled Java program run on any OS?
  4. What must the file containing public class Payment be called?
Answers
  1. JDK is the full developer kit (compiler + tools + JRE); JVM is only the engine that runs bytecode.
  2. A .class file containing bytecode.
  3. Because bytecode runs on the JVM, and there is a JVM for every OS.
  4. Payment.java.