JAVA • Beginner

Introduction to Java

Java is a high-level, class-based, object-oriented programming language designed by James Gosling at Sun Microsystems in 1995. It follows the principle "Write Once, Run Anywhere" (WORA) — meaning compiled Java code runs on any device with a Java Virtual Machine (JVM).

What is Java?

Java is a powerful, general-purpose programming language used to build everything from Android apps to enterprise banking systems. It's known for its platform independence, strong typing, and huge ecosystem.

Today, Java powers more than 3 billion devices — Android apps, web servers, banking systems, and even NASA rovers.

History of Java

  • 1991 — Project "Oak" started by James Gosling at Sun Microsystems
  • 1995 — Renamed to Java, first public release
  • 2010 — Oracle acquired Sun Microsystems
  • Today — Java 21+ is the latest LTS version

Why Learn Java?

  • Platform Independent — Write once, run on Windows, Mac, Linux, Android.
  • Object-Oriented — Clean structure with classes and objects.
  • Huge Job Market — 9 million+ Java developers worldwide; top demand in Varanasi and India.
  • Robust & Secure — Strong memory management and exception handling.
  • Rich Ecosystem — Spring, Hibernate, Android SDK, and thousands of libraries.

JVM vs JRE vs JDK

This is one of the most-asked Java interview questions.

JVM (Java Virtual Machine)

The JVM is the engine that runs compiled Java bytecode. It's platform-specific — each OS has its own JVM. This is what makes Java "Write Once, Run Anywhere".

JRE (Java Runtime Environment)

JRE = JVM + Core Libraries. It's what you need to run Java programs (not develop them). If you only want to use Java apps, install JRE.

JDK (Java Development Kit)

JDK = JRE + Development Tools (compiler, debugger, etc.). It's what you need to write and compile Java code. For developers, always install JDK.

JDK ⊃ JRE ⊃ JVM

JDK = JRE + Development Tools (javac, jar, javadoc)
JRE = JVM + Core Libraries
JVM = Executes bytecode

Your First Java Program

Save this as Hello.java (file name MUST match the public class name):

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Varanasi!");
    }
}

Compile and run:

javac Hello.java    // Compiles → Hello.class
java Hello          // Runs → Hello, Varanasi!

Breaking Down the Program

  • public class Hello — Every Java program lives inside a class. File name must match public class name.
  • public static void main(String[] args) — The entry point. JVM calls this method first.
  • public — Access modifier (visible to all).
  • static — Can be called without creating an object.
  • void — Returns nothing.
  • String[] args — Command-line arguments as an array.
  • System.out.println() — Prints to console with a newline.

Java Installation

  1. Download JDK 21 (LTS) from Oracle or AdoptOpenJDK
  2. Install and set JAVA_HOME environment variable
  3. Add bin folder to PATH
  4. Verify: java -version and javac -version
  5. Install an IDE — IntelliJ IDEA, Eclipse, or VS Code with Java Extension Pack
💡 Academy Tip

Java file name must **exactly match** the public class name (case-sensitive). Hello.java contains public class Hello. Mismatch causes compile error — a classic beginner mistake.

📝 Try Yourself

Create a Java program Profile.java that prints your name, age, and city on separate lines. Compile with javac Profile.java and run with java Profile. Try changing the file name to something else and see the error.

Quick Revision

  • Java is high-level, OOP, platform-independent.
  • Created by James Gosling in 1995 at Sun.
  • Follows WORA — Write Once, Run Anywhere.
  • JDK ⊃ JRE ⊃ JVM.
  • Every program lives inside a class.
  • Entry point: public static void main(String[] args).
  • Compile with javac, run with java.
  • File name must match public class name.

Interview Questions

Q: What is the difference between JDK, JRE, and JVM?

A: JVM executes bytecode. JRE = JVM + core libraries (for running Java apps). JDK = JRE + development tools (for writing/compiling Java code). Developers install JDK; end-users install JRE.

Q: Why is Java called "platform-independent"?

A: Java source code compiles to bytecode (not native machine code). Bytecode runs on any platform that has a JVM. This "Write Once, Run Anywhere" property makes Java platform-independent.

Q: What is bytecode in Java?

A: Bytecode is the intermediate code generated by the Java compiler (javac) from source code. It's stored in .class files and executed by the JVM. It's platform-independent — that's why Java works on any OS.

Q: Why is main method public static void?

A: public — JVM must access it from outside the class. static — JVM calls it without creating an object. void — it doesn't return anything.

Want to Master Java?

Join our Java course in Varanasi — practical classes and career support at our Sarnath centre.

Ask on WhatsApp
Chat with us