DEV Community

Cover image for Java Explained — What It Is, Why It Exists, and How It Actually Runs
DHANRAJ S
DHANRAJ S

Posted on

Java Explained — What It Is, Why It Exists, and How It Actually Runs

Hey!

Let me ask you something.

You write a program on your Windows laptop. Your friend opens it on a Mac. Your college server runs Linux.

Does the program work on all three?

In most languages — no. You would need to rewrite or recompile it for each system.

Java said — why should that be a problem?

And that one idea changed everything.


1. What Is Java?

Java is a programming language created by James Gosling at Sun Microsystems in 1995.

It is one of the most widely used languages in the world. Android apps, banking systems, enterprise software, web backends — Java is behind a huge part of the technology we use every day.

But what makes Java different from other languages?

One line answers it.

Write once. Run anywhere.

You write Java code once. It runs on Windows, Mac, Linux, Android — without changing a single line.

That is not just a tagline. It is how Java actually works. We will see exactly how in a moment.


2. Why Java? — Before Java, What Was the Problem?

Quick question for you.

Imagine you are a developer in 1990. You write a program in C or C++.

Your program works perfectly on Windows. But your client uses a different operating system. What do you do?

You rewrite the code. Or recompile it specifically for that system. Sometimes both.

Every operating system speaks a different language at the hardware level. A program built for Windows cannot just run on Linux.

This was a real headache for developers and companies. Especially as the internet grew and software needed to run everywhere.

Java solved this with a clever idea — the Java Virtual Machine.


3. How Does Java Actually Run?

This is the part most beginners skip. But it is the most important part to understand.

Let us go step by step.

Step 1 — You write Java code

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Enter fullscreen mode Exit fullscreen mode

This is your source code. Saved as a .java file.

Step 2 — The compiler converts it to bytecode

When you compile your Java file — the Java compiler does not convert it to machine code for Windows or Mac or Linux.

It converts it to something called bytecode. Saved as a .class file.

Bytecode is not tied to any operating system. It is a middle language. Universal.

Step 3 — The JVM runs the bytecode

Every operating system has its own JVM — Java Virtual Machine — installed.

The JVM on Windows reads the bytecode and translates it for Windows.
The JVM on Mac reads the same bytecode and translates it for Mac.
The JVM on Linux does the same for Linux.

Your Java Code (.java)
        ↓
   Java Compiler
        ↓
   Bytecode (.class)
        ↓
  ┌─────┼─────┐
  ↓     ↓     ↓
 JVM   JVM   JVM
 Win   Mac  Linux
Enter fullscreen mode Exit fullscreen mode

Same bytecode. Different JVMs. Works everywhere.

That is how "write once, run anywhere" actually works. The JVM does the translation work so you do not have to.


4. JDK, JRE, and JVM — What Is the Difference?

These three terms confuse every beginner. Let us clear them up simply.

JVM — Java Virtual Machine

Runs the bytecode. Every OS has its own JVM. This is what makes Java platform-independent.

JRE — Java Runtime Environment

JRE = JVM + libraries needed to run Java programs.

If you just want to run a Java program — install the JRE.

JDK — Java Development Kit

JDK = JRE + compiler + development tools.

If you want to write and compile Java programs — install the JDK.

Simple rule.

User who just runs Java apps → JRE.
Developer who writes Java code → JDK.


5. Your First Java Program — Let Us Read It

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Enter fullscreen mode Exit fullscreen mode

Quick question for you.

Before reading the explanation — can you guess what System.out.println does?

System.out.println("Hello, World!") — prints the text to the screen. Like print() in Python or console.log() in JavaScript.

public static void main(String[] args) — this is the entry point. Every Java program starts running from here. It is the first thing Java looks for when it runs your program.

public class Hello — in Java, everything lives inside a class. The class name must match the file name. This file must be saved as Hello.java.


6. Features of Java

These are the reasons Java has lasted 30 years and is still going strong.

Platform Independent

Already explained. Write once. Run anywhere. The JVM handles the rest.

Object Oriented

Everything in Java is built around objects and classes. This makes large programs easier to organize, reuse, and maintain.

Real world example — a Car class has properties like color and speed, and actions like start() and stop(). You create as many car objects as you need from that one class.

Strongly Typed

In Java — you must declare the type of every variable.

int age = 25;
String name = "Ravi";
double price = 99.99;
Enter fullscreen mode Exit fullscreen mode

You cannot put a string where a number is expected. Java catches this mistake before your program even runs. That means fewer bugs in production.

Automatic Memory Management

In C or C++ — you manage memory yourself. You allocate it. You free it. Forget to free it — your program leaks memory and slows down.

Java has a garbage collector. It automatically cleans up memory that is no longer needed. You focus on the logic. Java handles the memory.

Multithreading

Java can run multiple tasks at the same time.

Think of a banking app. One thread handles your login. Another thread processes a transaction. Another thread refreshes your balance. All happening together — without one waiting for the other.

Java has built-in support for this.

Secure

Java runs inside the JVM — which acts as a sandbox. Your Java program cannot directly access your operating system or hardware without permission. This makes Java a safer choice for web and enterprise applications.

Robust

Java checks for errors at two stages — when you compile and when you run. It has strong exception handling. Programs do not just crash silently. Errors are caught and handled properly.


7. Where Is Java Used Today?

Quick question for you.

Can you guess which mobile operating system runs on Java?

Android. Every Android app was traditionally written in Java. Even today — Kotlin, the newer Android language, runs on the same JVM.

Beyond mobile — Java is used in:

  • Banking and finance systems — most major banks run Java backends
  • Web applications — Spring is one of the most popular backend frameworks, built on Java
  • Enterprise software — large companies like Amazon, LinkedIn, and Uber use Java in their backend
  • Big Data — Hadoop and Kafka, which process massive amounts of data, are written in Java
  • Embedded systems — Java runs on smart cards, set-top boxes, and other devices

8. Java vs Other Languages — A Simple Comparison

Java Python JavaScript
Speed Fast Slower Medium
Syntax Verbose but clear Very clean Flexible
Typing Strongly typed Dynamically typed Dynamically typed
Best for Enterprise, Android, Big Data Data science, scripting, AI Web frontend and backend
Platform JVM — runs anywhere Interpreter per OS Browser or Node.js
Learning curve Moderate Easy Easy to start

Java is more verbose than Python. But that verbosity makes large codebases easier to read and maintain. When you are working in a team on a million-line codebase — clarity matters more than brevity.


Quick Summary — 5 Things to Remember

  1. Java was created in 1995 — and is still one of the most used languages in the world. Banking, Android, enterprise software — Java is everywhere.

  2. Write once, run anywhere — Java compiles to bytecode, not machine code. The JVM on each OS runs that bytecode. Same code. Every platform.

  3. JDK to write code. JRE to run code. JVM to execute bytecode — install JDK if you are learning Java.

  4. Strongly typed and object oriented — every variable has a type. Everything is built around classes and objects. This makes Java safe and organized.

  5. Automatic garbage collection — Java manages memory for you. No manual allocation or freeing.


Java might look more complex than Python or JavaScript at first. More lines. More structure. More rules.

But that structure is exactly what makes Java reliable for large, serious applications.

Once you get comfortable with the syntax — you will appreciate how organized Java forces you to be.

Start with the Hello World program above. Then try creating a simple class with a few variables and methods. That is where Java starts to make sense.

If you have a question — drop it in the comments below.


Thanks for reading. Keep building.

Top comments (0)