← Back to Week 1 Hub

Week 1 Cheat Sheet

Quick reference for Java fundamentals — keep this open while you code

1. Java Basics

package com.pluralsight; public class MathApp { public static void main(String[] args) { // Your code starts here System.out.println("Hello, YearUp!"); } }
Tip: Every Java program needs a public static void main(String[] args) method — this is where execution begins.

2. Data Types & Variables

TypeSizeRange / Notes
byte1 B-128 to 127
short2 B-32,768 to 32,767
int4 B~2.1 billion (most common)
long8 BNeeds L suffix: 100L
float4 BNeeds f suffix: 3.14f
double8 BDefault decimal type
char2 BSingle character: 'A'
boolean1 bittrue or false
Most used: int, double, boolean, String
Watch out: String is a class (capital S), not a primitive. Use double quotes "text" not single quotes.
Naming conventions:
Variables / methodscamelCasefirstName
ClassesPascalCaseMathApp
Packagesall lowercasecom.pluralsight
ConstantsUPPER_SNAKEfinal int MAX_SIZE = 10;

3. Operators & Expressions

Arithmetic

+  -  *  /  %

Assignment

+=  -=  *=  /=  %=
Integer division: int / int = int10 / 3 gives 3, not 3.333!
Fix: use double or cast: (double) num1 / num2
Pre/post increment:
++xIncrement first, then use the value
x++Use the value first, then increment
int x = 5; int a = ++x; // x becomes 6, a = 6 int y = 5; int b = y++; // b = 5, then y becomes 6
Type conversion:
Widening (safe, automatic):
byte short int long float double
Narrowing (dangerous, needs cast): reverse direction
int x = (int) 3.99; // x = 3 (truncates!)

4. Output & Input

Output
SpecifierUseExample
%dint / longprintf("%d", 42)
%ffloat / doubleprintf("%f", 3.14)
%.2f2 decimal placesprintf("%.2f", 3.14159) → 3.14
%sStringprintf("%s", name)
Scanner Input
import java.util.Scanner; Scanner scanner = new Scanner(System.in); String name = scanner.nextLine(); int age = scanner.nextInt(); double gpa = scanner.nextDouble();
Buffer gotcha: After nextInt() or nextDouble(), call scanner.nextLine(); to consume the leftover newline before reading a String.
MethodReturns
scanner.nextLine()String (full line)
scanner.nextInt()int
scanner.nextDouble()double
scanner.next()String (single word)

5. Conditionals

if (score >= 90) { grade = "A"; } else if (score >= 80) { grade = "B"; } else { grade = "C"; }

Comparison

==  !=  <  <=  >  >=

Logical

&& AND   || OR   ! NOT
String comparison: Use .equals("text") or .equalsIgnoreCase("text")NEVER use == for Strings!
Switch (enhanced):
switch (day) { case "Monday" -> System.out.println("Start of week"); case "Friday" -> System.out.println("Almost weekend"); default -> System.out.println("Regular day"); }
Ternary:
String result = (age >= 18) ? "Adult" : "Minor";
Tip: Traditional switch uses case value: ... break; — the enhanced arrow syntax (->) is cleaner and prevents fall-through bugs.

6. Methods

// Method signature public static returnType methodName(paramType paramName) { // body return value; // omit if void }
Best practice — Scanner pattern: Create Scanner once in main, pass it to other methods as a parameter.
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); displayMenu(scanner); } public static void displayMenu(Scanner scanner) { System.out.println("Enter your choice: "); int choice = scanner.nextInt(); }
Common mistake: Don't create a new Scanner in every method. Create it once, pass it around.

Week 1 — Java Fundamentals — YearUp Spring 2026

Glossary / Key Terms →