Java Fundamentals
IB Syllabus: B2.1 - Programming fundamentals
Overview
Before writing programs with loops and arrays, you need to understand the building blocks: variables, data types, operators, and how to get input from the user.
| # | Topic | Syllabus | Key Concepts | Level |
|---|---|---|---|---|
| 1 | Variables & Data Types | B2.1.1 | Declaring variables, primitives, Strings, operators, Scanner | SL + HL |
| 2 | String Methods | B2.1.2 | Manipulating text with built-in methods | SL + HL |
| 3 | Exception Handling | B2.1.3 | try/catch/finally for runtime errors | SL + HL |
| 4 | Debugging | B2.1.4 | Print statements, trace tables, breakpoints | SL + HL |
How Java Works
Java is both compiled and interpreted - a two-step process:
Your Code (.java) → Compiler (javac) → Bytecode (.class) → JVM → Output
The JVM (Java Virtual Machine) reads bytecode and translates it for whichever platform it runs on - this is why Java is “write once, run anywhere.”
Structure of a Java Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Key rules:
- The class name must match the filename exactly (
HelloWorld.java) - Java is case-sensitive -
mainis notMain - Every statement ends with a semicolon
; - Execution always begins in the
mainmethod