← Learning Hub
Beginner

Java Introduction and Setup

Java is a popular programming language used for Android apps, banking systems, online shops and big company software. Java code is compiled once and runs on any computer that has Java installed: "write once, run anywhere".

Java has been one of the world's most used languages for over 25 years. In India especially, a huge number of IT jobs - at service companies, banks, insurance and e-commerce - ask for Java. Android apps were traditionally written in Java, and many large back-end systems still are.

How Java runs: you write code in a .java file. The compiler (javac) checks it and turns it into bytecode (a .class file). The Java Virtual Machine (JVM) then runs that bytecode. Because every operating system has its own JVM, the same bytecode runs on Windows, Mac and Linux - that's the "write once, run anywhere" idea.

Java is strict: you must say the type of every variable, and the compiler catches many mistakes before the program even runs. Beginners sometimes find this slower at first, but it makes big programs safer and easier for teams to maintain.

Java 8 was a big update. It added lambda expressions, the Stream API, Optional and a new Date and Time API. You will learn all of them here.

Your first program

Install the JDK 8 (Java Development Kit). Then save this as Hello.java:

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

Every Java program lives inside a class, and starts running from the main method. The words public static void look scary at first: public means anyone can call it, static means it belongs to the class (no object needed), and void means it returns nothing. You'll understand each word properly in later lessons - for now, treat this as the standard starting template.

Compile and run it in a terminal:

Example
javac Hello.java     // compiles to Hello.class
java Hello           // runs it
// Output: Hello from Java!
  • The file name must match the public class name: Hello.java holds class Hello.
  • main is where the program starts.
  • Every statement ends with a semicolon ;.
Press ▶ Run under an example to see its output (checked with real Java). You can edit the code too, but changed code needs to be compiled, so run your own version on your computer or in an online Java editor.
Key points
  • Java code is compiled to bytecode and runs on the JVM, on any system.
  • Every program has a class and a main method where it starts.
  • Statements end with ; and the file name must match the public class.
  • Java 8 added lambdas, streams, Optional and a new date/time API.

📝 Test yourself

1. Which command compiles a Java file?
2. Where does a Java program start running?
3. Fill in the method that prints a line:
System.out.("Hi");