INDEX

−− (decrement) operator, 302–303

− (subtraction) operator, 306

! (boolean invert) logical operator, 309–310

! = (not equal to) operator, 292

% (remainder) operator, 299

& (non-short-circuit AND) operator, 288, 308

&& (short-circuit AND) operator, 306, 308, 548

* (multiplication) operator, 308

* quantifier, 495

· (dot) metacharacter, 497

· (dot operator), 25, 27

·java files, 791–792

/ (division) operator, 306

: (colons), 354

; (semicolons), 17, 41, 344–345, 675

? quantifier, 495

@argfiles command-line options, 791

(backslashes), 798

∧ (exclusive-OR [XOR]) logical operator, 288, 309–310, 553

∧ (regex carat) operator, 494

{} (curly braces), 329, 332

| (non-short-circuit OR) operator, 288, 308

| | (short-circuit OR) operator, 306, 308

+ (addition) operator, 288, 299, 307

+ quantifier, 495

++ (increment) operator, 302–303

+= (compound additive operator), 301

<? extends Animal> syntax, 618

<? super …> syntax, 619

<> (angle brackets), 600

<?> wildcard, 620

<E> placeholder, 622

<Integer> type, 602

<JButton> type, 608

<Object> type, 600

<X> type declaration, 629

= (assignment) operators

assigning one primitive variable to another, 198

compound, 197, 289–290

floating-point numbers, 196

literals too large for variable,

overview, 190–191, 288–289

primitive casting, 193–195

primitive variables, 191–193

reference variable, 198–200

variable scope, 200–202

= = (equals) operator, 245–246, 292–294, 544

A

absolute paths, 801–802

abstract classes, 16–19, 20

abstract keyword, 15

abstract methods, 41–45

access control

class access, 13

default access, 13–14, 32–34, 36–38

defined, 12

local variables, 38–39

modifiers, 24–26

private members, 29–32

protected members, 32–36

public access, 14–15, 26–29

access modifiers

declaring class members

default, 32–34, 36–38

local variables and, 38–39

overview, 24–26

private, 29–32

protected, 32–36

public, 26–29

defined, 12

method-local inner class, 682

add( ) method, 581, 620

addAll( ) method, 601, 603

addAnimals( ) method, 616–617

addition (+) operator, 288, 299, 307

addJob( ) method, 754–755

AND operators

& non-short-circuit, 288, 308

&& short-circuit, 306, 308, 548

angle brackets (< >), 600

animate( ) method, 102

anonymous arrays, 228–230

anonymous inner classes

argument-defined, 678–680

overview, 673–678

anotherObject object, 749

append( ) method, 440

applications, launching with java command, 793–796

appropriate use of assertions, 392–394

arg_index format string element, 507

args index, 796

arguments. See also var-args

anonymous inner classes defined by, 678–680

command-line, 393, 795–796

constructor, 238, 628

defined, 46

final, 41

just-in-time array, 229–230

using assertions to validate, 392–393

arithmetic operators

decrement, 302–303

increment, 302–303

overview, 298

remainder, 299

string concatenation, 299–301

ArrayIndexOutOfBoundsException subclass, 224, 368, 382

ArrayList class

basics, 567–568

Collection Interface Concrete Implementation, 565

List interface implementation, 562

mixing generic and non-generic collections, 601–607

of Strings, 596

arrays

constructing

anonymous, 228–230

multidimensional, 223

on one line, 226–228

one-dimensional, 221–222

overview, 220–221

declarations, 55–57, 219–220, 226–228

enhanced for loop for, 350–352

initialization blocks, 234–237

initializing

and constructing anonymous, 228–230

declaring, and constructing on one line, 226–228

elements in loop, 225–226

legal element assignments, 230

multidimensional, 233–234

of object references, 231–232

one-dimensional, 232–233

overview, 224–225

primitive, 230–231

reference assignments for one-dimensional, 232–234

instance variables, 206

length attribute, 437

as objects, 297

primitive, 230–231

returning values, 128

shortcut syntax, 226–228

use of brackets, 56

Arrays class

asList ( ) method, 579

collections, 576

converting to Lists, 579

key methods, 593

searching, 576–578

sort( ) method, 576

asList ( ) method, 579

assert statements, 386–389, 394

AssertionError subtype, 375, 381–382, 385, 393

assertions

appropriate use of, 392–394

disabling

at runtime, 390

selective, 390–391

enabling

compiling assertion-aware code, 388–389

identifiers versus keywords, 387–388

at runtime, 389

selective, 390–391

expression rules, 385–387

overview, 328, 383–385

assignment (=) operators

assigning one primitive variable to another, 198

compound, 197, 289–290

floating-point numbers, 196

literals too large for variable, 196–197

overview, 190–191, 288–289

primitive casting, 193–195

primitive variables, 191–193

reference variable, 198–200

variable scope, 200–202

assignments. See also arrays; garbage collection; wrappers

assignment operators

assigning one primitive variable to another, 198

floating-point numbers, 196

literals too large for variable, 196–197

overview, 190–191

primitive casting, 193–195

primitive variables, 191–193

reference variable, 198–200

variable scope, 200–202

autoboxing

equals( ) method, 245–246

equals operator, 245–246

overview, 244–245

use of, 246–247

heap, 184–185

literal values for primitive types boolean, 189

character, 189–190

floating-point, 188–189

integer, 186–188

overview, 186

string, 190

local variables

array references, 210

assigning one reference variable to another, 210–213

object references, 209–210

overview, 207

primitives, 207–209

overloading

with boxing and var-args, 249–250

in combination with var-args, 253–254

overview, 247–249

when combining widening and boxing, 251–253

widening reference variables, 250–251

passing variables into methods

object reference variables, 213–214

overview, 213

pass-by-value semantics, 214–215

primitive variables, 215–218

stack, 184–185

uninitialized variables

array, 206

object reference, 203–206

overview, 203

primitive, 203–204

atomic operations, 733–735

autoboxing

with collections, 568

equals( ) method, 245–246

equals operator, 245–246

overloading

with var-args and, 249–250

when combining widening and, 252–253

overview, 244–245

in switch statements, 337

use of, 246–247

automatic variables, 207. See also local variables

B

backed collections

key methods, 593–595

overview, 589–591

using PriorityQueue class, 591–592

backslashes (), 798

bar( ) method, 215

Bar object, 199, 679

behavior, 2. See also methods

binarySearch( ) method, 576

bitwise operators, 305

block variables, 201

blocked threads, 719–720

boolean add(element) interface method, 594

boolean containsKey(object key) interface method, 594

boolean contains(object) interface method, 594

boolean containsValue(object value) interface method, 594

boolean createNewFile( ) method, 446

boolean equals (Object obj) method, 543

boolean exists( ) method, 446

boolean hasNext( ) method, 580

boolean invert (!) logical operator, 309–310

Boolean wrapper, 239

booleans

arguments in backed collections, 590–591

assigning versus testing, 334

literals, 189

for loops, 346–347

and relational operators, 290–291

boxing

