Week 1

Environment setup

How Java works

Types and Variables

Arrays

Basic IO

Control Flow

Packages

OOP in Java

Static Members

Practice

Assignment

Back end Track

Content

Practice Exercises

Each section maps to a module. Exercises progress in difficulty across the week — early modules focus on concepts and simple code; later modules combine everything into more realistic problems.


Module 1 — Environment Setup

Exercise 1.1 — Concept: JDK Components

Match each tool to what it does. No code required.

Tool What it does
javac A) Packages compiled code into a distributable file
java B) Generates HTML documentation from source comments
jar C) Compiles .java source files into .class bytecode
javadoc D) Starts the JVM and runs a compiled program

Exercise 1.2 — Concept: JDK Distributions

Answer in your own words:

  1. You are starting a personal learning project. Which JDK distribution would you choose and why?
  2. Your company deploys Java applications on AWS. Which distribution might be worth investigating and why?
  3. A colleague says "I installed the JRE, so I can start writing Java." What is wrong with this statement?

Exercise 1.3 — Coding: Your First Program

Create a class called AboutMe with a main method that prints the following (replace the values with your own):

Name    : Alice van der Berg
City    : Rotterdam
Track   : Backend — Java
Goal    : Become a backend developer

Requirements:


Module 2 — How Java Works

Exercise 2.1 — Concept: The Compilation Pipeline

Put the following steps in the correct order by numbering them 1–5:


Exercise 2.2 — Concept: True or False

State whether each statement is true or false, and explain why in one sentence.

  1. The same .class file can run on Windows, Linux, and macOS without recompilation.
  2. The JVM is platform-independent.
  3. Java is slower than JavaScript for all use cases.
  4. Kotlin programs can run on the JVM.
  5. The Garbage Collector requires you to explicitly free memory when you're done with an object.

Exercise 2.3 — Coding: Compile Manually

Write the following class in a plain text editor (not IntelliJ) and save it as Circle.java:

public class Circle {
    public static void main(String[] args) {
        double radius = 7.5;
        double area = Math.PI * radius * radius;
        System.out.println("Area: " + area);
    }
}

Then in your terminal:

javac Circle.java
java Circle

Answer:

  1. What output did you get?
  2. What happens if you rename Circle.java to circle.java (lowercase c) and try to compile again? Why?
  3. What happens if you try to run java Circle before compiling? What does the error tell you?

Module 3 — Java Basics

Exercise 3.1 — Concept: Default Values

Without running any code, predict the output of the following program:

public class Defaults {
    static int count;
    static double price;
    static boolean active;
    static String label;

    public static void main(String[] args) {
        System.out.println(count);
        System.out.println(price);
        System.out.println(active);
        System.out.println(label);
    }
}

Then run it and check. Were you correct?


Exercise 3.2 — Bug Fixing: Type Errors

The following program has four bugs. Find and fix each one, then explain what was wrong.

public class BuggyTypes {
    public static void main(String[] args) {
        int score = 87.5;
        boolean passed = 1;
        char grade = "A";
        String message = 'Well done!';

        System.out.println(score + " " + passed + " " + grade + " " + message);
    }
}

Exercise 3.3 — Coding: Invoice Line

Declare the following variables and use printf to print a formatted invoice line:

Expected output:

Product  : Mechanical Keyboard
Quantity : 2
Price    : €79.99 each
Total    : €159.98
In stock : true

Requirements: calculate the total from quantity × unit price, do not hardcode it.


Exercise 3.4 — Coding: Type Casting Consequences

Run the following snippet and explain each line of output:

public class CastingDemo {
    public static void main(String[] args) {
        double a = 7.9;
        int b = (int) a;
        System.out.println(b);

        int max = Integer.MAX_VALUE;
        System.out.println(max + 1);

        double result = 0.1 + 0.2;
        System.out.println(result);
        System.out.println(result == 0.3);
    }
}

For each line of output:

  1. What is printed?
  2. Why does Java behave that way?
  3. How would you fix or guard against the issue where relevant?