Chapter 01 of 21
Chapter 01 โ€” Phase 1: Fundamentals
Introduction to
Programming & Java
Before writing a single line of code, understand what programming really is โ€” how a computer thinks, what Java is made of, and why learning it will change how you solve problems forever.
~45 min read
5 Core Topics
5 MCQs
25 Practice Problems
๐Ÿ’ก
1.1 โ€” ConceptWhat is Programming?

Imagine you want your younger sibling to make tea. They have never made tea before, so you write them a note: "Boil water โ†’ Add tea bag โ†’ Pour into cup โ†’ Add sugar โ†’ Stir." You just wrote a program โ€” a precise, step-by-step set of instructions for someone to follow.

Programming is exactly that, but for a computer. The only critical difference: your sibling can think, guess, and adapt. A computer is completely literal. It does exactly what you write โ€” nothing more, nothing less. This is why programming must be precise.

Technical Definition

A program is an ordered set of instructions written in a programming language, designed to perform a specific task or solve a problem. The act of writing these instructions is called programming (also called coding or software development).

Why Do We Need Programming?

Computers are incredibly fast and powerful machines, but they are completely brainless โ€” they cannot think independently. Every app on your phone, every website you visit, every ATM transaction โ€” all of it exists because a programmer told the computer exactly what to do, step by step.

What is a Programming Language?

Computers understand only one language: machine language โ€” sequences of 0s and 1s (binary). But humans find it nearly impossible to write millions of zeros and ones. So, programming languages were created as human-readable layers that get automatically translated to machine language.

YOU TYPE: System.out.println("Hello, World!"); โ†“ HIGH-LEVEL: Java, Python, C++ (readable by humans) โ†“ Compiler / Interpreter ASSEMBLY: MOV AX, 01h (closer to hardware) โ†“ Assembler MACHINE CODE: 01001000 01100101 (what CPU actually runs)
โš™๏ธ
1.2 โ€” Execution FlowHow Programs Work

Before writing Java code, understand the journey from your fingers to the screen. This is called the program execution model.

1
Write Source Code
You type instructions in a high-level language like Java. The file is human-readable and saved with a .java extension. Example: HelloWorld.java
2
Compilation
The Java compiler (javac) reads your source code and translates it into bytecode โ€” an intermediate, platform-neutral language. This produces a .class file.
3
JVM Loads Bytecode
The Java Virtual Machine (JVM) on your computer reads the .class bytecode and translates it into the actual machine language for your specific CPU and OS.
4
CPU Executes
The CPU runs the machine code. Your output appears on screen. The program has completed its run.
HelloWorld.java โ†’ javac โ†’ HelloWorld.class โ†’ JVM โ†’ Output (Source Code) (Compiler) (Bytecode) (Runtime) (Screen)
๐Ÿ”„
1.3 โ€” Core ConceptCompiler vs Interpreter

Both are programs that translate code to machine language โ€” but they work in completely different ways. This is one of the most frequently asked concepts in university exams.

The Best Analogy โ€” French Book

You have a French book to read but don't understand French.

Compiler = A translator who translates the entire book first, gives you the complete English copy, then you read it at full speed. Slow start, fast to read afterward.

Interpreter = A translator who sits next to you and translates sentence by sentence as you read. Starts immediately, but always slower because they translate in real time.

Compiler
  • Translates entire program at once
  • Creates a separate output file
  • All errors reported together
  • Faster execution (translation already done)
  • Examples: javac (Java), gcc (C/C++)
  • Must recompile after code changes
Interpreter
  • Translates and runs line by line
  • No separate output file created
  • Stops at first error found
  • Slower execution (translating while running)
  • Examples: Python, Ruby, PHP
  • No recompile needed โ€” just run again

Java's Special Hybrid Approach

Java = Compiled + Interpreted

Step 1: javac compiles .java โ†’ .class (bytecode) โ€” Compilation phase

Step 2: JVM interprets/executes the bytecode at runtime โ€” Interpretation phase

Step 3: Modern JVMs use JIT (Just-In-Time) compilation to convert hot bytecode directly to native machine code for near-native speed.

