Java History & Features
In this page:
History of Java
James Gosling led the team that created Java at Sun Microsystems, first releasing it in 1995 under the name Oak before renaming it Java -- the goal from the start was a simpler, safer alternative to C++.
Example: History of Java
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) {
// Declare originalName and set it to "Oak"
String originalName = "Oak";
// Declare releaseYear and set it to "1995"
String releaseYear = "1995";
// Print a line to the console
System.out.println("Java was created by James Gosling at Sun Microsystems in " + releaseYear + ", originally named " + originalName + ".");
}
}
Login to try C/C++/Java/PHP code in the editor
Platform Independence
Because the compiler targets bytecode instead of a specific CPU's machine code, the exact same compiled program runs unmodified on any operating system that has a JVM installed.
Example: Platform Independence
public class Main {
public static void main(String[] args) {
// This same Main.class file runs unmodified on Windows, Linux, and macOS
System.out.println("Compiled once, runs on any OS with a JVM installed.");
}
}
Login to try C/C++/Java/PHP code in the editor
Object-Oriented Programming
Java forces you to model your program as classes and objects from the ground up, which encourages breaking large problems into smaller, testable, reusable pieces rather than one long procedural script.
Example: Object-Oriented Programming
// Define the class Task
class Task {
String name;
Task(String name) { this.name = name; }
void run() { System.out.println("Running: " + name); }
}
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) {
// Create a new Task object and store it in task
Task task = new Task("Send Email");
task.run();
}
}
Login to try C/C++/Java/PHP code in the editor
Robustness and Security
The JVM validates bytecode before running it, enforces array bounds checking, and gives you no raw pointers to corrupt memory with -- trade-offs that sacrifice some raw speed for far fewer crash-causing bugs.
Example: Robustness and Security
public class Main {
public static void main(String[] args) {
int[] numbers = {1, 2, 3};
try {
System.out.println(numbers[5]); // out-of-bounds access
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Caught by JVM bounds checking: " + e.getMessage());
}
}
}
Login to try C/C++/Java/PHP code in the editor
Multi-threading Support
Since threads are a first-class part of the language (via the Thread class and java.util.concurrent), you can genuinely run independent tasks in parallel to keep a CPU-bound or I/O-bound program responsive.
Example: Multi-threading Support
// Define the class Main
public class Main {
// Program entry point: the JVM starts running here
public static void main(String[] args) throws InterruptedException {
// Create a new Thread object and store it in worker
Thread worker = new Thread(() -> System.out.println("Running independently on its own thread"));
// Start the thread; it runs in parallel with this code
worker.start();
// Wait for the thread to finish
worker.join();
}
}
Login to try C/C++/Java/PHP code in the editor
- Saying Java has no pointers so it has no memory problems, when object references can still be
nulland causeNullPointerException. - Assuming "platform independent" means the same
.javacompiles anywhere without a JDK, when the bytecode needs a JVM on the target machine. - Thinking automatic garbage collection means you can never leak memory, when objects that stay referenced are never freed.
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: