# Introduction to Java — JDK, JVM and Your First Program

Source: https://skills101.in/learn/java/java-introduction — Skills101 free tutorial (Java Programming). Updated 2026-11-09.

**Java** runs banking systems, Android apps and enterprise software around the world. Most service companies (TCS, Infosys, Wipro, Cognizant) hire for Java roles, which is why it is the most common language in fresher interviews.

## 1. How Java runs: compile once, run anywhere

![Main.java is compiled by javac into Main.class bytecode, which the JVM runs on Windows, Linux or Mac](https://skills101.in/learn-img/java/jvm-flow.svg)

1. You write `Main.java` (source code).
2. The compiler **`javac`** turns it into **bytecode** (`Main.class`).
3. The **JVM** (Java Virtual Machine) runs the bytecode.

Because every operating system has a JVM, the same `.class` file runs everywhere: **"Write Once, Run Anywhere"**.

## 2. JDK vs JRE vs JVM (a classic interview question)

![Nested boxes: the JDK contains the JRE plus tools like javac; the JRE contains the JVM plus the standard libraries](https://skills101.in/learn-img/java/jdk-jre-jvm.svg)

| | What it is | Who needs it |
|---|---|---|
| **JVM** | runs bytecode, manages memory (garbage collection) | part of the JRE |
| **JRE** | JVM + standard libraries | anyone who only **runs** Java programs |
| **JDK** | JRE + tools (`javac`, `jar`, debugger) | **developers** — install this |

## 3. Install the JDK

1. Download **JDK 21 (LTS)** from adoptium.net or oracle.com.
2. Install it, then open a terminal and check: `java -version` and `javac -version`.

## 4. Your first program

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

```text
Hello, Skills101!
```

Save it as **`Main.java`** (the file name must match the public class name), then:

```text
javac Main.java     ← compile: creates Main.class
java Main           ← run
```

### Line by line

| Code | Meaning |
|---|---|
| `public class Main` | every Java program lives inside a class |
| `public static void main(String[] args)` | the **entry point** — the JVM starts here |
| `public` | the JVM can call it from outside |
| `static` | runs without creating an object |
| `void` | returns nothing |
| `String[] args` | command-line arguments |
| `System.out.println(…)` | print a line |

Every statement ends with a **semicolon** `;`, and blocks use **curly braces** `{ }`.

## 5. print vs println

```java
public class Main {
    public static void main(String[] args) {
        System.out.print("Learn ");
        System.out.print("Java");
        System.out.println();
        System.out.println("Sum: " + (10 + 5));
        System.out.println("Sum: " + 10 + 5);
    }
}
```

```text
Learn Java
Sum: 15
Sum: 105
```

`print` stays on the same line; `println` moves to a new line. Notice the last line: `"Sum: " + 10` makes text first, then `+ 5` joins "5" — use brackets for maths.

## 6. Comments

```java
// single-line comment
/* multi-line
   comment */
/** documentation comment (used by the javadoc tool) */
```

## Common mistakes

- File name doesn't match the class name (`public class Main` must be in `Main.java`).
- Missing semicolons.
- Writing `system.out.println` — Java is case-sensitive: `System` has a capital S.

## Quick recap

- javac compiles .java → .class (bytecode); the JVM runs it on any OS.
- JDK ⊃ JRE ⊃ JVM. Developers install the JDK.
- `public static void main(String[] args)` is where execution starts.
- Statements end with `;`; blocks use `{ }`; Java is case-sensitive.


Practice quiz and free certificate: https://skills101.in/learn/java/java-introduction