Вы находитесь на странице: 1из 4

// sort

for (in
char
case for
boolean b = false;

double d = Math.sqrt(2); default




int x = 0, y = 0, z = -2; switch
char ch = X, int i = 5; // syntax error!!!
switch (variable) {
new
case value1: }

execute code statements here }

break;
boolean
case value2:

execute code statements here
cal = new Calendar();
break;
boolean: Hashtable ht = new Hashtable();
...
char: thread = new Thread( target );
default:
byte:
execute code statements here
short:
}
int:
type []
long: Calendar cal = new Calendar();
switch (ch) {
oat: Integer i1 = new Integer( 5 ), i2 = new Integer( -1 );
case y:
double: Thread t1 = new Thread( runnable1 );
System.out.println(Yes!);
boolean int
break;

case n:


StringString
String
System.out.println(No!);
break;

String default:
System.out.println(Invalid input!);
}


String str = new String(Hello world!);
String str = Hello World!;
(type) variableName String while do for
type variable = (type) expression; String.concat(String str) + break continue break
concat() continue


String str = Hello + world!; breakcontinue
String str = Hello.concat( world!);
while while
String s1 = Hello;

String s2 = world!; abstrac

Boolean String str = s1 + s2;
true

while (condition) {
class
execute code segments here }
public static void priva

main (String[] args)
int x = number; // assign x the value of number

// counts down from the current value of x to 0
50495



if (x <= 0)

System.out.println(Invalid value for x: + x);
return
else

while (x != 0)

System.out.println(--x);

ISBN 1-58663-916-1

System.out.println( x equals 0 );
9 781586 639167

switch // picks random numbers r, stops when 0.6 < r < 0.7 Object
double r = Math.random(); Object
Date while (!( r > 0.6 && r < 0.7)) {

LinkedListMyAmazingClass if (x < y) System.out.println( r );

System.out.println(x is less than + y); r = Math.random(); }

if (isTrue) {
do do while
x++;
do
System.out.println(Added one to x. );}
intdouble Object
true
StringTokenizer
do {
if if
execute code statements here

} while (condition); publi
boolean
type varName; publi

type varName1, varName2, varName3 ... ;


/* ips a coin, stops when the coin is heads (true) */


truefalse
boolean heads;
if (condition) {
boolean trueOrFalse; do {

execute code statements here }


oat cost, revenue, prot; myCoin = myCoin.ip();


InputStream myInputStream; if/else ifelse
heads = myCoin.getFace();

nal } while (!heads);

if

for for
trueelse
false

if (condition) {
for ( ; ; )
execute code statements here }
else { for

execute other code statements here }





=
if (number < 5) true
variable = value;
System.out.println(Less than ve.);

else if (number == 5) for (initialization; condition; increment) {
number = 3;
System.out.println(Equals ve.); execute code statements here }
letter = D; /* use single quotes to denote a
else
Unicode character */
System.out.println(Greater than ve.); int x = number; // assign x the value of number
bool = true;
// counts down from the current value of x to 0
switch switchelse
for ( ; x > 0 ; x-- )
ifswitch
System.out.println(x);
type varName = value; System.out.println(x = 0);

This downloadable PDF copyright 2004 by SparkNotes LLC. SPARKCHARTS JAVA Papers page 1 of 4


// sorts a char array k using bubble sort length 1


for (int i = 0; i < k.length(); i++) { java.util.Vector java.util.ArrayList String s = args[0] /* references the rst param-
char temp; eter on the command line */
case for (int j = i; j < k.length() - 1; j++) { File myFile = directory[k] /* references the

if (k[j] > k[j + 1]) { (k 1)th element of directory */

temp = k[j];
k[j] = k[j + 1];
int[] digits = new int[10];
k[j + 1] = temp; java.util.Arrays
File[] directory = new File[myDir.getSize()];
}
Object[] array = new Object[SIZE]; /* This array
} length length
will hold instances of any class, but will not
atements here }
hold primitive types. In order to store a primi-
kk.length - 1
tive type in this array, use a wrapper class such
binarySearch(Object[] array, Object obj)
as java.lang.Boolean or java.lang.Double. */
atements here arrayobj
equals(Object[] array1, Object[] array2)
[] truearray1array2
ll(Object[] array, Object obj)
atements here Object arrayName[index] objarray
new sort(Object[] array)
type [] arrayName = new type [size];
length 1
ArrayIndexOutOfBoundsException Comparable

tln(Yes!);
ArrayIndexOutOfBoundsException

tln(No!);

tln(Invalid input!);
Math
double cos = Math.cos( angle );

double rand = Math.random();





continue break
class Car {
ontinue
class Transmission {

code for Transmission here

}
class
more code for Car here
class
}
static

abstract




new
class myClass { ... }
nts here }
private class Node { ... }
import
ign x the value of number Dice rollDice() {

e current value of x to 0 return new Dice() {
import
int number = (int)( Math.random() * 6 ) + 1;
Invalid value for x: + x); };

import myClass /* myClass is in the same direc- }
tory as the current class */
tln(--x); Object
import java.util.StringTokenizer;
x equals 0 );
Object import
r, stops when 0.6 < r < 0.7
ObjectObject
(); static