equals( ) method, 245–246

equals operator, 245–246

overloading

with var-args and, 249–250

when combining widening and, 252–253

overview, 244–245

in switch statements, 337

use of, 246–247

brackets, array, 56

branching, if-else, 329–332

break statements

labeled, 354–356

in switch blocks, 338–340

switch statements, 335

unlabeled, 353–354

use of, 352–353

BufferedReader class, 443

BufferedWriter class, 444

byte variables, 192

C

Calculator class, 754

Calendar class, 477–479

call stack

constructors on, 133

overloaded constructors on, 141

propagating uncaught exceptions, 362–363

unwinding, 367

camelCase format, 7–8

can't-be-overridden restriction, 40

carat (∧) operator, 494

case constants

default, 341–342

evaluation of, 338

legal expressions for, 335–338

casting

primitive, 193–195

reference variables, 116–119

catch clauses, 357–359, 362

catch keyword, 357–359

ceiling( ) method, 587

ceilingKey( ) method, 587

chained methods, 442

chaining

combining I/O classes, 449–452

constructors, 132–133

changeNum( ) method, 470

changeSize( ) method, 110

character literals, 189–190

characters, Unicode, 51, 189, 426–427

charAt( ) method, 435

ChatClient class, 663–664

checked exceptions, 373–375

checkup( ) method, 608

class files, 791–794, 805

class literals, 738

ClassCastException class, 382, 547

classes. See also dates; exceptions; individual classes by name; inner classes; member declarations

cohesion, 3, 151–154

collections, 557–561

combining, 449–452

declaration

abstract classes, 16–19

class access, 13

default access, 13–14

final classes, 15–16

modifiers, 12–13, 15

overview, 10–11

public access, 13–15

source file rules, 11–12

defined, 2

File, 443, 445–447

finding other, 3–4

generic, 623–627

interfaces

implementing, 122

relationship with, 20

naming standards, 7

searching for

classpaths, 797–798

overview, 796–797

packages, 799–801

relative and absolute paths, 801-802

thread-safe, 742–744

wrapper, 237–238

classes directory, 791–793

−classpath option, javac command, 790–791, 794, 798

classpaths, 797–798, 808

close( ) method, 448–449

cmdProp=cmdVal property, 795

cohesion, 3, 151–154

Collection classes, 56

Collection interface, 557–559

collections. See also generics; hashCode( ) method

ArrayList basics, 567–568

autoboxing with, 568

backed

key methods, 593–595

overview, 589–591

using PriorityQueue class, 591-592

classes, 557–561

converting arrays to Lists to arrays, 579

interfaces

List, 561–562

Map, 563–564

overview, 557–561

Queue, 564–566

Set, 562–563

legacy code, 597–600

Lists, 580–581

Maps, 583–586

mixing generic and non-generic, 601–607

overriding Object methods

equals( ), 544–549

overview, 542

toString( ), 542–544

overview, 556–557

searching

arrays and, 576–578

TreeSets and TreeMaps, 586–588

Sets, 581–583

sorting

Arrays class, 576

Comparable interface, 571–573

Comparator interface, 574–575

overview, 569–571

Collections class, 593

Collections Framework, 556

Collections.sort( ) method, 571, 573–574, 576

Collections.synchronizedList( ) method, 743–744

colons (:), 354

combining I/O classes, 449–452

command-line arguments, 393, 795–796

commands

jar, 803–804

java command, 793–796

javac

assertion-aware code, 388–389

compiling with, 790–793

constructor code generated by, 137

failures, 350

JAR files, 804

warnings, 603

searching for other classes with

classpaths, 797–798

overview, 796–797

packages, 799–801

relative and absolute paths, 801–802

Comparable interface, 561, 566, 571–573

Comparator interface, 561, 574–575, 592

compare( ) method, 574

compareTo( ) method, 571–574

compiler

assertion-aware code, 388–389

constructor code generated by, 137

failures, 350

JAR files, 804

javac command, 790–793

searching for other classes

classpaths, 797–798

overview, 796–797

packages, 799–801

relative and absolute paths, 801–802

warnings, 603

compound additive operator (+=), 301

compound assignment operators, 197, 289–290

concat( ) method, 435–436

concatenation operator, string, 299–301

concrete classes, 42–44

conditional expressions, 346–347

conditional operators, 304–305

consistency of equals( ) method, 549

constant pool, String, 434

constant specific class bodies, 63, 65

constants

case

default, 341–342

evaluation of, 338

legal expressions for, 335–338

declaring interface, 22–23

enums, 63

MAX_VALUE, 807

values, 23

constructing arrays, 220–223

constructor arguments, 238, 628

constructors

chaining, 132–133

code causing to run, 222

compiler-generated, 137

declarations

in enums, 63–65

overview, 47–48

default, 135–139

overloaded, 139–145

overview, 130–132

rules for, 133–134

super, 136–139

wrapper, 239

continue statements

labeled, 354–356

overview, 352–353

unlabeled, 353–354

contracts

equals( ) method, 549

hashCode( ) method, 554–556

conversion format string element, 508

conversion utilities, wrapper

parseXxx( ) methods, 241

toString( ) method, 242

toXxxString( ) method, 242–243

valueOf( ) method, 241

xxxValue( ) methods, 240–241

copying reference variables, 213

correct use of assertions, 392–394

coupling, 151–153

covariant returns, 127–128

−cp abbreviation, java command, 798

CreateAnArrayList class, 628

curly braces ({}), 329, 332

currencies, 473–474, 482–487

−d option, javac command, 790–793

−D option, system properties, 794–795

D

daemon threads, 704

DataInputStream class, 473

DataOutputStream class, 473

Date class, 476–477

DateFormat class, 480–481, 484

dates

Calendar class, 477–479

Date class, 476–477

DateFormat class, 480–481

Locale class, 482–485

orchestrating classes related to, 474–475

overview, 473–474

dead thread state, 716, 720

deadlocks, thread, 745–746

"Deadly Diamond of Death" scenario, 100

decimal literals, 186

decision statements

if

if-else branching, 329–332

legal expressions for, 332–334

overview, 328

switch

break statement in, 335, 338–340

default case, 341–342

fall-through in, 338–340

legal expressions for, 335–338

overview, 328, 334–335

declaration

access modifiers

default, 32–34, 36–38

local variables and, 38–39

overview, 24–26

private, 29–32

protected, 32–36

public, 26–29

array, 219–220, 226–228

class

abstract, 16–19

access, 13

default access, 13–14

final, 15–16

modifiers, 12–13, 15

overview, 10–11

public access, 13–15

source file rules, 11–12

classpath, 797–798

constructor, 47–48

enum

constructors, methods, and variables in, 63–65

overview, 60–63

exception, 371–376

generics

classes, 623–627

methods, 627–630

overview, 622–623

interface

constants, 22–23

overview, 19–22

for loop, 346, 351

nonaccess modifiers

abstract methods, 41–45

final arguments, 41

final methods, 40

methods with var-args, 46–47

native methods, 46