This hybrid gives Java the portability of interpreters and the speed of compiled languages.

FeatureCompilerInterpreterJava (Hybrid)
TranslationAll at onceLine by lineCompiled to bytecode โ†’ JVM runs it
Speedโšก Fast execution๐Ÿข Slower๐Ÿš€ Fast (with JIT)
Error reportingAll at compile timeStops at first errorAll at compile time
Output fileYes (.exe/.out)NoYes (.class bytecode)
PortabilityPlatform-specificNeeds interpreter per OSPlatform-independent (via JVM)
ExamplesC, C++, GoPython, RubyJava, Kotlin, Scala
๐Ÿ—๏ธ
1.4 โ€” Java ArchitectureJVM, JDK, and JRE

You'll hear these three terms constantly. Most beginners confuse them. Let's fix that once and for all.

Pizza Restaurant Analogy

JVM (Java Virtual Machine) = The oven โ€” the machine that actually bakes (runs) the pizza (program).

JRE (Java Runtime Environment) = The restaurant โ€” everything needed to eat pizza (run Java programs). Includes the oven, tables, and staff.

JDK (Java Development Kit) = The restaurant + cooking school โ€” everything in JRE, PLUS all the tools to create new pizzas (write and compile Java programs). If you're a developer (chef), you need JDK.

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•— โ•‘ JDK (Java Development Kit) โ•‘ โ•‘ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ•‘ โ•‘ โ”‚ JRE (Java Runtime Environment) โ”‚ โ•‘ โ•‘ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ•‘ โ•‘ โ”‚ โ”‚ JVM (Java Virtual Machine) โ”‚ โ”‚ โ•‘ โ•‘ โ”‚ โ”‚ [Class Loader] [Execution Engine/JIT] โ”‚ โ”‚ โ•‘ โ•‘ โ”‚ โ”‚ [Garbage Collector] [Memory Areas] โ”‚ โ”‚ โ•‘ โ•‘ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ•‘ โ•‘ โ”‚ + Java Standard Libraries (java.lang, etc.) โ”‚ โ•‘ โ•‘ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ•‘ โ•‘ + javac (compiler) + javadoc + jdb + jar + tools โ•‘ โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• You are a developer โ†’ Install JDK End user (just running apps) โ†’ Needs only JRE Note: JDK 11+ bundles JRE โ€” no separate JRE download needed

JVM โ€” The Heart of Java

The Java Virtual Machine is a program that runs on your computer and acts as a virtual CPU. It reads bytecode and converts it to instructions your real CPU understands. The key insight: different operating systems have different JVMs, but they all understand the same bytecode.

JDK ToolCommandPurpose
javacjavac HelloWorld.javaCompiler โ€” converts .java โ†’ .class
javajava HelloWorldLauncher โ€” runs .class file via JVM
javadocjavadoc HelloWorld.javaGenerates HTML documentation
jarjar -cf app.jar *.classPackages .class files into archive
jdbjdb HelloWorldDebugger โ€” find bugs in programs
๐ŸŒ
1.5 โ€” Java's Superpower"Write Once, Run Anywhere"

Java's most famous feature โ€” officially called WORA (Write Once, Run Anywhere). Here's why it exists and exactly how it works.

The Problem Before Java

C++ compiles directly to machine code. Windows machine code โ‰  Mac machine code โ‰  Linux machine code. If you wrote a C++ program on Windows and wanted it to run on Mac, you had to recompile separately for every platform. For large projects, this was a nightmare.

C++ PROBLEM: source.cpp โ†’ Compile for Windows โ†’ .exe (Windows only) โ†’ Compile for Mac โ†’ binary (Mac only) โ†’ Compile for Linux โ†’ binary (Linux only) โœ— Must recompile for every platform JAVA SOLUTION: HelloWorld.java โ†’ javac โ†’ HelloWorld.class (bytecode) โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ–ผ โ–ผ โ–ผ JVM (Windows) JVM (Mac) JVM (Linux) runs fine โœ“ runs fine โœ“ runs fine โœ“ โœ“ Compile ONCE. Run on ANY platform with a JVM installed. Bytecode is platform-NEUTRAL. JVM is platform-SPECIFIC.
โš ๏ธ Examiner Trap โ€” "Is Java 100% Platform Independent?"

