You are on page 1of 7

Index

%(modulus) operator, 17, 18 access control, 63-67 Arithmetic application, 17-18


&&operator, 26, 27 levels, 63 arithmetic operations, 17-18
8 operator, 27 levels illustration, 67 evaluation, 18
* (multiplication)operator, 17, package, 63 types, 17
18 packages for, 60 ArraylndexOut ofBoundsException,
+ (addition) operator, 17, 18 private, 63-65 72
+ (concatenation) operator, 13 protected, 63, 65-66 arrays, 14-I 6
<= (less than or equal to) public, 63 of arrays, 15-16
operator, 26 ActionListener interface, declaration, 14
< (less than) operator, 26 125-126 defined, 14
== (equals) operator, 26 actionYerformed method, 125, elements, counting, 15
i= (not equals) operator, 26 126 two-dimensional
>= (greater than or equal to) defined, 125 implementation, 16
operator, 26 implementation, 133 assert statement, 80-81
> (greater than) operator, 26 See also event handling; assertionError exception, 81
! operator, 27 interfaces assertions, 80-81
- (subtraction) operator, 17, 18 anonymous inner classes, 69, runtime checking, 81
/ (division)operator, 17, 18 129, 134 uses, 81
^ operator, 27, 28 applets, 135-141 within else clause, 81
I operator, 27 class file, 136
I I operator, 26, 27 defined, 1 blocks
display height, 136 defined, 9
abstract classes, 57- 59 display width, 136 nested, 9
abstract methods, 58 HTML tags, 136 synchronized, 165
constructor, 58 life cycle, 137 See also statements
defined, 57-58 life cycle methods, 140-141 boolean data type, 12
example, 58 security, 141 BorderLayout, 122-123
instantiation and, 58 Swing, 117, 138-140 creating, 122-123
See also classes application programming defined, 122
abstract keyword, 58 interfaces (APIs), 6 illustrated, 122
Abstract Windows Toolkit (AWT), applications, 1 See also layouts
6 argument passing, 39-42 break statement, 25, 30-32
classes, Swing and, 108 primitive, 40-41 defined, 30
GUIs, 107 reference, 41-42 example, 30-31

173
1 74 Index []

break statement (continued) JComboBox, 112 compilation, 2


label, 32 JDialog, 118 components
See also iteration statements JFileChooser, 119 background/foreground
buffered streams, 93-95 JFrame, 117 colors, 116
buffer size, 93 JLabel, 114 borders, 115-116
creating, 93 JList, 114-115 button, 108-109
See also streams JOptionPane, 118-119 check box button, 112
BufferedReader stream, 94-95 JPanel, 120 combo box, 112
defined, 94 JRadioButton, 113 defined, 107
example, 94-95 JScrollPane, 120 disabling, 116
BufferedWrit er stream, 93-94 JTextArea, 113-114 enabling, 116
defined, 93 JTextField, 113 fonts, 116
example, 93-94 with methods, 35-37 inheritance hierarchy,
flushing, 94 MotifLookAndFeel, 124 110-111
buttons, 108-109 with no methods, 34-35 label, 114
check box, 112 Object, 53-57 list, 114-115
creating, 108-109 OutputStream, 83, 84 methods, 115-116
example, 108, 110 packages, 60-63 model class, 107
radio, 112-113 RandomAccessYile, 98-101 radio button, 112-113
See also components Reader, 83, 84 text area, 113-114
byte data types, 11 state, 33 text field, 113
String, 53 view class, 107-108
CalculateProduct example, Thread, 157, 166 See also Swing
22-24, 25-26 TreeMap, 152, 154 conditional statements, 21-26
casting objects, 52-53 WindowsLookAndFeel, 124 else if, 23-24
catch statement, 72, 91, 97 wrapper, 47-48 embedded, 24
characters, 12-13 Writer, 83, 85 if, 21-22
handled by FileInput- ClassNotYoundException if else, 22-23
Stream/FileOutputStream, exception, 103, 104 switch, 24-25
9 close method, 87 constants, 9-10
handled by File- code reuse, 49 character, 12-13
Re ader/Fil eWri t er, CollectExample, 144-146 class, 10
92 Collection interface, 143-144 declared, as final, 9
special, 12 collections, 143-155 declared, as static, 10
check box buttons, I 12 defined, 143 integer, 10-11
Circle program, 7-8 list, 151-152 constructors, 37-38
class constants, i0 map, 152-154 abstract class, 58
classes Set interface, 143-150 default, 38
abstract, 57-59 Collections class, 154-155 defined, 37
adapter, 128-129 Collections Framework, 55, example, 37-38
behavior, 33 143 identifier, 37, 50
Collections, 154-155 class hierarchy, 145 inner class, 68
defined, 33 defined, 143 overloaded, 39
defining, 33 hierarchy illustration, 144 containers, 117-120
exception, 74-76 top-level interfaces, 143 applets, 117
Exception, 74, 80 combo boxes, 112 content pane, 117
Hasl~ap, 152-153 defined, 112 defined, 107
HashTable, 153 example, 109, 112 dialogues, 117-119
inner, 67-69, 129 lists vs., 114 frame, 117
InputStream, 83, 84 See also components intermediate-level, 117,
instances of, 33 comments, 8 119-120
JApplet, 117 Comparable interface, 148-150, layouts, 120-123
java. io. File, 86 155 panels, 119-120
JButton, 108-109 compareTo method, 148-149, scrollpanes, 120
JCheckBox, 112 150 top-level, 107, 117
II Index 175

