🎯 What you will learn

Java powers over 3 billion devices — Android apps, bank transaction engines, Spring Boot microservices, and increasingly, AI inference gateways. Before any of that, you need one working terminal command:

The two commands you will use every single day:
javac MyFile.java — compile source to bytecode
java MyFile — run that bytecode on the JVM

This lesson installs the right version (JDK 21 LTS), runs your first program, and explains the compile → run lifecycle so you never stare at a cannot find symbol error without knowing why.

💼 Interview reality: "What is the difference between JDK, JRE, and JVM?" is asked in nearly every Indian IT services and banking campus interview. You will answer it perfectly after this lesson.

🔧 JDK vs JRE vs JVM — the three layers

Most beginners install the wrong thing. Here is the exact hierarchy:

JDK — Java Development Kit javac compiler · jar tool · jshell · debugger · profiler JRE — Java Runtime Environment class libraries (java.lang, java.util, java.io …) JVM — Java Virtual Machine Loads bytecode (.class) → interprets + JIT-compiles → native machine code Garbage collector lives here · Platform-specific (Mac / Linux / Windows)
TermContainsUsed by
JVMRuntime engine — executes .class bytecodeEveryone who runs Java
JREJVM + standard class librariesEnd users running Java apps
JDKJRE + javac compiler + dev toolsDevelopers writing Java code ← you need this

Why JDK 21? It is the current Long-Term Support (LTS) release — meaning security patches until at least 2031. Companies hiring Java developers today target JDK 11 or JDK 21. We go straight to 21.

📦 Installing JDK 21

macOS (Homebrew — recommended)

brew install openjdk@21
Terminal — macOS install theoretical — not executable

Windows

Download the installer from adoptium.net → choose Temurin 21 (LTS). The installer sets your PATH automatically. Open a new Command Prompt and run javac -version.

Linux (Ubuntu/Debian)

sudo apt install openjdk-21-jdk
Terminal — Linux install theoretical — not executable

VS Code setup (optional but recommended): Install the Extension Pack for Java from Microsoft. It adds syntax highlighting, inline errors, and a run button — but the terminal commands are what matter.

💻 Step-by-step: your first program

Open a terminal, create a folder called java-practice, and create a file called HelloWorld.java. The filename must match the class name exactly — Java is case-sensitive.

javac HelloWorld.java && java HelloWorld
HelloWorld.java Lesson 00 · your first program
verified output
Hello, World! Welcome to Java 21 at Ramayai AI Academy.

Now let Java tell you about itself. This program reads system properties — metadata the JVM exposes at runtime.

javac ShowVersion.java && java ShowVersion
ShowVersion.java Lesson 00 · system properties
verified output
Java version: 21.0.11 Vendor: Homebrew OS: Mac OS X

What just happened?

  1. javac HelloWorld.java compiled your source into HelloWorld.class — bytecode, not machine code.
  2. java HelloWorld launched the JVM, which loaded HelloWorld.class and executed main().
  3. The JVM's JIT compiler translated hot bytecode paths into native CPU instructions on the fly.

🏦 Real-world scenario

🏦
Real-world scenario · SouthBank India
Arjun's first day on the loan-processing team

Arjun is a junior backend engineer who just joined SouthBank India's Mumbai office. His tech lead asks him to write a simple program to print a loan application receipt before the real Spring Boot service is built. The team uses Java 21 and Maven, but for this prototype, plain javac is fine. Here is what Arjun writes:

javac LoanGreeting.java && java LoanGreeting
LoanGreeting.java SouthBank India · loan receipt prototype
verified output
SouthBank India — Loan Application System ========================================== Applicant : Arjun Sharma Branch : Mumbai Central Amount : ₹500,000 Status : Application received. Review in 2 business days.

✨ Modern Java 21 features you get for free

Java 21 ships with text blocks (multiline strings), records, pattern matching, and sealed classes. You will use all of these in later lessons. Here is a taste — text blocks that make JSON in Java readable:

javac TextBlocks.java && java TextBlocks
TextBlocks.java Java 15+ · text blocks
verified output
JSON payload: { "bank": "SouthBank India", "city": "Mumbai", "status": "active" } Character count: 73

🧩 Mini challenge

Three programs to write yourself
Task 1 — Personal greeting

Create Greeting.java. Print your name, your city, and the current Java version (use System.getProperty("java.version")). Compile and run it.

Task 2 — printf formatting

Use System.out.printf to print a salary figure with a ₹ symbol and comma formatting, e.g. ₹1,200,000. Hint: format string is "₹%,d%n".