Many students say "Yes!" โ€” but the precise answer is: Java programs (bytecode) are platform-independent. The JVM itself is platform-dependent (different JVM for Windows, Mac, Linux). The JVM is the bridge that makes Java programs appear platform-independent.

โœ“ Model Answer: "Java source code and bytecode are platform-independent. The JVM is platform-specific, but since JVMs are provided for all major operating systems, Java programs can run anywhere without modification."

โ˜•
1.6 โ€” First CodeThe Hello World Program โ€” Every Character Explained

This is every Java developer's first program. Don't just type it โ€” understand every single character before moving on.

HelloWorld.java โ€” Complete First Program
// File: HelloWorld.java
// This is your very first Java program

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello, World!");

    }

}
Output

Hello, World!

Line-by-Line Breakdown

public class HelloWorld
  • public โ€” Access modifier. This class is visible to everyone, including the JVM.
  • class โ€” Keyword declaring this is a class. Every Java program needs at least one class. A class is a container for your code.
  • HelloWorld โ€” The class name. Must EXACTLY match the filename (HelloWorld.java). Java is case-sensitive โ€” helloworld โ‰  HelloWorld.
  • { } โ€” Curly braces. Everything between them is the class body.
public static void main(String[] args)

This is the entry point of every Java program. The JVM searches for this exact signature when it starts running your program. If it's not there, the program won't run.

  • public โ€” The JVM (which is outside your class) needs to call this. Must be public.
  • static โ€” The JVM calls main without creating an object of your class first. static allows this.
  • void โ€” This method returns nothing to the caller.
  • main โ€” The exact name the JVM looks for. Cannot be changed or misspelled.
  • String[] args โ€” An array that holds command-line arguments. Can be empty โ€” you don't have to use it.
System.out.println("Hello, World!");
  • System โ€” A built-in Java class representing the computer system.
  • out โ€” A static field inside System representing the standard output (your screen).
  • println โ€” A method that prints text AND moves to a new line (print + line).
  • ("Hello, World!") โ€” The String argument โ€” text in double quotes.
  • ; โ€” Semicolon terminates every statement. Missing this is the #1 beginner mistake.
ANATOMY OF System.out.println("Hello, World!"); System . out . println ( "Hello, World!" ) ; โ”€โ”€โ”€โ”€โ”€โ”€ โ”€โ”€โ”€โ”€โ”€ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”€ Class field method String argument Statement name access call (what to print) terminator println() โ†’ prints text + moves cursor to NEXT line print() โ†’ prints text, cursor STAYS on same line printf() โ†’ formatted print, like C's printf

How to Compile and Run

1
Save the file
Save as HelloWorld.java. Filename must match class name exactly. Check capitalization carefully.
2
Open Terminal
On Windows: Command Prompt or PowerShell. On Mac/Linux: Terminal. Navigate to your file's folder with cd path/to/folder
3
Compile
Type: javac HelloWorld.java and press Enter. If no errors, a HelloWorld.class file appears in the folder.
4
Run
Type: java HelloWorld (no .class extension!) and press Enter. You should see Hello, World! printed.
๐Ÿšซ
1.7 โ€” Watch OutMost Common Beginner Mistakes
Top 7 Mistakes in Chapter 1
  1. Filename doesn't match class name โ€” Saving as hello.java but writing public class HelloWorld. Error: "class HelloWorld is public, should be declared in a file named HelloWorld.java"
  2. Missing semicolon โ€” System.out.println("Hi") without ;. Most common compile error.
  3. Wrong capitalisation โ€” system.out.println won't work. Java is case-sensitive. Must be System.out.println.
  4. Running with .class extension โ€” Typing java HelloWorld.class instead of java HelloWorld.
  5. Misspelling main โ€” Writing Main or MAIN instead of main. JVM won't find the entry point.
  6. Missing curly braces โ€” Every { needs a matching }. Count your braces.
  7. Code outside a class โ€” In Java, ALL code must live inside a class. Nothing can be written at the "top level" outside a class.