windows, 117 format, 23 Yile0utputStream stream, 86,


See also Swing See also conditional 92-93
content pane, 117 statements characters handled by, 92
continue statement, 31 embedded conditional constructors, 92
CreateAccount application, expressions, 24 write method, 93
34-35, 38 encapsulation, 64 YileReader stream, 86-92
CreateBothAccounts class, 51 EOFException exception, 97 characters handled by, 92
CreateEmployee application, 40, equals method, 53-55 example, 90-91
41 example, 55 YileWriter stream, 86-92
code, 40, 41 overridden, 54-55 characters handled by, 92
output, 40, 42 properties, 54 close method, 87
createLineBorder method, 116 for testing object contents, 53 example, 86-87
createLoweredBevelBorder equivalence relation, 55 write method, 87-88
method, 116 event handling, 124-129 filter streams, 83
CreateSavingsAccount class, 50 ActionListener interface, functionality, 83
CustomerDetails example, 125-126 wrapping, 98
130-135 adapters in, 128-129 See also streams
class names, 124 float data type, 12, 19
data types, 10-16 defined, 124 flow control, 21-32
arrays, 14-16 ItemListener interface, YlowLayout, 120-121
boolean, 12 126-127 creating, 121
byte, 11 ListSelectionList ener defined, 121
character, 12-13 interface, 127-128 dynamically adjusted, 121
conversion, 18-19 exception classes, 74-76 illustrated, 121
double, 10, 12 creating, 75-76 See also layouts
float, 12, 19 Exception, 74, 80 for loop, 30
int, 10, 11, 19 specific, 75 frames
integer, 10-11 exceptions defined, 117
long, 11 Arr ayIndex0ut ofBounds- parent, 118
real, 11-12 Exception, 72 registering, 134
short, 11, 19 AssertionError, 81
string, 13-14 catch decision, 80 getAetionCommand method,
target, 19 ClassNotFoundException, 103, 125
DataInputStream stream, 97-98 104 getClass method, 55
class methods, 95, 98 creation, as subclasses, 80 getParameter method, 137
defined, 95 EOYException, 97 getSelectedItem method, 126
Data0utputStream stream, 95-96 YileNotYoundException, 91-92 getSource method, 125
class methods, 95, 96 handling, 71-74 getter methods, 65
defined, 95 hierarchy outline, 74 graphical user interfaces. See
example, 95-96 InterruptedException, 158 GUIs
defaultRead0bject method, 104 Invalid0bjectException, 104 GridLayout, 123, 133
defaultWrite0bject method, 105 IOException, 104 GUIs
deserialization, 103 NumberFormatException, 72 AWT, 107
destroy method, 141 propagation of, 76-79 developing, 107-141
dialogues, 117-119 runtime, 72, 79-80 examples created in Swing,
defined, 117 subclassing, 79 108, 109, 110
illustrated, 118 thrown, 74, 77 look and feel, 123-124
parent frame, 118 ValueTooSmallException, 101
See also containers hashCode method, 55-56
do while loop, 29 YilelnputStream stream, 86, defined, 55
double data type, 10, 12 92-93 example, 56
characters handled by, 92 overridden, 56
else i f statement, 23-24 constructors, 92 HashMap class, 152-153
defined, 23 FileNotFoundException HashTable class, 153
example, 23-24 exception, 91-92 hasNext method, 146
1 76 Index m

