Learn Cheatsheet

Java

Core Java syntax and APIs at a glance.

Types & Variables
int n = 0; 32-bit integer primitive
double d = 3.14; 64-bit float primitive
boolean b = true; Boolean (lowercase in Java)
String s = "hi"; String object (not a primitive)
var x = 42; Local type inference (Java 10+)
OOP & Inheritance
class Dog extends Animal Single inheritance
class Circle implements Shape Interface implementation
@Override Mark method as intentionally overriding
super.method() Call parent implementation
abstract class / abstract method Must be implemented by subclass
final class / final method Cannot be extended or overridden
Collections
new ArrayList<>() Ordered list — duplicates allowed
new HashSet<>() Unordered set — no duplicates
new HashMap<>() Key-value pairs — unordered
list.add(x) Append element
map.put(k, v) Add or replace entry
map.getOrDefault(k, d) Get value or default if key absent
Stream API
.stream() Create stream from collection
.filter(n -> n > 0) Keep matching elements
.map(n -> n * 2) Transform each element
.sorted() Sort in natural order
.collect(Collectors.toList()) Terminal: collect into list
.forEach(System.out::println) Terminal: consume each element
Exception Handling
try { } catch (Ex e) { } Catch a specific exception
finally { } Always executes (cleanup)
throw new RuntimeException(msg) Throw an exception
throws IOException Declare checked exception in signature