overview, 39

strictfp methods, 46

synchronized methods, 45

var-arg rule, 47

variable

array, 55–57

in enums, 63–65

final, 57–58

generics and polymorphism, 608

instance, 51–53

local, 53–55

overview, 49

primitive, 49–51

reference, 51

static, 59–60

transient, 59

volatile, 59

declared return types, 129

decoupling reference variables, 258

decrement (−−) operator, 302–303

default access classes, 13–14

default access control type, 24

default constructors, 135–139

default hashcode method, 552

default keyword, 341–343

default members, 32–34, 36–38

default primitive and reference type values, 203

default priority, thread, 725

defining threads, 705–706

delete( ) method, 440–441

delimiters, 502

descending order, 588

development

compiling with javac command, 790–793

Java Archive files, 802–805

launching applications with java command, 793–796

overview, 789–790

searching for other classes

classpaths, 797–798

overview, 796–797

packages, 799–801

relative and absolute paths, 801–802

static imports, 806–807

direct subdirectories, 802

directories

classpaths, 797–798

javac command, 791–793

META-INF, 804

myApp, 803

relative and absolute paths, 801–802

root, 804

source, 792

working with files and, 452–457

disabling assertions

at runtime, 390

selective, 390–391

division (/) operator, 306

do loops, 344–345

doInsert( ) method, 620

doStuff( ) method, 114, 215, 670, 679

dot (.) metacharacter, 497

dot operator (.), 25, 27

downcasting, 117–118

E

early loop termination, 348

else if statement, 330–331

else statement, 329–332

enabling assertions

compiling assertion-aware code, 388–389

identifiers versus keywords, 387–388

javac, 388

at runtime, 389

selective, 390–391

encapsulation, 86–89

enclosing class, 682

engines, regex, 488

enhanced for loops, 350–352

entry points, 338

enums

declaring constructors, methods, and variables in, 63-65

equality operators for, 294–295

maps, 584

overview, 60–63

EOFException subclass, 370, 373

equal (=) sign, 191

equal to (= =) operator, 245–246, 292–294, 544

equality operators

for enums, 294–295

overview, 292

for primitives, 292–293

for reference variables, 293–294

equals (= =) operator, 245–246, 292–294, 544

equals( ) method

collections, 562–563

hashCode( ), 548–549

hashcodes, 586

inheritance, 91

maps, 583

overriding, 544–549

wrappers, 245–246

equalsIgnoreCase( ) method, 435–436

equals(java.lang.Object) method, 554

equals(Object) method, 554

Error class, 366–368, 373–375

error detection and handling. See exceptions

errors, scoping, 201–202

escape codes, 190, 498

events, 9

Exception class, 366–368, 374

ExceptionInInitializerError, 382

exceptions

catch keyword, 357–359

checked, 373–375

declaration and public interface, 371–376

defined, 357, 365–366

finally block, 359–362

hierarchy of, 366–369

JVM thrown, 379–380

matching, 369–371

overview, 328, 356–357

programmatic

defined, 379

list of, 382

programmatically thrown, 380–381

propagating uncaught, 362–365

rethrowing same, 376–378

try keyword, 357–359

unchecked, 373, 375

exclusive-OR (XOR) logical operator, 288, 309–310, 553

execution, threads of, 702, 709, 757

existingDir subdirectory, 454

explicit casts, 193, 197

expressions

assertions, 385–387

for case constant, 335–338

conditional, 346–347

for if statements, 332–334

iteration, 347–348

for statement, 351

for switch statements, 335–338

extends keyword

generic methods, 618

interfaces, 122–124

java.lang.Thread, 705–706

F

fall-through in switch blocks, 338–340

FIFO (first-in, first-out), 564

File class, 443, 445–447

file navigation

combining I/O classes, 449–452

creating files using class File, 445–447

directories, 452–457

FileWriter and FileReader classes, 447–449

overview, 443–445

FileNotFoundException subclass, 370–371

FileReader class, 443, 447–449

FileWriter class, 444, 447–449

final arguments, 41

final classes, 15–16

final keyword, 15, 40

final methods, 40, 103

final variables, 57–58, 303, 336

final void notify( ) method, 543

final void notifyAll( ) method, 543

final void wait( ) method, 543

finalize( ) method, 263, 542

finally clause, 359–362

find( ) method, 499

first-in, first-out (FIFO), 564

flags, 507

floating points, 15, 46, 188–189

floor( ) method, 587

floorKey( ) method, 587

flow control

assertions

enabling, 387–391

expression rules, 385–387

overview, 383–385

using appropriately, 392–394

exceptions

catch keyword, 357–359

declaration of, 371–376

defined, 365–366

finally block, 359–362

hierarchy of, 366–369

JVM thrown, 379–380

matching, 369–371

overview, 356–357

programmatically thrown, 380–381

propagating uncaught, 362–365

public interface and, 371–376

rethrowing same, 376–378

try keyword, 357–359

if statements

if-else branching, 329–334

legal expressions for, 332–334

overview, 328

loops

break statement, 352–353

continue statement, 352–353

do, 344–345

for, 345–352

labeled statements, 354–356

unlabeled statements, 353–354

while, 343–344

overview, 327–328

switch statements

break statement in, 338–340

default case, 341–342

fall-through in, 338–340

legal expressions for, 335–338

overview, 328, 334–335

flush( ) method, 448–449

Foo class

argument-defined anonymous inner classes, 679–680

compiler-generated constructor code, 137

natural order in, 561

overloaded methods, 114

reference variable assignments, 199

shadowing instance variables, 217–218

for loops

conditional expressions, 346–347

declaration, 346

enhanced, 350–352

initialization, 208, 346

issues with, 348–350

iteration expressions, 347–348

legacy collections, 598

overview, 345–346

PriorityQueue class, 592

threads, 714

forced exits, 347–348

forcing garbage collection, 260–262

for-each. See for loops

for-in. See for loops

format( ) method, 506–508

formatting

dates and numbers

Calendar class, 477–479

Date class, 476–477

DateFormat class, 480–481

Locale class, 482–485

NumberFormat class, 485–487

orchestrating classes, 474–475

overview, 473

tokenizing

and delimiters, 502

format( ) method, 506–508

overview, 501–502

printf( ) method, 506–508

Scanner class, 504–506

String.split( ) method, 502–504

G

garbage collection

code making objects eligible for

finalize( ) method, 263

forcing, 260–262

isolating references, 259–260

nulling references, 257–258

overview, 257

reassigning reference variables, 258–259

in Java, 255–257

memory management and, 254–255

generics

declaring

classes, 623–627

methods, 627–630

overview, 622–623

legacy code, 597–600

methods, 609–622

mixing with non-generic collections, 601–607

overview, 541–542, 595–597

polymorphism and, 607–609

get( ) method, 581, 584, 586, 599, 606

getDateInstance( ) method, 480–481

getInstance( ) method, 477, 480

getName( ) method, 710–711

getProperty( ) method, 795

getState( ) method, 708

getter methods, 8–9, 88

