Скачать как pdf или txt
Скачать как pdf или txt
Вы находитесь на странице: 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) {
�� float:���������������������������������������������� � 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ʼ:
������������
�� �������� ���������� ������� ������ ����� ��� �� ��������� ������
String������������String������������������������������������������
������������������������������������������� 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!”; break�����continue������������ �����������
������������������������������������������������������������ �� 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)) {
����������
LinkedList�����MyAmazingClass� �� 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.” );}
���������������������������������������������int����double�� �������������������������������������������������������������� Object����
������������������������ ���������������true� ������������
�����StringTokenizer�������������������������������������
�� do { ����������
����������������������������������������������� if�� ������� ������ ���������������� �������� ��� if�� ������ ��� ����
execute code statements here � ������
������ ��� �� ������������ ���������� ���� ���� ��� ����� ��������
������������������������������������������������� } while (condition); �� publi
������������ ���� ������������ ����� ��������� ��� �� boolean�� ����
�� type varName; � �������� �� publi
���������������������������������������

�������� ����������� ���� ������������� ��������� ��� ���� ������


��������������������������������������

�� type varName1, varName2, varName3 ... ;


������������������������������������

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


��������������������true��������������������������������false�
� ��������� boolean heads; ��������
�� if (condition) {
�� boolean trueOrFalse; do { �������
����������������������������

execute code statements here }


��������������������������������������

�� float cost, revenue, profit; myCoin = myCoin.flip();


�� InputStream myInputStream; if/else ������if���������������������������������������else� ������� ����
heads = myCoin.getFace();
������������
�� ��������������������������� final����������������������������� ���������������������������������������������������������� } while (!heads);
�����������
������������������������������������ ��������� ���������� if� ���� ��������� ��� ���� ������������ ������
������������������
��������������������

