Introduction to Java – What Is Java and How Does It Work?
Java is a general-purpose, object-oriented programming language that runs on billions of devices, from bank servers and Android phones to cloud services and smart cards. Its famous promise is "Write Once, Run Anywhere": you compile your code once, and the same compiled program runs on Windows, macOS, Linux or any other system that has a Java Virtual Machine.
This tutorial introduces Java for complete beginners: what it is, where it came from, how a Java program is compiled and run, its key features, its editions and versions, and what people build with it.
1. What Is Java?
Java is a high-level language, which means you write code in readable English-like statements instead of machine instructions. It is:
- Object-oriented: programs are built from classes and objects that combine data and behaviour.
- Platform-independent: code compiles to bytecode that runs on any Java Virtual Machine (JVM).
- Statically typed: every variable has a type checked by the compiler, which catches many mistakes before the program runs.
- Memory-managed: a garbage collector frees unused memory automatically.
- Backed by a huge ecosystem: a rich standard library plus frameworks such as Spring Boot, Hibernate and Jakarta EE.
Java is sometimes described as "not 100% object-oriented" because it also has primitive types such as int and double, which are not objects. Those are kept for speed.
2. Your First Java Program
Every Java application starts from a main method inside a class:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Welcome to Java.");
}
}
Hello, World! Welcome to Java.
public class HelloWorlddeclares a class; the file must be namedHelloWorld.java.public static void main(String[] args)is the classic entry point that thejavalauncher calls. Java 25 also allows a shorter form (see below).System.out.println()prints a line of text.
The tutorial on how to write a Java program explains each word in detail.
3. A Short History of Java

