Licenciado
tech facts at your fingertips
Get More Refcardz! Visit refcardz.com
CONTENTS INCLUDE:
n
Java Keywords Standard Java Packages Character Escape Sequences Collections and Common Algorithms Regular Expressions JAR Files
n
n
n
Core Java
By Cay S. Horstmann
Java Keywords, continued
Keyword Description the part of a try block that is always executed the single-precisionfloating-point type a loop type Example see try
float oneHalf = 0.5F; finally float
n
n
AbOUT CORE JAVA
This refcard gives you an overview of key aspects of the Java language and cheat sheets on the core library (formatted output, collections, regular expressions, logging, properties) as well as the most commonly used tools (javac, java, jar).
for
for (int i = 10; i >= 0; i--)System.out.println(i); for (String s : line.split("\\s+")) System.out.println(s);
JAVA KEywORDS
goto
Note: In the “generalized” for loop, the expression after the : must be an array or an Iterable not used a conditional statement
if (input == 'Q') System.exit(0); else more = true; class Student implements Printable { ... } import java.util.ArrayList; import com.dzone.refcardz.*; if (fredinstanceof Student) value = ((Student) fred).getId();
Keyword
abstract
Description an abstract class or method
Example
abstract class Writable { public abstract void write(Writer out); public void save(String filename) { ... } }
if
implements
defines the interface(s) that a class implements imports a package tests if an object is an instance of a class the 32-bit integer type anabstract type with methods that a class can implement the 64-bit long integer type a method implemented by the host system allocates a new object or array a null reference a package of classes a feature that is accessible only by methods of this class a feature that is accessible only by methods of this class, its children, and other classes in the same package
assert
with assertionsenabled, throws an error if condition not fulfilled the Boolean type with values true and false breaks out of a switch or loop
assert param != null;
Note: Run with -ea to enable assertions
boolean more = false;
import instanceof
boolean
break
while ((ch = in.next()) != -1) { if (ch == '\n') break; process(ch); }
Note: null instanceof T is always false
int interface int value = 0;interface Printable { void print(); } long worldPopulation = 6710044745L;
www.dzone.com
Note: Also see switch
byte
the 8-bit integer type a case of a switch the clause of a try block catching an exception the Unicode character type defines a class type
byte b = -1; // Not the same as 0xFF
Note: Be careful with bytes < 0
case catch
long
see switch see try
native
newchar input = 'Q'; null class Person { private String name; public Person(String aName) { name = aName; } public void print() { System.out.println(name); } } package private
Person fred = new Person("Fred");
char
Person optional = null; package com.dzone.refcardz;
class
see class
protected
const continue
not used continues at the end of a loop the default clause of a switch thetop of a do/while loop the double-precision floating-number type the else clause of an if statement an enumerated type defines the parent class of a class
while ((ch = in.next()) != -1) { if (ch == ' ') continue; process(ch); }
class Student { protected int id; ... }
→
default
see switch
do { ch = in.next(); } while (ch == ' '); double oneHalf = 0.5;
Get More Refcardz
(They’refree!)
n n n
do
double
else
see if
enum Mood { SAD, HAPPY }; class Student extends Person { private int id; public Student(String name, int anId) { ... } public void print() { ... } }
n n n n
Core Java
enum extends
Authoritative content Designed for developers Written by top experts Latest tools & technologies Hot tips & examples Bonus content online New issue every 1-2...
Regístrate para leer el documento completo.