- Primitive types:
int,double,boolean. Integer division truncates:7 / 2is3;7 % 2is1. - Casting:
(double) 7 / 2is3.5;(int) 3.9is3. - Objects are created with
newand store a reference. Call methods with dot notation. - String methods:
length(),substring(a, b)(from index a up to but not including b),indexOf(str)(−1 if not found),equals(other),compareTo(other). - Math:
Math.abs,Math.pow,Math.sqrt,Math.random()(a double from 0.0 up to 1.0).
String s = "computer";
System.out.println(s.substring(3, 6)); // "put"
System.out.println(s.indexOf("t")); // 5
int r = (int) (Math.random() * 6) + 1; // random int from 1 to 6
Compare Strings with
.equals(), never ==. The == operator checks whether two references point to the same object.