Introduction to Java

A complete beginner-friendly guide to understanding what Java is, how it works, and why it matters.

What is Java?

Java is a high-level, object-oriented, class-based programming language designed to have as few implementation dependencies as possible. It was created by James Gosling at Sun Microsystems and released in 1995. Today it is owned and maintained by Oracle Corporation.

The most important principle behind Java is "Write Once, Run Anywhere" (WORA). This means Java code compiled on one platform can run on any other platform that has a Java Virtual Machine (JVM) installed — without recompiling.

💡 Quick fact: As of 2024, Java consistently ranks among the top 3 most used programming languages worldwide (TIOBE Index).

A Brief History of Java

Year Milestone
1991 Project "Oak" started by James Gosling at Sun Microsystems
1995 Renamed to Java; officially released to the public
1996 Java 1.0 released — first stable version
2004 Java 5 — Generics, Annotations, Autoboxing introduced
2014 Java 8 — Lambda Expressions and Stream API (biggest modern update)
2017 Java 9 — Module System (Project Jigsaw)
2021 Java 17 — LTS release with Records, Sealed Classes
2023 Java 21 — LTS release with Virtual Threads (Project Loom)

How Java Works: Compilation & Execution

Unlike C or C++ which compile directly to machine code, Java uses a two-step process:

  1. Compilation: The Java compiler (javac) converts your .java source file into bytecode — a platform-neutral .class file.
  2. Execution: The Java Virtual Machine (JVM) on the target machine reads the bytecode and translates it into native machine instructions at runtime.
  YourProgram.java  ?  [javac compiler]  ?  YourProgram.class (bytecode)
  YourProgram.class ?  [JVM on any OS]   ?  Runs on Windows / Mac / Linux
      

This two-step design is why Java is platform-independent. The bytecode is the same everywhere; only the JVM differs per operating system.

How a Java program reaches the screen
Source codeHelloWorld.java
Written by you
Compilerjavac checks code
and creates bytecode
JVMReads bytecode
on your operating system
OutputProgram result
on the console

Easy way to remember: You write source code, javac translates it, and the JVM runs the translated bytecode.

JDK vs JRE vs JVM

These three terms confuse most beginners. Here's a clear breakdown:

Term Full Form What it does Who needs it?
JVM Java Virtual Machine Executes bytecode. Abstract layer between Java program and OS. Everyone (included in JRE)
JRE Java Runtime Environment JVM + core libraries needed to run Java programs. End users who only run Java apps
JDK Java Development Kit JRE + compiler (javac) + debugger + dev tools. Developers who write Java code

📌 Simple rule: To write Java ? install JDK. To run a Java app ? JRE is enough.

Variables in Java

A variable is a named location used to store a value while a program runs. Every Java variable has a data type, a name, and a current value. Java is statically typed, so the type is checked when the code is compiled.

int age = 25;
String name = "Asha";
boolean isLearning = true;

The general declaration format is:

dataType variableName = value;

In the example above, int, String, and boolean are data types. age, name, and isLearning are variable names.

Declaration, initialization, and reassignment

int score;       // declaration
score = 95;      // initialization
score = 100;     // reassignment

System.out.println(score); // 100

A local variable must be assigned a value before it is read. Java does not automatically give local variables a default value.

Common types of variables

Kind Declared where? Lifetime