View
0
Download
0
Category
Preview:
Citation preview
795
Symbols! operator 142!= operator 142, 146& operator 142, 145&& operator 143, 146* operator 142*= operator 143+ operator 142++ operator 142, 143, operator 147/ operator 142/= operator 143<%! tag> 712<%= tag> 712<> operator 601< operator> 601= operator 143, 146, 601== operator 142=> operator 142> operator 601>= operator 601>> operator 144>> operator 142? operator 143, 146^ operator 142, 145| operator 143|| operator 143, 146~ operator 142
Numerics1.5, see JDK 1.516-bit
ASCII, String, and binary 400
character output 403streams, why not use 406UCS transformation format
456Writer class 398, 399
4-layer TCP/IP model 6455K contest 75664-bit compatible 457-layer ISO model 6448-bit
ASCII, String, and binary 400
outputstream classes and methods 399
outputstreams 398
Aabstract 177
interface methods 230overriding, forcing on 177
abstract classes 234Abstract Factory pattern 312accept method 666access modifiers
interfaces 230overview 103syntax 104
accuracy 149, 150Acord 732action listeners
callback interfaces 240see also listeners
activation record 208adapter classes
class names 510event handling 508example 510listener adapter class 509major pitfall 511
Adapter pattern 312addAll method 345addresses
comparing String addresses 63
finding IP for machine name 673
INetAddress 674IP address, determining 642loopback address 664pointers, references 28
algorithmsgarbage collection 206scheduling, POSIX 275threads 269Turing machine 336
Index
justjava.book Page 795 Wednesday, June 2, 2004 2:09 PM
796 Just Java 2
alternating and pattern match-ing 479
Amazonweb services and REST 774web services beta kit con-
tents 772web services overview 759web services, running 773web services, using 771
anchors in pattern matching 477, 478
angle bracketsgenerics and 317syntax 136
anonymous classes 93event handling 508instance initializers 93
ANSIcodesets appendix 787SQL and 595
Ant 689Apache
configuration 703defined 689deployment 706servlet reference implemen-
tation 688API
interfaces 230networking 648Object class 57overview ofPOSIX threads standard
267reading Java API 79ServerSocket 666String class 58, 60
Apple’s Zen Garden 132Applet 559applets
astronomy applet 575containers 559life cycle 526Light Relief 199limitations 435methods 560Powers of 10 tutorial 200
application layer 645application libraries, see libraries
application programmer inter-face, see API
Application Service Provision 687
applications in jar files 102ArgumentIndex 396arguments
generic type parameters 325parameters versus 95, 318var-args 97variable arity 98
arithmetic shift operator 144ArrayList class 349, 352arrays
ArrayList class 349, 352arrays of arrays, instantiat-
ing in steps 193arrays of, declaring 191arrays of, description 190brackets 194bulk transfer from buffer to
448cloning 236compatibility 188creating 187description 185duplicating 189I/O output destination 399indexes, when checked 186indexing and 64-bit Java
195initializing 189iterating over 192length of array 187multi-dimensional 190object type 185output 400size 187terminology in other lan-
guages 191values method and enu-
meration 123ASCII
ASCII, String, and binary 400
character sets 454codesets appendix 787input 414MIME 702printable output 402
required encodings 456XML and 731
ASP overview 685assert
caveat 223complete example 222overview 221two key steps 221
assignmentoperator precedence 143operators 153
associativity 148astronomy applet 575attributes
databases, defined 583defined 591XML 726, 734
autoboxingoverview 55performance 56primitives and variable ari-
ty 98AVG function 602AWT
Canvas component 534Container class 553description 500inheritance example 162native library behavior 520
Axis 763
Bback references and pattern
matching 476beans
example in JSP 715Java beans and JSP 712, 715
bible code 546BigDecimal class 155, 392, 490big-endian storage 454BigInteger class 155, 392, 490binary
ASCII, String, and binary 400
byte-swapping binary data 459
input 414output to 401
justjava.book Page 796 Wednesday, June 2, 2004 2:09 PM
Index 797
bind method 666binding, late 174bitwise shift 142blackout and race conditions
290blank final variable 118blocked server I/O 443blocking I/O workaround 443blocks
statements, blocks of 69synchronized 292
BNF and generics 323book website 14boolean
defined 41description 43
BorderLayout 564Bosiak, Jon 731bounds
generic bounds that men-tion generic type 331
generic parameter bounds 333
type parameters 330wildcards 364wildcards, lower bounds
on 365BoxLayout 565braces 136brackets 194branches
break, omitting at end 72default branch 72
breakcontinue 76enumeration 124omitting at end of branch 72statement syntax 76
browsersdefined 684HTTP, retrieving pages 671protocols 693
BufferedInputStream class 420BufferedOutputStream class 408BufferedReader class 414BufferedWriter class 408buffers
bulk transfer from 448
creating 445current position 444memory 441memory mapping 451methods 446overview 441reading a file 446view buffers 447
business-to-business XML pro-cesses 732
buttonsJButton 531JButtonGroup 535JRadioButton 535radio buttons 535
bytedefined 41description 48
byte array input source 415byte-swapping binary data 459
CC++ 173CAFEBABE 420calculations
operator descriptions 143precision 149
Calendar class 484, 485numbers for months 486utilities 483
call chain 211callbacks
callback routine 501interface callbacks 239
Canvascorresponding Swing com-
ponent 534functionality 534
cardinality 583, 591Carnivore FBI program 667case 72casting
Class class 180classes, rules 170generics 320note on 47operator 153operator precedence 142
overflow 154subclasses and superclasses
169widening and narrowing
152see also conversion
Catalina 689catching
catch clause 211defined 211exceptions 214exceptions within throwing
method 214categories
event handling 507lightweight controls 523
certification examJava exams 313superclass/subclass com-
patibility 171CGI
client/server and 687defined 684, 689servlets versus 687
channelsclose-on-interrupt 443file channel 444overview 441reading a file 446transfer data methods 444when to use 441
chardefined 41description 43Filter to replace 407Unicode 45
character escape sequences 45character sets 454
encoders and decoders 440encodings 459results 458summary 460using specific 457
checkboxes 533CipherOutputStream 408Class class 179, 322class data sharing 19classes
access modifiers 103, 104
justjava.book Page 797 Wednesday, June 2, 2004 2:09 PM
798 Just Java 2
accessing member from within versus without 31
casting rules 170Class class 179Collection 320constant-specific class bod-
ies 130declaring with generic type
parameters 322defined 20, 160Double 241exception hierarchy 213File class 387finding 101forward referencing 138grouping in packages 23HashSet 353jar files, putting in 101Math class 195methods, syntax 95Object 57objects and 26packaging 99qualifying names 137static 113String 60TreeSet 356wrapping output classes
406classpath
jar files 102Java installation 782
client/serverclient sockets 655Java Studio Creator 610Mckoi JDBC driver mode
613server sockets 666TCP/IP model 650web programming 687
clock programcompiling and running 20main code for 32
Cloneable interface 235cloning
arrays 236Cloneable interface 235common pitfall 237defined 235protected and 237
shallow versus deep 236close method 405code
commenting out 78timing 493
codesets appendix 787COFFEEPOT property 148ColdFusion overview 685Collection classes 320collections
addAll method 345Collection interface 342, 343Collection summary 368Collections helper class 357constructors 346foreach 347HashMap class 372HashSet class 346, 353iterating and exceptions 349list classes 350lists 342Map interface 369, 370maps 342methods 345objects, declaring 345queues 342removeAll method 345retain method 345sets 342shuffling elements of 362TreeMap class 375TreeSet class 356
Collections helper class 357colliding data field names 167columns, defined 583comma operator 147command line input 390, 391command line output 393Command pattern 312comments
commenting out code 78conventions 78javadoc 78javadoc tool overview 80XML 726
commercial databases 611Comparable interface 232, 359
changes in JDK 1.5 233complete example 232
generic parameters 233type argument 233with generics 327without generics 327
Comparator interface 359compare method 361compareTo method 232, 233, 361comparingincorrect optimization 360
intern method 63objects 59SQL comparison operators
601Strings 63
compatibilityarrays 188Tomcat and servlet/JSP 689web services 761, 762XML 731
compile timegenerics error reporting 321literals 42
compilingclock program example 20Java 18, 781servlets 700
Component class 554components
debugging 561debugging lightweight 545defined 521, 552displaying 526heavyweight and light-
weight 522Swing component descrip-
tions 529Swing list 543toolkit 571see also GUI
composite typesdefined 22primitive types versus 22
concatenation 61conditional operator precedence
143conditional statements 69configuration
Tomcat 703Tomcat paths 705
justjava.book Page 798 Wednesday, June 2, 2004 2:09 PM
Index 799
connectingconnection methods 619Connection object and
transactions 625database connection 617databases 615networking connection
classes 649URLConnection 673
console input 390, 391constants
constant-specific class bod-ies 130
enumeration constants 121final keyword 117
constructorscollection constructors 346constructor calling another
91default no-arg 90enumeration 128inheritance 92inheritance and 174no-arg, when not to use 90overview 89syntax 90
container classes, see collectionscontainers
AWT containers 553class hierarchy 553, 555, 556layout 561overview 552servlet, defined 684Swing containers 554Tomcat 689
content length, tracking in serv-lets 703
context-sensitive parsing 122continue
break statement 76dowhile statement 75
controlsdefined 521, 552see also GUI
conversioncasting 47conversion specifiers 395overflow 154widening and narrowing
152
see also castingcookies
defined 690description 710
copyingarrays 189cloning 235
COUNT function 602covariant return types 238, 325CREATE
defined 596example 597
curly braces 136cursors
appearance 572icons 572result sets 604
Ddata
instance data versus static data 114
moving between threads 305
static 114validation, DTD 726
data race conditions 291data types
benefits 21primitives versus 22procedural language data
types 21SQL 598see also attributes, variables
databasescommercial 611connecting to 615connection 617connection methods 619defined 582design 584drivers
defined 615loading 616
entity integrity 587foreign keys 586Java bean in JSP, example
715
Java Studio Creator 610JDBC
complete example 627overview 610
mathematical concepts 584Mckoi
downloading and install-ing 592
jar files, setting up 593query tool 594running 613running sample code 613
noncommercial 612normal forms 590ODBC 615primary keys 586reducing duplicated data
585referential integrity 586relational
overview 582terminology 591
relationshipsmany-to-many 588one-to-many 587one-to-one 587
result set metadata 630SQL
data types 598executing commands on
databases 619execution methods 620functions 602overview 595statement categories 596
tablesadding 590defined 583
terminology 583transaction integrity 587transactions 625
datagrams 640datagram sockets 645diagram 641
datalink layer 645DataOutputStream class 401DateFormat class 484dates
Date class 483month numbers 486see also Calendar
justjava.book Page 799 Wednesday, June 2, 2004 2:09 PM
800 Just Java 2
deadlock 304debugging
GUI 561lightweight components
545servlets 707sockets 666telnet 667threads bug 303
decoders, character set 440decrement operator 142, 143deep clone 236default no-arg constructor 90degrees 196, 583delayed binding 174delegation-based model 501DELETE
defined 596example 605
demonssendmail 657threads 280
deploying servlets 706deprecated
interfaces 485thread methods 283
description 159descriptors
defined 390standard in, out, err 391
design patterns1.1 event handling 513Factory 738, 749Factory summary 753overview 311, 312
designing databases 584destructor 95Digital Signature Algorithm in-
terfaces 490dippy birds 286directories for Java classpath 102disk
freeing disk space 14objects, writing to 436
dispose method 207DNS servers 648Document Type Definition, see
DTD
documentation 608doGet 697DOM
defined 733example 737nodes 741SAX versus 745using 736
domains 583doPost 697double
defined 41largest double precision
number 51overflow 154range of values 50strictfp 198
Double class 241double-byte characters 411double-clickable jar files 102dowhile 75downloading
Amazon web services beta kit 771
Google web services beta kit 764
Java 781Mckoi database 592Tomcat 691
DriverManager 617drivers
defined 615DriverManager 617loading 616
DROPdefined 596example 606
DTDbusiness-to-business pro-
cesses 732defined 727, 734Shakespeare’s plays 729syntax 727
dump program 419, 432dumping a file to hexadecimal
418duplicating
arrays 189see also cloning, copying
DVDsillegal prime number 424illegal tshirt 463
dynamic content 684, 687
EEBCDIC 454, 731, 787EDSAC 335eggs, standard size and enumer-
ation 128elements, XML 725email 657, 659, 667
debugging 667embedded mode 613empty bodies and listener
adapter classes 509encoders, character set 440encoding, HTTP 696encodings
character sets 459required 456
endian, big and little 454end-of-line characters 386Englebart, Doug 516ENIAC 334Enterprise Edition
J2EE features 339overview 14
entities 734entity integrity 587Entscheidungsproblem 334enumeration
1.5, how done before 112break statements 124complicated types 127constants 121constant-specific class bod-
ies 130constructors 128egg example 128enumerated type benefits
119final ints, drawbacks 119import static 126predefined members 129qualified name 125servlets 699statement updates for 121
justjava.book Page 800 Wednesday, June 2, 2004 2:09 PM
Index 801
static and final 112switch statement 124type name, importing 125values method and 123why enumerate types 119
enumerations 111environment variables and
properties 493EOFException 418equality
comparing objects 59see also comparing
equals method 59, 63errors
assertion error 222detecting early, generics
320generics 326window, JOptionPane 537
escape characters and pattern matching 474
escape sequences 45evaluating
arrays 141expressions 139operands 141
evaluation and conversions 152event dispatcher 502, 527event handlers
anonymous classes 508interface callbacks 239
event handling1.1 design pattern 5131.1 event object hierarchy
5041.1 event passing 503actions 500categories 507events 507events, defined 501framework for all 507interface for each Swing
component 543interfaces 507Java event model 501listener adapter class 509overview 501registering several listeners
513slimmer code 508
summary 512threads 502
event-driven programming 501events
1.1, event object hierarchy 504
1.1, how passed in 503defined 501Swing events list 543
exceptionscatching within throwing
method 214causing 212class hierarchy 213defined 211fancy stuff 219how methods declare 218how propagates if not
caught in throwing meth-od 217
I/O 417iterating through collec-
tions 349method that threw 220overview 210related 216servlets 703summary 221terminology 211thrown, what happens 211user-defined 213
executable application in a jar file 102
exercisesadvanced I/O 460advanced threads 312classes and objects 38collections 377constructors and visibility
107containers and layout 574event handling 515I/O 423interfaces 242JDBC 631networking 679polymorphism and inherit-
ance 183regular expressions 496servlets and JSP 717SQL 607
statements 83Swing 546XML 755
expression statements 70expressions
conversions 152evaluating 139precision 149regular expressions 470syntax 139
extend, defined 160
Ffactoring out, defined 585Factory design pattern 738, 749,
753fall-through 72FBI Carnivore program 667fields
access modifiers 104forward referencing 138
file channels 444File class 387, 388file descriptors
defined 390standard in, out, err 391
file locking 452, 454files
example of output to 401I/O output destination 399input source 415random access file 430
FilterInputStream class 421FilterOutputStream class 408FilterReader class 414filters 407FilterWriter class 406final 176
blank final variable 118description 117interface data fields 230ints, using to enumerate 119overriding, forcing off 175
finalizersdescription 205JLS citation 207
finallycatching exceptions 214
justjava.book Page 801 Wednesday, June 2, 2004 2:09 PM
802 Just Java 2
cleaning up with, note 216purpose in exceptions 215
firewalls 648, 652Flags 396float
defined 41overflow 154range of values 52
floating-pointdivision operator 143double 50extension 151float 52inaccuracy issues 150overflow 154significant figures 149types overview 49
flow of controlassert statement 78dowhile statement 75exceptions 211throw statement 78transfer of control state-
ments 77FlowLayout 562flush after use 405footprint reduction 19for
arrays, iterating over 192enumeration and 121statement syntax 73
foreachcollections, iterating
through 347enumeration 122
foreign keys 586Formatter class 394formatting
format specifiers 396string output 436
formsdoGet and doPost 697example 704headers 696normal form 590POST and GET 695servlets and 694
forward referencing names 138fragmentation 204
frames 561frameworks
event handling framework 507
Java Collection Framework 341
logging 384thread pools 310
FTP 640functions, SQL 602Furby 156
Ggarbage collection 204
algorithms 206costs and benefits 205description 202, 204finalizers 205fragmentation 204weak references 207
generic methods 366, 367generic parameters 362generics
arguments for generic type parameters 325
arguments versus parame-ters 318
bounds 330clone method and 325Comparable interface with
327Comparable interface with-
out 327declaring class with generic
type parameters 322defined 317, 319generic class example 334generic interface example
334generic interfaces 326generic method example
334generic methods 362generic type parameters 322generic type restrictions 328instantiating object 325invoking methods on ob-
jects 326methods, invoking on ob-
jects 326parameter bounds 333parameter bounds that
mention generic type 331problem solved by 319purpose 321table example 324terminology 334three parts 322using outside Collection
classes 322GET
defined 690HTTP GET command 669POST and 695
GIFimage I/O 384importing images into pro-
gram 558JFrame 557
Googlegooglewhacking 778web services beta kit con-
tents 764web services overview 759web services, running 768web services, using 764WSDL file 766
goto 68grammar, defined 8greater than operator, prece-
dence 142GregorianCalendar class 484,
485, 486grep program for pattern match-
ing 482GridLayout 564groups and pattern matching
476GUI
cursor icons 572event handling actions 500event handling overview
501functionality, four basic ar-
eas 499heavyweight and light-
weight components 522JFC overview 520JFC terminology 521
justjava.book Page 802 Wednesday, June 2, 2004 2:09 PM
Index 803
JFrame, displaying compo-nents 526
layout managers 562pluggable look and feel 549printing screen 571Swing component descrip-
tions 529see also AWT, Swing, event
handlingGUI event handlers 239gzip 409, 421GZIPInputStream class 421GZIPOutputStream class 408
Hhandlers 211
event handlers and inter-face callbacks 239
see also event handlersHank the Angry, Drunken
Dwarf 717Hard Luck Hard Disk 83hardware for networking 646has a 166hash tables
defined 371hashcodes 59HashMap class 369, 372HashSet class 346
collections and lists 351using 353
Hatless Atlas song 65header files
use in other languages 23headers
HTTP 696servlet request methods 699
heapdefault size 202description 202garbage collection 202storage lifetime 203
heavyweight 522Hello World 783hexadecimal 418Hindi output 401HotSpot 19
HTML5K contest 756overview 723, 724POST and GET 695servlets, invoking with 694XML versus 722XML’s advantages over
722, 724HTTP
1.1 enhancements 702browsing 671defined 690GET command 669headers 696mapped I/O HTTP server
677multithreaded HTTP server
675POST and GET 695requests and responses 695response syntax 696servlet requests 698servlets and 693version comparison 702
hubs 647
II/O
16-bit character output 403ASCII printable output 402basic reader methods 411binary output 401blocked server 443buffers 441channels 441design philosophy 385exceptions 417File class 387file locking 452formatted string output 436input 410input methods 415input sources 411, 415inputstream wrappers 420interrupting 283java.io package 382key File class members 388keyboard 390, 391memory-mapped 449Multics 450
multiplexed non-blocking 441
non-blocking 440number of classes 382output 397output destinations 399packages 384piped I/O for threads 305platform differences 386practical output examples
400printstreams 391problems 382processes, limitations on
running 435program output, reading
432random access file 430reader wrappers 413reading file and dumping
to hexadecimal 418threads, stopping 283wrappers 383wrapping additional out-
put classes 406writer wrappers 406XML support class 439zip files, outputting 409see also input, output
IBM Linux watch 108icons for cursors 572identifiers
defined 137legal Java identifiers 138names versus identifiers
137overview 137
identity conversions 152IDEs 18if statement syntax 71illegal
prime number 424tshirts 461
images, importing into program 558
IMAP 640immutability and final keyword
117immutability of Strings 61, 63,
64
justjava.book Page 803 Wednesday, June 2, 2004 2:09 PM
804 Just Java 2
implicit fall-through 72importing
import static syntax 126type name, enumeration
125IN operator 601indexes
array indexes, when checked 186
arrays 195INetAddress 674inheritance
benefits of 165casting 169casting rules 170constructors 92constructors and 174data field name collision
167description 159example of real-world 160interfaces 228, 230Java example 162multiple inheritance 167Object and polymorphism
174summary 167superclass object acting as
subclass 169toString method 175
initializing arrays 189inner classes and event handlers
508input
basic methods 415description 410double-byte characters 411InputStream wrappers 420problem 412reader methods, basic 411reader wrappers 413sources 411, 415see also I/O
InputStream class 415InputStreamReader class 421inputstreams
piped I/O 305TCP/IP diagram 650wrappers 420
INSERT
defined 596example 598
insolvent pachyderms 778installing
Mckoi database 592Tomcat 691
instance initializers 93instance methods and enumera-
tion variables 129instanceof 145
instead of switch 743operator 145
instantiatingarrays 187constructors 89objects, constructors 89
intdefined 41description 46
integritydefined 591entity 587referential 586transaction 587
interface, see GUIinterfaces
abstract classes versus 234callbacks 239Comparable 232defined 230, 234deprecated 485event handling 507generic interfaces 326generic parameter bounds
333Java Native Interface 495JDBC, interfaces versus
classes 618locks and memory map-
ping 440member behavior 230overview 227problem solved by 228summary 231Swing event handler inter-
faces 543intern method 63Internet Protocol, see IPinterpreter
performance boosts 19program for Java 18
interruptingI/O 283interrupt method 304threads 303
introspection 180ints
enumeration and final int drawbacks 119
overflow 154IP 640
address, determining 642current connections, show-
ing 668defined 650finding address for ma-
chine name 673INetAddress 674loopbackaddress 664ports and 652protocols built on 645version 4 versus version 6
646ipconfig 642is a 166ISO
codesets appendix 787ISO-8859-1 456seven-layer model 644
ISPs, blocking 633iterating
collections 347collections, exceptions 349Iterator interface 347
JJ2EE
features 339overview 14
J2ME overview 12J2SE overview 13Jakarta 690JApplet
example 526subclass of Panel 559
jar filesapplications, storing in 102
justjava.book Page 804 Wednesday, June 2, 2004 2:09 PM
Index 805
classpath 102creating 101double-clickable 102executable application in
102Google web services 765location JDK looks for 102Mckoi 629Mckoi, setting up 593servlet deployment 706
Jasper 690Java
classpath, installation 782clock program, main code
for 32compiling 18, 781downloading 781early names for 378event model 501J2EE overview 14J2ME overview 12J2SE overview 13JRE overview 18JVM overview 18language overview 8Microsoft and 7objects, introduction to 17operator descriptions 143operator precedence 142overview 3package list 11portability benefits 4portability, importance 5running program 18strongly typed, defined 42see also JDK
Java Foundation Classes, see JFCJava Native Interface 495Java Studio Creator 610javac 18javadoc 78
comments 78tool, overview 80using 82
JAXB 733JAXM 733JAXP 733, 735JButton
description 530example 527
internationalization 531JButtonGroup 535JCheckBox 533JComponent
actions 524component descriptions
529controls 525debugging components 545description 524features provided 522JFrame, arranging 527overview 522
JContentPane 556JDBC
additional information 631complete example 627drivers, loading 616interfaces versus classes 618overview 582, 610prepared statements 626SQL connection methods
619SQL execution methods 620stored procedures 627transactions 625transactions, batching 624versions 614
JDiskReport 14JDK
classes, finding 101features in each release xixsee also Java
JDK 1.1event handling pattern 513event object hierarchy 504event passing 503
JDK 1.5arrays, iterating over 192autoboxing and unboxing
55class data sharing 19concurrent package 310deprecated thread methods
283ellipsis token 136enum keyword 136enumerations 111footprint reduction 19generics 181, 317
java.nio I/O package 440new features summaryStringBuilder 64variable arity 97
JEditorPanedescription 541JTabbedPane and 539
JFCadvantages 521overview 520terminology 521
JFramecontainers 557displaying components 526example 504, 527, 557
JGlassPane 556JLabel 529JLayeredPane 556JMenuBar
556jobs and Java 6JOptionPane 537JPanel 556
alternative using JLabel 534description 534JTabbedPane and 539KeyListener 535using 558
JPG 558JRadioButton 535, 550JRE overview 18JRootPane 556JScrollPane 538JServ 690JSP
container, Tomcat 689example 714executing 713Java beans 712, 715Java beans example 715overview 683, 685, 710servlets versus 710Struts 714syntax 711tag libraries 716tags 712terminology 689
JTabbedPane 539description 539
justjava.book Page 805 Wednesday, June 2, 2004 2:09 PM
806 Just Java 2
JTextField 532JToolTip 531Just in Time compiling 19Just Java website 14JVM overview 18JWindow 560
KKenobi, Obi-Wan 545KeyAdapter 511keyboard I/O 390, 391keyboard output 393KeyListener 535keys 586keywords 136
enum, new 112Java 136
Kleene star 468Knuth, Donald 80
Llabels, JLabel 529languages
definition of programming language 7
see also object orientation 21late binding 174layers
ISO seven-layer model 644TCP/IP four-layer model
645layout
combining layout manag-ers 566
containers 561grid layout 564layout managers
BorderLayout 564BoxLayout 565combining 566FlowLayout 562GridLayout 564
layout managers overview 562
left bitwise shift 142length 186length of arrays 187
less than operator, precedence 142
librariesgrouping classes 23Java libraries list 11JAXP 735JSP tag libraries 716overview of libraries 9run-time library overview
10life cycle for servlet 708lifetime for object on the heap
203Light Relief
500 Mile Limit on Email 680Apples and Crays 497applets 198Computable Numbers and
the Entscheidungsprob-lem 334
Early Names for Java 378Furby’s Brain Transplant
156googlewhacking 778Hatless Atlas 65Haunted Zen Garden of
Apple 132Illegal Prime Number 424Java Certification 313Java-Powered Toaster 242JDiskReport 14MiniScribe, the Hard Luck
Hard Disk 83Napster and Limewire 38NASA Spirit Rover 224Nerd Detection System 184Reading the Docs 608Sky View Cafe astronomy
applet 574Spam 632The Bible Code 546The Illegal Tshirt 461The Motion Sensor Solution
(Dippy Birds) 285The Mouse That Roared 515Using Java to Stuff an On-
line Poll 717View Source on Kevin’s
Life 756lightweight
components, debugging
545controls list 523defined 522
LIKE operator 601Limewire 38LineNumberInputStream class
421LineNumberReader class 414link layer 645Linnaean taxonomy 160Linux
portability of Java 4watch 108
list of items 185listeners
adapter class pitfall 511callback interfaces 240example 509listener adapter class 509pluggable look and feel 551registering several for same
event 513top-level class, making into
508lists
ArrayList class 349, 352collections 342LinkedList class 349List class 349maps and 342sorting for collections 359
literalsboolean literals 43byte literals (none) 48char literals 44defined 42int literals 46long literals 47short literals (none) 49String literals 60Strings, immutable 61
little-endian storage 455local thread storage 308locks
deadlock 304file locking 452read/write 291
logging servlets 703long
justjava.book Page 806 Wednesday, June 2, 2004 2:09 PM
Index 807
defined 41description 46
loopback address 664loops
break statement 76continue statements 75dowhile statement 75for loop and enumeration
123for statement 74looping statement syntax
73mutually exclusive threads
298variable, declaring 74
MMacintosh
portability of Java 4web services 777
mail500 mile limit 680MIME 702sending 657
main methodexample 32static 116
many-to-many relationships 588Map interface
HashMap 372TreeMap 375
mapped I/O HTTP server 677maps
collections 342defined 343
Maps interface 369mark and sweep 206Matcher class 469Math class 195, 318, 392math package 196, 490MAX function 602Mckoi
class path 629downloading and installing
592jar files 629jar files, setting up 593query tool 594
running 613running sample code 613
memory management 202finalizers 205garbage collection 202, 204heap 202leaks 203memory no longer in use,
indicating 204reclaiming objects 94reference types and 28stack 208weak references 207
memory mapping interface 440memory-mapped I/O 449, 450metacharacters and pattern
matching 474metadata
File class 387File class members 388result sets 630
metawords in pattern matching 480
methodsaccess modifiers 104activation record 208catching exception within
throwing method 214exceptions, declaring 218File class 388finding method that threw
exception 220forward referencing 138generic methods 362generic, example 334grouping in packages 23I/O metadata 388instance methods and enu-
meration variables 129interfaces 230invoking static method
through instance variable 116
overloading 96, 171overriding 172overview 95parameterizing 366reference variables, passing
parameters to methods 96servlet request methods 699
servlet response methods 700
stack 208static methods 116static, common pitfall 117Swing interface methods
543variable-arity 97see also generic methods
MFC memory leaks 203Micro Edition overview 12MicroQuill 203Microsoft
Java and 7memory leaks 203OpenOffice.org office suite
competitor 6MIME 702MIN function 602MiniScribe 83modal Window 560monitors and threads 291months
numbers for 486see also Calendar
motion sensors 285mouse inventor 515Multics 450Multics and wait/notify 297multi-dimensional arrays 190multidimensional arrays 190multiple inheritance 167
interfaces 229multiplexed non-blocking serv-
er I/O 441multithreading, see threadsmutually exclusive threads 287
communicating 295example 288over a method 294over block of statements
293over entire class 292
MVCoverview 552Struts 715
justjava.book Page 807 Wednesday, June 2, 2004 2:09 PM
808 Just Java 2
Nnaming
data field collision 167early names for Java 378forward referencing 138names versus identifiers
137package names and
namespaces 100package names, unique 100package naming rules 99qualifying 137subclasses and data field
names 167XML namespaces 729
Napster 38narrowing conversion 152NASA Spirit Rover 224Native Interface 495native library behavior in AWT
520negation and pattern matching
479nerd detection system 184nested classes 104nesting 166netstat 668network layer 645networking
additional information 679hardware 646IP and UDP diagram 641ISO seven-layer model 644library 648overview 639TCP/IP four-layer model
645Windows 657see also sockets, packets,
protocolsnew features in 1.5, see JDK 1.5new keyword 90no-arg constructor 90nodes and DOM 741non-blocking I/O 440, 442noncommercial databases 612non-polling I/O 442normal form 590
notify method 297, 303NTP 655, 656null
databases 587null reference 27
null bodies and listener adapter class 509
numbersrandom 492see also Math class
OObject class
equals method 59inheriting from 174overview 57
object orientationclasses, defined 20inheritance 159inheritance and construc-
tors 92inheritance example 162polymorphism 159terminology 160
object references 96ObjectOutputStream class 408objects
arrays, similarities 186arrays, similarities and dif-
ferences 186autoboxing 55code example, simple 30collection objects, declaring
345comparing value 59defined 26heap 202instantiating
constructors 89steps that occur 93
instantiating for generics 325
introduction to 17memory management 94no longer in use, indicating
204object wrapper classes for
primitive types 54pass by value versus pass
by reference 96primitives versus 27reference to an object ver-
sus 29static 113storage lifetime 203wrappers for primitives 53writing objects to sockets
437writing to disk 436
Observer pattern 312octal escape sequences 45ODBC 615one-to-many relationships 587one-to-one relationships 587OOP, see object orientationOpenOffice.org office suite 6operand evaluation 141operating cycle of servlets 708operating systems
I/O differences among 386portability, benefits 4portability, importance 5
operatorscast and assignment 153description 140Java operator descriptions
143precedence 142SQL comparison 601
optimizationincorrect 360servlets 709
order of evaluationoperands 140see also evaluating
outputarrays 400destination options 399practical examples 400readers versus output-
streams 397reading program output
432Width 396wrapping additional out-
put classes 406zip files 409see also I/O
justjava.book Page 808 Wednesday, June 2, 2004 2:09 PM
Index 809
OutputStream class 408outputstreams
16-bit characters 398binary output 401example 400piped I/O 305readers versus 397servlets 703TCP/IP diagram 650wrappers 408
OutputStreamWriter class 408overflow
BigInteger 155casting 154
overloading 171description 171methods, syntax 96overriding versus 174
overridingcovariant return types 238forcing off with final 175forcing on with abstract 177methods 172overloading versus 174
Ppackages
classpath 102defined 99finding classes 101grouping classes in 23I/O packages 384Java package list 11naming rules 99packaging classes 99unique names 100visibility 98
packetsdiagram 641, 643routers and 647UPD 649watching 667
p-and-v semaphores 291parallel processing 269, 281parameterized type 334parameters
arguments versus 95, 318generic methods 366
generic parameter bounds 333
generic type 322pass by value versus pass
by reference 96passed by reference 96passed by value 96primitives and parameter-
passing 96reference variables, passing
parameters to methods 96wildcard parameters 362
parentheses 136parsers
DOM 736SAX 744SAX versus DOM 745
pass by reference 96pass by value 96Pattern class 469pattern matching
alternating 479anchors 477anything but feature 473anything except this word
feature 479capturing groups 476cautions 469classes 469escape characters 474grep program 482metawords 480methods 470patterns, forming 470quantifiers 475ranges 473sample program 472single-character metachar-
acters 474three main steps 468using 469when used 468word negation 479
patternsdesign pattern summary
753design patterns overview
312Factory design pattern 749pattern matching and I/O
440PatternSyntaxException 469performance
autoboxing 56batching SQL statements
and transactions 624interpreter performance
boosts 19servlets 709strictfp 198StringBuilder 64
petservletpetform.html 704results 705
pi 195, 318, 394ping programs 653, 654pipes
example of output to 401I/O output destination 399input source 415piped I/O for threads 305pitfall 305
pluggable look and feelillustration 551overview 549
pointers 28polls, rigging results 717polymorphism 159, 171
description 171late binding 174Object, inheriting from 174overloading 171overloading versus over-
riding 174overriding 172parametric 319
populating tables with INSERT 599
portabilitybenefits 4I/O 386I/O design philosophy 385importance 5jobs, effect on 6OpenOffice.org 6pluggable look and feel 549web based software 686XML 731
ports
justjava.book Page 809 Wednesday, June 2, 2004 2:09 PM
810 Just Java 2
defined 652firewalls and 652predefined 652
POSIXscheduling algorithm 275thread standard 267
POSTdefined 690GET and 695
post-increment operator 142, 143
Powers of 10 tutorial 200powers of two table 785precedence 142
associativity versus 148operator precedence 142operators 142
precisioncalculation accuracy 149calculations 149floating-point 149, 151floating-point arguments
396pre-increment operator 142, 143prepared statements
description 606using 626
primary key 586prime numbers
example program finding 281
illegal 424primitives
autoboxing 55boolean, description 43byte, description 48casting 47, 153char, description 43composite types versus 22data types versus 22defined 21descriptions 41int, description 46long, description 46object wrapper classes for
primitive types 54object wrappers 53objects versus 27short, description 49
printfmethod 394variable-arity of methods
97printing screen 571println 670PrintStream class 402printstreams 391PrintWriter class 403priority 275private
access modifiers 103, 105protected versus 106
procedural language data types 21
programming language, see lan-guages
propertiesenvironment variables
equivalent 493predefined 494processing 494
protectedaccess modifier rationale
106access modifiers 105cloning and 237defined 237JLS citation 239private versus 106servlet request and re-
sponse 698protocols
HTTP and web components 693
IP, built on 645remote and println 670socket 663SPAM, reducing 636Trusted Internet Protocol
636provisioning 687proxy servers 648public
access modifiers 103, 105interface methods and
fields 230punctuation
defined 136
operators 140PushbackInputStream class 421PushBackReader class 414
Qquantifiers and pattern match-
ing 475queries
Mckoi query tool 594SELECT example 599SELECT result sets 603SELECT statement 596speeding up 624SQL executeQuery method
620SQL subqueries 602
queuescollections 342
Rrace conditions
avoiding 291blackout 290defined 289
radians, converting to degrees 196
radio buttons 535, 566raising 211Random Access File class 430Random class 492ranges and pattern matching
473read/write locks 291readers
basic methods 411outputstreams versus 397reader classes 397reader classes for input 411reader wrappers 413
reading from System.in 391records
DELETE and DROP 596deleting 605DROP 596UPDATE statement 596updating 605
reference counting 206
justjava.book Page 810 Wednesday, June 2, 2004 2:09 PM
Index 811
reference implementation, serv-let 688
reference typesarrays 185defined 27key points 22string comparison 63why used 28
reference variablespassing parameters to
methods 96tree data structures 29why used 28
referencesback references and pattern
matching 476forward-referencing names
138objects versus reference to
an object 29pass by value versus pass
by reference 96pointers, addresses 28
references typesmemory management and
28referential integrity 586regular expressions
pattern matching 470properties 493
related threads 280relational databases 581
defined 582many-to-many relation-
ships 588mathematical concepts 584see databases, relationaltables 582
relations 583relationships 587reliability and enumeration con-
stants 121removeAll method 345repetition and pattern matching
quantifiers 475requests
HTTP 695servlet 698servlet requests, key meth-
ods 699servlets 697
reserved words 136responses
HTTP 695, 696servlet responses, key
methods 700servlets 697, 699syntax 696
RESTAmazon web services 774overview 775
result setscontents 603metadata 630SELECT example 601sorted 604
retain method 345return statement syntax 77right bitwise shift 142Robocode software 110RosettaNet 732routers
defined 646packets and 647
rows 583rules
generic type parameter bounds 330
googlewhacking 779XML 725
run method 271, 274, 282Runnable interface
creating new thread 270object, turning into thread
272Swing threads 528Thread class 284using 272
run-time amnesia 328run-time internals 202, 208run-time library
overview 10source code 62
SSAX
defined 733
DOM versus 745example 746using 744
Scanner class 391SCJP 313screen, printing 571scrolling 538searching and web services 770Searching class 325second normal form 590sections of XML documents 728security
firewalls 648serializing and 438web services 772
SELECTdefined 596example 599pitfalls 604result sets 603
selection statements 71selector-based multiplexing 442semaphores, p-and-v 291SequenceInputStream class 421serializing
objects, making serializable 437
security and 438writing objects to disk 436
servlet containersdefined 684Tomcat 689
servletsCGI versus 687compiling 700container, defined 684debugging 707deployment 706development tips 707dynamic content 684example 701example, running 692exceptions 703forms and 694HTML to invoke 694logging 703operating cycle 708outputstreams 703overview 683
justjava.book Page 811 Wednesday, June 2, 2004 2:09 PM
812 Just Java 2
pathnames for executing 705
petservlet results 705products replaced by 687reference implementation
688requests 698requests and responses 697requests, key methods 699responses 699responses key methods 700specification location 710terminology 689threads 709tips 703Tomcat configuration 703tracking content length 703web services and 687why use 686writing 700
sessions 710sets
collections 342HashSet class 353maps and 342Set interface, defined 355see also result sets
shadowing field names 167Shakespeare DTD 729shallow clone 236shift, bitwise 142short
defined 41description 49
signed shift operator 144significant figures
double, largest possible 51floating-point 49
SimpleDateFormat class 484, 488
SimpleTimeZone class 484single-character metacharacters
474Singleton pattern 312Sky View cafe 575SmartHeap 203SMTP 657, 658SNMP 640SOAP 763
socketsbackground 642blocking I/O 443C/C++ 653client socket 655client versus server 645connections 645datagram 645datagram diagram 641debugging 666defined 652diagram 643I/O output destination 399input source 415Java 653networking classes 648println and 670protocols 663server socket 660server sockets 666ServerSocket 666stock finder 672stream sockets 645TCP/IP diagram 650URLconnection 673writing objects to 437
sortinginterfaces for collections
359result sets 604
Sorting class 325source code of Java run-time li-
brary 62spam
lovely 632pattern matching 468preventing 634
Spirit Rover 224SQL
comparison operators 601cursor 604data types 598executing statements 619execution methods 620functions 602overview 595prepared statements 606result sets 603statement categories 596statements, batching 624
stored procedures 606support for SQL types 490
square brackets 136, 194SSEC 335stack
description 208diagram 209servlet stack trace 707Stack class 489stack cracking 208stack frame 208strack trace, defined 211threads and 210
Standard Edition overview 13standard in, out, err 391start method 271statements
assert 221branches 72break statements 76common Java statements 67dowhile statement 75dowhile statements 75empty statement ( 69enumeration, updates for
121expression statements 70for statements 73if statements 71looping statements 73organizing 69overview 68return statements 77selection statements 71SQL statement categories
596SQL statements, batching
624switch statements 71switch’s design flaws 73transfer of control 77
staticdata 114defined 112, 113description 113import static syntax 126main method 113, 116methods 116methods, common pitfall
117
justjava.book Page 812 Wednesday, June 2, 2004 2:09 PM
Index 813
mutual exclusion over class static methods 293
threads 293what you can make static
114stderr 391stdin 391stdout 391stop and copy 206storage
big-endian 454little-endian 455thread local storage 308
storage lifetime 203stored procedures
defined 592description 606using 627
stream sockets 643, 645streams
closing after use 405input and output streams
397memory-mapped I/O 449selecting class for 398
strictfp 151, 198String class
concatenation 61creating new 61methods, important 64overview 58, 60toString method 58
StringBuffer 415Strings
ASCII, String, and binary 400
comparing 63formatted output 436I/O output destination 399intern method 63StringBuffer 63StringBuilder 64
strongly typed 42Struts
finding more information 715
overview 714subclasses
casting 169
data field names 167defined 160inheritance example 163interfaces 228overriding 172superclass acting as sub-
class 169subqueries
examples 603SQL 602
subtypesdefined 160see also subclasses
SUM function 602super
keyword 164using 166
superclassescasting 169defined 160superclass acting as sub-
class 169supertypes
defined 160see also superclasses
swapping bytes 459Swing
component descriptions 529
containers 554debugging lightweight
components 545error message windows 537event-dispatching thread
requirement 528events list 543JComponent, description
524lightweight controls 523most useful component 538threads warning 527threads, Runnable interface
528switch
break statement 76design flaws 73enumeration and 124instanceof instead of 743statement syntax 71
switches
defined 646hubs versus 647layer 3 646
synchronizationblocks 292defined 277events and threads 502Multics 297mutual exclusion over
block of statements 293mutual exclusion over
method 294servlets 709solutions 291wait/notify 295
syntactic sugar 122, 332syntax
angle brackets 317arguments versus parame-
ters 95arrays 185, 187arrays and brackets 194arrays of arrays 191comments 78constructors 90CREATE 597DELETE 605doGet and doPost 698DROP 606DTD 727exceptions, catching 214expressions 139generic methods 366generics 334HTTP 696identifier rules 137INSERT 598JSP 711methods 95operators 140overloading methods 96punctuation 136SELECT 599SELECT pitfalls 604SQL operators 601statements 69UPDATE 605XML 725XML comments 726
System.in 391System.out.println 393
justjava.book Page 813 Wednesday, June 2, 2004 2:09 PM
814 Just Java 2
Ttables
CREATE statement 596creating 597database, adding to 590defined 583DELETE and DROP 596deleting 605inserting records 598
tabsadding tab and component
541escape sequences 44JTabbedPane 539
tagsattributes 726DTD 727element tags 725HTML tags 723JSP 712JSP tag libraries 716XML 734XML tags 724
TCP/IP 640client/server model 650diagram 643four-layer 645overview 640Windows 657
Telnet 640telnet 667templates, see genericstest-and-set instructions 291text editors and pattern match-
ing 468text fields 532TFTP 640third normal form 590Thread class
diagram 271example 284non-private members 284
threads 271advanced topics 287, 295API 267bug 303categories of thread pro-
gramming 277concurrent package 310
creating 270defined 267demon 280deprecated methods 283diagram 278event handling and 502interrupting 303local storage 308moving data between 305Multics 297mutually exclusive 277, 287mutually exclusive, com-
municating 295mutually exclusive, exam-
ple 288pipe pitfall 305piped I/O 305prime number program 281race conditions 289read/write locks 291reasons to use 269related 280Runnable interface 272Runnable interface and
Swing threads 528running 271servlets 709stack allocated for 210stopping 283Swing threads warning 527synchronization 277, 709synchronization solutions
291synchronized blocks 292unrelated 278, 280unsynchronized 280volatile 304wait/notify 295XML 753
three-dimensional arrays 190throwing exceptions 211time
global timeservers 656NETP 655time-sharing 268time-slicing 275see also Calendar
TimeZone class 484timing your code 493toaster, Java-powered 242Tomcat
configuration 703defined 690deployment 706downloading 691installing 691overview 689running JSP 713servlet debugging tips 707starting and stopping 692versions 689
tooltips 531toString method 58, 175traceroute 647transactions
batching 624Connection object 625transaction integrity 587
transfer of control statements 77Transmission Control Protocol,
see TCPtransport layer 645TreeMap class 369, 375trees
DOM parser, example 740DOM XML parser 737reference variables 29reference variables and 29XML document structure
727TreeSet class 356triggers 592true/false, boolean 43Trusted Internet Protocol 636try
after completed 216exceptions 214overhead 218statement example 215
tuple, defined 583, 592Turing, Alan 335two, powers of, table 785two-dimensional arrays 190type arguments 334type erasure 328type name 125type parameters 334types
array compatibility 188composite types 22
justjava.book Page 814 Wednesday, June 2, 2004 2:09 PM
Index 815
conversion 47covariant return types 238enumerated type benefits
119enumerating, why 119floating-point 49generic type restrictions 328generics 320grouping in packages 23reference types 27reference, why used 28type parameter and bounds
330see also data types
UUDDI
defined 763overview 775
UDP 640, 641unboxing, see autoboxingUnicode
char and 45operating systems and 45
unrelated threads 278, 279, 280unsynchronized threads 279,
280UPDATE
defined 596example 605
URLsI/O output destination 399URLConnection 673
user datagrams 640user interface, see GUIUTF 456utilities
BitSet class 489calendar and time 483Properties class 494Random class 492Stack class 489
Vvalidation, DTD 726values method
enumeration and 123
predefined members 129var-args 97variable-arity 97variables
casting note 47data types versus primi-
tives 22enumeration variables and
instance methods 129pass by value versus pass
by reference 96reference variables, passing
parameters to methods 96see also attributes, data
typesVector class thread bug 303versions
IP 646JDBC 614JDK xixservlet reference imple-
mentation 688XML 733
view buffers 447virtual 173visibility 98
access modifiers 104keywords 98protected 237see also access modifiers
volatile 304votebot 718
Wwait method 297wait/notify 295, 297war files 706warnings and JOptionPane 537weak references 207web browsers
defined 684protocols 693
web componentsJSP overview 711portability 686servlet and JSP overview
683terminology 689
web searches 468web servers 661
defined 684multithreaded HTTP server
675protocols 693
web servicesAmazon beta kit, down-
loading 771coding your own 770conclusions 777defined 761four components 762Google beta kit, download-
ing 764overview 759problem they solve 761REST 774running Amazon web ser-
vices 773running Google web servic-
es 768security 772servlets and 687terminology 763writing, steps 763
website for book website 14well formed XML documents
726widening and narrowing con-
versions 152widening conversion 47, 152widgets 521wildcards
defined 334generic methods, combin-
ing with 367lower bounds on 365parameters 362wildcarding generic pa-
rameters 362Window
containers 560JComponent overview 522JFrame example 504window listener 509
window listenersexample 509see also listeners
Windows
justjava.book Page 815 Wednesday, June 2, 2004 2:09 PM
816 Just Java 2
portability of Java 4TCP/IP 657
windowserror message, JOptionPane
537JTabbedPane 539see also GUI
winipconfig 642wireless devices 12word negation in pattern match-
ing 479wrappers
autoboxing 55defined 383InputStream wrappers 420object wrapper classes for
primitive types 54object wrappers for primi-
tives 53output classes 406primitives, why wrap in ob-
jects 53reader wrappers 413writer wrappers 406
writers16-bit characters 398writer classes 397
WSDLdefined 763Google WSDL 766overview 775
XXML 735
attributes 726business-to-business pro-
cesses 732comments 726document tree structure 727DOM, using 736DTD 726elements 725Factory design pattern 749HTML versus 722HTML, advantages over
722, 724information resources 755
Java XML notes 753JAXP library 735namespaces 729origin 731problem it solves 731rules 725SAX versus DOM 745SAX, using 744sections 728Shakespeare DTD 729support class, I/O 439tags 734terminology 733threads 753validation 726well formed documents 726
XSLT 733, 763
ZZen Garden 132Zermelo-Frankel set theory 122zip files 409ZipOutputStream class 408
justjava.book Page 816 Wednesday, June 2, 2004 2:09 PM
Recommended