Professional Documents
Culture Documents
Oov1 Cheat Sheet: by Via
Oov1 Cheat Sheet: by Via
x = a ? a true? x = b, a false? x = c Methods in intefaces are implicitly public and String c = new new String-
b : c abstract and can't be private. String("Prog1"); Object
short 16 bit, -32.768 ... 32.767 Arrays.equals( Compare array content Student other = (Student)obj;
a, b) return regNumber ==
int 32 bit, -231 to +231 -1
Arrays.deepEq Compare x dimensional other.regNumber;
long 64 bit, -263 to +263 -1, long x =
uals(a, b) array }
100l;
}
public enum Enum
float 32 bit, float x = 100f;
Weekday{ If equals() is changed, hashCode() has also be
double 64 bit, double x = 100d; changed! x.equals(y) -> x.hashCode() ==
MONDAY, ...,
y.hashCode()
SUNDAY }
Java type casting
String a = new reference to String- Keywords
"Prog1"; Object "Prog1" (if already
exists, otherwise create public can be seen by all that imports this
it) package
package can be seen by all classes in this public int hashCode() { LinkedList<O add("ICTh"),
package return firstName.hashCode() + bject> l1 = add(int, "Bsys1"),
private can be seen only by this class 31 * surName.hashCode(); new remove(int),
final can only be defined once and not Java compareTo example
Set<String> add("Test"),
changed later. Class: no
class Person implements s1= new remove("Test"),
subclasses, Method: no overriding
Comparable<Person> { TreeSet<>(); size() checks if already
static Means this is a constant
private String firstName, or added -> if so, return false.
final
lastName; Set<String> TreeSet = sorted, always
s2= new efficient. HashSet =
// Constructor…
Javadoc unsorted, usually very
@Override HashSet<>();
efficient
Start with /** end with */ each public int compareTo(Person
line * Map<Integer, get(key), put(key,
other) {
@author name author class / Object> m1= "Test"),
int c =
interface new remove(key),
compareStrings(lastName,
@version number version class / HashMap<>(); containsKey(key),
other.lastName);
interface or size(), TreeMap =
if (c != 0) { return c; }
@param name parameter method
Map<Integer, sorted by key, always
else { return
description Object> m2= efficient. HashMap =
compareStrings(firstName, unsorted, usually very
new
@return description returnvalue method other.firstName); }
TreeMap<>(); efficient
@throws/@exception potential method }
type description exception Iterator<String> it=
private int compareStrings(String
@deprecated deprecated method m1.iterator(); while(it.hasNext())
a, String b) {
description (outdated) {..}
if (a == null) { return b == null
? 0 : 1; }
Java inheritance
else { return a.compareTo(b); }
} Vehicle v1 = new Vehicle = static
} Car(); type, Car =
dynamic type
Java inheritance (cont) Java Lambdas / Stream API (cont) Nested class
Vehicle v = new Error -> Dynamic people.stream() .filter(p pattern Use this if a class is only used in another class
Vehicle; Car c = type can't be down -> has to be No seperate classfile
casted final!
(Car)v; p.getLastName().contains( The inner class can use all members of the
if(v instanceof Test if dynamic type
pattern)) outer class (this include private members)
from super class newRandom(4711); random Can be declared in a method -> All variables
Stream.generate(random::n stream from outside are getting final eg Car
((SuperSuperClass) Hiding: variable
this).variable from "super.super" extInt) getSuperCar() { class SuperCar
class .forEach(System.out::prin extends Car { @Override public int
1{3} exactly 111 assertNotSame(expe expected != actual different Interfaces with & to ensure other
(only reference functionality like serializable
-?1 -1 or 1, "-" is optional cted, actual)
comparation) Wildcard type: Node<?> undefinedNode;
Mo|Di Or
assertTrue(conditi condition undefinedNode = new Node<Integer>
[a-z] any letter from a to z on) (4); undefinedNode= new
Serializable (cont)