greedy quantifiers, 495–497

group( ) method, 499

H

HardToRead class, 543

HAS-A relationships, 96–98

hashCode( ) method

equals( ) method, 548–549

HashSet, 562

Maps, 583

overriding

contract, 554–556

implementing, 552–554

overview, 549–552

real-life hashing, 551

HashMap class

Collection interface, 557, 565

collections, 566

hashCode( ) method, 555–556

LinkedHashMap, 564

Map interface implementation, 563

overriding equals( ), 545

use of, 583

HashSet class, 562, 565

Hashtable class, 557, 560, 564–565

headMap( ) method, 590

headSet( ) method, 590

heap, 220–221, 255

hexadecimal literals, 187–188

hierarchy of exceptions, 366–369

high cohesion, 152–153

higher( ) method, 587

higherKey( ) method, 587

higher-level classes, 460

highest-priority threads, 724

I

IDE (Integrated Development Environment) tool, 8

identifiers

versus keywords, 387–388

legal, 5–6

Map interface, 563

overview, 2–4

IEEE 754 standard, 15

if statements

if-else branching, 329–332

initialization, 208

legal expressions for, 332–334

overview, 328

illegal overrides, 109, 114

IllegalArgumentException, 381–382, 393

IllegalMonitorStateException, 749–750

IllegalStateException, 382

immutability of strings, 426–433

implementation classes, 121–122, 560, 680

implementers, interface, 677–678

implementing

equals( ) method, 546–549

hashCode( ) method, 552–554

interfaces, 120–125

java.lang.Runnable, 706

implicit casts, 193

import statements, 3–4, 11, 799–800, 805–806

imports, static, 806–807

increment (+ +) operator, 302–303

increment expression, 350

indenting, 331–332

indexOf( ) method, 561, 581

IndexOutOfBoundsException, 368

indirect implementations, 296

inheritance

versus dot operator for member access, 27

HAS-A relationship, 96–98

IS-A relationship, 94–95

overview, 3, 90–94

and serialization, 468–472

and subclasses, 25–26

initialization blocks, 234–237

initializing

arrays

anonymous, 228–230

elements in loop, 225–226

legal element assignments, 230

multidimensional, 233–234

of object references, 231–232

on one line, 226–228

one-dimensional, 232–233

overview, 224–225

primitive, 230–231

reference assignments for one-dimensional, 232–234

local variables, 54

for loops, 346

inner classes

anonymous

argument-defined, 678–680

overview, 673–678

coding regular, 664–668

instances, 664, 682

method-local, 670–672

overview, 661–664

referencing inner or outer instance from within, 668–670

static nested classes, 680–681

insert( ) method, 441, 602–603

insertion points, 576

instance methods, 102

instance variables

array, 206

defined, 51–53

hashCode( ) method, 552–553

object reference, 203–206

primitive, 203–204

protecting, 31

scope of, 201

uninitialized

array, 206

object reference, 203–206

overview, 203

primitive, 203–204

instanceof operator

compiler error, 297–298

equals( ) method, 547

inheritance, 90

IS-A relationship, 233

overview, 295–298

instances

initialization blocks, 234–235, 237

for java.text and java.util classes, 487

static nested classes, 680

instantiating

constructors

chaining, 132–133

default, 135–139

overloaded, 139–145

overview, 130–132

rules for, 133–134

inner classes, 666–668

outer class, 667

static nested classes, 681

threads, 706–708

int hashCode( ) method, 543

int indexOf(object) interface method, 594

int size( ) interface method, 594

int variable, 192

Integer class, 242, 807

integer literals

decimal, 186

hexadecimal, 187–188

octal, 187

Integrated Development Environment (IDE) tool, 8

interactions, thread

notifyAll( ), 752–757

overview, 746–751

interfaces

as array types, 231

collections

List, 561–562

Map, 563–564

overview, 557–561

Queue, 564–566

Set, 562–563

declaring

constants, 22–23

overview, 19–22

implementers, 677–678

implementing, 120–125

naming standards, 7

overview, 3

relationship with classes, 20

invoking

overloaded methods, 111–113

superclass version of overridden methods, 107–108

I/O

class File, 445–447

combining classes, 449–452

FileReader, 447–449

files and directories, 452–457

FileWriter, 447–449

java.io.Console class, 457–459

overview, 443–459

IOException class, 370–371, 373

IS-A relationship, 94–95, 233, 251, 547

isAlive( ) method, 40, 708

isEmpty( ) method, 755

islands of isolation, 259

isolating references, 259–260

iteration

defined, 560

expressions and for loops, 347–348

Iterators, 580, 594

J

JAR (Java Archive) files, 802–805, 808

jar command, 803–804

Java 6 compiler. See javac command

Java Archive (JAR) files, 802–805, 808

Java Code Conventions, 4, 6–8

java command

launching applications with, 793–796

searching for other classes

classpaths, 797–798

overview, 796–797

packages, 799–801

relative and absolute paths, 801–802

Java Virtual Machine (JVM)

exceptions, 379–380, 382

thread scheduler, 716

JavaBeans standards, 4, 8–10

javac command

assertion-aware code, 388–389

compiling with, 790–793

constructor code generated by, 137

failures, 350

JAR files, 804

searching for other classes

classpaths, 797–798

overview, 796–797

packages, 799–801

relative and absolute paths, 801–802

warnings, 603

java.io Mini API, 450

java.io.Console class, 457–459

java.lang.Class instances, 737

java.lang.Enum class, 584

java.lang.Object class, 718

java.lang.Runnable interface, 706

java.lang.Thread class, 705–706, 717

java.text class, 487

java.text.DateFormat, 474

java.text.NumberFormat, 474

java.util class, 487, 796

java.util package, 566, 805

java.util.ArrayList class, 567

java.util.Calendar, 474

java.util.Collections class, 558, 569

java.util.Date class, 474

java.util.HashMap class, 796

java.util.jar package, 805

java.util.Locale, 474

java.util.NavigableMap interface, 586

java.util.NavigableSet interface, 586

java.util.Properties class, 794

java.util.regex package, 805

java.utils.Arrays.sort( ) method, 571

JButton class, 608

jobs list, 755–756

join( ) method, 716–717, 726–728

jre/lib/ext subdirectory tree, 805

just-in-time array arguments, 229–230

JVM (Java Virtual Machine)

exceptions, 379–380, 382

thread scheduler, 716

K

keys, 795

keywords

abstract, 15

catch, 357–359

chart, 6

default, 341–343

extends

generic methods, 618

interfaces, 122–124

java.lang.Thread, 705–706

final, 15, 40

versus identifiers, 387–388

new, 222

overview, 3

strictfp, 15, 46

super, 619

throw, 367

try

exceptions, 357–359

with finally block, 359–361

wait( ) method, 750

without catch block, 361

without finally block, 361

L

labeled statements, 354–356

launching applications with java command, 793–796

legacy code, 597–602

legal array element assignments, 230

legal expressions

for case constant, 335–338

for if statements, 332–334

for switch statements, 335–338

