Content
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.
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 |
Answer in your own words:
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:
printf or manual spacing)Put the following steps in the correct order by numbering them 1–5:
.java file.class file into memoryjavac compiles the source file into a .class bytecode fileState whether each statement is true or false, and explain why in one sentence.
.class file can run on Windows, Linux, and macOS without recompilation.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:
Circle.java to circle.java (lowercase c) and try to compile again? Why?java Circle before compiling? What does the error tell you?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?
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);
}
}
Declare the following variables and use printf to print a formatted invoice line:
"Mechanical Keyboard" (String)2 (int)79.99 (double)true (boolean)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.
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: