Java quick reference
Keywords and everyday methods on one page.
| Keyword | Meaning |
|---|---|
public / private / protected | Who can access a member |
static | Belongs to the class, not an object |
final | Cannot be changed, overridden or extended |
abstract | Must be completed by a subclass |
extends / implements | Inherit a class / fulfil an interface |
this / super | The current object / the parent class |
throw / throws | Raise an exception / declare one |
new | Create an object |
| Method | Purpose |
|---|---|
s.length() | String length |
s.equals(t) | Compare text |
s.split(",") | Break into an array |
Integer.parseInt(s) | Text to int |
String.valueOf(n) | Value to text |
Arrays.sort(a) | Sort an array |
Collections.sort(list) | Sort a list |
Math.max(a, b) | The larger value |
map.getOrDefault(k, d) | Value for k, or d if missing |