legal identifiers, 4

legal overloaded methods, 110

legal overridden methods, 109

legal return types

covariant, 127–128

on overloaded methods, 126–127

on overridden methods, 127–128

returning values, 128–130

length attributes, array, 437

length( ) method, 435–436

length variable, 225–226

LinkedHashMap class, 557, 564–566

LinkedHashSet class, 560, 563, 565

LinkedList class, 562, 564–565, 580

List class, 608

List interface

collections, 561–562

in Collections Framework, 557

converting to arrays, 579

generic declarations, 622

key methods, 594–595

use of, 580–581

List<?> syntax, 620

List<Integer> syntax, 621

List<Object> syntax, 620–621

list.add( ) method, 620

listeners, 9

lists, enumerated. See enums

literals

boolean, 189

character, 189–190

floating-point, 188–189

integer

decimal, 186

hexadecimal, 187–188

octal, 187

string, 190, 434

live objects, 257

local arrays, 210

local object references, 209–210

local primitives, 207–209

local variables

access member modifiers and, 38–39

array references, 210

assigning one reference variable to another, 210–213

defined, 53–55

inner classes, 671

object references, 209–210

overview, 207

primitives, 207–209

scope of, 201

uninitialized, 203

Locale class, 482–485

locks, 735–737, 739–740

logical operators

bitwise, 305

boolean invert, 309–310

non-short-circuit, 308–309

short-circuit, 306–308

XOR, 309–310

Long class, 242, 807

loops

break statement, 352–353

continue statement, 352–353

do, 344–345

for

conditional expression, 346–347

declaration, 346

enhanced, 350–352

initialization, 346

issues with, 348–350

iteration expression, 347–348

legacy collections, 598

overview, 345–346

PriorityQueue class, 592

threads, 714

initializing elements in, 225–226

labeled statements, 354–356

unlabeled statements, 353–354

wait( ) in, 753–757

while, 343–344

loose coupling, 152

lower( ) method, 587

lowerKey( ) method, 587

lower-level classes, 460

lower-priority threads, 724

M

Machine class, 754

main( ) method, 546, 665, 702, 710, 713

makeArrayList( ) method, 627

makeInner( ) method, 666

makeWithdrawal( ) method, 734

MANIFEST.MF file, 804

Map interface

collections, 563–564

key methods, 594–595

use of, 583–586

MapTest.main( ) method, 585

marker interfaces, 461, 562

Matcher class, 498–501

matching, exception, 369–371

MAX_VALUE constant, 807

meaningfully equivalent instances, 245–246

Meeks, Jonathan, 97

member classes, 662

member declarations

access modifiers

default members, 32–34, 36–38

local variables and, 38–39

overview, 24–26

private members, 29–32

protected members, 32–36

public members, 26–29

constructor, 47–48

enum

constructors, methods, and variables in, 63-65

overview, 60–63

nonaccess modifiers

abstract methods, 41–45

final arguments, 41

final methods, 40

methods with var-args, 46–47

native methods, 46

overview, 39

strictfp methods, 46

synchronized methods, 45

variable

array, 55–57

final, 57–58

instance, 51–53

local, 53–55

overview, 49

primitive, 49–51

reference, 51

static, 59–60

transient, 59

volatile, 59

visibility and access, 39

member methods, 662

member modifiers applied to inner classes, 670

member variables, 662. See also instance variables

memory

garbage collection, 257

management and garbage collection, 254–255

and String class, 433–434

metacharacters

and searches, 490–492

and strings, 497–498

META-INF directory, 804

method-local inner classes, 670–672

methods. See also hashCode( ) method; individual methods by name

backed collections, 593–595

chained, 442

comparison of modifiers on, 53

declarations, 41

declaring in enums, 63–65

defined, 2

effects of static on, 150

generic, 609–622, 627–630

in interfaces, 20–21

JavaBean signatures for, 10

naming standards, 7

overriding Object

equals( ), 544–549

toString( ), 542–544

overriding rules, 106–107

passing variables into

object reference, 213–214

overview, 213

pass-by-value semantics, 214–215

primitive, 215–218

String class, 434–438

StringBuffer, 440–442

StringBuilder, 440–442

synchronizing static, 737–739

thread scheduler, 717–718

with var-args, 46–47

mkdir( ) method, 453

modifiers. See also individual modifiers by name

applied to inner classes, 670

class access

default, 13–14

public, 14–15

class nonaccess

abstract, 16–19

final, 15–16

member access

default members, 32–34, 36–38

local variables and, 38–39

overview, 24–26

private members, 29–32

protected members, 32–36

public members, 26–29

member nonaccess

abstract methods, 41–45

final arguments, 41

final methods, 40

methods with var-args, 46–47

native methods, 46

overview, 39

strictfp methods, 46

synchronized methods, 45

overview, 12–13

variables and methods, 53

Moof class, 546

moofValue instance variable, 546–547

multidimensional arrays, 57, 223, 233–234

multiple inheritance, 100

multiplication (*) operator, 308

multithreading, 702, 713–716

myApp directory, 803

myApp.engine package, 804

myApp.utils package, 804

MyClass class, 738, 791

MyInner class, 666

MyOuter class, 666

MyOuter2 class, 670

N

name variable, 586

names.get(0) method, 743

names.remove(0) method, 744

names.size( ) method, 743–744

naming standards

classes, 7

interfaces, 7

JavaBean listeners, 9

JavaBean properties, 8–9

methods, 7

variables, 7

narrowing, 193

native methods, 46

natural order, 561

NavigableMap interface, 566

NavigableSet interface, 566

navigating

files

combining I/O classes, 449–452

creating files using class File, 445–447

directories, 452–457

FileWriter and FileReader classes, 447–449

overview, 443–445

methods relating to, 588

TreeSets and TreeMaps, 586–588

nested classes, static, 680-681. See also inner classes

new keyword, 222

new threads, 716, 718

next( ) method, 581

nextXxx( ) methods, 505–506

no-arg constructors, 133–134

NoClassDefFoundError exception, 382

nonabstract methods, 17–18

nonaccess class modifiers

abstract classes, 16–19

defined, 12

final classes, 15–16

nonaccess member modifiers

abstract methods, 41–45

final arguments, 41

final methods, 40

methods with variable argument lists (var-args), 46–47

native methods, 46

overview, 39

strictfp methods, 46

synchronized methods, 45

non-final local variables, 682

non-generic collections, 597, 601–607

non-serializable elements, 472

non-short-circuit AND (&) operator, 288, 308

non-short-circuit logical operators, 308–309

non-short-circuit OR ( | ) operator, 288, 308

non-static inner class instantiation code, 667

non-static methods, 735, 740–741

non-static synchronized methods, 739, 741

nonstatic variables, 147–148

non-synchronized methods, 736–737

non-transient variables, 556

non-type safe code, 602–607

NoSuchElementException class, 743

not equal to (!=) operator, 292

notify( ) method, 542, 746, 748, 752–756

notifyAll( ) method, 542, 746, 752–757