for�� ���� for� ���������� �������� �� ������ ��� ����� �������� ��� ��� ��������
��������true�����������������������������else�����������������
������������������������������������ ����������������������������� 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 five.”); ���������������������������
� ��������� ����������
else if (number == 5) �� for (initialization; condition; increment) {
�� number = 3; ����������
System.out.println(“Equals five.”); execute code statements here }
�� letter = ʻDʼ; /* use single quotes to denote a ����������
else � ���������
Unicode character */ ��������
System.out.println(“Greater than five.”); �� int x = number; // assign x the value of number
�� bool = true; ����������
� // counts down from the current value of x to 0
����������������������������������������������������������������� switch ������switch����������������������������������������else� ���������
for ( ; x > 0 ; x-- )
��������������������������������������������������������� if�����������������switch������������������������������������ ��������
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 first 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-
������������������������������k����k.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 ��������� ������ ��������� ���� ����������� ��� ����������� ����� � ���������array����������������obj�
��������������������������������������������������������������� �������������������������� �� equals(Object[] array1, Object[] array2)
��������������������������������������������������������������� ���������������������������������������[]��������������������� �� ��������true����array1��������array2�
�������������������������������������������������������������� ����������������������������������������������������������� �� fill(Object[] array, Object obj)�
atements here �������������������������Object��������������������������������� �� arrayName[index] � ������������������obj��������������������array�
����������������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
Object����������������������������Object� ���������������������������������������������������������������
(); ���������������������������������������� 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
����� ��� ���� ��������� ��������� ���������� ������� ������ ������ �����������������������������������������������������������
�������������������������������������������������
����������
���� �� ������� ���������� ����� ��������� ��� �� ���� ��� ����������� ��������������������
���������
��������� ��� ������������� ���� ������������ ������� �� ������� ������� ����������� ���� ������� ���������� ������ �� ��������� ��������������������������������������������������� ����������
�������������������������������������������������������������� ������� ����������� ���������� ��� �������� ����� ������� �� ���������� ������� ����� �� ���������� ����� ��� ������� ��� �� ���������
���������������������������������������������������������� ���������� ��������� ��� ���� ����� ��������� ��� �� ����������� �����������������������������������������������������������
��������������������������������������������������������������� �����������
������������������������������������������������������������� ���������� ���� ������� ������ ��� ���� �������� ����� ��������
���������������������������������������������� �����������
��� ������� ����������� ���� ������ ������� �������������� ����� ���� �����������������������������������������
� Modifiers returnType methodName (Parameters) { �����������
������������������������������������������������������������� �� ���������� ������� ����� �� ���������� ����� ��� ������� ��� ��
method body here } ������ ������
��������������������������������������������������������� �������� ����� ���� ������ ��� ���� ��������� ���������� ����� ����
��������� �
�������� � ������� ���� ���� ���� ����� ������������ ����� ������ �� ������������������������������������������������ ������� �������� ��� ������� ���� ����� ��� ���� �������� ��� �����
�����������
������� ��� �������� ����� �������� ����������� ��������� ���� ���� � ��������� ������ ���� �������� ��� ���� ������� ��� ������ ���� ������ �������
�����������
��������������static��final������synchronized� ��� 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) {
�� ���������������������������������������public��private�� �������������������������������������������������������������� number = startNumber; } �������
��� protected� ��� ����������� ����� ��� �������� ��� ���� ����� ����� ��� ����� ��������� ��������� ���� �������� ���� ���������� }
�������� ��� ���� ����������� ������� �� ������ ���� ���������
���������
���������������������������������������������������������������
�������������������������������������������������� ������� ������������� ���� �������� ��� ���� ����� ������ ���� ����������
�������������������������������������������������
�� Static� �������� ��������� ������������ ��� ���� ��������� ����� ���� ����� ����� ��� ����� ��� ������ ������� ����������� ���� �����������
�� object.method (parameters);
������������������������������������������������������������ ������������
��������������� ��� �� �������� ����� ���� ������� ����� ������� ������ �� class.method (parameters);
������������������������������������������������������������ ����������
������� ����� ������ ������������ ��� ���� ��������� ��������������� �� object.method1(parameters).method2(parameters) ... ;
���� ����������� ��������� ����� ��������� ���� ������� ������ ���������
��������������������������������������������������������������� ������������this�������������������������������������������������
���������������������������������������������������������������� ����������������������������������������������������������������� ���������� �������� ����� ��� ���� ������� ������������ ���� ����
������� �������� ���� ���� �������� ������� �������� ����� �������
���
������������������������������������������������������� ����������������������������������� this�������������������������
�� Final� �������������������������������������������� Final� ���������������������������������������� ���� ������� ����������� ���� ���������� ����� ���� ������������
������������������������������������������������������������ �� this.myMethod(); ���� ����� ������ ��� �������� �������� ��������� ����� �������� ���� �����
final���������������������������������� �� myMethod(); ������� ����� ��� ����� ����� ���� ������ �������� ������� ����� ���� �����������
�� ������������� �������� ���� ����� ����� �� �������� ��� ������������������ ���������
�������� ��������� �������� ��� ����������� ����� ���� �������
����������������� �� public class Thing { �����������
��������� synchronized� ���� ��� �������� ��� �� ������ ���� ������������������������������������������������������ � int size; ��������
���������������������������������������� ���� ����� �������� ������������������������������������������������ final int DEFAULT_SIZE = 20; ���������
������������������ ���������������������������������� private Thing(int s) { �����������
�� changeColor(Color.RED); /* red is a final field 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� �������� ��� ����� ��� ������ ��� ���� ������������ Runnable��Throwable������Observable ������������������
������������������� ����������� 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
�������� ������������ ����������� ���� �������� ����� ����� ���������
������� ��������� �������� ���� ���������� ����� ��� ��� ������
����������������class���������������������interface� FilterIn
public class Triangle extends Polygon {
��������������������������������������������������������������� ���������
final 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/finally�� ���������� ��������� ��� ����� �������� ���� ����������������������������������������������������������������
��� ���������
����java.lang.Exception��������������������������� try� ���� catch� ������������ ����� ����� ������ ��������� ��� �������������������������������������������������������������
����� �������
������������������������������������������������� ���������������������������try���������������������������������� �� try/catch ��������������������������������������������������
��
������������������������������������������������� ���������������try�������try���������������������������������� ���� �������� �������� ���� ���������� ��� ����������� �������� ����
������ ���������������������������������������������������� ���� ��� ����� catch� �������� ����� ��� �������� �� ����� ��� ������� ������� ����� ������ ������ ��� �������� ���� main� �������� ��� �����
������� ��� �� ���������������������������������������������� ������������������������catch ����������������������������� ���������������������������������������������������������������
������������� Exception� ��� ������������� ��������� ����� ��� ���� try� ������ �����������������������������������������������������������������
����������� ���� �������� ���� java.lang.Throwable� ������ ���� ����� ������������ ��������� ��� ���� �� �������� ���������� �����
���� �������� ��������������������������������������������������������������
�������������������������Exception�����Error����������������� ����� ���� ����������� ������� ��� ������� ������� ����� ����������
���������������������catch�������
���������������������������������������������������������� �����������������������
������� ��� ��

��
�� try {

�����������
������ �������� ������ ��� ������� ���� �������� �������� ��� ���� ����
���� ����� ���� exception generating code here
��������� ����������� ���� ��������� ����� ������ ���� �������� �������������������������������������������������������������
������ ��� ����� } catch (Exception1 e1) { exception handling code
������������������������������������������������������������� java.lang.Exception������������������������������������������
������ ������� here
����������������������������� �������������������������������������������extends�Exception�
������������� } catch (Exception2 e2) { exception handling �������������������������
����� �������� �������� ���� ���������� ������������ �� RuntimeException� code here � ��������
�� ������������ �java.lang.RuntimeException �� ��� �� ����������� ��� } ... �� public class myException extends Exception { ... }
RuntimeException� ��� ����������� ��� ���������� ����������� ���������������������������������������������������������������
�������� ������ ��� ��� ������� ��� ��������� ���� ��������� ������� ������������������� ��������������������������������������������������������������
������� ����
���������� �������� ���� ���������� ������ ��� �������� ����� ����� ���������������������������������������������������������������
w������������� ��finally����������������������catch���������������������������
���������������������������������������������������������� ���������������������������������������String����������������
���������������� ����������������������������������������������������finally�������
����������������������������������������������������������������� ��������������������������������������������������������������
�������������� ������������������������������������������������������
�������� ������������ �������� ����� ���� ��������� ����� ������ ������������������������������������������������String�
���������� �� try {
���������������������������������������������������������� � ��������
exception generating code here } �� public class myException extends Exception {
����������������������������������������������������������������
catch (Exception e) { exception handling code here } String data;
����������������������������������������������������������
finally { public myException (String someData) {
���������������������������������������������������
clean-up code here } super(“Exception involving ” + someData);
������������������ data = someData;
������������ ������������ ���� ���������� ����� ��� ���� �������
������������������������������������������������������� ������������������������������������������������������������ }
��� ������ ���� ����������������������������������������������������� ����������������throws��������� }
��������� ���� ��������������������������������������������������� � ��������
��������������������������������������������������������� ������������toString()�����������Exception�����������������
������������ �� public void findCar(Car c) throws NoCarException,
�������������������������������������������������� Object �������������String������������������������������������
�������������� MyException
����������������������������������������� null�� ������������� ����� �� String� ���������� ���� ������� ����
����� ������
�������������������������������������
���� ���� ����
�� ����� �������
� ������������
���� ���� �����
������������
���� ����� ���� ��������������������������������������������������� ��������� ������� �������
�������������������������������������������������� ���������������������������������������������������������� �����������������������������������������������������
��������������������������������������������������������� ����������������������������������������������������� ����������������������������������������������������
�������������������������������������������������� ������������������������������������������� ���������������������������������������������
����������������������������������������������������� �� Vector ���� ArrayList� ���� ���������������� ��� ����������������������������������������������������
�������������������� ��������� �������� ������� ArrayList�� Vector� �������� ���� ��������������������������������������������������
�������������� ������� Vector� ����������� ���� ������������� �����������������������������������������������������
������ ��� ArrayList ����������������������������� ������������������������������������������������������
���������������������������������������������������� �� Hashtable ����Hashmap ���������������������������������� ��������������������
������������������������������������������������ ���������� �� MouseEvent� ��� ��� ������� ���������� ��������� ���� ������
�������������������������������Object��Method��Class�� �� Stack������������������������������� ������ ��� ��������� ���� ������ ������� ��� ��������� ����
System �������������������������������������������� �� LinkedList ���� Iterator�������������������������������� MouseListener ���� MouseMotionListener� �����������
���������������������������������������������������� ����������������������������������������������������LinkedList �����������MouseEvent��
���������������������������� ��������������������Iterator� �� ActionEvent� ��� ��� ������� ���������� ��� ����������� �����
�� Object� ��� ��� ���� ����� ��� ���� ������ ����������� ���� �������� �� Date� ����������� �� �������� ������ �������� ��� ���� �������� ��� Button����� CheckBox�������� ActionListener�����������
��������������������������������������������������������� ������������ ������������ActionEvent��
������ ���� �� Math ����StrictMath��������������������������������������� �� GregorianCalendar�������������������������������� �� KeyEvent� ��� ��� ������� ���������� ��������� �� ����������

������������������������������
���� ��������� ������ ������������� ����������� ���� ���� �������� ���� ����� �� EventObject ��� ���� ����� ������ ���� ���� ������� ����� ������������KeyListener�������������KeyEvent��
t������������ ��������� ���� StrictMath� ��� ����� ���������� ��� �������������� java.awt.event �� �� WindowEvent� ��� ��� ������� ���������� ��������� ���� �������

�����������������������
���������� ��� �������������������������������������������������� �� Timer ������� ������������� ��� ��������� ���������� ��� ��� �� ������� �������� ������� ����� �� ������� ��� ������� ���
������ �� Boolean�� Character�� Double� Float ���� Integer� ���� ��������� ������������ ���� WindowListener� ���������� ��������� ���

������������������������������������������������������������������
������������������
�������� ��������� ����� ��� ������ ���������� ������ ��� ��������� �� StringTokenizer� ������� �� ������� ����� �������� ������� WindowEvent��
����� �������� �������� ���� ������������ �������� Strings� ������� ��� �������� ����������� ����������� ������ ������ ���
���������� �������������������������������� ����������������������������������������������������������� ���������������
��� �� System� ���������� ���� ��������� ������� �������� ���� ������ ����������������������������������
���� �������������Pattern�����Matcher���������������������
�����������������������������������������������System ����� �� Random� ����������� �� ������������� ������� ����������� ��������������������������������
����� ������������������������������������������ ���������� ��� ���� ������� �������� ��� �������� ������� �� �� Pattern���������������������������������
��������� �� String ���� StringBuffer� ���������� ���������� ��������� �� ��������� ����� ������� ��������� ��������� ��� ��������� �� Matcher�����������������������������������������Pattern����
���������


������������������������������������������� ��������������������������������������������������������� ���������������������������
��
�������������������������
�� Thread� ����������� �� ������� ��� ����������� ����� ��� �� ������ �����������������

����� �����
�������������� ���������������������������������������������������������� ���� �������
�������������� ���������� ������� �
����������������

���������������������������������������������������
������������� ����������������������������������������������� �������������������������������������������java.awt�
�������������� ������� ������������������������������������������������������ ��������������������������������������������
�������� ������������������������������������������������������ �����������������������java.awt������������������� ��������������������������������������������������
������������������������������������������������� ��������� �������������������������������������������������
rWheelDrive, ���������� �� Graphics� ��� ���� ����� ������ ���� ���� ���������� ������������ ���������������������������������������������������
�� File ����������������������������������������� ��� ��������� �������� ���� �������� ������� ���� Strings� ���������������������������������������������������
����������� �� InputStream� ����������� �� ������� ��� ��������� ����� ��� �� Canvas� �������� ���� Graphics2D� ������ extends� ���� ��������
���������� ������ ��� ��� ��� ��������� ������� ����������� ��� ����� Graphics��������������������������������� �� JComponent� ��� ���������� ��� ��� ���� Component�� ��� ��� ����

����������� �������� ��� FileInputStream�� FilterInputStream�� �� Component� ����������� �� �������� ������� ����� ���� ����� ���� ����� ������ ���� ���� ��� �������� ���������� ��������� ����� ���
ObjectInputStream�� ���� PipedInputStream�� ������������������������� Button�� Label����� Scrollbar��������� JButton��JFrame�����JLabel�
����� ���������
FilterInputStream ��� ����� ����� ��� �������������� ��� �� �������������Component� �� JPanel ����JFrame���������������������������JComponent��
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

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