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 entry point the JVM calls.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 | Java moves to a new feature release every six months. |
| 2021–2025 | Long-term-support releases Java 17, 21 and 25 add records, sealed classes, pattern matching and virtual threads. |
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 in parallel, 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. Modern Java at a Glance
Java has changed a lot since its early days. Here are a few modern features in one small program:
import java.util.List;
public class ModernJava {
// Records (Java 16+): a compact class for plain data
record Order(String item, int quantity, double price) {
double total() { return quantity * price; }
}
sealed interface Shape permits Circle, Square { }
record Circle(double radius) implements Shape { }
record Square(double side) implements Shape { }
// Pattern matching for switch (Java 21)
static double area(Shape s) {
return switch (s) {
case Circle c -> Math.PI * c.radius() * c.radius();
case Square q -> q.side() * q.side();
};
}
public static void main(String[] args) {
var orders = List.of(new Order("pen", 3, 10.0), new Order("book", 1, 250.0));
double sum = orders.stream().mapToDouble(Order::total).sum(); // Streams (Java 8+)
System.out.println("Order total: " + sum);
System.out.printf("Circle area: %.2f%n", area(new Circle(1)));
System.out.println("Square area: " + area(new Square(3)));
String json = """
{"language": "Java", "since": 1995}"""; // text block (Java 15+)
System.out.println(json);
}
}
Order total: 280.0
Circle area: 3.14
Square area: 9.0
{"language": "Java", "since": 1995}
Records, sealed interfaces, pattern matching for switch, var, streams and text blocks all make modern Java code shorter and clearer.
8. 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. |
9. Java Versions and LTS Releases
Since 2017, a new Java version is released every six months, in March and September. Every few releases is a Long-Term Support (LTS) version that companies use for years:
| 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. The examples on this site run on Java 21 or later.
10. 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).
11. 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 |
12. 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.
13. 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.
Reference: dev.java: Learn Java
Frequently Asked Questions (FAQ)
Q1. What is Java?
Java is a high-level, object-oriented, general-purpose programming language. Java source code is compiled into bytecode that runs on the Java Virtual Machine, so the same program works on any operating system with a JVM.
Q2. Who created Java and when?
James Gosling and his team at Sun Microsystems started the project in 1991. Java was announced in 1995, and JDK 1.0 was released in 1996. Oracle took over Java when it acquired Sun in 2010.
Q3. Why is it called Java?
The language was first named Oak, but that name was already trademarked. The team chose "Java", inspired by Java coffee from Indonesia, which is also why Java's logo is a coffee cup.
Q4. What does "Write Once, Run Anywhere" mean?
You compile Java code once into bytecode. That bytecode runs unchanged on any device that has a JVM, whether it runs Windows, macOS or Linux, without recompiling for each platform.
Q5. Is Java compiled or interpreted?
Both. javac compiles source code into bytecode. The JVM then interprets that bytecode and uses a JIT compiler to turn frequently used parts into native machine code at runtime.
Q6. Is Java 100% object-oriented?
No. Java has primitive types (int, char, boolean and so on) that are not objects, and it supports static methods that do not belong to any object. Everything else is organised into classes and objects.
Q7. Is Java the same as JavaScript?
No. They are different languages with different designs. Java is statically typed and compiled to bytecode; JavaScript is dynamically typed and mainly runs in browsers and Node.js. The similar name was a 1990s marketing decision.
Q8. Is Java free to use?
Yes. OpenJDK is open source and free, and many vendors (Eclipse Temurin, Amazon Corretto, Microsoft, Azul, Oracle) offer free OpenJDK builds. Some commercial support offerings are paid.
Q9. Which Java version should I learn?
Use the latest long-term-support (LTS) release, currently Java 25, or Java 21, which is still very widely used. The core language you learn applies to all modern versions.
Q10. Is Java good for beginners?
Yes. Its syntax is clear, the compiler catches many mistakes early, error messages are helpful, and there are plenty of learning resources. Learning Java also makes C#, Kotlin and C++ easier to pick up later.
Q11. What is bytecode?
Bytecode is the compact, platform-independent instruction format produced by javac and stored in .class files. The JVM understands bytecode and translates it into the instructions of the actual processor.
Q12. What is the JVM?
The Java Virtual Machine is the program that loads, verifies and runs Java bytecode. It manages memory with garbage collection and optimises code with its JIT compiler. Each operating system has its own JVM implementation.
Q13. What is the difference between JDK and JRE?
The JDK (Java Development Kit) contains everything to develop Java programs, including the compiler javac. The JRE (Java Runtime Environment) contains only what is needed to run them. Modern Java distributions ship the JDK, and you can create a custom runtime with jlink.
Q14. What can I build with Java?
Web back-ends and REST APIs, microservices, Android apps, desktop applications, big-data pipelines, trading systems, games, developer tools and embedded software.
Q15. What is an LTS release of Java?
A Long-Term Support release receives security and bug-fix updates for many years, so companies standardise on it. Java 8, 11, 17, 21 and 25 are LTS releases; the versions in between are supported for about six months.
Q16. Is Java still relevant today?
Yes. Java consistently ranks among the most used languages, runs critical systems at banks, retailers and tech companies, and keeps evolving with a new release every six months.
Q17. Why does Java not have pointers?
Pointer arithmetic is a common source of crashes and security holes. Java uses references to objects instead, which cannot be manipulated as raw memory addresses, making programs safer and simpler.
Q18. What is garbage collection in Java?
The JVM automatically finds objects that are no longer reachable and frees their memory, so you never call free() or delete. See Garbage Collection in Java.
Q19. What is the main method in Java?
public static void main(String[] args) is the starting point of a Java application. The JVM calls it when you run the class. Newer Java versions also allow simpler instance main methods in single-file programs.
Q20. Which companies use Java?
Java is used by a very large number of companies, including major banks, retailers, airlines and technology firms. Netflix, LinkedIn, Uber and Amazon, for example, have publicly described Java-based back-end systems.