null references, 205, 209, 224, 257–258, 563–564

NullPointerException class, 224, 247, 373, 380, 382

NumberFormat class, 484–487

NumberFormatException class, 381–382

numbers, formatting, 473–487

numeric primitives, 50

O

Object class. See also hashCode( ) method

arrays, 579

influencing thread scheduler, 718

overriding methods

equals( ), 544–549

toString( ), 542–544

overview, 542

object get( ) interface methods, 594

object graphs, 461–465

object next( ) method, 580

object orientation

cohesion, 151–154

constructors

chaining, 132–133

default, 135–139

overloaded, 139–145

overview, 130–132

rules for, 133–134

coupling, 151–153

encapsulation, 86–89

implementing interfaces, 120–125

inheritance

HAS-A relationship, 96–98

IS-A relationship, 94–95

overview, 90–94

legal return types

covariant returns, 127–128

on overloaded methods, 126–127

on overridden methods, 127–128

returning values, 128–130

overloaded methods

invoking, 111–113

legal, 110

overview, 109–110

polymorphism in, 113–115

overridden methods

examples of legal and illegal, 109

invoking superclass version of, 107–108

overview, 103–107

polymorphism, 98–102

reference variable casting, 116–119

statics

accessing, 148–151

overview, 145–148

object reference instance variables, 203–206

object reference variables

arrays of, 231–232

assigning null to, 199

passing into methods, 213–214

Object type, 572

Object[] toArray( ) interface method, 594

ObjectInputStream method, 460–461

object-oriented design, 97

ObjectOutputStream method, 460–461

objects

arrays as, 297

defined, 2

uneligiblizing for garbage collection, 263

wrapper, 239–240

octal literals, 187

offer( ) method, 562, 591–592

one-dimensional arrays, 221–222, 232–233

operands, 298

operators. See also individual operators by name

arithmetic

decrement, 302–303

increment, 302–303

overview, 298

remainder, 299

string concatenation, 299–301

assignment

compound, 197, 289–290

overview, 288–290

conditional, 304–305

instanceof

compiler error, 297–298

overview, 295–297

logical

bitwise, 305

boolean invert, 309–310

non-short-circuit, 308–309

short-circuit, 306–308

XOR, 309–310

precedence, 290

relational

equality operators, 292–295

overview, 290–291

OR operator

non-short-circuit, 288, 308

short-circuit, 306, 308

ordered collections, 560

outer classes

instantiating inner class from within, 666–668

overview, 664

referencing from within inner classes, 668–670

static members of, 681

OutOfMemoryError subtype, 375

outside outer class instance code, 666–668

overloaded constructors, 139–145

overloading methods

with boxing and var-args, 249–250

in combination with var-args, 253–254

invoking, 111–113

legal, 110

legal return types on, 126–127

versus overridden methods, 115

overview, 109–110, 247–249

polymorphism in, 113–115

when combining widening and boxing, 251–253

widening reference variables, 250–251

overridden methods. See also hashCode( ) method

invoking superclass version of, 107–108

legal and illegal, 109

legal return types on, 127–128

Object

equals( ), 544–549

toString( ), 542–544

versus overloaded methods, 115

overview, 103–107

polymorphism in, 113–115

versus static methods, 151

P

packages, 3, 11–12, 799–801

parameterized type, 598, 626–628

parameters, 46

parentheses, 300

parse( ) method, 481

parseXxx( ) methods, 241

parsing

locating data via pattern matching, 498-501

overview, 487–488

searches

greedy quantifiers, 495–497

overview, 488–489

predefined dot, 495

simple, 489–490

strings and metacharacters, 497–498

using metacharacters, 490–492

using quantifiers, 492–495

Part class, 566

pass-by-value semantics, 214–215

passing variables into methods

object reference variables, 213–214

overview, 213

pass-by-value semantics, 214–215

primitive variables, 215–218

Pattern class, 498–501

pattern matching, 498–501

peek( ) method, 562, 591

poll( ) method, 562, 588, 591–592

pollFirst( ) method, 588

pollFirstEntry( ) method, 588

pollFirstXxx( ) method, 591

polling, 588

pollLast( ) method, 588

pollLastEntry( ) method, 588

polymorphism

anonymous inner classes, 675

defined, 92

generics and, 607–610

in overloaded methods, 113–115

in overridden methods, 113–115

overriden methods, 108

overview, 98–102

pool, String constant, 434

populateList( ) method, 570

precedence, 299

precision format string element, 507

predefined dot, 495

preventing thread execution, 720–721

primitive arrays, 230–231

primitive instance variables, 203–204

primitive literals

boolean, 189

character, 189–190

defined, 186

floating-point, 188–189

integer, 186–188

string, 190

primitive return types, 128–129

primitive variables

assignments, 191–193

casting

assigning floating-point numbers, 196

assigning literals too large for, 196–197

assigning one primitive to another, 198

overview, 193–195

declaration, 49–51

defined, 49

equality operators for, 292–293

passing into methods, 215–218

ranges, 49–51

printf( ) method, 506–508

PrintWriter class, 444

priorities, thread, 724–728

PriorityQueue class

backed collections, 591–592

Collection interface, 565

methods, 594

overview, 564–566

private access, 32

private constructors, 133

private members, 29–32

private method-local inner class, 672

private methods, 11, 393

private variables, 733

programmatic exceptions

defined, 379

list of, 382

programmatically thrown exceptions, 380–381

propagating uncaught exceptions, 362–365

properties, system, 794–795

protected access, 37

protected members, 32–36

protected method-local inner class, 672

public access

classes, 14–15

effects of, 32

public boolean

equalsIgnoreCase(String s)

method, 436

public char charAt(int index) method, 435

public int length( ) method, 436

public interface, 371–376

public members, 26–29

public methods, 11, 392–393, 672

public modifier, 21

public static String toString( ) methods, 593

public static void sort( ) method, 593

public String concat(String s) method, 435–436

public String replace(char old, char new) method, 436

public String substring( ) methods, 436–437

public String toLowerCase( ) method, 437

public String toString( ) method, 438, 441–442

public String toUpperCase( ) method, 438

public String trim( ) method, 438

public StringBuilder delete(int start, int end) method, 440–441

public StringBuilder insert(int offset, String s) method, 441

public synchronized StringBuffer append(String s) method, 440

public synchronized StringBuffer reverse( ) method, 441

put(key, value) interface method, 594

Q

quantifiers

greedy, 495–497

and searches, 492–495

Queue interface, 557, 564–566, 594–595

queues, 562, 591–592, 717

R

race conditions, 733

RandomAccess interface, 562

ranges, primitive variable, 49–51

reachable references, 257

read( ) method, 746

readLine( ) method, 455, 457

readObject( ) method, 465–468

readPassword method, 457

reassigning reference variables, 258–259

Red-Black tree structure, 563

reference type, 113

reference variables

anonymous inner classes, 674, 676

assignments, 198–200

casting, 116–119

declaring, 51

defined, 49, 191

equality operators for, 293–294

isolating, 259–260

nulling, 257–258

polymorphism, 99

reassigning, 258–259

and string objects, 429

widening, 250–251

references, reachable, 257

referencing instances from within inner classes, 668–670

reflexiveness of equals( ) method, 549

regex (regular expressions)

engines, 488

Matcher class, 498–501

overview, 488, 510

Pattern class, 498–501

searches

dot metacharacter, 495

greedy quantifiers, 495–497

overview, 488–489

simple, 489–490

string and metacharacters, 497–498

using metacharacters, 490–492

using quantifiers, 492–495

tokenizing, 501–506

regions, 500

regular expressions (regex)

engines, 488

Matcher class, 498–501

overview, 488, 510

Pattern class, 498–501

searches

dot metacharacter, 495

greedy quantifiers, 495–497

overview, 488–489

simple, 489–490

string and metacharacters, 497–498

using metacharacters, 490–492

using quantifiers, 492–495

tokenizing, 501–506

regular inner classes, 664–668

relational operators

equality

for enums, 294–295

overview, 292

for primitives, 292–293

for reference variables, 293–294

overview, 290–291

relative paths, 801–802

remainder (%) operator, 299

removeFirst( ) method, 743–744

remove(index) interface method, 594

remove(key) interface method, 594

remove(object) interface method, 594

replace( ) method, 435–436

rethrowing exceptions, 376–378

return types, legal

covariant returns, 127–128

on overloaded methods, 126–127

on overridden methods, 127–128

returning values, 128–130

reverse( ) method, 441, 593

roll( ) method, 479

root directory, 804

rules for constructors, 133–134

run( ) method

Thread class

completion, 716

instantiating, 708

leaving running state, 728

making thread, 704–705

order of actions, 714

overview, 710

using wait( ) in loop, 755–757

Runnable interface, 678, 705–709

runnable threads, 716–719, 726

running multiple threads, 713–716

running threads, 719, 733

runtime

disabling assertions at, 390

enabling assertions at, 389

Runtime class, 261

RuntimeException class, 366–368, 373–374

S

s variable, 200

Scanner class, 501, 504–506

scheduler, thread, 716–718, 728

scope, variable, 200–202, 349

searching

arrays, 576–578

Java Archive files and, 803–805

for other classes, 796–802

classpaths, 797–798

overview, 796–797

packages, 799–801

relative and absolute paths, 801–802

simple searches, 489–490

TreeSets and TreeMaps, 586–588

using metacharacters, 490–492

using quantifiers, 492–495

seeOuter( ) method, 670

selective enabling and disabling of assertions, 390–391

semantics, pass-by-value, 214–215

semicolons (;), 17, 41, 344–345, 675

serial numbers, 566

serialization

and inheritance, 468–472

object graphs, 461–465

ObjectInputStream methods, 460–461

ObjectOutputStream method, 460–461

overview, 459–460

readObject method, 465–468

and statics, 472–473

transient variables, 59

writeObject method, 465–468

Set interface

implementations for collections, 562–563

key methods, 594–595

use of, 581–583

Set keySet( ) interface method, 594

setParseIntegerOnly( ) method, 486

setPriority( ) method, 725

setProperty method, 795

setter methods, 8–9, 88

shadowing variables, 54–55, 201, 216–218

short-circuit AND (&&) operator, 306, 308, 548

short-circuit logical operators, 306–308

short-circuit OR ( | | ) operator, 306, 308

shortcut syntax, array, 226–228

side effects, assertion, 394

signed number types, 49

simple searches, 489–490

size( ) method, 581, 743

sleep( ) method, 717, 721, 723, 727, 757

sleeping threads, 719–724

sort( ) method

ArrayList class, 569

Arrays class, 576, 593

Collections class, 571–572, 574

SortedMap class, 591

SortedSet class, 591

sorting collections

Arrays class, 576

Comparable interface, 571–573

Comparator interface, 574–575

defined, 561

overview, 569–571

source directories, 792

source file declaration rules, 11–12

-source option, javac command, 790

split( ) method, 502–504

spontaneous wakeup, 755

square brackets, 219–220

StackOverflowError subtype, 380, 382

standards, JavaBeans, 4, 8–10

start( ) method

Matcher class, 499

threads, 708–709, 716, 718, 757

starting threads

overview, 709–712

and running multiple, 713–716

thread scheduler, 716–718

statements. See also decision statements assert, 386–389, 394

break

labeled, 354–356

in switch blocks, 338–340

switch statements, 335

unlabeled, 353–354

use of, 352–353

continue

labeled, 354–356

overview, 352–353

unlabeled, 353–354

else, 329–332

else if, 330–331

import, 3–4, 11, 799–800, 805–806

labeled, 354–356

unlabeled, 353–354

states

defined, 2

thread

overview, 718–720

preventing execution, 720–721

priorities and yield( ), 724–728

sleeping, 721–724

static boolean equals( ) method, 593

static Comparator reverseOrder( ) method, 593

static compile( ) method, 499

static imports, 806–807

static initialization blocks, 234–235

static inner classes, 680

static int binarySearch( ) method, 593

static List asList( ) method, 593

static methods

accessing, 148–151

blocked threads, 720

defined, 59–60

inner classes, 667–668

local classes declared in, 672

overview, 145–151

sort( ), 576

synchronizing, 737–741

in Thread class, 756

Thread.sleep( ), 721

static modifier, 45, 59–60, 145, 682

static nested classes, 680–682

static synchronized methods, 739, 741

static Thread.currentThread( ) method, 711

static Thread.yield( ) method, 726

static variables

accessing, 148–151

defined, 59–60

overview, 145–151

scope of, 201

and serialization, 472–473

static void reverse( ) method, 593

static void sort( ) method, 593

stop( ) method, 720

Stream classes, 444

strictfp keyword, 15, 46

String class

creating new strings, 434

immutability, 426–433

important methods, 434–438

and memory, 433–434

overriding equals( ), 546

overview, 426

reference variables, 211–213

split( ) method, 502–504

toString( ) method, 543

string concatenation operator, 299–301

String constant pool, 434

StringBuffer class

important methods, 440–442

overview, 438–440

synchronizing code, 738–739

thread-safe, 742

StringBuilder class

important methods, 440–442

overview, 438–440

thread-safe, 742

StringIndexOutOfBoundsException subclass, 368

strings

collections, 566

generics, 596

literals, 190, 434

Maps, 584

and metacharacters, 497–498

overview, 426

reference variables, 211–213

String class

creating new, 434

immutability, 426–433

important methods, 434–438

and memory, 433–434

overview, 426

StringBuffer class

important methods, 440–442

overview, 438–440

StringBuilder class

important methods, 440–442

overview, 438–440

synchronizing code, 738

subclasses

and inheritance, 3, 25–26

inner classes, 677

versus interfaces, 122

protected and default members, 32–34

Thread class, 705

subMap( ) method, 589–590

subSet( ) method, 590

substring( ) method, 435–437

subtraction (−) operator, 306

subXxx( ) method, 591