< 0.7)) {

tln( r );
import java.io.*; /* A class headed by this
(); }
statement can refer to any of the classes in
while the java.io package. */
do java.lang.Object
Object Object
equals(Object obj) true obj
extends



ents here true
public class Rectangle extends Polygon { ... } package
obj
public class Square extends Rectangle { ... } equals()hashCode()
Object
en the coin is heads (true) */ == Objects
package packageName;
equals()true

java.util.regex
(); getClass()
static
ace(); hashCode()
import java.util.*
java.util.regex clone()
Cloneable
toString() String

java.lang.Math


for ( ; ; )



dition; increment) {
for while
ments here }


ign x the value of number

e current value of x to 0
for

x);

0);

This downloadable PDF copyright 2004 by SparkNotes LLC. SPARKCHARTS JAVA Papers page 2 of 4







java.l












Modiers returnType methodName (Parameters) {

method body here }






staticnalsynchronized public static void main(String[] args) { ... }
public private Iterator getIterator(List list) { ... }
private protected public double distance(Point p1, Point p2) { ... } java.lang.
public double 3dDistance RuntimeExc
(Point p1, Point p2, Point p3) { ... }

public protected syncronized void holdThread
new
(int milliseconds) { ... }



private


public class Count {
protected
int number;


public Count(int startNumber) {
publicprivate number = startNumber; }
protected }





Static
object.method (parameters);

class.method (parameters);

object.method1(parameters).method2(parameters) ... ;

this



this
Final Final
this.myMethod();
nal myMethod();


public class Thing {
synchronized int size;
nal int DEFAULT_SIZE = 20;
private Thing(int s) {
changeColor(Color.RED); /* red is a nal eld of size = s;
the Color class */ }
double vol = myPrism.getVolume(height, width, public Thing() {
return
length); new Thing( DEFAULT_SIZE );

}
return
}
void System


Object

Math

java.lang.Object abstract

Boolean
Object



System

extend
super RunnableThrowableObservable
super() String

super.name name
super.myMethod() myMethod() Thread
extends




public class Polygon throws Exception { implements

int sides;


public Polygon(int n) {
sides = n; class Suburban extends Car implements FourWheelDrive,
if (n < 3) throw TooFewSidesException} SixCylinder File

InputStr
public int angleMeasure() {
return 180 * (sides - 2); }
} ObjectIn


classinterface FilterIn
public class Triangle extends Polygon {

nal int SIDES = 3; public interface Runnable { ... }

public interface MouseMotionListener { ... } OutputSt
(className) variable; public Triangle() {
className variable = (className) expression; super(SIDES); }
} ObjectOu
FilterOu
Object

Reader
public interface Runnable {
public void run() {}
Buff
}
StringRe
public interface MouseMotionListener {
Writer
public void mouseDragged(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
Buff
} StringWr

This downloadable PDF copyright 2004 by SparkNotes LLC. SPARKCHARTS JAVA Papers page 3 of 4


try/catch/nally

java.lang.Exception try catch

try try/catch

trytry
catch main
catch
Exception try
java.lang.Throwable

ExceptionError
catch


try {



exception generating code here

} catch (Exception1 e1) { exception handling code
java.lang.Exception
here
extendsException
} catch (Exception2 e2) { exception handling
RuntimeException code here
java.lang.RuntimeException } ... public class myException extends Exception { ... }
RuntimeException



w nallycatch
String
nally


String
try {

exception generating code here } public class myException extends Exception {

catch (Exception e) { exception handling code here } String data;

nally { public myException (String someData) {

clean-up code here } super(Exception involving + someData);
data = someData;

}
throws }

toString()Exception
public void ndCar(Car c) throws NoCarException,
Object String
MyException
null String











Vector ArrayList
ArrayList Vector
Vector
ArrayList
Hashtable Hashmap
MouseEvent
ObjectMethodClass Stack
System LinkedList Iterator MouseListener MouseMotionListener
LinkedList MouseEvent
Iterator ActionEvent
Object Date Button CheckBox ActionListener
ActionEvent
Math StrictMath GregorianCalendar KeyEvent


EventObject KeyListenerKeyEvent
t StrictMath java.awt.event WindowEvent


Timer
Boolean Character Double Float Integer WindowListener



StringTokenizer WindowEvent
Strings

System
PatternMatcher
System Random
Pattern
String StringBuffer MatcherPattern


Thread


java.awt

java.awt

rWheelDrive, Graphics
File Strings
InputStream Canvas Graphics2D extends
Graphics JComponent Component

FileInputStream FilterInputStream Component


ObjectInputStream PipedInputStream Button Label Scrollbar JButtonJFrameJLabel

FilterInputStream Component JPanel JFrameJComponent
rface
BufferedInputStream Container Component JComponent
OutputStream ImageIcon Image Icon Icon
... }
javax.swing
FileOutputStream FilterOutputStream Window BoxLayout OverlayLayout
ObjectOutputStream PipedOutputStream Point
FilterOutputStream
BufferedOutputStream Polygon setLayout(LayoutManager)
Reader
Color
BufferedReader FileReader PipedReader
StringReader Color int
Writer
t e) {}
e) {} BufferedWriter FileWriter PipedWriter
StringWriter

This downloadable PDF copyright 2004 by SparkNotes LLC. SPARKCHARTS JAVA Papers page 4 of 4

Вам также может понравиться