Basics

What is Java?

Introduction
💡 Java is like writing a recipe that can be cooked in any kitchen (computer) in the world.

Java is a programming language we use to give instructions to a computer. It was created in 1995 and is still used everywhere today — apps, websites, games, all of it.

The best part: "Write Once, Run Anywhere". Meaning you write Java code once, and it can run on Windows, Mac, Linux — anywhere — without rewriting it!

How? Your .java file is first "compiled" into a .class file (bytecode). Then the JVM (Java Virtual Machine) understands that bytecode on any computer and runs it — like a universal translator!

public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello, Code10x!");
  }
}
Java is like writing a recipe that can be cooked in any kitchen (computer) in the world.
1 / 7
⚡ Quick Recap
  • Java = programming language (since 1995)
  • Write Once, Run Anywhere
  • Code -> Compiler -> Bytecode -> JVM -> Run
On this page (4 subtopics)

The JVM (Java Virtual Machine) is a "virtual computer" that reads bytecode and runs it on the actual hardware — this is exactly what makes Java platform-independent. The JVM itself is OS-specific (Windows has its own JVM, Linux its own, Mac its own), but they all understand the same bytecode — that's the whole secret behind "Write Once, Run Anywhere".

JRE (Java Runtime Environment) = JVM + standard libraries (java.lang, java.util, java.io, etc.) + supporting files. If you just want to run a Java program someone else built (like a .jar file), installing the JRE is enough — the JVM is already included in it. A regular user (who only runs apps, doesn't write code) only needs the JRE.

JDK (Java Development Kit) = JRE + development tools — the most important being javac (the compiler that turns .java into .class), but it also includes a debugger, javadoc (documentation generator), and the jar tool (for packaging). A developer (who writes and compiles code) always needs the JDK — that's why when you set up Java on your computer, you search for "install JDK", not just JRE.

An analogy: if Java is a recipe book, the JVM is the oven that actually cooks the recipe. JRE = oven + the whole kitchen setup (without which you can't cook at all). JDK = the whole kitchen + a chef's tools (knife, a notebook for writing new recipes) — so you can create a brand new recipe (a new program) yourself too.

JVMJREJDK
What it isBytecode execution engineJVM + librariesJRE + dev tools (compiler)
Can you run code?Yes (this is what does it)YesYes
Can you write/compile code?NoNoYes
Who needs itEveryone (internally)End-usersDevelopers
// javac Hello.java   -> compiler (JDK ka part), banata hai Hello.class
// java Hello          -> JVM (JRE ka part) chalata hai bytecode ko
💡Tip: Run both "java -version" and "javac -version" in a terminal — if both work, you have the JDK properly installed. If only "java" works, you just have the JRE.

Step 1 — Writing: you write a .java file in a text editor/IDE (like Hello.java), containing human-readable Java source code.

Step 2 — Compilation: the javac compiler reads it, checks for syntax errors, and if everything's fine, produces a .class file containing "bytecode" — it's neither human-readable nor machine code, but an in-between format that's universal for any JVM.

Step 3 — Class Loading: when you run "java Hello", the JVM's Class Loader loads that .class file into memory — if the program uses other classes too (like ArrayList), they get loaded as needed.

Step 4 — Bytecode Verification: the JVM's Bytecode Verifier checks that the bytecode is safe — no memory corruption, illegal type casts, or security violations. This is at the core of Java's "Secure" feature.

Step 5 — Execution: bytecode can now run in two ways — the Interpreter translates and runs it line by line (simple, a bit slow), or the JIT (Just-In-Time) Compiler converts frequently-run parts ("hot code") directly into native machine code, so it runs much faster next time. Modern JVMs combine both — interpreting at first, then JIT-compiling the hot paths.

💡Tip: Run javap -c Hello.class and see for yourself what bytecode looks like — instructions like "aload_0", "invokespecial" and so on. Worth trying once out of curiosity!

Java's design goals are the biggest reason for its success. Every feature solves a real-world problem that existed in older languages (like C++).

FeatureWhat It Means
Object-OrientedEverything is organized around classes/objects — code becomes reusable and maintainable
Platform IndependentBytecode runs on any OS via its JVM (Write Once, Run Anywhere)
RobustStrong compile-time type-checking + automatic memory management — very few crashes
SecureNo direct pointers (unlike C/C++), bytecode verifier, sandboxed execution
MultithreadedBuilt-in support for doing multiple things at once (Thread class, synchronized, etc.)
High PerformanceJIT compiler gives near-native speed, faster than pure-interpreted languages
DistributedBuilt-in tools for networking (java.net) and remote method invocation
DynamicNew classes can be loaded at runtime (like plugins)

Android apps: a huge share of the world's Android apps are built in Java (or Kotlin, which also runs on the JVM) — the entire Android Studio ecosystem is based on Java.

Enterprise Backend: big companies (banks, e-commerce, telecom) build their server-side backend in Java, often with the Spring/Spring Boot framework — for robustness and scalability.

Big Data: tools like Hadoop and Spark are themselves written in Java (or JVM-based languages), and Java is common for working with them.

Java is also used in Desktop Applications, embedded systems, and scientific computing. Learning Java isn't just learning a language — it opens up an entire career path — even today, Java remains one of the most in-demand languages in the job market.