Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master them — home row to !@#$%Practice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM level
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & mission
Pricing
Start Typing
Tools/Java Syntax

Java Syntax Cheat Sheet

Primitive types, reserved keywords, and the most common Java patterns — class declarations, loops, collections — all in one reference with typing practice links.

Primitive Data Types

TypeSizeRangeUse
int32-bit−2,147,483,648 to 2,147,483,647Whole numbers
long64-bit−9.2 × 10¹⁸ to 9.2 × 10¹⁸Large whole numbers — suffix L
double64-bit~±1.8 × 10³⁰⁸Decimal numbers (default float type)
float32-bit~±3.4 × 10³⁸Smaller decimal numbers — suffix f
boolean1-bittrue / falseBoolean value
char16-bit\u0000 to \uFFFFSingle Unicode character
byte8-bit−128 to 127Tiny integer
short16-bit−32,768 to 32,767Small integer
StringObjectAny textSequence of characters (not primitive)

Essential Keywords

KeywordMeaning
publicVisible everywhere
privateVisible only in the declaring class
protectedVisible in the package and subclasses
staticBelongs to the class, not an instance
finalCannot be changed / overridden / subclassed
abstractClass cannot be instantiated / method has no body
interfaceDeclare a contract of methods
implementsClass fulfils an interface contract
extendsSubclass a parent class
newCreate an object instance
thisReference to the current object
superReference to the parent class
returnReturn a value from a method
voidMethod returns no value
nullAbsence of an object reference
instanceofRuntime type check
try / catch / finallyException handling
throw / throwsRaise or declare exceptions
synchronizedThread-safe block or method
volatileAlways read from main memory (multi-threading)
enumDefine a fixed set of named constants
importInclude a class or package
packageDeclare the package namespace

Common Code Patterns

Class Declaration & Main Method

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

For Loop Variants

// Traditional for loop
for (int i = 0; i < 10; i++) {
    System.out.println(i);
}

// Enhanced for loop (for-each)
int[] numbers = {1, 2, 3, 4, 5};
for (int n : numbers) {
    System.out.println(n);
}

// While loop
int count = 0;
while (count < 5) {
    System.out.println(count++);
}

ArrayList Usage

import java.util.ArrayList;
import java.util.List;

List<String> languages = new ArrayList<>();
languages.add("Java");
languages.add("Python");
languages.add("Go");

for (String lang : languages) {
    System.out.println(lang);
}

System.out.println("Size: " + languages.size());
languages.remove("Go");
boolean hasJava = languages.contains("Java");

HashMap Usage

import java.util.HashMap;
import java.util.Map;

Map<String, Integer> scores = new HashMap<>();
scores.put("Alice", 95);
scores.put("Bob", 87);
scores.put("Carol", 92);

// Access
int aliceScore = scores.get("Alice");
scores.putIfAbsent("Dave", 78);

// Iterate
for (Map.Entry<String, Integer> entry : scores.entrySet()) {
    System.out.println(entry.getKey() + ": " + entry.getValue());
}

Interface & Implementation

public interface Shape {
    double area();
    double perimeter();
}

public class Circle implements Shape {
    private final double radius;

    public Circle(double radius) {
        this.radius = radius;
    }

    @Override
    public double area() {
        return Math.PI * radius * radius;
    }

    @Override
    public double perimeter() {
        return 2 * Math.PI * radius;
    }
}

Practice typing these in CodeSpeedTest →

Java's verbosity means muscle memory matters more than in most languages. Start with Hello World and build up to collections and OOP patterns.

Start typing Java →Browse all languages
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Resources

Pro ⚡ PricingCertifyFAQBlogContactLeaderboardRaceChallengesFree ToolsWPM CalculatorPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.