Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Core Java & Object-Oriented Architecture 15 mins read Free Lesson

Java Introduction, JDK, JVM & Hello World

Understand the Java runtime environment (JRE), JDK compiler, bytecode, and write your first Java program.

How Java Works (Write Once, Run Anywhere)

Java source code (.java) is compiled by the javac compiler into platform-independent Bytecode (.class). This bytecode is executed by the Java Virtual Machine (JVM).

Your First Java Program

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

Syntax Breakdown:

  1. public class Main: Every line of executable code in Java must reside inside a class.
  2. public static void main(String[] args): The entry point method called by the JVM runtime.
  3. System.out.println(): Standard output stream method that prints text to the console with a trailing newline.

Practice Exercises

Exercise 1: Write a Java Main Method

Easy

Write a Java class named Calculator with a main method that prints "Ready".

Starter Code:
public class Calculator {
    // write main method here
}
💡 Hint: Use public static void main(String[] args) and System.out.println("Ready");
Solution:
public class Calculator {
    public static void main(String[] args) {
        System.out.println("Ready");
    }
}