Introduction to Java Programming
Learn what Java is, how the JVM and JDK fit together, and the role Java plays in modern software development.
Java is a general-purpose, statically typed, object-oriented programming language designed for portability. Programs compile to bytecode that runs on the Java Virtual Machine (JVM), so the same .class file can execute on Windows, macOS, Linux, or any other system that has a compatible JVM installed. That portability — captured in the original "write once, run anywhere" tagline — is still the language's defining feature.
This chapter introduces the language, the platform, and the parts of the Java ecosystem you'll meet in the rest of the book.
What Java is
Java was released by Sun Microsystems in 1995 and is now stewarded by Oracle. It draws its syntax from C and C++ but trades manual memory management for an automatic garbage collector, and it leaves out features (like pointer arithmetic and multiple inheritance of classes) that frequently cause bugs in lower-level languages. The result is a language that's fast to learn, hard to crash, and well suited to long-lived applications maintained by large teams.
Key traits you'll notice as you work through this book:
- Statically typed. Every variable has a type known at compile time, so the compiler catches many mistakes before the program ever runs.
- Object-oriented. Code is organized around classes that bundle data with the methods that operate on it.
- Portable. Source compiles to platform-neutral bytecode, executed by any JVM.
- Memory-managed. The garbage collector reclaims objects you no longer reference.
- Multi-threaded. Threads, locks, and modern concurrency utilities are part of the standard library.
- Backward compatible. Programs written for older Java versions almost always run unchanged on newer ones.
Where Java is used
Because the JVM runs on almost every server and desktop platform, Java has spread to nearly every corner of software development:
- Server-side applications — most large e-commerce, banking, and enterprise backends use Java (often with Spring, Jakarta EE, or Quarkus).
- Android apps — Android's standard library is largely a Java API, even when apps are written in Kotlin.
- Big-data and streaming — Hadoop, Spark, Kafka, Flink, Elasticsearch are written on the JVM.
- Tooling and build systems — Maven, Gradle, Jenkins, and many CI tools run on Java.
- Embedded and IoT — smart cards, point-of-sale terminals, and industrial controllers.
JDK, JRE, and JVM
The three acronyms confuse beginners more than anything else in Java. Here is the breakdown:
- JVM (Java Virtual Machine) — the runtime that loads bytecode and executes it. Each operating system ships its own native JVM.
- JRE (Java Runtime Environment) — the JVM bundled with the core class libraries you need to run a Java program. It's the minimum you need to run Java code.
- JDK (Java Development Kit) — the JRE plus the tools you need to compile and debug Java code:
javac(compiler),jshell(REPL),javadoc(documentation), and others.
To write Java you install the JDK; the JRE comes bundled inside it, so you do not install the two separately. Oracle's JDK is only one option — OpenJDK is the free, open-source reference implementation, and distributions such as Eclipse Temurin, Amazon Corretto, and Azul Zulu all package the same OpenJDK with their own long-term support. Any of them will run the code in this book; pick one and move on.
You'll set this up step by step in Java Install and Java Environment Setup.
A first look at a Java program
You'll write a complete Hello World in Java Hello World Program. For now, here's what a minimal Java program looks like — the same code, compiled and executed on the server:
A few things to notice without worrying about every detail yet:
- Every program lives inside a class (here,
Hello). - Execution starts in a method called
mainwith the signaturepublic static void main(String[] args). - Statements end with semicolons, and blocks are wrapped in braces
{ ... }. System.out.printlnwrites a line to standard output.
Java versions and the release cadence
Since Java 9 (2017), a new major version ships every six months, with a Long-Term Support (LTS) release every two years. The current LTS versions you're most likely to meet at work are Java 17 and Java 21. This book is written against Java 21 and notes earlier versions only when the difference matters.
What this book covers
The chapters that follow walk you from a fresh JDK install through the modern language: the syntax basics, control flow, object-oriented programming, the collections framework, exceptions, generics, lambdas and streams, I/O, concurrency, JDBC, modules, and newer features like records, sealed types, pattern matching, and virtual threads. The sidebar groups chapters into 28 parts — read them in order for a guided path, or jump to whatever you need.