Welcome to Java: Write Once, Run Anywhere

Java was released by Sun Microsystems in 1995 (Sun was later acquired by Oracle, which maintains Java today) and was built around a single defining promise: “write once, run anywhere.” Rather than compiling directly to a specific computer’s machine code, Java compiles to an intermediate format called bytecode, which runs on the Java Virtual Machine […]

Variables, Data Types and Type Casting

Unlike Python or JavaScript, Java is statically typed — you declare a variable’s type when you create it, the compiler checks that type is respected everywhere the variable is used, and it can never silently change to a different type later. int age = 25; double price = 19.99; String name = “Tutoline”; boolean isActive […]

Operators and Control Flow

Conditionals int score = 82; String grade; if (score >= 90) { grade = “A”; } else if (score >= 75) { grade = “B”; } else { grade = “C”; } Loops for (int i = 0; i < 5; i++) { System.out.println(“Lesson ” + i); } int attempts = 0; while (attempts < […]

Methods and Parameters

A method is Java’s term for a function defined inside a class — in Java, every single function you write lives inside some class, there’s no such thing as a standalone function floating outside a class definition. public class MathHelper { public static int add(int a, int b) { return a + b; } } […]

Arrays and ArrayLists

Arrays — fixed size String[] courses = {“Python”, “Java”, “SQL”}; System.out.println(courses[1]); // Java System.out.println(courses.length); // 3 — note: length, not length(), no parentheses A Java array’s size is fixed the moment it’s created — there’s no way to add a fourth item to courses above without creating an entirely new, larger array. This limitation is […]

Object-Oriented Programming: Classes and Objects

A class is a blueprint; an object is a specific instance built from that blueprint. Java was designed as an object-oriented language from the ground up, so this concept underpins essentially everything else in the language. public class Course { private String title; private int lessonCount; public Course(String title, int lessonCount) { this.title = title; […]

Inheritance, Interfaces and Polymorphism

Inheritance public class CertifiedCourse extends Course { private String certificateName; public CertifiedCourse(String title, int lessonCount, String certificateName) { super(title, lessonCount); this.certificateName = certificateName; } } extends gives CertifiedCourse everything Course already has — every field and method — plus its own additional field. super(…) calls the parent class’s constructor, so the shared setup logic in […]

Exception Handling and What’s Next

Try/catch try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.println(“Can’t divide by zero: ” + e.getMessage()); } finally { System.out.println(“This always runs.”); } finally runs whether an exception was thrown or not — it’s the right place for cleanup code, like closing a file or a network connection, that absolutely […]

Generics and Collections Framework

Generics let a class or method work with any type while the compiler still checks type-safety at compile time — this is exactly what powers ArrayList and every other collection type you’ve already used in this course. public class Box<T> { private T contents; public void set(T contents) { this.contents = contents; } public T […]