Task 3 — Text block

Write a text block that contains a two-field JSON object representing a mobile wallet top-up. Print it. Verify the line count with .lines().count().

🎤 Interview Q&A

Easy What is the difference between JDK, JRE, and JVM?
+

JVM (Java Virtual Machine) is the runtime engine that executes Java bytecode. It provides memory management, garbage collection, and platform abstraction. JRE (Java Runtime Environment) bundles the JVM with the standard class libraries needed to run compiled Java applications. JDK (Java Development Kit) bundles the JRE with the javac compiler, jar packager, jshell REPL, and other developer tools. Developers need the JDK; end users running pre-compiled apps only need the JRE.

Easy What does javac produce and what does java execute?
+

javac compiles .java source files into .class files containing Java bytecode — an intermediate instruction set that is platform-neutral. java launches the JVM, which loads those .class files and either interprets bytecode directly or JIT-compiles hot paths into native machine code for the current CPU architecture. This "write once, run anywhere" model is why the same .class file runs on Windows, Linux, and macOS without recompilation.

Medium Why does the filename have to match the public class name in Java?
+

The Java Language Specification requires that a file containing a public class be named exactly as that class (case-sensitive, .java extension). The compiler uses this rule to locate source files during compilation and to generate the corresponding .class file. The class loader later locates classes on the classpath using the same fully-qualified name convention. A mismatch causes a compile-time error: class X is public, should be declared in a file named X.java.

Medium What is the JIT compiler and why does Java need it?
+

The JIT (Just-In-Time) compiler is part of the JVM. Rather than interpreting every bytecode instruction one-by-one, the JIT profiles running code and compiles frequently-executed "hot" methods into native machine code at runtime. This means a Java program starts up quickly (interpreted) and then gets faster as it runs (native-compiled hot paths). Modern JVMs (like HotSpot in JDK 21) are competitive with C++ for throughput workloads because of this adaptive compilation strategy.

Hard Why is Java 21 preferred over Java 17 or Java 11 for new projects?
+

Java 21 is the latest LTS release (security patches until 2031+) and adds several production-ready features: Virtual Threads (Project Loom — millions of lightweight threads, critical for high-throughput REST APIs), Record Patterns and Pattern Matching for switch (cleaner data-handling code), Sequenced Collections (consistent first/last access on List/Set/Map), and String Templates (preview). For AI gateway microservices, virtual threads alone justify the upgrade: a Spring Boot service on Java 21 can handle significantly more concurrent LLM calls with the same heap size as Java 17 using platform threads.

📝 Quiz — 5 questions

Question 1 of 5
What file extension does javac produce?
Question 2 of 5
Which tool do you need to write and compile Java code (not just run it)?
Question 3 of 5
If your public class is named BankApp, what must the source file be named?
Question 4 of 5
Which Java 21 feature allows millions of lightweight concurrent threads?
Question 5 of 5
What does the JIT compiler do?
0
/ 5
Quiz complete!

Strong foundation → move to Lesson 01 and start writing real Java code.

⚠️ Common mistakes

Wrong filename case
If your class is HelloWorld but your file is helloworld.java, javac will refuse. Java filenames are case-sensitive on Linux/Mac — always match the public class name exactly.
Running javac on the .class file
javac HelloWorld.class fails — javac takes source (.java), not bytecode. java takes the class name without extension: java HelloWorld, not java HelloWorld.class.
Installing JRE instead of JDK
If you install only the JRE, you get java but not javac. The compiler lives in the JDK. Always install the JDK (Development Kit), not just the runtime.
Multiple JDK versions on PATH
Having both JDK 11 and JDK 21 installed causes confusion when javac -version shows the wrong one. Run which javac to see which binary is active, and update PATH to prefer JDK 21.

✅ Key takeaways

  • The JDK contains the compiler (javac) + runtime (JVM) + libraries — always install the JDK for development.
  • javac File.java produces File.class bytecode; java File runs it on the JVM — two separate steps.
  • The public class name must match the filename exactly (case-sensitive) — Java enforces this at compile time.
  • Java 21 LTS is the correct version for new projects — virtual threads, records, text blocks, and pattern matching are all production-ready.
  • Java is "write once, run anywhere" because bytecode runs on any JVM, not on a specific CPU or OS.
  • The JIT compiler profiles hot paths at runtime and compiles them to native code — Java gets faster as it runs, not slower.
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

From javac to production Spring Boot

Join the Best AI Programs — three 5-month courses, fully online, with placement assistance. Week 1 is free.

Explore our AI-era courses →