Board Formulas
β˜• JavaπŸ“… Day 1

Introduction to Java

What Java is, why it is popular, how the JVM works, and how to run your first Java program.

🎯

Learning objectives

  • β†’Understand what Java is and where it is used
  • β†’Learn the role of the JVM, JRE and JDK
  • β†’Compile and run a Hello World program

πŸ’‘ Key points

  • Java is a statically-typed, object-oriented, class-based language.
  • Java code is compiled to bytecode (.class) and executed by the JVM β€” 'write once, run anywhere'.
  • JDK = compiler + tools + JRE. JRE = JVM + libraries.
  • Every Java program starts from a public static void main(String[] args) method.

πŸ’» Code examples(2)

#1Hello World
java
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Output
Hello, World!
Class name Hello must match filename Hello.java. main is the entry point. System.out.println writes to standard output.
#2Compile and run
bash
javac Hello.java   # produces Hello.class
java Hello         # runs the bytecode
javac compiles source to bytecode. java runs the class through the JVM.

🎯 Practice

Q1. What does JVM stand for and what is its job?+

Java Virtual Machine β€” it loads and executes Java bytecode on any platform that has a compatible JVM installed.

Q2. Why must the class containing main be public and the method static?+

public so the JVM can access it from outside the class; static so the JVM can call it without creating an instance first.

πŸ“ Notes

Why learn Java?

Java runs on billions of devices β€” Android apps, enterprise backends, Big Data (Hadoop, Spark), and embedded systems. Learning Java teaches you object-oriented thinking that transfers to C#, Kotlin, and Scala.

The Java toolchain

| Component | What it is | |---|---| | JDK | Developer kit β€” includes javac, java, jar, and the JRE | | JRE | Runtime environment β€” JVM + standard libraries | | JVM | The virtual machine that executes .class bytecode |

Install the JDK, verify with java -version and javac -version.