๐Ÿ”
1.8 โ€” Trace ItDry Run โ€” What Exactly Happens
๐Ÿ“‹ Complete Execution Trace โ€” HelloWorld
StepActionByResult
1User types javac HelloWorld.javaTerminalCompiler starts reading source file
2Compiler checks for syntax errorsjavacNo errors found
3Compiler translates source to bytecodejavacHelloWorld.class created on disk
4User types java HelloWorldTerminalJVM starts up
5JVM loads HelloWorld.classJVMBytecode loaded into memory
6JVM searches for public static void main(String[] args)JVMFound in HelloWorld class
7JVM executes System.out.println("Hello, World!")JVMHello, World! printed to screen
8main() body ends, no more statementsJVMProgram terminates normally
๐Ÿง 
1.9 โ€” Remember ItMemory Tips & Tricks
Memory Tricks โ€” Chapter 1
  • JDK / JRE / JVM: "D is for Developers, R is for Running, V is the Virtual machine inside" โ†’ JDK (develop), JRE (run), JVM (virtual engine)
  • WORA: Think of bytecode as a universal power adapter โ€” same plug (bytecode) works in any country's socket (OS via JVM).
  • public static void main: "Please Stop Visiting My house" โ†’ Public Static Void Main
  • Compiler vs Interpreter: Compiler = full book translator (translate all, then read). Interpreter = live translator (sentence by sentence, right now).
  • Semicolons: Every Java statement ends with ; โ€” treat it like the full stop (period) at the end of an English sentence.
  • Java file naming: Class name = filename. Always. PascalCase. No exceptions.
๐Ÿ“
1.10 โ€” ExamUniversity Exam Preparation

Theory Questions with Model Answers

2 Marks โ€” Short Answer

Q: What is a program? Why is it needed?

Answer: A program is an ordered set of instructions written in a programming language that directs a computer to perform a specific task. Programs are needed because computers have no intelligence of their own โ€” they require precise, step-by-step instructions for every operation. Without programs, a computer is an inert machine incapable of any useful function.

4 Marks โ€” Compare

Q: Distinguish between a compiler and an interpreter with examples.

Answer: A compiler translates the entire source code into machine code or an intermediate form at once, before execution begins. It detects all syntax errors at compile time and produces a separate executable file. Examples: javac (Java), gcc (C/C++). An interpreter translates and executes the source code line-by-line at runtime. It stops at the first error encountered and produces no separate file. Examples: Python interpreter, Ruby. Java uniquely combines both: javac compiles source to bytecode (.class), then the JVM interprets and executes that bytecode at runtime.

5 Marks โ€” Explain in Depth

Q: Explain the role of JVM in making Java platform-independent. Differentiate between JVM, JRE, and JDK.

Answer: Java achieves platform independence through a two-step process. First, the Java compiler (javac) compiles source code (.java) into bytecode (.class files) โ€” a platform-neutral intermediate format not tied to any specific OS. Second, the JVM installed on each target OS reads bytecode and converts it to platform-specific machine code at runtime. Since every major OS has its own JVM implementation, the same bytecode runs unchanged on all platforms โ€” this is "Write Once, Run Anywhere."

JVM (Java Virtual Machine): The runtime engine that executes bytecode. Platform-specific โ€” a different JVM exists for Windows, Mac, and Linux.
JRE (Java Runtime Environment): Contains the JVM plus the Java standard class libraries. Used to RUN Java programs.
JDK (Java Development Kit): Contains the JRE plus development tools (compiler javac, debugger jdb, etc.). Used to DEVELOP and compile Java programs.

Viva Questions

MCQ Bank

