Three dense quick references by persona—syntax and collections for beginners,
streams and concurrency for mid-level, JVM and architecture for senior engineers.
Use Copy sheet for plain text, persona filters to focus one level, or print (Cmd/Ctrl+P).
beginnermidsenior
⌕
Beginner Cheat Sheet
Syntax, primitives, control flow, String API, core Collections, exceptions. Deep dives: Basics, Collections, Exceptions.
beginner
Data types & variables
Type
Size
Example / notes
byte
8-bit
-128 … 127
short
16-bit
Rare except I/O buffers
int
32-bit
Default for integers
long
64-bit
Suffix L: 1_000_000L
float
32-bit
Suffix f
double
64-bit
Default for decimals
char
16-bit UTF-16
'A', not a string
boolean
—
true / false only
var (10+)
inferred
Local only; must have initializer
int count = 0;
final String name = "Ada"; // reference final — can't reassign ref
var list = new ArrayList<String>(); // inferred type
Operators & control flow
Construct
Syntax
Notes
if / else
if (x > 0) { } else { }
Condition must be boolean
for
for (int i = 0; i < n; i++)
Classic index loop
enhanced for
for (var x : list)
Iterable / array
while
while (cond)
Pre-test loop
do-while
do { } while (cond);
Runs at least once
switch
switch (x) { case 1 -> … }
Arrow form: no fall-through
break / continue
inside loops/switch
Labeled break rare
ternary
cond ? a : b
Both branches evaluated type-compatible
String methods (high-use)
Method
Returns
Use
length()
int
Char count (not UTF-8 bytes)
isEmpty() / isBlank()
boolean
Blank = whitespace only (11+)
equals(s)
boolean
Content compare; never == for strings
equalsIgnoreCase(s)
boolean
Case-insensitive
compareTo(s)
int
Sort order; sign = less/greater
substring(b, e)
String
[begin, end) index
indexOf / lastIndexOf
int
-1 if missing
contains / startsWith / endsWith
boolean
Search helpers
strip() (11+)
String
Trim Unicode whitespace
split(regex)
String[]
Regex split; limit param for max parts
join(delimiter, parts)
String
Static — join collection/array
formatted / format
String
"%s %d".formatted(a, n)
toLowerCase / toUpperCase
String
Locale overload for i18n
// Text blocks (15+)
String sql = """
SELECT id, name FROM users
WHERE active = true
""";
Common Collections
Interface
Implementations
Key ops
List
ArrayList, LinkedList
add, get(i), remove, size
Set
HashSet, TreeSet
add, contains — unique elements
Map
HashMap, TreeMap
put, get, getOrDefault, keySet
Queue
ArrayDeque
offer, poll — FIFO
List<String> list = new ArrayList<>();
list.add("a");
Map<String, Integer> map = new HashMap<>();
map.put("k", 1);
for (var e : map.entrySet()) {
String k = e.getKey();
int v = e.getValue();
}
Exception handling
Form
When
try { } catch (E e) { }
Handle checked or unchecked
finally { }
Always runs (except System.exit)
try-with-resources
try (var in = …) { } — auto-close
throw new E("msg")
Signal error
throws E
Declare checked exceptions on method
Unchecked
RuntimeException, IllegalArgumentException — no throws required
try (var reader = Files.newBufferedReader(path)) {
// use reader
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Map<String, List<User>> byDept = users.stream()
.filter(User::active)
.collect(Collectors.groupingBy(User::department));
// Parallel — only when data large & ops cheap; watch ordering
long n = list.parallelStream().filter(x -> x > 0).count();
Optional
Method
Purpose
of(v) / ofNullable(v)
Present box; nullable safe
empty()
Singleton empty
isPresent() / isEmpty()
Check (11+ isEmpty)
ifPresent(Consumer)
Run if present
orElse(x) / orElseGet(Supplier)
Default value
orElseThrow()
Fail if empty
map / flatMap
Transform without nested Optional
filter
Empty if predicate false
stream() (9+)
0 or 1 element stream
// Don't use Optional fields/parameters by default in domain models
String city = Optional.ofNullable(user)
.flatMap(User::address)
.map(Address::city)
.orElse("unknown");
Generics wildcards (PECS)
Wildcard
Means
Producer / Consumer
<T>
Type parameter
Definition site
? extends X
Upper bound — read as X
Producer — get items out
? super X
Lower bound — accept X
Consumer — put X in
?
Unbounded
Only safe via Object
// PECS: Producer Extends, Consumer Super
void copy(List<? extends Number> src, List<? super Integer> dest) {
for (Number n : src) dest.add(n.intValue());
}
Concurrency utilities
API
Use
synchronized
Intrinsic lock on object
volatile
Visibility — not atomic compound ops
ReentrantLock
Explicit lock, tryLock, fairness
AtomicInteger etc.
Lock-free CAS counters
ConcurrentHashMap
Thread-safe map — segment/CAS
CopyOnWriteArrayList
Read-heavy, rare writes
ExecutorService
submit, invokeAll, shutdown
Executors
newFixedThreadPool, newCachedThreadPool
CountDownLatch
Wait for N events
CyclicBarrier
Threads rendezvous
Semaphore
Limit concurrent access
CompletableFuture
Async pipeline — see senior sheet
BlockingQueue
ArrayBlockingQueue, LinkedBlockingQueue
ExecutorService pool = Executors.newFixedThreadPool(4);
Future<String> f = pool.submit(() -> "ok");
pool.shutdown();
pool.awaitTermination(30, TimeUnit.SECONDS);