Java Reference Sheet
1. Java Operators
1 Arithmetic: + - * / %
2 Assignment: = += -= *= /= %= &= |= ^= <<= >>=
3 Comparison: == != > < >= <=
4 Logical: && || !
5 Bitwise: & | ^ ~ << >> >>>
6 Increment/Decrement: ++ --
7 Ternary: condition ? valueIfTrue : valueIfFalse
8 Instanceof: obj instanceof ClassName
2. Common Built-in Methods
String Methods
1 length(), charAt(i), substring(start, end), toUpperCase(), toLowerCase()
2 indexOf(str), lastIndexOf(str), equals(str), equalsIgnoreCase(str)
3 contains(str), startsWith(str), endsWith(str), replace(old, new)
4 trim(), split(delimiter), isEmpty()
Math Methods
1 [Link](x), [Link](a, b), [Link](a, b)
2 [Link](a, b), [Link](x), [Link](x)
3 [Link](x), [Link](x), [Link](x), [Link]()
4 [Link](x), [Link](x), [Link](x), [Link], Math.E
Arrays ([Link])
1 [Link](array), [Link](array), [Link](arr1, arr2)
2 [Link](array, newLength), [Link](array, value)
3 [Link](array, key)
Collections ([Link].*)
1 ArrayList: add(), get(), set(), remove(), size(), clear(), contains()
2 HashMap: put(key, value), get(key), remove(key), containsKey(key), keySet(), values()
3 HashSet: add(), remove(), contains(), size(), clear()
4 [Link](list), [Link](list), [Link](list), [Link](list)
3. Control Structures
1 if, else if, else
2 switch(expression) { case x: ... break; default: ... }
3 for(init; condition; update)
4 while(condition)
5 do { ... } while(condition)
6 for-each: for(Type var : array)
4. Key Java Concepts
1 Class: Blueprint for creating objects.
2 Object: Instance of a class.
3 Constructor: Special method used to initialize objects (same name as class).
4 Method Overloading: Same method name, different parameters.
5 Method Overriding: Subclass provides specific implementation of a superclass method.
6 Encapsulation: Use private variables with getters/setters.
7 Inheritance: 'extends' keyword to inherit from another class.
8 Polymorphism: Using the same interface for different underlying data types.
9 Abstraction: Hiding complex implementation using abstract classes/interfaces.
10 Static: Belongs to the class, not an instance.
11 this: Refers to the current object.
12 super: Refers to parent class.
5. Exception Handling
1 try { ... } catch(Exception e) { ... }
2 finally { ... } (executes regardless of exception)
3 throw new ExceptionType(message)
4 throws keyword: declares an exception that a method might throw
6. Input/Output (I/O)
1 Scanner input = new Scanner([Link]);
2 nextInt(), nextDouble(), nextLine(), next()
3 BufferedReader br = new BufferedReader(new FileReader("[Link]"));
4 FileWriter fw = new FileWriter("[Link]"); [Link]("text"); [Link]();
7. Common Java Packages
1 [Link] – Core language classes (String, Math, Object, etc.)
2 [Link] – Collections, Scanner, Arrays, Date, etc.
3 [Link] – File handling (FileReader, FileWriter, BufferedReader, etc.)
4 [Link] – Date and time API (LocalDate, LocalTime, etc.)
5 [Link] – Networking (Socket, URL, etc.)
6 [Link] – GUI components