Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
FAQs Support
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

Getting Started with Java

JDK, JRE, and JVM

Before writing your first Java program, it's important to understand the three core components of the Java platform.

ComponentFull NameDescription
JVMJava Virtual MachineExecutes Java bytecode. Platform-specific — there is a different JVM for Windows, Linux, and macOS.
JREJava Runtime EnvironmentJVM + standard libraries. Required to run Java programs.
JDKJava Development KitJRE + compiler (javac) + tools. Required to develop Java programs.

Installing the JDK

Follow these steps to install the JDK on your machine:

  • Visit oracle.com/java/technologies/downloads and download the latest JDK (Java 21 LTS recommended).
  • Run the installer and follow the on-screen instructions.
  • Set the JAVA_HOME environment variable to the JDK installation directory (e.g., C:\Program Files\Java\jdk-21).
  • Add %JAVA_HOME%\bin to your system PATH.
  • Verify the installation by opening a terminal and running java -version.

Your First Java Program

Every Java program starts with a class. The entry point is the main method. Let's break down the classic Hello World program line by line.

Hello World
// HelloWorld.java
public class HelloWorld {                          // 1. Class declaration
    public static void main(String[] args) {       // 2. Entry point
        System.out.println("Hello, World!");       // 3. Print to console
    }
}
  • public class HelloWorld — declares a public class. The filename must match the class name exactly: HelloWorld.java.
  • public static void main(String[] args) — the JVM calls this method to start the program.
  • System.out.println() — prints a line to standard output.

Compile and Run

Java is a compiled language. You first compile the source file to bytecode, then run the bytecode on the JVM.

StepCommandResult
Compilejavac HelloWorld.javaCreates HelloWorld.class (bytecode)
Runjava HelloWorldExecutes the bytecode on the JVM

Reading User Input with Scanner

The java.util.Scanner class lets you read input from the keyboard (standard input).

Reading User Input
import java.util.Scanner;

public class UserInput {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter your name: ");
        String name = scanner.nextLine();

        System.out.print("Enter your age: ");
        int age = scanner.nextInt();

        System.out.println("Hello, " + name + "! You are " + age + " years old.");

        scanner.close(); // always close the scanner
    }
}

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.