Java Desk Reference Handout
Ref ID: JV-BLU-01
JAVA SYNTAX BLUEPRINT
SYSTEMS & ARCHITECTURE DIRECTORY
SCOPE: SYNTAX & TYPES
TARGET: JDK 17+
DESK REFERENCE
1. Boilerplate Structure & Anatomy Required Code
public class Main { ← Class name MUST match file name exactly (Main.java)
public static void main(String[] args) { ← Program entry point; VM looks for this exact signature
System.out.println("Hello, World!"); // Prints output to terminal + moves to next line
}
}
public static void Accessible everywhere, runs without creating instances, returns nothing.
String[] args An array of text arguments passed dynamically from command terminal.
"Hello, World!" String literal. Must always be inside double-quotes.
Semicolon ; CRITICAL! Acts as a sentence period. Missing it triggers compilation error.
2. Brackets & Punctuation
{ }
CURLY BRACES (Code Blocks)
Defines boundaries of classes, methods, and loops. Keep them paired and indented!
( )
PARENTHESES (Arguments)
Encloses method parameters, logical conditions, and mathematically groups calculations.
[ ]
SQUARE BRACKETS (Arrays)
Indicates array type or element index. Index values range from 0 to length - 1.
//
COMMENTS (Compiler-Ignored)
// single-line comment
/* multi-line comment block */
3. Variables & Declarations
DECLARATION PROTOCOL
DataType variableName = value;
- Variables must have a declared type prior to compile use.
- Names must begin with a letter,
$, or _.
- Names are case-sensitive (
score ≠ Score).
- CamelCase is standard for multi-word variables.
| Category | Type | Size / Default | Example Use |
|---|
| Integer | int | 32-bit / 0 | Counting objects (42) |
| Decimals | double | 64-bit / 0.0 | Accurate pricing (19.99) |
| Logical | boolean | 1-bit / false | Toggle switch (true) |
| Character | char | 16-bit / '\0' | Single symbol ('A') |
| Object | String | Dynamic / null | Text chains ("Java") |
4. Java Memory Architecture Tips Core Concepts
STACK MEMORY (Local Variables)
Extremely fast execution block that holds local primitive variables and memory references to object variables. Managed in a strictly ordered Last-In-First-Out sequence.
Stack: [ int x = 5 ] → [ objectRef ] [Automated Clean]
HEAP MEMORY (Dynamic Objects)
Dynamic storage segment that houses all objects, arrays, and classes. Access is slower than stack. Periodic cleaning is automated by the **Java Garbage Collector (GC)**.
Heap: [ String data = "Hello" ] [Garbage Collected]
COMPILED BY: Lenny, Expert Inst. Designer TOPIC: Java Syntax Basics
PAGE 1 OF 2
Ref ID: JV-BLU-02
LOGIC & CONTROL FLOW
DECISION TREE & ITERATION MAP
SCOPE: LOGIC & LOOPS
TARGET: JDK 17+
DESK REFERENCE
1. Boolean Logic Truth Tables
AND && True ONLY if both are true.
OR || True if any one is true.
NOT ! Flips truth value entirely.
| A | B | A && B | A || B | !A |
| --- | --- | --- | --- | --- |
| true | true | true | true | false |
| true | false | false | true | false |
| false | true | false | true | true |
| false | false | false | false | true |
Short-Circuiting Optimization: If evaluating the left side of && is false, or left side of || is true, Java bypasses evaluating the right side entirely.
2. Decision Trees (Conditionals)
// 1. Standard If-Else If Chain
if (score >= 90) {
grade = 'A';
} else if (score >= 80) {
grade = 'B';
} else {
grade = 'F';
}
// 2. Switch Case Structure
switch (direction) {
case "NORTH":
y += 1; break;
case "SOUTH":
y -= 1; break;
default:
System.out.println("No move");
}
// 3. In-line Ternary Operator Shortcut
String status = (age >= 18) ? "Adult" : "Minor";
3. Loop Patterns & Iteration Structures Iteration Blueprints
FOR LOOP (Definite)
Best for running code a designated, precise number of times.
for (int i = 0; i < 10; i++) {
// Runs exactly 10x
}
WHILE LOOP (Indefinite)
Runs indefinitely as long as condition remains active/true.
while (energy > 0) {
work();
energy--;
}
DO-WHILE (Execute Once First)
Executes body once first, then validates logic condition.
do {
showMenu();
} while (option != 0);
4. Critical Compilation & Syntax Pitfalls Avoid These Errors
==
Comparing Objects with ==
== compares memory references! Always compare values (like String literals) using .equals().
✖ name == "Admin" | ✔ name.equals("Admin")
;
Accidental Loop Statement Termination
Placing a semicolon immediately after a for or while loop expression ends the loop block instantly.
✖ for(...); { doStuff(); } ← DoStuff runs only ONCE!
COMPILED BY: Lenny, Expert Inst. Designer TOPIC: Java Logic & Control Flow
PAGE 2 OF 2
Java Classroom Poster
JAVA QUICK ENGINE
Classroom Reference Anchor Chart
1. Every Java Program Boilerplate File Name: Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Run your code here!"); // Statement ends with a semicolon ;
}
}
2. Bracket Pairing Rules
{ }
CURLY BRACES Enclose your classes, methods, loops & branch code structures.
( )
PARENTHESES Enclose if conditions, function parameters & method calls.
[ ]
SQUARE BRACKETS Create and index arrays. Remember: arrays start counting at index 0.
3. Variables Quick-Pick
int score = 100;
Whole Numbers
double price = 19.99;
Decimals / Fractions
boolean isOpen = true;
True / False
char grade = 'A';
Single Symbol
String name = "Java";
Text Sentences
4. Loop Blueprint Matrix
Definite Loop
for (int i=0; i<5; i++) {
// Runs 5 times
}
Indefinite Loop
while (count < 5) {
// Must change count!
}
5. CRITICAL STRINGS PITFALL
Never compare String values using ==! That checks if memory storage blocks are identical, not literal text!
Incorrect Code name == "Admin"
Correct Code name.equals("Admin")
PROJECT: Java Computer Lab Anchor Chart STATION ID: ANCH-01 VERSION: 1.1