I/O, 83-105 instance0f operator, 57 Java


buffered streams, 93-95 instances argument passing, 39-42
implementations, 83 defined, 33 automatic garbage collection,
random access files, 98-100 inner class, 68-69 6
Terminal example, 85-86 methods, 44 case sensitivity, 3
identifiers int data type, 10, 11, 19 development environments, 3
constructor, 37, 50 integer data types, 10-11 exception handling, 71-74
defined, 9 interfaces, 59-60 features, 5-6
example, 9 ActionListener, 124, 125- as multithreaded language, 1,
IDEs (integrated development 126 6
environments), 3 Collection, 143-144 object wrapper class support,
compiling/nmning programs Comparable, 148-150, 155 6
in, 3 defined, 59 as object-oriented language, 6
complexity, 4 example, 59-60 release, 1
i f else statement, 22-23 ItemListener, 126-127 syntax, 7-19
defined, 22 List, 151-152 tools, 4-5
example, 22-23 ListSelectionListener, as "write once, run
format, 22 127-128 everywhere," 5
See also conditional Map, 152-154 Java Database Connectivity
statements methods, 60 (JDBC), 6
i f statement, 21-22 for multiple inheritance, 60 java interpreter
braces and, 22 Runnable, 160-164 classpath option, 62-63
defined, 21 Set, 143-150 defined, 5
example use, 21 SortedMap, 154 format, 5
format, 21 SortedSet, 147 functions, 5
See also conditional types of, 124 using, 2
statements WindowListener, 128 java. io. File class, 86
import keyword, 62 InterruptedException exception, Java Virtual Machines (JVMs)
inheritance 158 defined, 2
chains of, 52 Invalid0b j ectExc ept ion environments, 5
defined, 49 exception, 104 size, 5
multiple, form for, 60 IOException exception, 104 javac, 4-5
single, 52 isAlive method, 166 in 1.3 compatibility mode, 81
Swing component hierarchy, isSelected method, 126 classpath option, 62-63
110-111 ItentListener interface, 126-127 -d destination, 5
init method, 140 defined, 126 defined, 4
inner classes, 67-69 example, 127 options, 5
anonymous, 69, 129, 134 implementation, 133 -verbose, 5
constructor, 68 itemStateChanged method, javadoc, 8
defined, 67 126-127 JButton class, 108-109
embedding, 69 See also event handling; JCheckBox class, 112, 126
instances, 68-69 interfaces JComboBox class, 112, 126
local, 69 itemStateChanged method, JDialog class, 118
member variable access, 67 126-127 JFileChooser class, 119
schematic, 67 iteration statements, 28-32 JFrame class, 117
uses, 69 break, 30-32 JLabel class, 114
See also classes continue, 31 JList class, 114-115
InputStream class, 83 do while loop, 29 JOptionPane class, 118-119
defined, 83 for loop, 30 dialogue windows available
hierarchy, 84 while loop, 28-29 through, 118
instance variables, 42-43 Iterator object, 146 showMessageDialog method,
defined, 42 118-119
examples, 42 JApplet class, 117 JPanel class, 120
values, 42-43 jar files, 105, 141 JRadioButton class, 113
See also variables jar tool, 105 JScrollPane class, 114, 120
" Index 177

JTextArea class, 113-114 main method, 3, 77, 78 setBorder, 115