| Year | Milestone |
|---|---|
| 1991 | James Gosling, Mike Sheridan and Patrick Naughton start the "Green Project" at Sun Microsystems. The language is first called Oak, after a tree outside Gosling's office. |
| 1995 | Renamed Java (after Java coffee) and announced publicly. Web browsers start running Java applets. |
| 1996 | JDK 1.0 is released. |
| 1998 | Java 2 (J2SE 1.2) adds the Collections Framework and Swing. |
| 2004 | Java 5 adds generics, enums, annotations and the enhanced for loop. |
| 2006–2007 | Sun releases Java as open source (OpenJDK). |
| 2010 | Oracle acquires Sun Microsystems and becomes Java's steward. |
| 2014 | Java 8 adds lambdas and the Stream API, a major modernisation. |
| 2017–2018 | Java adopts a six-month feature-release cycle, starting with Java 10 in March 2018. |
| 2021–2025 | Long-term-support releases Java 17, 21 and 25 bring records (Java 16), sealed classes (Java 17), pattern matching and virtual threads (Java 21), and compact source files (Java 25). |
James Gosling is known as the father of Java. The language was originally designed for interactive television, which turned out to be ahead of its time, before finding its place on the web and then on servers.
4. How a Java Program Runs
Java uses both a compiler and a virtual machine:
- Write source code in a
.javafile. - Compile it with
javac. The compiler checks the code and produces bytecode in a.classfile. Bytecode is not tied to any processor. - Run it with
java. The JVM loads the bytecode, verifies it for safety, and executes it, first by interpreting it and then by compiling frequently used parts into fast native machine code with the JIT (Just-In-Time) compiler.
javac HelloWorld.java # creates HelloWorld.class (bytecode)
java HelloWorld # the JVM runs the bytecode
# Since Java 11, a single-file program can also be run directly:
java HelloWorld.java
Because every operating system has its own JVM, the same .class file runs everywhere. That is the secret behind "Write Once, Run Anywhere". The roles of the JDK, JRE and JVM are explained in JDK vs JRE vs JVM.
5. Java Is Object-Oriented
In Java, you model real things as classes and create objects from them. This bank account keeps its balance private and changes it only through its methods:
// A class is a blueprint; objects are built from it
public class BankAccount {
private final String owner;
private double balance;
public BankAccount(String owner, double openingBalance) {
this.owner = owner;
this.balance = openingBalance;
}
public void deposit(double amount) {
if (amount <= 0) throw new IllegalArgumentException("Amount must be positive");
balance += amount;
}
public void withdraw(double amount) {
if (amount > balance) {
System.out.println("Insufficient funds for " + owner);
return;
}
balance -= amount;
}
public double getBalance() { return balance; }
public static void main(String[] args) {
BankAccount asha = new BankAccount("Asha", 1000);
asha.deposit(500);
asha.withdraw(2000);
asha.withdraw(300);
System.out.println("Asha's balance: " + asha.getBalance());
}
}
Insufficient funds for Asha Asha's balance: 1200.0
The four OOP principles, encapsulation, inheritance, polymorphism and abstraction, are covered in the OOPs concept tutorials.
6. Key Features of Java
| Feature | What it means |
|---|---|
| Simple | Familiar C-style syntax without pointers or manual memory management. |
| Object-oriented | Code is organised into classes and objects. |
| Platform-independent | Bytecode runs on any JVM. |
| Secure | Bytecode verification, no pointer arithmetic, and a managed runtime. |
| Robust | Strong typing, exception handling and garbage collection. |
| Multithreaded | Built-in support for running tasks concurrently, including lightweight virtual threads (Java 21). |
| High performance | The JIT compiler turns hot code into optimised machine code. |
| Distributed | Rich networking APIs for building connected applications. |
Each feature is explained with examples in Features of Java.
7. Java Editions
| Edition | Used for |
|---|---|
| Java SE (Standard Edition) | The core language and libraries; desktop apps, tools and the base for everything else. |
| Jakarta EE (formerly Java EE) | Enterprise web and server applications: servlets, persistence, messaging. |
| Java ME (Micro Edition) | Small and embedded devices. |
| Java Card | Smart cards and SIM cards. |
8. Java Versions and LTS Releases
Since Java 10 (March 2018), a new feature release arrives every six months, in March and September. Some releases are Long-Term Support (LTS) versions that companies use for years; since Java 17, an LTS release has come every two years (17, 21, 25):
| LTS version | Released | Highlights |
|---|---|---|
| Java 8 | 2014 | Lambdas, Stream API, new Date-Time API |
| Java 11 | 2018 | var in lambdas, HTTP Client, running single-file programs |
| Java 17 | 2021 | Records, sealed classes, text blocks, pattern matching for instanceof |
| Java 21 | 2023 | Virtual threads, pattern matching for switch, record patterns, sequenced collections |
| Java 25 | 2025 | Compact source files, module imports, flexible constructor bodies, scoped values |
For learning and new projects, use the latest LTS release, Java 25. The examples in this tutorial were compiled and run with JDK 25.
Java Version Improvements and Java 25 Updates
Java 25 makes the first steps easier. With compact source files and instance main methods (JEP 512, standard in Java 25), the Hello World program from section 2 no longer needs a class declaration, public static or String[] args:
void main() {
IO.println("Hello, World!");
IO.println("Welcome to Java.");
}
Hello, World! Welcome to Java.
Run it with java HelloWorld.java. The classic version still works and is required on Java 21 and earlier. Other standard Java 25 features include module import declarations (import module java.base;), flexible constructor bodies and scoped values. Features marked preview in a release, such as primitive types in patterns in Java 25, must be enabled with --enable-preview and may still change.
9. Where Is Java Used?
- Back-end and web services: Spring Boot, Jakarta EE, Quarkus and Micronaut power APIs for banks, retailers and streaming services.
- Android apps: Android's APIs are Java-based, and Java runs alongside Kotlin.
- Big data: Hadoop, Kafka, Spark (on the JVM), Elasticsearch and Cassandra are written in Java or JVM languages.
- Enterprise systems: banking, insurance, trading and e-commerce platforms.
- Desktop and tools: IntelliJ IDEA, Eclipse and many developer tools.
- Cloud and microservices: containers, serverless functions and native images with GraalVM.
- Embedded and IoT devices, and even Minecraft (Java Edition).
10. Advantages and Limitations
| Advantages | Limitations |
|---|---|
| Runs on any platform with a JVM | Uses more memory than C or C++ programs |
| Huge ecosystem and community | Start-up time is longer than native programs (improved by newer JVMs and GraalVM) |
| Strong typing catches errors early | More verbose than languages such as Python, though modern features help |
| Automatic memory management | Less direct control over hardware than C |
| Excellent performance for long-running servers | Garbage collection pauses must be tuned for very low-latency systems |
11. What to Learn Next
- Install Java and set up your environment.
- Understand JDK, JRE and JVM.
- Learn data types, variables and operators.
- Practise conditions and loops.
- Move on to classes and objects and the OOP concepts.
12. Summary
- Java is a high-level, object-oriented, statically typed language created at Sun Microsystems and released in 1995–96.
- Source code compiles to bytecode, which the JVM runs on any platform.
- Key strengths are portability, safety, performance and a huge ecosystem.
- New versions arrive every six months; LTS versions (8, 11, 17, 21, 25) are used in production.
- Java powers back-end services, Android, big-data systems and enterprise software.