Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. Launched by Sun Microsystems in 1995, Java operates on the core philosophy of "Write Once, Run Anywhere" (WORA). This means compiled Java code can run on any platform that supports Java without the need for recompilation.
1. The Core Architecture (JDK, JRE, and JVM)
The Java ecosystem relies on three core pillars that work together to compile and execute code:
JDK (Java Development Kit)
The full software development environment. It contains everything needed to write and compile Java programs, including the JRE, compiler (javac), and development tools.
JRE (Java Runtime Environment)
The implementation software that allows Java programs to run. It bundles the JVM, core libraries, and necessary components to execute files, but cannot compile new programs.
JVM (Java Virtual Machine)
The engine that executes Java Bytecode. The JVM is OS-specific and converts bytecode into native machine instructions, enabling cross-platform portability.
2. Key Features of Java
- Object-Oriented Programming (OOP): Everything in Java is treated as an object. It enforces software design through classes, inheritance, polymorphism, encapsulation, and abstraction.
- Platform Independence: Java programs compile into intermediate bytecode rather than direct machine code, allowing execution on any device running a compatible JVM.
- Automatic Memory Management: Developers do not manually allocate or free memory. Java uses an automated process called the Garbage Collector to find and delete unreferenced objects.
- Robust Security: Java avoids explicit memory pointers to prevent security flaws. Applications execute inside a secure virtual machine sandbox to block unauthorized malware behavior.
- Multithreading: Java natively supports concurrent execution, allowing a single program to perform multiple heavy operations simultaneously to maximize CPU performance.
3. The Java Execution Workflow
The timeline below details how Java source files transform into a running application:
- Writing: The developer writes code and saves the file with a .java extension (e.g., App.java).
- Compilation: The JDK compiler converts the source code into bytecode using the command: javac App.java. This generates a .class file.
- Loading: The JVM ClassLoader loads the bytecode into the computer memory.
- Verification: A Bytecode Verifier checks the code structure to ensure it complies with security rules and does not corrupt system memory.
- Execution: The Just-In-Time (JIT) compiler translates the bytecode into native machine code for real-time execution.
4. Syntax Example: Hello World
A standard configuration for a minimal, working Java application:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}