Java Introduction

Java is a general-purpose, statically-typed, object-oriented language. It runs on the JVM (Java Virtual Machine), which is why the same compiled program runs on Windows, Linux, macOS, and Android without change — "write once, run anywhere".

Where Java is used

  • Android apps (alongside Kotlin, which also runs on the JVM)
  • Enterprise backends — banking, insurance, government systems
  • Big data — Hadoop, Spark, Kafka are all JVM software
  • Desktop tools — anything built with Swing or JavaFX

In Nepal, Java is the backbone of most core banking software and a large share of BSc CSIT / BE Computer coursework.

Your first program

Java
public class Main {
    public static void main(String[] args) {
        System.out.println("Namaste, Nepal!");
    }
}

Save it as Main.java — the file name must match the public class name exactly. Then:

Bash
javac Main.java   # compile → Main.class (bytecode)
java Main         # run on the JVM

Since Java 11 you can skip the separate compile step for single files:

Bash
java Main.java

Reading that program

Part Meaning
public class Main Everything in Java lives inside a class
public static void main(String[] args) The entry point the JVM looks for
static Belongs to the class, so no object is needed to run it
void Returns nothing
String[] args Command-line arguments
System.out.println(...) Print a line to the console

The main signature is fixed — change any part of it and the JVM will not find your entry point.

JDK vs JRE vs JVM

  • JVM runs bytecode.
  • JRE = JVM + standard libraries (running only).
  • JDK = JRE + compiler and tools (what you need to develop).

Install a JDK — version 17 or 21 (both long-term-support releases) is a good default.

Knowledge Check

4 questions — test your understanding

1

What is the difference between `==` and `.equals()` in Java?

2

What does `final` mean when applied to a variable?

3

What is an interface in Java?

4

What does `String` being immutable mean in Java?