JTextField class, 113 MapExample, 152-153 setCharAt, 46
just-in-time compilers (JITs), 5 marker interface, 102 setEnabled, 116
member variables, 33, 34, 43 setFont, 116
keySet method, 153-154 inner class access to, 67 setYoreground, 116
keywords specifying, 45 setPreferredSize, 130
abstract, 58 methods, 35-37 setter, 65
import, 62 abstract, 58 showMessageDialog, 118-119
new, 76 accessor, 65 sleep, 163
super, 52, 58 body, 35 sort, 155
synchronized, 164 call stack, 77 start, 141,163
this, 45-46, 165 close, 87 static, 44-45
transient, 104 compareTo, 148-149, 150 stop, 141,164
createLineBorder, 116 subList, 152
labels, 114 creat eLoweredBevelBorder, t oString, 56- 57
layouts, 120-123 116 valueChanged, 128
BorderLayout, 122-123 declaration form, 35 void, 36
FlowLayout, 120-121 defaultReadObject, 104 write, 87-88, 93
GridLayout, 123 defaultWriteObject, 105 writeChars, 100
types of, 120 defined, 35, 33 MotifLookAndYeel class, 124
See also containers destroy, 141 Multiply class, 71, 72-73
length method, 99 equals, 53-55 Multiply. html, 135
List interface, 151-152 example, 35-36 Multiply. java, 1-4
ListIterator, 152 example statements using, 37 code, 1-2
methods, 151 exiting, 36 defined, 2
subList method, 152 getActionCommand, 125 as standalone application, 2
listener interface, 124, 169-171 getClass, 55 MultiplyApplet
lists, 114-115 getParameter, 137 Applet viewer invoking, 138
as collection, 151 getSelectedItem, 126 code, 136-137
combo boxes vs., 114 getSource, 125 constructor, 140
creating, 115 getter, 65 defined, 135
defined, 114 hashCode, 55-56 Internet Explorer invoking,
list model, 114, 115 hasNext, 146 139
selection model, 114 1nit, 140 Swing version, 139-140
See also components instance, 44 MultiplyClass class, 75, 76-77,
ListSelectionListener interface, mvocation syntax, 37 78, 79-80
127-128 isAlive, 166
defined, 127 isSelected, 126 new keyword, 76
example, 128 itemStateChanged, 126-127 next method, 146
valueChanged method, 128 keySet, 153-154 NumberFormatException, 72
See also event handling; length, 99
interfaces mutator, 65 Object class, 53-57
local inner classes, 69 next, 146 defined, 53
logical operators, 26-28 overloading, 39 equals method, 53-55
listof, 27 overriding, 49, 50, 52 getClass method, 55
output, 27-28 paint, 137 hashCode method, 55-56
precedence, 26, 167 paintComponent, 129 toString method, 56-57
use of, 27 readChar, 98, 100 See also classes
long data type, 11 readFloat, 98 ObjectlnputStream stream, 101,
loops remove, 146 103
do while, 29 repaint, 163 defaultReadObject method,
for, 30 reverse, 155 104
inner, 31 run, 160, 164 defined, 101
nested, 31 seek, 99, 100 ObjectOutputStream stream, 101,
while, 28-29 setBackground, 116 103
| ~8 Index I

objects strategy, 64-65 seek method, 99, I00