Sun's Java Code Conventions, 4

super constructors, 136–139

super keyword, 619

superclasses, 3

suspend( ) method, 720

switch statements

break statement in, 335, 338–340

default case, 341–342

fall-through in, 338–340

legal expressions for, 335–338

overview, 328, 334–335

symmetry of equals( ) method, 549

synchronized methods

in code synchronization, 734–740

defined, 45

thread interaction, 751

Vector, 562

wait( ) in loops, 756

synchronizedList( ) method, 744

synchronizing code

atomic operations, 733–735

deadlock, 745–746

if thread can't get lock

locks, 735–737

overview, 728–733

static methods, 737–739

thread-safe classes, 742–744

when synchronization is needed, 740–742

syntax

array shortcut, 226–228

generics, 598

system properties, 794–795

System.gc( ) method, 261

System.out.println( ) method, 504, 542, 630

T

T[ ] toArray(T[ ]) interface method, 594

tailMap( ) method, 590

tailSet( ) method, 590

tailXxx( ) method, 591

target Runnables, 707

ternary operators, 304

test expressions, 347

TestClass class, 800

testIt( ) method, 33

this reference, 29, 668

Thread class

extending, 705–706

final methods, 40

influencing thread scheduler, 717

instantiating thread, 706–708

methods, 704–705, 720

one-dimensional arrays, 222

run( ) method completion, 716

starting thread, 709–712

thread scheduler, 716–718, 728

threads

blocked, 719–720

dead, 716, 720

defining, 705–706

of execution, 702, 709, 757

instantiating, 706–708

interaction

notifyAll( ), 752–757

overview, 746–751

making, 704–705

new, 716, 718

overview, 701–704

runnable, 716–719, 726

running, 719, 733

sleeping, 719–724

starting

overview, 709–712

and running multiple, 713–716

thread scheduler, 716–718

states and transitions

overview, 718–720

preventing execution, 720–721

priorities, 724–728

sleeping, 721–724

yield( ) method, 726

synchronizing code

atomic operations, 733–735

deadlock, 745–746

if thread can't get lock, 739-740

locks, 735–737

overview, 728–733

static methods, 737–739

thread-safe classes, 742–744

when needed, 740–742

waiting, 719–720

thread-safe classes, 742–744

Thread.sleep( ) method, 721

throw keyword, 367

Throwable class, 366–368

thrown exceptions, 357

tight coupling, 152

toArray( ) method, 579, 581

tokenizing

and delimiters, 502

format( ) method, 506–508

overview, 501–502

printf( ) method, 506–508

Scanner class, 504–506

String.split( ) method, 502–504

toLowerCase( ) method, 437

toString( ) method

overriding, 542–544, 570

overriding equals( ), 548

public string, 438

in String class, 435

StringBuffer class, 441–442

wrapper conversion, 242

toUpperCase( ) method, 438

toXxxString( ) method, 242–243

transient method-local inner class, 672

transient modifier, 465

transient variables, 59, 460, 470, 555–556

transitions, thread

overview, 718–720

preventing execution, 720–721

priorities and yield( ), 724–728

sleeping, 721–724

yield( ), 724–728

transitivity of equals( ) method, 549

TreeMap class

backed collections, 589–590

collections, 557, 565–566

methods, 588, 590

overview, 564

searching, 586–588

subMap( ), 589

TreeSet class

backed collections, 590

Collection interface, 565

methods, 588, 590

overview, 563, 582

searching, 586–588

trim( ) method, 438

try keyword

exceptions, 357–359

with finally block, 359–361

wait( ) method, 750

without catch block, 361

without finally block, 361

t.start( ) method, 713

two-dimensional arrays, 223

type erasure, 604–605

type parameters, 598, 626–628

type safe code, 602–606

U

UML (Unified Modeling Language), 97

unboxing

equals( ) method, 245–246

equals operator, 245–246

overloading

with var-args and, 249–250

when combining widening and, 252–253

overview, 244–245

in switch statements, 337

use of, 246–247

uncaught exceptions, propagating, 362–365

unchecked exceptions, 373, 375

Unicode characters, 51, 189, 426–427

Unified Modeling Language (UML), 97

uninitialized variables

array instance, 206

object reference instance, 203–206

overview, 203

primitive instance, 203–204

unique hashcodes, 585

unique identifiers, 563

unlabeled statements, 353–354

unwinding stack, 367

upcasting, 118

use cases, date and number, 475

V

valueOf( ) methods, 240–241

values, constant, 23

var-args (variable argument lists)

declaration rules for, 47

methods with, 46–47

overloading, 249–250, 253–254

syntax, 796

variable scope, 200–202, 349

variables. See also individual variables by name

assignment operators

assigning one primitive to another, 198

floating-point numbers, 196

literals too large for, 196–197

overview, 190–191

primitive, 191–193

primitive casting, 193–195

reference, 198–200

scope, 200–202

comparison of modifiers on, 53

declarations

arrays, 55–57

in enums, 63–65

final, 57–58

generics and polymorphism, 608

instance, 51–53

local, 53–55

overview, 49

primitive, 49–51

reference, 51

static, 59–60

transient, 59

volatile, 59

effects of static on, 150

in interfaces, 20–21

local

access member modifiers and, 38–39

array references, 210

assigning one reference to another, 210–213

defined, 53–55

inner classes, 671

object references, 209–210

overview, 207

primitives, 207–209

scope of, 201

uninitialized, 203

naming standards, 7

passing into methods

object reference variables, 213–214

overview, 213

pass-by-value semantics, 214–215

primitive variables, 215–218

uninitialized

array instance, 206

object reference instance, 203–206

overview, 203

primitive instance, 203–204

Vector class, 562, 564–565

VirtualMachineError subtype, 375

void finalize( ) method, 543

void return types, 129

volatile variables, 59

W

wait( ) method

lock status, 740

in loops, 753–757

overview, 718

thread interaction, 746–752

threads leaving running state, 728

waiting threads, 719–720

wakeup, spontaneous, 755

warnings, compiler, 603

while loops, 343–344, 756

widening

overloading when combining boxing and, 251–253

reference variables, 250–251

wrapper classes, 251

width format string element, 507

wrappers

autoboxing

equals( ) method, 245–246

equals operator, 245–246

overview, 244–245

use of, 246–247

classes

overriding equals( ), 546

overview, 237–238

and widening, 251

constructors, 239

conversion methods, 243

conversion utilities

parseXxx( ) methods, 241

toString( ) method, 242

toXxxString( ) method, 242–243

valueOf( ) method, 241

xxxValue( ) methods, 240–241

NullPointerException, 247

valueOf( ) methods, 240

wrapping I/O classes, 449–452

writeObject( ) method, 465–468

X

x variable, 200

x2 variable, 200

x3 variable, 200

−Xlint:unchecked flag, 605

XOR (exclusive-OR) logical operator, 288, 309–310, 553

xxxValue( ) methods, 240–241

Y

y variable, 200

yield( ) method, 724–728

Z

z variable, 200

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.169.100