Introduction to Java
What is Java?
Java is a high-level, class-based, object-oriented programming language originally released by Sun Microsystems in 1995 and now maintained by Oracle. It was designed around one core promise: "Write Once, Run Anywhere" (WORA). Code written in Java is compiled into an intermediate format called bytecode, which can run on any device that has a Java Virtual Machine (JVM) installed — regardless of the underlying operating system or hardware.
Java is used everywhere: Android apps, enterprise backend systems, banking software, e-commerce platforms, big data tools like Hadoop, and even embedded systems. It remains one of the most in-demand languages in the software industry.
Why Learn Java?
- Platform Independent — thanks to the JVM, the same compiled code runs on Windows, macOS, and Linux.
- Object-Oriented — everything is modeled around objects and classes, making large codebases easier to organize and maintain.
- Strongly Typed — variable types are checked at compile time, catching many bugs before the program even runs.
- Huge Ecosystem — a massive standard library plus frameworks like Spring, Hibernate, and Android SDK.
- Automatic Memory Management — Java's garbage collector frees you from manually allocating and releasing memory.
How Java Code Runs
Understanding the Java execution pipeline is key to understanding the language itself:
| Step | What Happens |
|---|---|
| 1. Write | You write source code in a file ending with .java |
| 2. Compile | The javac compiler converts it into bytecode (.class file) |
| 3. Run | The JVM reads the bytecode and executes it on your machine |
Your First Java Program
Every Java application must have at least one class, and execution begins at a special method called main. Here is the classic first program:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}Let's break this down:
public class HelloWorld— declares a class namedHelloWorld. The file must be saved asHelloWorld.java(the class name and file name must match).public static void main(String[] args)— the entry point of every Java program. The JVM looks for this exact method signature to start running your code.System.out.println(...)— prints text to the console, followed by a new line.
Compiling and Running from the Terminal
javac HelloWorld.java // creates HelloWorld.class
java HelloWorld // runs the compiled program
Note: When running with thejavacommand, you do not include the.classextension — just the class name.
Setting Up Your Environment
To start writing Java, you need:
- A JDK (Java Development Kit) — includes the compiler, JVM, and standard libraries. Download the latest LTS version from Oracle or use OpenJDK.
- A code editor or IDE — popular choices are IntelliJ IDEA, Eclipse, or VS Code with the Java extension pack.
Key Terms to Remember
| Term | Meaning |
|---|---|
| JDK | Java Development Kit — tools needed to write and compile Java code |
| JRE | Java Runtime Environment — needed to run (but not develop) Java programs |
| JVM | Java Virtual Machine — executes bytecode on a specific platform |
| Bytecode | Platform-independent compiled code produced by javac |
Coming up next: In the next topic, we'll dive into variables, data types, and how Java stores information in memory.