casting, 52-53 See also access control Serializable interface, 102
contents, testing, 53 protected access, 63, 65-66 serialization,101-105
defined, 33 defined, 65 controlling, 104-105
YileReader, 86 example, 65-66 defined, 101
FileWriter, 86 See also access control deserialization and, 103
initializingstate of, 27 public access, 63 static variables and, 102
Integer, 47, 48 topics, 101
Iterator, 146 radio buttons, 112-113 servlets, 6
PrintStream, 86 example, 109, 112 Set interface, 143-150
serialization,101-105 groups, 112-113 defined, 143
String, 13-14, 47, 48 setting default, 134 methods, 143-144
StringBuffer, 46 See also components setBackground method, 116
SynchronizedSumming, 165 random access files, 98-100 setBorder method, 115
throwable, 76 reading from, 100 setCharAt method, 46
wrappers, 47-48 writing to, 99-100 setEnabled method, 116
OneToTwenty applet, 161 RandomAccessYile class, 98-101 setYont method, 116
operator precedence, 26, 167 constructor, 99, 100 setYoreground method, 116
OutputArray program, 15, 29 defined, 98 setPreferredSize method, 130
OutputStream class, 83 length method, 99 setter methods, 65
defined, 83 readChar method, 100 short data type, 11, 19
hierarchy, 84 seek method, 99, 100 showMessageDialog method,
OutputStreamWriter stream, writeChars method, 100 118-119
88-89 ReadAccount program, 103 sleep method, 163
characters written to, 89 ReadBinYile example, 97 Software Development Kit (SDK),
defined, 88 ReadBufYile example, 94-95 3, 124
readChar method, 98, 100 defined, 3
package access, 63 Reader class, 83, 84 tools, 4-5
packages, 60-63 ReadYile program, 90-91 sort method, 155
for access control, 60 readYloat method, 98 Sorte~ap interface, 154
defined, 60 ReadRAYexample, 100 SortedSet interface, 147
documentation, 62 ReadWriteYile example, 92 start method, 141,163
hierarchies, 61 real numbers, 11-12 statements, 8-9
naming convention, 62 relational operators, 26 blocks, 9
prefix, 62 remove method, 146 conditional, 21-26
Sun Microsystems-supplied, repaint method, 163 defined, 8
62 reverse method, 155 example, 8
supplied, 62 RMI (Remote Method Invocation), iteration, 28-32
See also classes 101 static methods, 3, 44-45
paint method, 137 run method, 160, 164 defined, 44
paintComponent method, 129 Runnable interface, 160-164 identification, 44
PaintPanel example, 129-130 applet class declaration, 162 instance variable access and,
panels, 119-120 defined, 160 45
agePanel, 134 implementation, 162, 164 static variables, 43-44
defined, 119 run method, 160 defined, 43
freqPanel, 133 specification, 160 example, 43
PerformTransaction interface, 60 RunThreads program, 158-159 prefix, 44
polymorphism, 39, 50 runtime exceptions, 72, 79-80 serialization and, 102
PrintNumbersThread program, defined, 79 See also variables
158 example, 79-80 stop method, 141, 164
PrintStream object, 86 use of, 80 streams, 83
PrintWriter stream, 89-90 buffered, 93-95
private access, 63-65 SavingsAccount class, 49-50 BufferedReader, 94-95
defined, 63 scrollpanes, 120 BufferedWriter, 93-94
example, 63-64 security, applet, 141 byte, 101
II Index 1 79

DataInputStream, 97-98 Terminal I/O example, 85-86 variables, 9


DataOutputStream, 95-96 text areas, 113-114 character, 12-13
YileInputStream, 86, 92-93 default, 114 declaring, 9
YileOutputStream, 86, 92-93 defined, 113 defined, 9
FileReader, 86-92 example, 109, 113 as identifier example, 9
YileWriter, 86-92 See also components instance, 42-43
filter, 83 text fields, 113 integer, 10-11
ObjectInputStream, 101, 103 this keyword, 45-46, 165 local, 4 5
ObjectOutputStream, 101, 103 Thread class, 157, 166 member, 33, 34, 43, 45
OutputStreamWriter, 88-89 YhreadedNumbers applet, 162 private, 68
PrintWriter, 89-90 ThreadForEver applet, 163-164 as references, 46
String class, 53 threads, 157-166 static, 43-44
String object, 13-14, 47, 48 alive, 166 Vectors, 47
StringBuffer object, 46 dead, 166
strings, 13-14 defined, 157 while loop, 28-29
declaring, 13 execution delay, 157 example, 29
defined, 13 finite applet example, syntax, 28-29
immutability, 14 161-163 See also iteration statements
subclasses, creating, 49-53 infinite applet example, WindowListener interface,128
subList method, 152 163-164 windows, 117
SumOddArguments program, 30-31 new, 166 WindowsLookAndFeel class,124
SumSomeArguments program, not runnable, 166 wrapper classes,47-48
31-32 priorities, 160 write method, 87-88, 93
super keyword, 52, 58 runnable, 166 WriteAccount program, 102
Swing, 6 starting, 160, 163 WriteBinFile example, 95-96,
applets, 117, 138-140 states, 166 98
AWT classes and, 108 synchronizing, 164-165 WriteBufFile example, 93-94
components, 107-115 toString method, 56-57 writeChars method, 100
concepts, 107 defined, 56 WriteFile example, 86-88
containers, 107, 117-120 example, 57 WritePrintFile program, 89
event handling, 107 explicit invocation, 56 Writer class,83, 85
events, 169-171 implicit invocation, 56-57 WriteRAF example, 99
painting with, 129-130 transient keyword, 104
See also GUIs transitive closure, 104
switch statement, 24-26 TreeMap classes, 152, 154
example, 25-26 try statement, 72
format, 24-25
synchronized keyword, 164 valueChanged method, 128
SynchronizedSumming class, ValueTooSmallException
164-165 exception, 101

You might also like