Java Cheat Sheet
by CommanderJak via cheatography.com/121316/cs/22168/
Primitives - raw data types Exceptions/Errors (cont) File I/O - data access outside JRE
int (32-bits) short (16) throw commands e be thrown FileInput/OutputSteam read/write bytes
float (32) double (64) useful for testing FileReader/Writer by characters
throw new Exceptio‐
char (16) long (64) BufferedReader/Writer line by line
nType();
byte (8) boolean (1) BufferedWriter bw = new Buffer‐
Create by extending Exception
Wrapper Class - object version of primitive, edWriter (new FileWriter(".../‐
Exception class
can convert by un/autoboxing java/src/main/resources.io.tex‐
public Money
Literal - represents a primitive value (d, f, ' ', t"));
Exception{
" ", L)
super("Error Messag‐
final Keyword
e")};
Strings - immutable, final sequence of
Class cannot be extended
chars try{must have try & catch/‐
Method cannot be overridden
finally not just try}
String Pool area in Heap that
catch( ExceptionType e){catches+ Variable cannot change value
stores String literals to
save memory but only 1 runs}
Terms
finally{always executes };
String s1 = draws from same
Catches go from specific exception to Java classed-based object-oriented
"hi"; memory address
general programming (OOP), write
String s2 =
once run anywhere (WORA),
"hi"; stored in heap not pool
Advanced Operators automatic memory manage‐
String s3 =
ment, pass by value or copy
new String + Concat‐ only operator overloading
reference, strong types
enation in Java
("hi");
IDE Integrated Development
% Modulus returns reminder (7 % 5 =
StringBuilder mutable Environment
2)
StringBuffer +threadsafe Linter auto compiles and catches
! Not returns opposite boolean
Integer Pool - range -128 to 127 errors in IDE
++/-- pre (println(++5)=6)
Reflection allows java to write code at
Increment post (println(5++)=5)
Array - object holding elements of one API runtime where classes, fields,
type &&/|| And/Or short-circuit evaluates one methods are treated as objects
side
int[] numbers = {1, 2, 3}; Recursion calling a method within itself
& / | And/Or evaluates both sides
int[] numbers = new int[size]; Code how much reachable tested
^ Exclusive both cannot be true Coverage code
int[][] 2dArray = new int[rows]‐
Or
[columns]
? Ternary (if condition)? return:else Memory
return
Object Class - everything inherits from MetaSpace unchanging info
.toStrin‐ prints memory address HeapSpace variable content
Access Modifiers
g(); StackSpace method calls/variable
Public all
references
.equa‐ checks for same memory
Private only class
ls(); address
Protected also children
.hashCod‐ id not guaranteed to be
(Default) only package
e(); unique
Object - an instance of a class Scopes - where does reference extend
Class - blueprint for object
Class static
Exceptions/Errors Object instance
Method local
Block local
Static { block runs at beginning
Error cannot recover from when class first accessed,
stackoverflow, syntax... initialization};
Checked/C‐ cannot compile,
ompile compiler sees
FiloIO, SQLException...
Unchecked/Ru‐ not required to be
ntime handled
NullPointer, Arithmetic...
throws throws e to method
caller
By CommanderJak Not published yet. Sponsored by Readable.com
Last updated 26th March, 2020. Measure your website readability!
Page 1 of 2. https://readable.com
cheatography.com/commanderjak/