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