1. Introduction
Java is a general-purpose, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. It is one of the most widely used programming languages in the world, powering everything from Android apps and enterprise backend systems to embedded devices and large-scale distributed systems.
Cricket analogy: Just as cricket is played the same way from IPL stadiums to backyard tape-ball games, Java's design keeps it usable everywhere from Android apps to embedded devices without changing the core rules.
Unlike languages such as C or C++ that compile directly to machine code for a specific processor, Java takes a two-step approach: source code is first compiled into an intermediate form called bytecode, and that bytecode is then executed by the Java Virtual Machine (JVM). This design is the core reason Java earned the slogan 'Write Once, Run Anywhere' (WORA).
Cricket analogy: Unlike a pitch groundskeeper who prepares a wicket for one specific stadium, Java first prepares a neutral bytecode pitch that any JVM ground crew, whether in Mumbai or Melbourne, can host a match on.
2. Syntax
Every standalone Java program needs at least one class, and execution begins from a special method called main. The basic skeleton of a Java program looks like this:
Cricket analogy: Just as every cricket match must start with the toss before any ball is bowled, every standalone Java program must start execution at the main method inside some class.
public class HelloWorld {
public static void main(String[] args) {
// program execution starts here
}
}3. Explanation
Java is often loosely described as an 'interpreted' or a 'compiled' language, but the precise description is: Java is a compiled-then-interpreted language. The javac compiler translates .java source files into .class files containing platform-independent bytecode. This bytecode is not native machine code — it is a set of instructions understood only by the JVM.
Cricket analogy: Java is like a match played in two stages: javac is the selection committee turning raw talent into a squad list of bytecode, which only the match umpire, the JVM, knows how to interpret on field.
When you run a program, the JVM loads the .class file and executes the bytecode. Modern JVMs use a Just-In-Time (JIT) compiler that translates frequently executed bytecode into native machine code at runtime, giving Java near-native performance while retaining portability. It is the JVM implementation that is platform-specific (there is a different JVM binary for Windows, Linux, macOS, etc.), not the Java source code or the compiled bytecode — this is exactly what makes 'Write Once, Run Anywhere' possible.
Cricket analogy: The JVM is like the host broadcaster's production truck: different equipment in every country, Windows versus Linux versus macOS, but it reads the same match footage format and, with a JIT-like instant replay system, renders it at near-live speed.
Write Once, Run Anywhere (WORA) means the SAME .class bytecode file can run unmodified on any operating system that has a compatible JVM installed. You do not need to recompile your Java source code for each platform.
Common exam trap: Do NOT say 'Java is a purely interpreted language' or 'Java is a purely compiled language like C++'. The correct, precise answer is that Java is compiled to bytecode by javac, and that bytecode is then interpreted and/or JIT-compiled by the JVM. Getting this half right is a frequent source of lost marks.
4. Example
public class Greeting {
public static void main(String[] args) {
String message = "Hello, Java World!";
System.out.println(message);
System.out.println("This bytecode can run on any OS with a JVM.");
}
}5. Output
Hello, Java World!
This bytecode can run on any OS with a JVM.6. Key Takeaways
- Java is a class-based, object-oriented, general-purpose programming language.
- Java source code (.java) is compiled by javac into platform-independent bytecode (.class), not directly into machine code.
- The JVM executes bytecode via interpretation and JIT compilation, which is why Java is best described as compiled-then-interpreted.
- The JVM itself is platform-specific, but the bytecode it runs is not — this enables 'Write Once, Run Anywhere'.
- Every standalone Java application requires a main method with the exact signature public static void main(String[] args).
Practice what you learned
1. How is Java best described in terms of execution model?
2. What makes Java's 'Write Once, Run Anywhere' principle possible?
3. Which file type does the Java compiler (javac) produce from a .java file?
4. What is the correct signature of the Java program entry point method?
5. Which statement about Java's platform independence is TRUE?
Was this page helpful?
You May Also Like
History and Evolution of Java
Trace Java's origins from Sun Microsystems' 'Oak' project through its 1995 public release to its current ownership by Oracle, and understand key milestones in its evolution.
Features of Java
Explore the core features that make Java popular — object-oriented design, platform independence, robustness, security, multithreading, and high performance via JIT compilation.
JVM, JRE and JDK Explained
Understand the precise differences and containment relationship between the JVM, JRE, and JDK — a foundational concept and one of the most frequently asked Java interview questions.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics