Please note that index links point to page beginnings from the print edition. Locations are approximate in e-readers, and you may need to page down one or more times after clicking a link to get to the indexed material.
A
abandoned strings, 260–263
absolute() method, 883–884
abstract classes, 20
creating, 23–24
implementation, 118
vs. interfaces, 25–26
overview, 22–23
abstract factory pattern, 562
abstract methods
overview, 43–47
subclass implementation, 100–101
acceptChanges() method, 920
access and access modifiers, 29–31
classes, 17–21
constructors, 128
encapsulation, 85
key points, 69
levels, 53
local variables, 41–42
overloaded methods, 106
overridden methods, 102–103
private, 33–36
protected and default members, 35–39
public, 31–33
static methods and variables, 143–144
AclFileAttributeView interface, 509
add() method
ArrayList, 293
BlockingQueue, 802
Calendar, 424
collections, 590
addAll() method, 800
addition
compound assignment, 225–226
operator, 235
addRowSetListener() method, 918–919
alive thread state, 720
American National Standards Institute (ANSI), 871
ampersands (&)
bitwise operators, 241–242
logical operators, 242–245
searches, 437
AND expressions, 242–245
angle brackets (<>) in generic code, 291, 631, 633
anonymous arrays, 282–283
anonymous inner classes
argument-defined, 697–699
key points, 703
overview, 692
plain-old, flavor one, 693–696
plain-old, flavor two, 696–697
ANSI (American National Standards Institute), 871
APIs, 544
append() method, 270–271
appending strings, 259–260, 270–271
appendReplacement() method, 445
appendTail() method, 445
applications, launching, 12
arg_index element in format strings, 452
@argfiles options, 11
argument-defined anonymous inner classes, 697–699
arguments
assertions, 385–388
final, 43
overridden methods, 103
vs. parameters, 48
quotes for, 444
super constructors, 132–134
variable argument lists, 48
arithmetic operators, 235–240
basic, 235
increment and decrement, 238–240
key points, 247
remainder, 235–236
string concatenation, 236–238
ArrayIndexOutOfBoundsException class, 342
description, 358
out-of-range array indexes, 279
superclass, 344–345
in collection hierarchy, 589–590
collections, 797
description, 593
duplicates, 291–292
element order, 592
key points, 297
methods, 292–294
sorting, 604–606
uses, 289–291
arrays, 273–274
constructing, 275–277, 280–282
converting with lists, 613–614
declaring, 56–57, 274–275, 280–283, 644–645
default element values, 188, 191, 210
element assignments, 284–288
enhanced for loops, 328–329
initializing, 277–284
instanceof comparisons, 234
length attribute, 267
methods, 626–627
polymorphism, 642–644
reference assignments, 286–288
returning, 124
searching, 611–613
type-safe, 629
Arrays.asList() method, 613, 627
ASCII set, 52
assert keyword, 383
AssertionError class, 351, 357, 380
appropriate use, 386
description, 358
expression rules, 381
assertions
appropriate, 386–389
compiling assertion-aware code, 383-384
disabling, 384–386
enabling, 382–386
expression rules, 381–382
key points, 404
overview, 378–380
running with, 384
assignments
array elements, 284–288
compiler errors, 178–179
floating-point numbers, 178
key points, 210
object compatibility, 232
reference variables, 180–181, 191–193, 286–288
asterisks (*)
compound assignment operators, 225–226
globs, 520–522
multiplication, 235
searches, 439–442
SQL queries, 845
atomic operations, 742
atomic package, 786–787
atomic variables, 786–789, 829
AtomicInteger class, 789
attributes
BasicFileAttributes, 509–511
common, 513
DosFileAttributes, 512–513
interface types, 508–509
PosixFileAttributes, 512–513
reading and writing, 506–507
auto-commit mode, 922–923, 925
autoboxing with collections, 600–603
AutoCloseable interface, 905
autocloseable resources
key points, 405
with try-with-resources statements, 396–401
automatic local variables, 54–56
Automatic Resource Management feature, 397
automatic variables. See local variables
available processors, 811
await() method, 794–795
B
b in format strings, 453
\B in searches, 435–436
\b in searches, 435–436
backed collections, 622–624
backslashes (\)
escaped characters, 172, 448, 930
globs, 520–522
property resource bundles, 456
searches, 442–443
base 2 (binary) integers, 168
base 8 (octal) integers, 168–169
base 10 (decimal) integers, 168
base 16 (hexadecimal) integers, 168
literals, 170
searches, 437–440
basic for loops, 323–324
conditional expressions, 325–326
declaration and initialization, 324–325
iteration expressions, 325–326
loop issues, 326–328
BasicFileAttributes interface, 508–511
BasicFileAttributeView interface, 508
beforeFirst() method, 884, 886–887
behaviors, description, 4
BIGINT data type, 875
BINARY LARGE OBJECT (BLOB), 871
binary literals, 169
binarySearch() method
arrays, 627
collections, 627
overview, 611–613
bitwise operators, 241–242
BLOB (BINARY LARGE OBJECT), 871
blocked thread state
considerations, 748–749
deadlocks, 753–754
description, 729–730
blocking queues, 801–805
BlockingQueue collection, 801
behavior, 802
bounded queues, 803
LinkedTransferQueue, 803–805
special-purpose queues, 803
blocks
initialization, 138–140
synchronized, 745–746
synchronizing, 747–748
variables, 183
bookseller database overview, 847–850
boolean type and values
bit depth, 52
default values, 186
do loops, 323
in for loops, 324–325
format strings, 453
if statements, 312–313
invert operator, 245–246
literals, 171
relational operators, 226
while loops, 322
wrappers, 602
boundaries in searches, 435–436
bounded queues, 803
braces ({}). See curly braces ({})
branching
if-else, 308–313
switch statements. See switch statements
break statement
in for loops, 326
key points, 362
loop constructs, 330–331
switch statements, 314, 317–319
buckets for hashcodes, 582–585
BufferedReader class
description, 479
using, 484
BufferedWriter class
description, 479–480
using, 484
buffering file I/O, 484
bugs. See exceptions
bytes
case constants, 314
default values, 186
and int, 174
ranges, 51
wrappers, 602
C
c in format strings, 453
cached thread pools, 811
CachedRowSet, 919–920
Calendar class
description, 419
instance creation, 431
working with, 422–424
call stacks
exceptions, 339–340
Callable interface, 813–814
CallableStatement interface, 907
key points, 933–934
overview, 910–912
CamelCase, 9
cancelRowUpdates() method, 890–892
canExecute() method, 508
canRead() method, 508
canWrite() method, 508
capacity of strings, 270
carats (^)
bitwise operators, 241–242
exclusive-OR operators, 245
CAS (Compare And Swap) feature, 789
case sensitivity
identifiers, 7
SQL, 846–847
string comparisons, 266–267
case statements, 313–316
casts, 174
assignment, 225
with equals(), 579
explicit, 175–176
implicit, 176
overview, 113–116
precision, 178–179
primitives, 176–178
catch clause. See try and catch feature
chained methods, 272–273
chaining
constructors, 127–128
I/O classes, 484
changeable data, synchronizing, 749
CHARACTER LARGE OBJECT (CLOB), 871
characters and char type, 875
bit depth, 52
case constants, 314
comparisons, 227
default values, 186
format strings, 453
globs, 521
literals, 171–172
searches, 435
wrappers, 602
charAt() method, 266
checked exceptions
handling, 350
interface implementation, 117
overloaded methods, 106
Class class, 746
.class files, 12
Class.forName() method, 860–861
description, 358
downcasts, 114
with equals(), 579
classes
access, 17–21
compiling, 11–12
constructors. See constructors
declaring, 17–18
defining, 9–10
description, 4
import statements, 13–15
inner. See inner classes
interface implementation, 118
launching applications with java, 12
literals, 747
main() method, 13
member, 682
member declarations, 28–29
source file declaration rules, 10–11
thread-safe, 751–753
wrapper, 356
cleaning up garbage collection, 207–208
clear() method, 293
clearWarnings() method, 903
CLOB (CHARACTER LARGE OBJECT), 871
close() method, 483–484, 903–906
Closeable interface, 398–399
closing SQL resources, 903–906
code overview
coding to interfaces, 599
conventions, 7–9
synchronizing, 738–744
cohesion
IS-A and HAS-A, 544–545
key points, 565
packages, 484
cohesive classes, 5
Collection interface, 589–590
collections and Collections Framework, 574, 588
ArrayList basics, 598–599
vs. arrays, 56
autoboxing, 600–603
backed, 622–624
blocking queues, 801–805
Comparable interface, 606–608
Comparator interface, 608–609
concurrent, 797–805
converting arrays and lists, 613–614
copy-on-write, 799
diamond syntax, 603–604
hashcodes for, 581
interfaces and classes, 589–594
legacy, 630–632
List interface, 593–594
lists, 614–616
Map interface, 595–596
maps, 617–620
methods, 626–627
mixing generic and nongeneric, 633–638
operations, 588
ordered, 591–592
overview, 588
polling, 621–622
PriorityQueue class and Deque interface, 625–626
Queue interface, 596–597
searching, 611–613
searching TreeSets and TreeMaps, 620–621
Set interface, 594–595
sets, 616–617
sorted, 592–593
sorting, 604–611
thread-safe, 800
unboxing problems, 639
working with, 797–798
Collections class, 589–590, 604
Collections.synchronizedList() method, 751–753, 798
colons (:)
assertions, 380
conditional operators, 240–241
labels, 332
URLs, 496
column indexes, 872
combining I/O classes, 484–487
metacharacters, 443
commas (,)
as delimiters, 447
in for loops, 324–325
format strings, 453
variables, 175
comments
property resource bundles, 456–457
source code files, 10
commit() method, 924–925
Comparable interface, 593, 801
vs. Comparator, 610
working with, 606–608
Comparator interface, 593, 801
vs. Comparable, 610
working with, 608–609
Compare And Swap (CAS) feature, 789
compare() method, 609
compareAndSet() method, 789
compareTo() method, 606–609
comparisons
instanceof, 232–235
relational operators, 226–232
strings, 266–267
compile() method, 444
compiler and compiling
assertion-aware code, 383-384
casts, 114
interface implementation, 117
javac, 11–12
overloaded methods, 109
versions, 383
warnings and fails, 635–636
compiler errors
assignments, 178–179
instanceof, 234
compound assignments
with casts, 179
operators, 225–226
strings, 237–238
compute() method
ForkJoinTask, 818
RecursiveAction, 821
concat() method, 266
concatenating strings, 236–238, 248, 266
concrete classes
abstract methods implemented by, 100–101
creating, 23–24
subclasses, 44–46
CONCUR_READ_ONLY cursor type, 880–881, 894
CONCUR_UPDATABLE cursor type, 881–882, 889
atomic variables, 786–789
collections, 797–805
Executors. See Executors
Fork/Join Framework. See Fork/Join Framework
key points, 767
locks, 789–796
ThreadPools. See ThreadPools
ConcurrentHashMap class, 801
ConcurrentMap interface, 801
ConcurrentSkipListMap class, 801
ConcurrentSkipListSet class, 801
Condition interface, 794
conditional operators
key points, 248
overview, 240–241
conditions
do loops, 323
in for loops, 324–326
if-else branching, 308–313
locks, 794–795
switch statements. See switch statements
while loops, 322
connect() method, 856
connected RowSets, 916–919
Connection interface, 851–852, 903
connections
databases, 844–845
DriverManager class, 853–858
consistency in equals() contract, 581
Console class
working with, 491–493
console() method, 491
constant specific class body, 63, 65
case, 314
enum, 61
interface, 27–28
names, 9
String class, 264
constructing
statements, 864–867
constructors, 126
basics, 126–127
chaining, 127–128
declarations, 49–50
enums, 63–64
inherited, 133–134
key points, 152–153
overloaded, 134–138
rules, 128–129
strings, 259
super() and this() calls, 137–138
consumed search characters, 434
contains() method
collections, 590
description, 293
lists, 628
containsKey() method, 628
containsValue() method, 628
continue statement
key points, 362
loop constructs, 330–331
contracts in JDBC, 851
controls, 17–18
conventions
code, 7–9
identifiers, 6
names, 4
conversions
arrays and lists, 613–614
format strings, 453
return type, 124
strings to URIs, 496
types. See casts
copy() method, 498–499
copy-on-write collections, 799
copying files, 498–499
CopyOnWriteArrayList collection, 799
CopyOnWriteArraySet collection, 799
cost reduction, object-oriented design for, 95
counting
instances, 141
references, 201
country codes, 427
countTokens() method, 451
coupling
IS-A and HAS-A, 543–544
key points, 565
covariant returns, 123–124
CPU-intensive vs. I/O-intensive tasks, 807–808
create() method, 558
createNewFile() method, 481–482, 487–488
creationTime() method, 513
credentials for database, 855
CRUD operations, 845–846
curly braces ({})
abstract methods, 44
anonymous inner classes, 694, 697
globs, 521
instance variables, 186
methods, 44
optional, 309
currency
formatting, 429
key points, 463
working with, 419–420
currently running thread state, 727
currentThread() method, 722–723
cursor types for ResultSets, 881
cursorMoved() method, 918
D
d in format strings, 453
\D in searches, 435
\d in searches, 435
D suffix, 171
daemon threads, 716
DAO (Data Access Object) design pattern, 555
benefits, 559
key points, 566
problem, 555–556
solution, 556–559
dashes (-)
compound assignment operators, 225–226
decrement operators, 238–239
format strings, 453
searches, 437
subtraction, 235
data types in ResultSets, 871
DatabaseMetaData class, 896–900
databases
connections, 844–845
credentials, 855
JDBC. See JDBC API
overview, 842–844
DataOutputStream class, 480
DataSource class, 859
Date class, 419
instance creation, 431
with SQL, 871
working with, 420–422
DateFormat class
description, 419–420
instance creation, 431
locale setting, 428
working with, 425–426
dates
Calendar class, 422–424
DateFormat class, 425–426
format attributes, 507
key points, 463
overview, 419–420
working with, 420–422
DAY_OF_WEEK field, 424
dead thread state, 720, 730–731
deadlocks
key points, 768
threads, 753–754
tryLock() for, 792
Deadly Diamond of Death, 97
decimal (base 10) integers, 168
decimal literals with underscores, 169
declarations
arrays, 56–57, 274–275, 280–282, 644–645
basic for loops, 324–325
class members, 28–29
classes, 17–18
constructors, 49–50
enhanced for loops, 329
enum elements, 63–65
enums, 61–63
exceptions, 347–352
generics, 652–653
interface constants, 27–28
interfaces, 24–27
polymorphic, 291
reference variables, 52
return types, 122–125
source file rules, 10–11
variables, 50–60
decoupling tasks from threads, 809–811
decrement operators
key points, 248
working with, 238–240
default access
description, 17–18
overview, 19
default case in switch statements, 319–320
Default protection, 29
defaults
delimiters, 449–451
locales, 458
primitive and object type instance variables, 185–188
thread priorities, 735
defining
classes, 9–10
exceptions, 342
inner classes, 690
threads, 714–718
Delayed interface, 803
delete() method
DAO, 558
strings, 271
DELETE operation for SQL, 846
deleteIfExists() method, 499
deleteRow() method, 892
deleting
files, 498–499
strings, 271
delimiters
default, 449–451
tokens, 446–447
demarcation in transactions, 924
depth-first searches, 517
Deque interface, 625–626
deques, 797
descending order in collections, 622
descendingMap() method, 622–623
descendingSet() method, 622–623
design patterns
DAO. See DAO (Data Access Object) design pattern
factory. See factory design patterns
singleton. See singleton design pattern
Design Patterns: Elements of Reusable Object-Oriented Software, 550
diamond syntax, 603–604
digits
globs, 521
in searches, 435
directories
creating, 497–498
DirectoryStream, 514–515
FileVisitor, 515–519
iterating through, 514–515
key points, 529
renaming, 525
working with, 487–491
DirectoryStream interface, 514–515
disabling assertions, 384–386
disconnected RowSets, 919–920
Disk Operating System (DOS), 508
distributed-across-the-buckets hashcodes, 583
divide and conquer technique, 816–817
division
compound assignment, 225–226
operator, 235
do loops, 323
DOS (Disk Operating System), 508
DosFileAttributes interface, 508, 510, 512–513
DosFileAttributeView interface, 509
dots (.)
access, 30–33
class names, 144
instance references, 144
variable argument lists, 48
double quotes (”) in format strings, 452
double type, 875
casts, 176
default values, 186
floating-point literals, 170
ranges, 51
underscores, 169
downcasts, 114
DriverManager class, 844
description, 853
key points, 932
overview, 854–856
registering JDBC drivers, 856–858
drivers, JDBC, 852, 856–858, 860–861
DRY programmers, 923–924
duplicates in ArrayLists, 291–292
duration of threads, 726
E
eager initialization, 553
element() method, 802
elements in arrays. See arrays
elevator property, 460
eligible thread state, 727
ellipses (…) in variable argument lists, 48
else statements, 308–313
embarrassingly parallel problems, 824–826
enabling assertions, 382–386
encapsulation
benefits, 95
key points, 149
overview, 84–87
reference variables, 294–295
engines, regex, 432
ENTRY_CREATE type, 524–525
ENTRY_DELETE type, 524–525
ENTRY_MODIFY type, 524–525
entry points in switch statements, 317
Enum class, 618
Enumerator interface, 450
enums, 60
case constants, 314
constants, 61
declaring, 61–63
declaring elements, 63–65
equality tests, 231–232
key points, 73
equal signs (=)
compound assignment operators, 225–226
equality tests, 227–232
property resource bundles, 456–457
reference equality, 577
relational operators, 226–227
wrappers, 601–602
equality and equality operators
enums, 231–232
hashcodes, 585–586
primitives, 228
equals() method, 574
arrays, 627
contract, 581
description, 575
implementing, 578–580
key points, 661–662
maps, 617–618
objects, 230–231
overriding, 576–578
Set, 594
wrappers, 601–602
equalsIgnoreCase() method, 266–267
erasure, type, 637
Error class, 343
escape characters and sequences
globs, 521
PreparedStatements, 909
println(), 448
event handlers, 683–684
Exception class, 342–343
ExceptionInInitializerError class
description, 358
init blocks, 140
exceptions, 334
creating, 353–354
declarations, 347–352
defining, 342
hierarchy, 343–345
interface implementation, 117
JDBC, 901–906
JVM thrown, 355–356
key points, 363
list of, 357–358
matching, 345–347
programmatically thrown, 356–357
propagating, 339–342
sources, 355
suppressed, 401–402
try and catch. See try and catch feature
try-with-resources feature, 396–401, 405, 905–906
exclamation points (!)
boolean invert operator, 245–246
property resource bundles, 457
relational operators, 226–227
wrappers, 601–602
exclusive-OR (XOR) operator
hashcodes, 585
overview, 245
description, 867
overview, 865–866
executeQuery() method
description, 867
overview, 864
stored procedures, 911–912
executeUpdate() method
description, 867
overview, 864–865
execution entry points in switch statements, 317
ExecutionException class, 814
Executor class, 809
Executors, 805–806
Callable interface, 813–814
CPU-intensive vs. I/O-intensive tasks, 807–808
decoupling tasks from threads, 809–811
ExecutorService shutdown, 814–815
key points, 831
parallel tasks, 806–807
thread limits, 807
thread pools, 811–812
ThreadLocalRandom, 814
turns, 808–809
Executors.newCachedThreadPool() method, 812
Executors.newFixedThreadPool() method, 812
Callable, 813
shutdown, 814–815
ExecutorService.shutdownNow() method, 815
exit() method
loops, 326
threads, 815
try and catch, 360
explicit casts, 175–176
explicit values in constructors, 127
expressions
assertions, 381–382
enhanced for loops, 329
globs, 521–522
if statements, 312–313
regular. See regular expressions (regex)
extended ASCII set, 52
extending
inheritance in, 89
interfaces, 119
Thread class, 717–718
extends keyword
illegal uses, 121
IS-A relationships, 92
F
f in format strings, 453
F suffix, 170–171
factory design patterns, 560
benefits, 563
example, 853–854
key points, 566
problem, 560
solution, 560–563
fails vs. warnings, 636
fall-through in switch statements, 317–319
false value, 171
FIFO (first-in, first-out) queues, 596
File class
creating files, 480–482
description, 479
files and directories, 487
key points, 528–529
File.list() method, 490
file:// protocol, 496
FileNotFoundException class, 346–347, 391
FileOwnerAttributeView interface, 509
FileReader class
description, 479
working with, 482–484
files, 487–491
attributes. See attributes
copying, moving, and deleting, 498–499
key points, 528
navigating, 478–480
permissions, 507–508
renaming, 525
searching for, 490–491
Files.delete() method, 499
Files.deleteIfExists() method, 499
Files.getLastModifiedTime() method, 507
Files.notExists() method, 497, 499
Files.walkFileTree() method, 515–516
FileSystems.getDefault() method, 519
FileUtils class, 499
FileVisitor interface, 515–519
FileWriter class
description, 479
working with, 482–484
FilteredRowSet, 919–920
final arguments, 43
final constants, 27
final methods
nonaccess member modifiers, 42–43
overriding, 103
final modifiers
increment and decrement operators, 240
finalize() method
description, 575
garbage collection, 207–208
finally clauses
key points, 405
with try and catch, 336–339, 389–392
find() method, 444–445
FindMaxPositionRecursiveTask task, 824
first-in, first-out (FIFO) queues, 596
fixed thread pools, 811
flags in format strings, 453
flat transactions, 924
flexibility from object orientation, 84
float type and floating-point numbers, 875
assigning, 178
casts, 177
classes, 20
comparisons, 227
default values, 186
format strings, 453
literals, 170–171
ranges, 51
underscores, 169
flow control, 308
break and continue statements, 330–331
do loops, 323
for loops, 323–329
if-else branching, 308–313
labeled statements, 331–333
switch statements. See switch statements
unlabeled statements, 331
while loops, 321–322
flush() method, 483–484
for loops
basic, 323–328
enhanced, 328–329
for-each loops, 799
forced exits from loops, 326
forcing garbage collection, 204–207
foreign keys, 850
Fork/Join Framework, 815–816
divide and conquer technique, 816–817
embarrassingly parallel problems, 824–826
ForkJoinPool, 817
ForkJoinTask, 817–818
join(), 820–821
key points, 831
RecursiveAction, 821–822
RecursiveTask, 822–824
work stealing, 819–820
fork() method, 818
ForkJoinPool class, 817
ForkJoinTask class, 817–818
format strings, 452–454
Formatter class, 452
formatting
key points, 464–465
with printf() and format(), 451–454
reports, 879–880
forName() method, 860–861
fractions, 170
fromMillis() method, 513
fully qualified names, 13
Future class, 813–814
G
Gang of Four, 550
garbage collection
cleaning up before, 207–208
forcing, 204–207
key points, 211
objects eligible for, 202–204
overview, 199
garbage collector
operation, 201
overview, 200
running, 200
gc() method, 204–206
classes, 653–657
declarations, 652–653
equals(), 576–581
hashCode(), 581–587
key points, 664–666
legacy code, 633
mixing with nongeneric, 633–638
overview, 629–630
polymorphism, 639–640
toString(), 575–576
get() method
ArrayLists, 293
paths, 495–496
unboxing problems, 639
getAndIncrement() method, 789
getBoolean() method, 873
getBundle() method, 455, 458–459
getColumnCount() method, 876–877
getColumnDisplaySize() method, 878
getColumnName() method, 877
getColumns() method, 897
getConnection() method, 854–856, 860
getCurrencyInstance() method, 429
getDate() method, 874
getDateInstance() method, 425
getDelay() method, 803
getDisplayCountry() method, 428
getDisplayLanguage() method, 428
getDouble() method, 873
getDriverName() method, 897, 900
getDriverVersion() method, 897, 900
getErrorCode() method, 901
getFileAttributeView() method, 513
getFileName() method, 500
getFloat() method, 873
getId() method, 727
getInstance() method
DateFormat, 425
NumberFormat, 429
singleton design pattern, 552–553
getInt() method, 873
getLastModifiedTime() method, 507
getLong() method, 873
getMaximumFractionDigits() method, 430
getMessage() method, 901
getMetaData() method, 896–897
getMoreResults() method, 912
getNameCount() method, 500
getNextException() method, 901–902
getObject() method, 458, 874, 880, 893
getParent() method, 500
getPathMatcher() method, 519
getProcedures() method, 897, 899
getResultSet() method, 866–867
getRoot() method, 500
getRow() method, 884
getRuntime() method, 205
getSQLState() method, 901
getState() method, 720
getString() method, 874
getSuppressed() method, 906
getTableName() method, 878
getters encapsulation, 85
getTimestamp() method, 874
getUpdateCount() method, 866–867
getUrl() method, 915
getWarnings() method, 903
greater than signs (>) for relational operators, 226–227
greedy quantifiers, 440–442
GregorianCalendar class, 423
group() method, 444
groups
PosixFileAttributes, 512–513
in searches, 438
guarantees with threads, 725–726, 735
guarded regions, 335
H
handle and declare pattern, 392
hard-coding credentials, 855
HAS-A relationships, 542
cohesion, 544–545
coupling, 543–544
key points, 149
object composition, 546–547
overview, 91–95
hashCode() method
contract, 585–587
generics, 574–575
HashSet, 594
implementing, 584–585
key points, 661–662
maps, 617–618
overriding, 581–584
hashcodes overview, 581–584
HashMap collection, 589
description, 595
hashcodes, 581
HashSet collection, 589
description, 594
hashcodes, 581
ordering, 616
Hashtable collection, 589
description, 595
keys, 578
ordering, 592
hasMoreTokens() method, 450
Head First Design Patterns, 550
headMap() method, 623–624
headSet() method, 623–624
heap
garbage collection, 200
key points, 209
overview, 166–167
hexadecimal (base 16) integers, 168
literals, 170
searches, 437–440
hiding implementation details, 85
hierarchy
exceptions, 343–345
tree structures, 501
higher() method, 621
Hunt, Andy, 923
I
IDE (integrated development environment), 11
identifiers, 4
assert, 382–383
key points, 68
legal, 6–7
Map, 595
threads, 727
if-else branching
key points, 361
overview, 308–313
IllegalArgumentException class
description, 358
programmatically thrown exceptions, 357
IllegalMonitorStateException class, 758, 793
IllegalStateException class, 358
IllegalThreadStateException class, 726
immutable objects
strings, 258–264
thread safe, 799
implementation details, hiding, 85
implementers of interfaces, 696
implementing interfaces
key points, 151
overview, 116–121
implements keyword
illegal uses, 121
IS-A relationships, 92
implicit casts
assignment, 225
primitives, 176
import statements, 5
key points, 68
overview, 13–15
source code files, 11
static, 15–17
IN parameters
CallableStatements, 911–912
PreparedStatements, 908
increment operators
key points, 248
working with, 238–240
indexes
columns, 872
List, 593
out-of-range, 279
searches, 611
string, 266
zero-based, 12
indexOf() method
ArrayLists, 293
IndexOutOfBoundsException class
subclasses, 344
threads, 751
indirect interface implementation, 233
information about ResultSets, 876–878, 896–900
inheritance
access modifiers, 30–32, 37–38
constructors, 133–134
event handlers, 684
HAS-A relationships, 93–95
IS-A relationships, 91–93
key points, 149
multiple, 97
inherited methods, overriding, 104
initialization
basic for loops, 324–325
eager and lazy, 553
loop elements, 279–280
object references, 190–191
primitives, 189–190
initialization blocks, 138–140, 153
injection attacks, 866
anonymous. See anonymous inner classes
defining, 690
instantiating, 686
key points, 702
method-local, 690–692
modifiers, 689
objects, 687–688
overview, 683–684
referencing instances, 688–689
regular, 685–686
static, 699–700
INOUT parameters for CallableStatement, 911–912
input/output (I/O), 477
combining classes, 484–487
Console class, 491–493
directories. See directories
files. See files
key points, 528
path creation, 495–496
Runnable and Callable, 814
WatchService, 523–526
input-output intensive vs. CPU-intensive tasks, 807–808
InputStream.read() method, 808
INSERT operation, 845–846
rows, 894–896
string elements, 272
insertion points in searches, 611
instance methods
overriding, 103
polymorphic, 99
instance variables, 52–53
constructors, 127
default values, 185–188
on heap, 166–167
instanceof operator
key points, 247
object tests, 232–235
instances
counting, 141
initialization blocks, 139
instantiation
inner classes, 686
key points, 152–153
static nested classes, 700
integers and int data type, 875
and byte, 174
case constants, 314
casts, 176–177
comparisons, 227
default values, 186
format strings, 453
literals, 168
ranges, 51
remainder operator, 236
wrappers, 602
integrated development environment (IDE), 11
interfaces, 4
vs. abstract classes, 25–26
attributes, 508–509
constants, 27–28
constructors, 129
declaring, 24–27
extending, 119
indirect implementation, 233
JDBC, 851–852
key points, 70–71
names, 8–9
overview, 5
interrupt() method, 815
InterruptedException class
Callable, 813
Conditions, 794
sleep(), 732
WatchService, 525
intersections in searches, 437
invert operator, 245–246
invokeAll() method, 822
invoking
overloaded methods, 107–110
polymorphic methods, 98
I/O. See input/output (I/O)
IOException class
checked exceptions, 349
directories, 489
IS-A relationships, 542
cohesion, 544–545
coupling, 543–544
object composition, 546–547
overview, 91–93
polymorphism, 96
return types, 125
isAlive() method, 720
isDirectory() method, 509
isHidden() method, 513
isInterrupted() method, 815
ISO Language codes, 427
ISO Latin-1 characters, 52
isolation
references, 203–204
transactions, 922
isReadOnly() method, 513
Iterable class, 501
iteration
basic for loops, 325–326
directories, 514–515
paths, 501
iterator() method
lists, 628
sets, 628
Iterators
collections, 799
lists, 614–615
J
java.io.Console class
working with, 491–493
java.io.IOException class
checked exceptions, 349
directories, 489
java.io package
classes, 484–485
files and directories, 487–491
java.io.PrintStream class, 451
java.lang.Class class, 746
java.lang.ClassCastException class
description, 358
downcasts, 114
with equals(), 579
java.lang.Enum class, 618
java.lang.Exception class, 342–343
java.lang.Integer class, 15–16, 356
java.lang.Object class, 88, 574
java.lang.Object.equals() method, 230–231, 586
java.lang.Runnable interface
executing, 806
implementing, 718
I/O activities, 814
java.lang.Runtime class
available processors, 811
garbage collection, 205
java.lang.RuntimeException class, 343, 348–351
java.lang.StringBuilder class, 258, 269
key points, 296
methods, 271–272
vs. StringBuffer, 269–270
thread safeness, 751
java.lang.Thread class, 714, 716–717
extending, 717–718
methods, 728
thread methods, 764
Java Naming and Directory Interface (JNDI) lookup, 860
java.nio.file package, 493–494, 514
java.nio.file.attribute package, 493, 506
java.nio.file.Path interface
key points, 528–529
methods, 500–501
working with, 493–494
Java resource bundles, 457–458
java.sql.Connection interface, 851–852, 903
instance creation, 431
working with, 420–422
java.sql.Driver interface, 856, 860
java.sql.DriverManager class, 844
description, 853
key points, 932
overview, 854–856
registering JDBC drivers, 856–858
java.sql package, 851
java.sql.ResultSet interface, 851–852, 915
java.text.DateFormat class
description, 419–420
instance creation, 431
locale setting, 428
working with, 425–426
java.text.NumberFormat class
description, 420
instance creation, 431
locale setting, 428
working with, 428–430
java.util.ArrayList class. See ArrayList class
java.util.Calendar class
description, 419
instance creation, 431
working with, 422–424
java.util.Collection interface, 589–590
java.util.Collections class, 589–590, 604
java.util.concurrent.atomic package, 786–787
java.util.concurrent.Callable interface, 813–814
java.util.concurrent.Delayed interface, 803
java.util.concurrent.Executor class, 809
java.util.concurrent.ForkJoinPool class, 817
java.util.concurrent.ForkJoinTask class, 817–818
java.util.concurrent.Future class, 813–814
java.util.concurrent.locks.Condition interface, 794
java.util.concurrent.locks.Lock interface, 791
java.util.concurrent.locks package, 786–787, 789–790
java.util.concurrent.locks.ReentrantLock class, 791–794
java.util.concurrent package, 786. See also concurrency
java.util.concurrent.ThreadLocalRandom class, 814
java.util.concurrent.ThreadPoolExecutor, 812
java.util.Date class, 419
instance creation, 431
with SQL, 871
working with, 420–422
java.util.Formatter class, 452
java.util.GregorianCalendar class, 423
java.util.List interface, 291, 589
threads, 797
java.util.Locale class
description, 420
instance creation, 431
overview, 426–429
resource bundles, 455
java.util.NavigableMap interface, 589, 620
java.util.NavigableSet interface, 589, 620
java.util.regex.Matcher class, 443–444
java.util.regex.Pattern class, 435, 437, 443
java.util.ResourceBundle class, 455–456
java.util.Scanner class
searching with, 445–446
tokenizing with, 449–450
java.util.StringTokenizer class, 450–451
Java Virtual Machine (JVM), invoking, 12
JavaBeans properties, 915
javac
compiling with, 11–12
versions, 383
javax.sql.DataSource class, 859
javax.sql package for RowSets, 914
javax.sql.rowset package, 913
JDBC API, 842
CallableStatements, 910–912
database connections, 844–845
database overview, 842–844
driver implementation versions, 860–861
DriverManager class, 853–858
exceptions and warnings, 901–906
interfaces, 851–852
key points, 932
PreparedStatements, 906–910
query submissions, 861–867
result sets. See ResultSets
RowSet objects, 913–920
SQL queries, 845–847
statements, 863–867
test database, 847–850
transactions, 921–927
URL, 858–859
JdbcRowSet interface, 914–920
JIT (Just In Time) compiler, 788
JNDI (Java Naming and Directory Interface) lookup, 860
join() method
class source, 764
Fork/Join Framework, 818, 820–821
key points, 767
locks, 749
join tables, 850
JoinRowSet, 919–920
Just In Time (JIT) compiler, 788
JVM (Java Virtual Machine), invoking, 12
key.pollEvents() method, 525
key.reset() method, 525
key/value pairs in property resource bundles, 456–457
keys
hashtables, 578
Map, 595
keySet() method, 628
keywords, 4
assert, 382–383
list of, 7
L
L suffix, 169
labeled statements, 331–333
Labels_en.properties file, 455
Labels_fr.properties file, 455
LARGE OBJECT types, 871
large tasks, divide and conquer technique for, 816–817
lastModified() method, 508
lastModifiedTime() method, 513
launcher versions, 383
launching applications, 12
lazy initialization, 553
left-justification in format strings, 453
legacy code in generics, 633
legal identifiers, 6–7
length() method, 267
length of arrays and strings, 267
less than signs (<) for relational operators, 226–227
letters in searches, 435
LIKE operator, 869
linefeeds, 443
LinkedBlockingDeque class, 801, 803
LinkedBlockingQueue class, 801, 803
LinkedHashMap class, 589, 595–596
LinkedHashSet class, 589, 592, 594
LinkedList class, 589, 594, 614
LinkedTransferQueue class, 801, 803–805
list.iterator() method, 799
list() method, 490
ListIterator, 799
ListResourceBundle class, 457–458
lists and List interface, 291, 589
ArrayLists. See ArrayList class
converting with arrays, 613–614
description, 591
key points, 664
threads, 797
working with, 614–616
literals
binary, 169
boolean, 171
character, 171–172
class, 747
floating-point, 170–171
format strings, 452
globs, 521
hexadecimal, 170
integer, 168
key points, 209
octal, 169
primitive assignments, 173–174
local arrays, 191
local object references, 190–191
local primitives, 189–190
local variables, 188
access modifiers, 41–42
description, 183
inner classes, 691
key points, 72
working with, 54–56
Locale class
description, 420
instance creation, 431
overview, 426–429
resource bundles, 455
locales
default, 458
grouping separators in format strings, 453
resource bundles. See resource bundles
localhosts in URLs, 858
Lock interface, 791
locks, 789–790
conditions, 794–795
key points, 829
obtaining, 748–749
ReentrantReadWriteLock, 796
synchronization, 744–747
locks package, 786–787, 789–790
logical operators, 241
bitwise, 241–242
key points, 248
non short-circuit, 244–246
long type
default values, 186
ranges, 51
LONGVARCHAR data type, 875
loop constructs, 321
break and continue, 330–331
do, 323
element initialization, 279–280
for, 323–329
key points, 362
wait() in, 761–763
while, 321–322
loosely coupled classes, 543
lower() method, 621
lowercase characters
natural ordering, 628
strings, 268
M
main() method, 13
exceptions, 341–342
overloaded, 110
threads, 714–715
maintainability, object orientation for, 84
maps and Map interface, 589, 595–596
description, 591
working with, 617–620
mark and sweep algorithm, 201
Matcher class, 443–444
matching
exceptions, 345–347
key points, 529
pattern, 443–446
MAX_VALUE constant, 16
meaningfully equivalent objects, 230
member modifiers, nonaccess, 42–49
members
access. See access and access modifiers
declaring, 28–29
key points, 72–73
memory
garbage collection. See garbage collection
strings, 264–265
memory leaks, 199
META-INF/services/java.sql.Driver file, 860
metacharacters in searches, 434–435, 442–443
metadata for ResultSets, 876–878, 896–900
method-local inner classes, 690
key points, 702–703
working with, 691–692
methods
abstract, 43–47
access modifiers. See access and access modifiers
anonymous inner classes, 694
ArrayLists, 292–294
assertions, 386–388
chained, 272–273
description, 4
enums, 63–64
interface implementation, 116–117
names, 9
native, 47
overloaded, 106–112
overridden, 100–106
parameters, 504
recursive, 356
stacks, 339–340
strictfp, 47–48
String, 265–268
StringBuilder, 271–272
synchronized, 47
variable argument lists, 48–49
minus signs (-)
compound assignment operators, 225–226
decrement operators, 238–239
format strings, 453
searches, 437
subtraction, 235
MissingResourceException class, 459
mixing generic and nongeneric collections, 633–638
mkdir() method, 488
modifiers. See access and access modifiers
modulus operator, 235–236
monitors for locking, 744, 789
move() method, 498–499
moveToCurrentRow() method, 890, 896
moveToInsertRow() method, 890, 895
moving files, 498–499
moving in ResultSets, 869–870, 880–889
multi-catch clauses, 389–392, 405
multidimensional arrays
reference assignments, 287–288
multiple inheritance, 97
multiple threads, starting and running, 724–727
multiplication
compound assignment, 225–226
operator, 235
multithreading, 714
mutable data, synchronizing, 749
mutators in encapsulation, 85
N
\n escape sequence, 443
names
classes and interfaces, 8–9, 385
constants, 9
conventions, 4
dot operator, 144
fully qualified, 13
labels, 332
methods, 9
shadow variables, 197–198
threads, 722
variables, 9
narrowing conversions, 176
native methods, 47
native threads, 715
natural ordering, 628
NavigableMap interface, 589, 620
NavigableSet interface, 589, 620
navigation
searches, 437
TreeSets and TreeMaps, 620–621
negative numbers
from casts, 179
format strings, 453
representing, 51
nested classes, 17
inner. See inner classes
nested if-else statements, 309
nested methods, 184
new keyword
arrays, 275
inner classes, 687
new thread state
description, 729
starting threads, 720
newCachedThreadPool() method, 812
newFixedThreadPool() method, 812
next() method
Iterator, 614–615
Scanner, 449–450
nextInt() method, 814
nextToken() method, 450
nextXxx() methods, 450
NIO.2, 493
attributes, 506–513
DirectoryStream, 514–515
files and directories, 497–506
files and paths, 493–496
FileVisitor, 515–519
key points, 528–529
PathMatcher, 519–522
permissions, 507–508
WatchService, 523–526
no-arg constructors, 127–129
NoClassDefFoundError class, 358
non-digits in searches, 435
non-static fields, synchronizing, 749–750
non-synchronized method, 745
nonaccess member modifiers, 20, 42
abstract methods, 43–47
final arguments, 43
final methods, 42–43
key points, 69–70
methods with variable argument lists, 48–49
native methods, 47
strictfp methods, 47–48
synchronized methods, 47
nongeneric code, updating to generic, 633
nongeneric collections, mixing with generic, 633–638
normalize() method, 502–503
normalizing paths, 501–503
NoSuchFileException class, 499
not equal operator (!=), 227
notify() method
class source, 764
description, 575
key points, 768
locks, 749
Object, 813
threads, 728, 755–757, 760, 762–764
notifyAll() method
class source, 764
description, 575
Object, 813
null values
returning, 124
wrappers, 603
nulling references, 202
NullPointerException class, 350
arrays, 277
description, 358
reference variables, 355–356
wrapper variables, 603
number signs (#) in property resource bundles, 456–457
NumberFormat class
description, 420
instance creation, 431
locale setting, 428
working with, 428–430
NumberFormatException class
description, 358
string conversions, 357
numbers
key points, 463
overview, 419–420
primitives. See primitives
random, 814
with string concatenation, 236–237
with underscores, 168–169
O
Object.notify() method, 813
Object.notifyAll() method, 813
object orientation, 83–84
benefits, 95
casting, 113–116
constructors. See constructors
DAO design pattern, 554–559
encapsulation, 84–87
factory design pattern, 560–563
inheritance, 88–95
initialization blocks, 138–140
interface implementation, 116–121
IS-A and HAS-A, 542–545
key points, 565–566
overloaded methods, 106–112
overridden methods, 100–106
return types, 122–125
singleton design pattern, 549–554
statics, 140–146
Object.wait() method, 813
objects and object references
composition principles, 545–548
default values, 185–188
garbage collection, 202–208
on heap, 166–167
initializing, 190–191
inner classes, 687–688
instanceof comparisons, 232–235
overloaded methods, 108–109
passing, 194–196
strings as, 258–259
updating columns with, 893–894
octal (base 8) integers, 168–169
offer() method
BlockingQueue, 802
LinkedList, 594
PriorityQueue and Deque, 625–627
one-dimensional arrays
constructing, 275–277
reference assignments, 286–287
operands, 224
operating system thread limits, 807
operators, 223–224
arithmetic, 235–240
assignment, 224–226
conditional, 240–241
increment and decrement, 238–240
instanceof, 232–235
logical, 241–246
relational, 226–232
opposites matches in searches, 435
OR expressions, 243–245
order
ArrayList elements, 592
collections, 622
instance initialization blocks, 139
natural, 628
threads, 727
ordered collections, 591–592
out-of-range array indexes, 279
out-of-scope variables, 184
OUT parameters for CallableStatements, 911–912
OutOfMemoryException class, 207
OutputStream.write() method, 808
overloaded constructors, 134–138
overloaded methods, 106
invoking, 107–110
key points, 150
polymorphism, 110
return types, 122–123
overridden methods, 100–104
illegal, 105–106
invoking superclass, 104–105
polymorphism, 110
return types, 123–124
static, 146
overriding
anonymous inner class methods, 694
equals(), 576–578
hashcode(), 581–584
private methods, 35
run(), 717
P
package-centric languages, 18
package-level access, 19
package statement in source code files, 10–11
packages, 5
access, 17–18
assertions, 385
classes in, 14
padding format strings, 453
parallel Fork/Join Framework. See Fork/Join Framework
parallel tasks, identifying, 806–807
parameterized types, 631–632
vs. arguments, 48
CallableStatements, 911–912
methods, 504
multi-catch and catch, 391–392
PreparedStatements, 908
parentheses ()
conditional operator, 240
in for loops, 324
format strings, 453
operator precedence, 226, 236–237
searches, 439
string concatenation, 237
try-with-resources, 905–906
ParseException class, 426
parseInt() method, 356–357
parsing
dates, 425–426
key points, 464–465
searches. See searches
passing
key points, 211
object reference variables, 194–196
pass-by-value, 195–196
primitive variables, 196–197
passwords, hard-coding, 855
PathMatcher, 519–522
paths and Path interface
creating, 495–496
iterating through, 501
key points, 528–529
methods, 500–501
normalizing, 501–503
relativizing, 505–506
resolving, 503–504
retrieving, 500–501
working with, 493–494
Paths.get() method, 495–496
pattern matching in searches, 443–446
patterns, design
DAO. See DAO (Data Access Object) design pattern
factory. See factory design patterns
singleton. See singleton design pattern
Peabody, Marc, 175
peek() method
BlockingQueue, 802
LinkedList, 594
PriorityQueue and Deque, 625–627
percent signs (%)
format strings, 452
LIKE operator, 869
remainder operator, 235–236
performance
singleton design pattern, 554
stored procedures, 910
permissions
files, 507–508
PosixFileAttributes, 512–513
phone number searches, 440
pipe (|) characters
bitwise operators, 241–242
logical OR operator, 243–245
multi-catch clauses, 390
plus signs (+)
addition, 235
compound assignment operators, 225–226
format strings, 452–453
increment operators, 238–239
searches, 438–439
string concatenation, 236–238
poll() method
BlockingQueue, 802
LinkedList, 594
PriorityQueue and Deque, 625–627
WatchService, 525
pollEvents() method, 525
pollFirstEntry() method, 622–623
polling, 621–623
pollLastEntry() method, 622–623
polymorphism, 548
abstract classes, 23
anonymous inner classes, 695
arrays, 642–644
declarations, 291
generics, 639–640
inheritance, 90
key points, 149–150
overloaded and overridden methods, 110
overview, 96–99
pools
String constants, 264
threads. See ThreadPools
Portable Operating System Interface (POSIX), 508
PosixFileAttributes interface, 508
PosixFileAttributeView interface, 509–510, 512–513
possessive quantifiers, 440
postfix increment operators, 238–239
postVisitDirectory() method, 517
pound signs (#) in property resource bundles, 456–457
precedence of operators, 226, 236–237
precision
floating-point literals, 171
floating-point numbers, 178
format strings, 453
precompiled PreparedStatements, 907–908
preemptive multitasking, 808
preemptive priority-based scheduling, 734–738
prefix increment operators, 238–239
prepareCall() method, 911
PreparedStatement interface
key points, 933–934
overview, 906–910
transactions, 923
prepareStatement() method, 908
preventing thread execution, 731
previous() method, 883, 885–886
preVisitDirectory() method, 517
primary database keys, 843, 848
primitives
comparisons, 228
declarations, 50–52
default values, 185–188
final, 58
initializing, 189–190
literals, 168–172
passing, 196–197
returning, 124
printf() method, 451–454
printing
file permissions, 507
formatting, 451–454
reports, 878–880
printStackTrace() method, 344
PrintStream class, 451
PrintWriter class, 480, 484–485
priority of threads, 728, 734–738
PriorityBlockingQueue, 801
PriorityQueue class, 589, 596, 625–626
private modifiers, 29
inner classes, 689
overriding, 35
overview, 33–36
processors, available, 811
programmatically thrown exceptions, 356–357
propagating uncaught exceptions, 339–342
properties
JavaBeans, 915
resource bundles, 456–457
setter methods, 916–917
protected modifiers, 29
inner classes, 689
overview, 35–39
public access, 19–20
public interface for exceptions, 347–352
public modifiers, 29
constants, 27
encapsulation, 85
inner classes, 689
overview, 31–33
public static void main() method, 13
BlockingQueue, 802
maps, 628
putIfAbsent() method, 801
Q
quantifiers
greedy, 440–442
searches, 437–440
queries
key points, 932–933
result sets. See ResultSets
SQL, 845–847
submitting, 861–867
query strings, 866
question marks (?)
conditional operators, 240–241
generics, 659
globs, 520
searches, 439–442
queues
blocking, 801–805
bounded, 803
description, 591
LinkedTransferQueue, 803–805
methods, 626
special-purpose, 803
threads, 727
quotes (’, “)
arguments, 444
SQL, 847
R
race conditions, 742
random numbers, 814
RandomInitRecursiveAction task, 824
ranges
numbers, 51
searches, 437
RDBMSs (Relational Database Management Systems), 843
reachable objects, 200
read-only objects, 799
readAttributes() method, 511, 513
reading
attributes, 506–507
ResultSets, 870–875
readLine() method, 486, 489–492
readPassword() method, 491–492
REAL data type, 875
reassigning reference variables, 202–203
recursive methods, 356
RecursiveAction class, 821–822
RecursiveTask task, 822–824
Red-Black tree structure, 595
redefined static methods, 146
ReentrantLock class, 791–794
ReentrantReadWriteLock object, 796
reference counting, 201
references, 96
arrays, 277
declaring, 52
description, 173
encapsulation, 294–295
inner classes, 688–689
instances, 144
isolating, 203–204
multidimensional arrays, 287–288
nulling, 202
one-dimensional arrays, 286–287
overloaded methods, 108–109
passing, 194–196
reassigning, 202–203
returning, 124
strings, 260–261
reflexivity with equals(), 581
regex language, 432