Java Introduction
In this page:
What is Java?
Java is a class-based, object-oriented language designed to have very few implementation dependencies, meaning code that runs correctly on one platform should run the same way on any other with minimal changes.
Example: What is Java?
public class Main {
public static void main(String[] args) {
System.out.println("Java is class-based and object-oriented.");
}
}
Login to try C/C++/Java/PHP code in the editor
Write Once, Run Anywhere
WORA means you compile a Java program once into bytecode, then run that same bytecode on Windows, Linux, or macOS without recompiling -- the JVM handles the platform-specific translation for you.
Example: Write Once, Run Anywhere
public class Main {
// javac Main.java -> Main.class (bytecode)
// java Main runs identically on Windows, Linux, or macOS
public static void main(String[] args) {
System.out.println("Same bytecode runs on any OS with a JVM.");
}
}
Login to try C/C++/Java/PHP code in the editor
How Java Works
Your .java source file is compiled by javac into .class bytecode files, and the Java Virtual Machine reads that bytecode and translates it into instructions your specific CPU can execute.
Example: How Java Works
public class Main {
// Step 1: Main.java (source)
// Step 2: javac Main.java -> Main.class (bytecode)
// Step 3: java Main -> JVM translates bytecode for your CPU
public static void main(String[] args) {
System.out.println("Compiled to bytecode, then run by the JVM.");
}
}
Login to try C/C++/Java/PHP code in the editor
Applications of Java
Java powers a huge range of real systems: Android app internals, large enterprise backends at banks and e-commerce companies, and cloud services, largely because its JVM and standard library are mature and battle-tested at scale.
Example: Applications of Java
public class Main {
public static void main(String[] args) {
String[] uses = {"Android app internals", "Enterprise backends", "Cloud services"};
for (String use : uses) {
System.out.println("Java powers: " + use);
}
}
}
Login to try C/C++/Java/PHP code in the editor
Benefits of Java
Beyond portability, Java is valued for automatic memory management via its garbage collector (so you rarely manage memory by hand) and strict compile-time type checking, which catches many bugs before the program ever runs.
Example: Benefits of Java
public class Main {
public static void main(String[] args) {
String text = "auto-managed"; // no manual free() - garbage collector handles it
// int number = text; // fails at COMPILE time - type checking catches this early
System.out.println("Memory is " + text + " by the garbage collector.");
}
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: