Head First Java Chapter 01 — Breaking the Surface
2 min readJun 8, 2022
Hello Readers,
This article is to highlight the main points include in the chapter.
- Write-once / Run anywhere, Because Java is consider as a Platform Independent Language.
The way Java works
- Write the Source code → Compile the Source Code → Compiler Creates the Java Bytecode (.class) → Bytecode can run on any device through JVM
Structure of a class
- When the JVM starts running, JVM looking for a especial class called main
- Then JVM executing every lines in main class inside the {}.
What can you say in the main method?
- Your code can tell JVM to:
- Do Something — Statements : declaration, assignments, method calls, etc.
- Do Something Again and Again — Loops : For, While, Do While loops
- Do Something Under a Condition — Branches : If Else, Switch cases
Loops
The key to a loop is the conditional test. In Java, a conditional test is an expression that results in a Boolean value — in other words, something that is either true or false.
You can do a simple Boolean test by checking the value of a variable, using a comparison operator including:
- < (Less than)
- > (Greater Than)
- == (Equality)
Condition Branches
In Java, an if test is basically the same as the Boolean test in a while loop — except instead of saying, “while there’s still beer…”, you’ll say, “if there’s still beer…” (Source: Head First Java)
BULLET POINTS
- Statements end in a semicolon ;
- Code blocks are defined by a pair of curly braces { }
- Declare an int variable with a name and a type: int x;
- The assignment operator is one equals sign =
- The equals operator uses two equals signs ==
- A while loop runs everything within its block (defined by curly braces) as long as the conditional test is true.
- If the conditional test is false, the while loop code block won’t run, and execution will move down to the code immediately after the loop block.
- Put a Boolean test inside parentheses: while (x == 4) { }