WECNCODE CODING BASICS
JAVA ESSENTIALS
"Battle-Hardened" Java Cheatsheet—updated for 2026. This focuses
on modern syntax (Java 17-21+) because life is too short for
boilerplate code.
The Core Syntax (The Basics)
In the old days, we typed everything out. Now, we let the compiler
do the heavy lifting where it makes sense.
Category Snippet / Keyword Note from the Trenches
Use var for local variables to
Variables var name = "Gemini";
keep code clean.
Constants final double PI = 3.14159; Always use final unless you
know it must change.
Text blocks are a lifesaver for
Strings """Multi-line text"""
SQL or JSON.
Your best friend for "Caveman
Printing [Link]();
Debugging."
The Anatomy of a Program
Every piece of Java code lives inside a Class. Think of the main
method as the "Power Button"—it's where everything starts.
PUBLIC CLASS MYFIRSTAPP {
PUBLIC STATIC VOID MAIN(STRING[] ARGS) {
[Link]("HELLO, JAVA 2026!");
}
}
Storing Data (Variables)
Java is Statically Typed, meaning you have to tell the computer what
kind of data you're storing.
2
WECNCODE CODING BASICS
The "Big Four" Primitives
Type Holds... Example
int Whole numbers int age = 25;
double Decimals double price = 19.99;
boolean True/False boolean isCoding = true;
char Single characters char grade = 'A';
Pro Tip: In modern Java, you can use var. The compiler is smart
enough to figure out the type for you.
var message = "I'm lazy but efficient"; // This is a String
Making Decisions (Control Flow)
If your code can't make decisions, it’s just a calculator.
If-Else Logic
IF (ENERGYLEVEL > 5) {
[Link]("KEEP CODING!");
} ELSE {
[Link]("FIND COFFEE.");
}
Modern Switch (The "Arrow" Syntax)
Gone are the days of forgetting break; statements.
STRING RESULT = SWITCH (SCORE) {
CASE 10 -> "PERFECT";
CASE 5 -> "AVERAGE";
DEFAULT -> "TRY AGAIN";
};
3
WECNCODE CODING BASICS
Doing it Again (Loops)
Don't repeat yourself. Let the machine do the grunt work.
For Loop: Use when you know exactly how many times to run.
for (int i = 0; i < 10; i++) { ... }
While Loop: Use when you're waiting for a condition to change.
while (isSearching) { ... }
For-Each (The Modern Way): Best for looking at every item in a
list. for (String item : cart) { ... }
Object-Oriented Basics (OOP)
This is where Java gets its power. We model the real world using
Classes (Blueprints) and Objects (the actual things built from those
blueprints).
Encapsulation: Keep your variables private. Use "Getters" and
"Setters" to access them.
Inheritance: A Tesla is a Car. It inherits the drive() method but
adds its own charge() method.
Records (The 2026 Standard): If a class is just there to hold data,
use a record. It’s one line of code instead of fifty.
public record User(String name, String email) {}
Managing Many Things (Collections)
You’ll rarely deal with just one piece of data. You’ll use the
Collection Framework.
ArrayList: A list that can grow or shrink (like a grocery list).
HashMap: Stores "Key-Value" pairs (like a dictionary where you
look up a word to find a definition).
The Toolbox (Terminology)
If you want to talk like a pro, you need to know these acronyms:
JDK (Java Development Kit): Your "Work Bench." It has the
compiler and the tools you need to build apps.
JVM (Java Virtual Machine): The "Engine." This is what actually
runs your code on any computer (Windows, Mac, Linux).
4
WECNCODE CODING BASICS
Maven/Gradle: The "Delivery Trucks." They go out and grab
libraries (pre-written code) so you don't have to build
everything from scratch.
Your First Mission
The best way to learn is to break things. Try this: Create a simple
"Coffee Order" program that uses an int for quantity and a switch
statement to print different prices for "Latte", "Espresso", and
"Water".
Break things and learn a new way of Java Programming catered to
the modern development era.
HAPPY LEARNING AND HAPPY HACKING! 👽