Q1.Which of the following is the correct extension of a compiled Java file?
A.java
B.class
C.exe
D.jar
โœ“ .class files contain bytecode produced by the javac compiler. .java is the source file. .exe is a Windows executable. .jar is a Java Archive (package of .class files).
Q2.Which component of Java is platform-dependent?
ABytecode (.class file)
BSource code (.java file)
CJVM (Java Virtual Machine)
DJava Standard Library
โœ“ The JVM is platform-dependent โ€” a different JVM binary exists for Windows, Mac, and Linux. Bytecode and source code are platform-neutral. The JVM is what makes Java programs appear platform-independent by doing the platform-specific translation at runtime.
Q3.What is the correct signature of the main method in Java?
Apublic void main(String args)
Bstatic void main(String[] args)
Cpublic static void main(String[] args)
Dpublic static int main(String[] args)
โœ“ The exact signature must be: public static void main(String[] args). Every keyword matters. Missing 'public' or 'static' causes a runtime error: "Main method not found in class."
Q4.What happens if you run: java HelloWorld.class?
AProgram runs normally
BError: Could not find or load main class HelloWorld.class
CCompilation error
DWarning printed but runs
โœ“ The java command takes a class name, not a filename. java HelloWorld.class looks for a class literally named "HelloWorld.class" (with a dot), which doesn't exist. The correct command is java HelloWorld (no extension).
Q5.Which of the following BEST describes a JDK?
AOnly the runtime environment for running Java programs
BOnly the Java compiler
CA complete package including JRE plus development tools like javac, jdb, javadoc
DJust the Java Virtual Machine
โœ“ JDK = JRE + development tools. JRE is for running programs. JDK includes JRE AND adds the compiler (javac), debugger (jdb), documentation generator (javadoc), and other tools developers need.

Output Prediction Exercises

Predict Before You Click

Code 1:

Predict Output
System.out.println("Line 1");
System.out.print("Line 2");
System.out.println("Line 3");
Line 1
Line 2Line 3

Why: println("Line 1") prints and moves to next line. print("Line 2") prints WITHOUT moving to next line. println("Line 3") prints on the same line as "Line 2", then moves to next line.

Code 2:

Predict Output
System.out.println("Hello\nWorld");
System.out.println("A\tB\tC");
Hello
World
A    B    C

Why: \n is the newline escape sequence โ€” moves to next line mid-string. \t is the tab escape sequence โ€” adds horizontal spacing.

Debugging Exercises

Bug Hunt โ€” Find ALL Errors
Buggy Code #1
Public Class myProgram {
    public static Void Main(String[] args) {
        system.out.println("Hello")
    }
}
Bug 1: Public โ†’ must be public (lowercase p)
Bug 2: Class โ†’ must be class (lowercase c)
Bug 3: Void โ†’ must be void (lowercase v)
Bug 4: Main โ†’ must be main (lowercase m โ€” JVM looks for "main")
Bug 5: system โ†’ must be System (capital S)
Bug 6: Missing semicolon after println("Hello")
Quick Revision โ€” Chapter 1 โ€” All Key Points
A program is a set of precise instructions for a computer. Computers are fast but completely literal.
Compiler translates all at once (C, Java's javac). Interpreter translates line-by-line (Python). Java uses both.
JVM = engine that runs bytecode (platform-specific). JRE = JVM + libraries (run programs). JDK = JRE + tools (develop programs).
Java platform independence: javac compiles to platform-neutral bytecode โ†’ JVM on each OS executes it. WORA.
JVM is platform-specific; Java programs (bytecode) are platform-independent. This is the precise answer.
public class ClassName โ€” class name must exactly match filename (case-sensitive).
public static void main(String[] args) โ€” exact JVM entry point. Every word matters. Trick: Please Stop Visiting My house.
System.out.println() prints + newline. System.out.print() prints, no newline. System.out.printf() formatted.
Every Java statement ends with ; โ€” missing it is the most common error.
Compile: javac FileName.java. Run: java ClassName (no .class extension).
๐Ÿ’ช
1.11 โ€” PracticePractice Problems

Easy Problems

P1.1
Hello Name
Write a Java program that prints "Hello, [YourName]!" to the screen. Run it from the terminal and confirm the output.
Easy
P1.2
Three-Line Bio
Print your full name, university name, and department โ€” each on a separate line using three println() calls.
Easy
P1.3
Same-Line Print
Print "Hello " and "World!" on the SAME line by combining print() and println(). Expected: Hello World!
Easy
P1.4
Escape Sequences
Using a SINGLE println(), print three lines of text using \n inside the string. Then add tabs using \t.
Easy
P1.5
Print a Box
Using only print/println statements, draw this box in the console:
***** / * * / * * / *****
Easy
P1.6
Quote Inside String
Print the text: She said "Java is amazing!" โ€” the double quotes must appear in the output. Use \".
Easy
P1.7
Windows File Path
Print the path: C:\Users\Student\Desktop\Java. You need \\ for each backslash. Tricky!
Easy
P1.8
Fix the Bugs
Fix every error: public Class Test { public static void main(String args) { System.out.println("Hi") } }
EasyDebug
P1.9
Count the Errors
How many errors does this have? Public class test { Public Static Void Main(String[] Args) { system.out.Println("ok") }}
EasyDebug
P1.10
Terminal Practice
Write HelloWorld, compile it with javac, run with java in the terminal. What files are created? What happens if you skip compilation?
EasyPractical

Medium Problems

P1.11
Formatted Table
Use \t to print a table with three columns (Name, Age, City) and three rows of data. Columns should be aligned.
Medium
P1.12
ASCII Art Name
Print your first name using ASCII art โ€” each letter made of stars. Each letter must be at least 5 rows tall.
Medium
P1.13
Output Prediction
Predict the output of: System.out.println(1 + 2 + "3"); and System.out.println("1" + 2 + 3);. Explain why they differ, then verify.
MediumPredict
P1.14
Multiple Classes Experiment
Create one .java file with two non-public classes (ClassA and ClassB), each with a main. Compile. Then run java ClassA vs java ClassB. What do you observe?
Medium
P1.15
JVM Architecture
In a Java comment block, draw an ASCII diagram showing: source file โ†’ javac โ†’ bytecode โ†’ JVM (Class Loader โ†’ Execution Engine) โ†’ Output. Annotate each step.
Medium
P1.16
printf Practice
Use printf to print: "Name: Ahmed, Score: 95.50, Grade: A" using format specifiers %s, %.2f, %c.
Medium
P1.17
Missing Main Experiment
Write a Java class with no main method. Compile it (does it succeed?). Try to run it (what error appears?). Document: what is the difference between compile-time and runtime errors?
Medium
P1.18
Unicode Characters
Run: System.out.println("\u0048\u0065\u006C\u006C\u006F"); โ€” what prints? Research what Unicode is and write a 3-sentence explanation in a comment block.
MediumResearch
P1.19
WORA Essay in Code
Write a Java program that prints (as output) a full explanation of platform independence โ€” what it is, how bytecode enables it, and what JVM's role is. At least 5 lines of output.
Medium
P1.20
Comment Documentation
Rewrite the HelloWorld program with thorough Javadoc comments explaining every line โ€” use /** */ style. Practice professional documentation habits from day one.
Medium

Hard Problems

P1.21
Command-Line Greeter
Modify HelloWorld to use args[0]: running java Greeter Alice prints "Hello, Alice!". Handle the case where no argument is provided (use args.length check).
Hard
P1.22
Self-Describing Program
Write a Java program whose output describes its own structure: prints the class name, main method signature, and all statement descriptions โ€” formatted like a report.
Hard
P1.23
Escape Sequence Master
Using ONLY System.out.print() and escape sequences, produce this exact output on three lines: (1) a quoted sentence, (2) a Windows file path, (3) a tab-aligned table row.
Hard
P1.24
JIT Research
Research what JIT (Just-In-Time) compilation is. Write a 200-word explanation in a comment block: what it is, how it differs from normal compilation, and why it makes Java faster at runtime.
Hard
P1.25
Java vs Python Deep Compare
In a comment block, write a structured comparison of Java and Python covering: compilation model, platform independence, typing system, speed, and typical use cases. Use a table format in the comment.
Hard
Chapter 1 Challenge

If you can answer all of these without notes, you truly own Chapter 1.

  • Write the complete HelloWorld program from memory โ€” every keyword, every punctuation mark, correct capitalisation.
  • Explain to a friend (out loud): the entire Java execution pipeline from source code to screen output.
  • Answer without looking: What is the difference between JDK, JRE, and JVM? Which do you install as a developer and why?
  • Predict and explain: System.out.println("A" + "B" + 1 + 2); vs System.out.println(1 + 2 + "A" + "B");