abstract |
an abstract class or method |
abstract class Writable { public abstract void write(Writer out); public void save(String filename) { ... } } |
assert |
with assertions enabled, throws an error if condition not fulfilled |
assert param != null; Note: Run with -ea to enable assertions |
boolean |
the Boolean type with values true and false |
boolean more = false; |
break |
breaks out of a switch or loop |
while ((ch = in.next()) != -1) { if (ch == '\n') break; process(ch); } Note: Also see switch |
byte |
the 8-bit integer type |
byte b = -1; // Not the same as 0xFF Note: Be careful with bytes < 0 |
case |
a case of a switch |
see switch |
catch |
the clause of a try block catching an exception |
see try |
char |
the Unicode character type |
char input = 'Q'; |
class |
defines a class type |
class Person { private String name; public Person(String aName) { name = aName; } public void print() { System.out.println(name); } } |
continue |
continues at the end of a loop |
while ((ch = in.next()) != -1) { if (ch == ' ') continue; process(ch); } |
default |
1) the default clause of a switch
2) denotes default implementation of an interface method |
1) see switch
2)
public interface Collection<E> {
@Override
default Spliterator<E> spliterator() {
return Spliterators.spliterator(this, 0);
}
} |
do |
the top of a do/while loop |
do { ch = in.next(); } while (ch == ' '); |
double |
the double-precision floating-number type |
double oneHalf = 0.5; |
else |
the else clause of an if statement |
see if |
enum |
an enumerated type |
enum Mood { SAD, HAPPY }; |
extends |
defines the parent class of a class |
class Student extends Person { private int id; public Student(String name, int anId) { ... } public void print() { ... } } |
final |
a constant, or a class or method that cannot be overridden |
public static final int DEFAULT_ID = 0; |
finally |
the part of a try block that is always executed |
see try |
float |
the single-precision floating-point type |
float oneHalf = 0.5F; |
for |
a loop type |
for (int i = 10; i >= 0; i--) System.out.println(i); for (String s : line.split("\\s+")) System.out.println(s); Note: In the "generalized" for loop, the expression after the : must be an array or an Iterable |
if |
a conditional statement |
if (input == 'Q') System.exit(0); else more = true; |
implements |
defines the interface(s) that a class implements |
class Student implements Printable { ... } |
import |
imports a package |
import java.util.ArrayList; import com.dzone.refcardz.*; |
instanceof |
tests if an object is an instance of a class |
if (fred instanceof Student) value = ((Student) fred).getId(); Note: null instanceof T is always false |
int |
the 32-bit integer type |
int value = 0; |
interface |
an abstract type with methods that a class can implement |
interface Printable { void print(); } |
long |
the 64-bit long integer type |
long worldPopulation = 6710044745L; |
native |
a method implemented by the host system |
|
new |
allocates a new object or array |
Person fred = new Person("Fred"); |
null |
a null reference |
Person optional = null; |
package |
a package of classes |
package com.dzone.refcardz; |
private |
a feature that is accessible only by methods of this class |
see class |
protected |
a feature that is accessible only by methods of this class, its children, and other classes in the same package |
class Student { protected int id; ... } |
public |
a feature that is accessible by methods of all classes |
see class |
return |
returns from a method |
int getId() { return id; } |
short |
the 16-bit integer type |
short skirtLength = 24; |
static |
a feature that is unique to its class, not to objects of its class |
public class WriteUtil { public static void write(Writable[] ws, String filename); public static final String DEFAULT_EXT = ".dat"; } |
strictfp |
Use strict rules for floating-point computations |
|
super |
invoke a superclass constructor or method |
public Student(String name, int anId) { super(name); id = anId; } public void print() { super.print(); System.out.println(id); } |
switch |
a selection statement |
switch (ch) { case 'Q': case 'q': more = false; break; case ' '; break; default: process(ch); break; } Note: If you omit a break, processing continues with the next case. |
synchronized |
a method or code block that is atomic to a thread |
public synchronized void addGrade(String gr) { grades.add(gr); } |
this |
the implicit argument of a method, or a constructor of this class |
public Student(String id) {this.id = id;} public Student() { this(""); } |
throw |
throws an exception |
if (param == null) throw new IllegalArgumentException(); |
throws |
the exceptions that a method can throw |
public void print() throws PrinterException, IOException |
transient |
marks data that should not be persistent |
class Student { private transient Data cachedData; ... } |
try |
a block of code that traps exceptions |
try { try { fred.print(out); } catch (PrinterException ex) { ex.printStackTrace(); } } finally { out.close(); } |
void |
denotes a method that returns no value |
public void print() { ... } |
volatile |
ensures that a field is coherently accessed by multiple threads |
class Student { private volatile int nextId; ... } |
while |
a loop |
while (in.hasNext()) process(in.next()); |
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}