pgjc4 jse8 ocakhalid/ocajp8/pgj8-oca-index.pdf · members 7 methods 132 120 name 97...

22
Index Symbols - 169 -- 176 ^ 184, 189 ^= 185 _ 32 ; 50 : 110 ! 184 != 181, 342 ?: 194 . 7, 72, 97, 108 ... 81, 85 ' 32, 33 " 34 [] 59, 61, 195 {} 50, 60, 117 @FunctionalInterface 442, 443 @Override 270 @param 49, 56 @return 225 @throws 253 * 100, 163, 167 *= 172 / 167 /* and */ 35 /** and */ 36 // 35 /= 172 \ 33 & 184, 189 && 186 &= 185 % 167, 168 %= 172 + 169, 174 + concatenation 364 ++ 176 += 172 < 180 <= 180 <> 414, 415, 416 -= 172 = 158 == 181, 342, 351, 359 -> 195, 439, 444 > 180 >= 180 | 184, 189 |= 185 || 186 ~ 189 A ability interfaces see marker interfaces abrupt method completion 232 absolute adjusters 470 abstract classes 120 interfaces 290 methods 136, 291, 442 abstract 120, 136, 290, 291, 442 abstract method declarations 442 in interfaces 290, 291 abstraction 2, 10 accessibility 7, 17, 114 default 118, 127 members 114, 120, 123 modifiers 118 package 118 PGJC4_JSE8_OCA.book Page 619 Monday, June 20, 2016 2:31 PM

Upload: others

Post on 07-Apr-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Index

Symbols- 169-- 176^ 184, 189^= 185_ 32; 50: 110! 184!= 181, 342?: 194. 7, 72, 97, 108... 81, 85' 32, 33" 34[] 59, 61, 195{} 50, 60, 117@FunctionalInterface 442, 443@Override 270@param 49, 56@return 225@throws 253* 100, 163, 167*= 172/ 167/* and */ 35/** and */ 36// 35/= 172\ 33& 184, 189&& 186&= 185% 167, 168%= 172+ 169, 174

+ concatenation 364++ 176+= 172< 180<= 180<> 414, 415, 416-= 172= 158== 181, 342, 351, 359-> 195, 439, 444> 180>= 180| 184, 189|= 185|| 186~ 189

Aability interfacessee marker interfaces

abrupt method completion 232absolute adjusters 470abstract

classes 120interfaces 290methods 136, 291, 442

abstract 120, 136, 290, 291, 442abstract method declarations 442

in interfaces 290, 291abstraction 2, 10accessibility 7, 17, 114

default 118, 127members 114, 120, 123modifiers 118package 118

PGJC4_JSE8_OCA.book Page 619 Monday, June 20, 2016 2:31 PM

620 INDEX

private 128protected 126public 124UML notation 124

accessibility modifiers 48, 53activation frame 384

see method execution 230actual parameter 72actual parameter list 72, 315adding to class 264additive operators 169aggregation 10, 12, 267

hierarchy 267versus inheritance 331

aliases 6, 75, 182, 183see also references

ambiguous call 316analyzing program code 512and operator 189annotations

@Override 270anonymous arrays 63, 66

[] 63anonymous classes 436anonymous functions 439API (application programming interface)

22apostrophe 33application 16architecture neutral 23argument

see actual parameterarguments to main method 85arithmetic compound assignment

operators 172ArithmeticException 236arity 81array creation expression 59, 63array initializer 60, 63, 66array store check 311array types

see arraysArrayIndexOutOfBoundsException 61, 236ArrayList 366, 414

add collection 419add element 417, 419autoboxing 421capacity 416clear list 420comparison with arrays 425constructing 415constructors 418

converting to array 424element search 423element type 415filtering 434import 415inheritance hierarchy 415initial capacity 417insertion order 414list of lists 417membership test 422modifying 419nested lists 417object value equality 422open range-view operations 414ordered 414position-based access 415positional index 422positional order 414positional retrieve 422querying 422references 415remove collection 420remove element 419replace element 419size 416, 422sorting 425subtype relationship 418textual representation 417traversing 423trim to size 420type-safety 416, 417, 418unchecked conversion warning 416zero-based index 414

arrays 58, 342[] 59, 61{} 60anonymous 63, 66array creation expression 59array initialize list 60, 63array initializer 60, 66array name 59array size 60array store check 311ArrayIndexOutOfBoundsException 61bounds 61construction 59declarations 59default initialization 59, 60dynamic 415element access expression 61element default value 310element type 59

PGJC4_JSE8_OCA.book Page 620 Monday, June 20, 2016 2:31 PM

INDEX 621

elements 58, 61index 58index expression 61initialization 60, 65iterating over 217length 58multidimensional 63, 65objects 342ragged 65reference 59, 62, 311searching 69sorting 68subtype covariance 309traverse an array 62using 61

arrays of arrays 59, 65multidimensional 65

ArrayStoreException 311, 418, 424arrow -> 195, 439, 444ASCII 32, 38AssertionError 237assignable 147, 314assignment compatible 148, 314, 416assignment conversions 147assignment operator 5assignments

arithmetic compound operators 172bitwise 192cascading 159compound operators 185, 192expression statement 159implicit narrowing 160multiple 159numeric conversions 160operator 151, 158primitive values 159references 159widening reference conversions 267

association 12aggregation 267composition 267realization 296

associativity 152atomic values 13attributes see propertiesautoboxing 68, 348

for(:) statement 218AutoCloseable 387automatic garbage collection 6, 384automatic variables see local variables

Bbackslash 33backspace 33base 30, 349, 352base class 264basic for statement

215Before Current Era (BCE) 464behavior 433behavior parameterization 434, 441binary

numeric promotion 150operators 151

binary searcharrays 69

bit mask 190bit patterns 154bitwiseand operator 189assignment 192complement 189compound assignment 192operators 189or operator 189xor 189

bitwise AND& 189

bitwise complement~ 189

bitwise exclusive OR^ 189

bitwise OR| 189

bitwise XOR^ 189

blank final variable 80, 134blocks 49, 50, 117

scope 117, 448try 240

boilerplate code 436Boolean

condition 200Boolean wrapper class 355booleans 37, 39

casting 149expressions 180literals 32

boxing conversions 145, 146break statement 205, 206, 221BS see backspacebuilding abstractions 10byte 30, 38

PGJC4_JSE8_OCA.book Page 621 Monday, June 20, 2016 2:31 PM

622 INDEX

bytecode 16, 23

CC 137C++ 23, 137cache 139call by reference 77call by value 77call chaining 72call signature 316call stack

see JVM stack 230callee 72caller 72, 224capacity 416carriage return 33, 35cascading assignments 159cascading if-else statements 203case labels 203, 205case sensitivity 28cast operator 145, 148, 151, 162, 172, 182,

320casting 147, 148, 149

see also conversionscatch clause 240

uni- 239catching exceptions 230catch-or-declare 251CertView 509chaining 406

constructors 287, 406finalizers 391

char 38character case 364character sequences

see strings and string builderscharacter set

ASCII 32, 38ISO Latin-1 32, 38Unicode 32, 38

Character wrapper class 354characters 38

literals 32searching for 367

CharSequence interface 360, 365, 369checked exceptions 237child class 264choosing between String and StringBuilder

class 374Class class 343class file 16

class hierarchysee inheritance hierarchy

class inheritancesee implementation inheritance

class method 10class modifiers 48class path 107

absolute pathnames 110entries order 110entry-separator character 110fully qualified package name 109path-separator character 110relative pathnames 110search in a named package 109searching for classes 107whitespace 110

class search pathsee class path

class variable 10ClassCastException 236, 321classes

abstract 120accessibility 118adding to 264base 264body 48child 264cohesion 335concrete 121, 122, 436constructors 53, 282coupling 336declarations 48, 96definitions 2, 5derived 264diagram 8, 9encapsulation 335extending 122, 264final 122final vs. abstract 122fully qualified name 107fully qualified package name 98generalized 266grouping 97header 48implementing interfaces 291initialization 409instance members 48instances 4members 7methods 132modifiers 120name 97

PGJC4_JSE8_OCA.book Page 622 Monday, June 20, 2016 2:31 PM

INDEX 623

normal 121Object 342parent 264runtime 343scope 114searching for 107specialized 266static members 48subclass 10, 264superclass 10, 264variables 132wrappers 342, 346

ClassLoader class 342ClassNotFoundException 235CLASSPATH environment variablesee class path

-classpath optionsee class path

clausescatch 240extends 264finally 240, 245implements 291throws 251

cleaning up 386clean-up code 245client 7, 16Cloneable interface 343CloneNotSupportedException 343cloning objects 343code optimizations 134code reuse 23, 264, 334CodeRanch 508cohesion 335

coincidental 335functional 335high 335

coincidental cohesion 335Collection 414collections 414

as single entity 414elements 414ordered 414sorting 414

command 17java 17javac 17

command line 17, 86command prompt 17comments 35communication 7, 72Comparable interface 350, 363, 376, 425

comparing objects 342comparing strings 363comparison 180compilation unit 98compiling Java source code 17complement

~ 189completes abruptlysee exception propagation 232

composite object 10composition 12, 267compound statement 50concatenation of strings 364concatenation operator 174concrete classes 436concrete method 134ConcurrentModificationException 424condition

Boolean 200expressions 200

conditional 180and 186operators 186, 194or 186statements 200

conditional expressions 194associativity 195nested 195precedence 194short-circuit evaluation 194side effects 194

conditions 180connecting punctuation character 28const 29constant declarations 290constant expression 147, 160, 161, 176constant field values

case labels 208constant string expressions 208constant values 30, 133constant variable 161constants 302constituent objects 10constituents 12constructing array 59constructor chaining 283, 287, 406constructors 3, 53, 282

accessibility 124accessibility modifier 53body 53chaining 283, 287class name 53

PGJC4_JSE8_OCA.book Page 623 Monday, June 20, 2016 2:31 PM

624 INDEX

declaration 48default 54header 53implicit default 54local declarations 53no-argument 53, 54, 283, 287non-zero argument 55, 287, 288overloading 56superclass constructor 54

constructs 28high-level 28loops see iteration statements

containersee collections

contains characters 368continue statement 223contract 2, 291, 293, 334, 335control flow

break 205, 221continue 223do-while 214for(;;) 215for(:) 217if 200if-else 201iteration see iteration statementsloops see iteration statementsreturn 224statements 50, 200switch 203throw 249transfer statements 219while 213

control transfer 219conversion categories 147conversion contexts 147conversions 144, 311

assignment 147contexts 147identity 172implicit narrowing 173method invocation 148narrowing reference 320number systems 157numeric promotions 149parameters 73reference casting 320string concatenation 175to strings 369truncation 161type-safe 315unsafe casts 321

widening reference 267, 320converting number systems 157converting values 348, 349, 350, 352, 353,

355, 369counter-controlled loops 215coupling 336

loose 336covariant return 269, 273-cp option

see class pathCR see carriage returncrab 217creating

objects 195criteria object 436currency symbol 28current directory

. 108Current Era (CE) 464current object 50

D-d option 106dangling references 384data structures 414data types see typesdate

see temporal objectsdate units 474date/time formatters

customized 486, 495format styles 490formatting 487immutability 487ISO-based default 486, 487ISO-based predefined 486, 488letter pattern 495localized 486, 490parsing 487pattern letters 495, 496thread-safety 487

date-based values 462date-time

see temporal objectsDateTimeException 463DateTimeFormatter class

see date/time formattersDateTimeParseException 477, 491DayOfWeek enum type 468declaration statement 4, 41, 171, 177, 187,

216

PGJC4_JSE8_OCA.book Page 624 Monday, June 20, 2016 2:31 PM

INDEX 625

declarationsarrays 59, 196classes 48, 96interfaces 96local 50main method 85methods 49multidimensional arrays 63packages 96, 98statements 50variable arity method 81

declared type 268, 274, 275, 315declared-type parameters 445declaring see declarationsdecoupling 330decrement operator 176deep copying 343default

accessibility 118, 124, 127constructor 54exception handler 232method 297values 42, 400, 406

default 297label 204method 297

default constructor 54default method 297, 442, 443

multiple inheritance 298overriding 298

default package 98deferred execution 451definitions

inheritance 296interfaces 290

delegating requests 334derived class 264destination directory 106destination stream 18destroying objects 390diagrams

class 3object 5see also UML

diamond operator (<>) 416dictionary order 363distributed 23divide-and-conquer algorithm 69dividend 168division

floating-point 167integer 167

division operator/ 167

divisor 168documentation 35documentation comment 35, 36

tags 36documenting see documentationdot 97double 31, 39double quote 33do-while statement 214downcasting 145duplicating objects 343Duration class 476

time-based 476dynamic 23dynamic arrays 415dynamic binding

see dynamic method lookupdynamic method lookup 277, 329, 330dynamic type 268, 274, 275

Eeffectively final 448element type 59, 415elements 58, 414eligible for garbage collection 385ellipsis 81else clause matching 203embedded applications 22empty statement 50empty string 358encapsulation 22, 97, 335encapsulation of implementation 334ends with characters 368enhanced for loop 213enterprise applications 22enum constant 87

symbolic names 87values 87

enum types 87, 103, 209, 303declaring 87finalization 391named constants 87natural order 90ordinal value 90, 209switch expression 204using 88

enumerated typessee enum types

EOFException 235

PGJC4_JSE8_OCA.book Page 625 Monday, June 20, 2016 2:31 PM

626 INDEX

equality 181, 342equals method 183, 342object value 183objects 183primitive values 181reference values 182

equals method 183, 342Error 237escape sequences 33evaluation order 152, 187

arithmetic expressions 164evaluation short-circuits 187exam 507

multiple-choice 513program 510questions 511registration 508result 511testing locations 510voucher 509

exam objectivesOCAJP8 515

Exception class 236exception handler 230

see also exceptionsexception handling

advantages 254exceptions 230, 239

customized 238default handler 232handler 230ignored 390propagation 230situations 235throw 249throwing see throwing exceptionsthrown by JVM 235thrown by method 49thrown programmatically 235throws 251types 233uncaught 232unchecked 237

exchanging information 72explicit

garbage collection 393explicit traversal 452exponent 31expression statements 50, 159, 177, 216,

217, 446expressions 205

actual parameters 72

boolean 180case labels 205conditional 194deterministic evaluation 150label 205return 224statements 50throw 249

extendingclasses 264interfaces 294

extends clausesee extending

extensions.class 16.java 16

external libraries 403extracting substrings 369

Ffall-through 204, 205false literal 32FF see form feedfield declarations 48field hiding 275field initialization 406fields 2file name 96file path 105

separator character 105filtering 434final

classes 122members 133parameters 80

finalization 385finalization mechanism 385finalize method 343, 390finalizer chaining 391finalizer see finalize methodfinally clause 240, 245fixed arity method 81fixed arity method call 84float 31, 39floating-point 37

double 39float 39literals 31

floating-point arithmetic 165strictfp 166

floating-point data types 31

PGJC4_JSE8_OCA.book Page 626 Monday, June 20, 2016 2:31 PM

INDEX 627

floating-point division 167floating-point remainder 169flow control see control flowfor(;;) statement 215

backward 216forward 215traverse array 62

for(:) statement 217traverse array 62

for-each loop 213form feed 33, 35formal parameters 49, 53, 72, 117, 315

modifier 49name 49type 49

formal type parameter 290format specifications 18, 370format specifier 19format styles 486, 490FormatStyle enum type 486, 490formatted output 18

format specifier 19formatted string 370formatting 35, 462, 486forward reference 400, 401, 403, 405, 406fractional signed numbers 37fully qualified class name 107fully qualified package name 97, 98, 100fully qualified type name 97, 101function 451function type 450functional cohesion 335functional interface 438

@FunctionalInterface 442, 443abstract method 442function type 450functional method 442general-purpose 443generic 441Predicate<T> 440, 451primitive values 444target type 450see also lambda expressions

functional method 442functional programming 24functionality 433functional-style programming 433

Ggarbage collection 387, 389, 390, 393

automatic 384

facilitate 387general abstractions 266general loops 215generalization 10generalized classes 266generic method 423generic type 414goto 29, 220grammar rules 28grouping 97

Hhandles see referenceshas-a relationship 267hash code 52, 343hash tables 52heap 384hiding internals 335high cohesion 335high-performance 24horizontal tab 33hotspots 24HT see horizontal tab

IIDE (integrated development

environment) 508identifiers 28

predefined 29reserved 29variable 40

identity conversion 146, 172identity of object 5IEEE 754-1985 38if block 200if-else statement 201ignored exceptions 390IllegalArgumentException 236, 495immediate superclass 285immutable 462immutable objects 346, 357immutable strings 357implementation inheritance 264implementations 2, 266, 335

inheritance hierarchy 122implementing

interfaces 291implements clause 291implicit

inheritance 264

PGJC4_JSE8_OCA.book Page 627 Monday, June 20, 2016 2:31 PM

628 INDEX

narrowing conversions 173implicit default constructor 54import

declaration 100see also static importsingle-type-import declaration 100statement 96type-import-on-demand declaration 100

importingenum constants 103reference types 99static members 101

increment operator 176index 58index expression 61IndexOutOfBoundsException 361, 369, 375,

376, 419, 422individual array elements 61inequality 181

see also equalityinferred-type parameters 445infinite loop 217infinity 165, 349

negative 165positive 165

information hiding 335inheritance 10, 267

hierarchy 266supertype–subtype relationship 267

initial capacity 417initial state of object 406initialization

arrays 60, 65code 60default values 42for statement 215objects 5references 41variables 41

initializer 399declaration-before-reading rule 401static 400, 401, 405, 409

initializer blockinstance 404static 402

initializer expression 400initializers

non-static block 48non-static field 48static block 48static field 48

initializing see initialization

insertion order 414insertion point 69instance

members 9, 48methods 9, 49, 50variable initialization 42variables 9, 44see also object

instance initializer block 404instance methods 6instance variables 6, 406instanceof operator 195, 320, 321instantiation 4int 30, 38integer arithmetic 165integer bitwise operators 189integer constant expressions 148integer data types 30integer division 167integer remainder operation 168integers 38

and operator 189byte 38complement 189data types 38int 38literals 30long 38or operator 189representation 154short 38types 38xor 189

integral types 37, 38, 144interface constant antipattern 102interfaces 290

abstract 290abstract methods 291accessibility 118body 290constants 302declarations 96default methods 297extending 294header 290implementing 291initialization 409marker 291realization 296references 296static methods 300subinterfaces 294

PGJC4_JSE8_OCA.book Page 628 Monday, June 20, 2016 2:31 PM

INDEX 629

superinterfaces 294

UML 295

variables 302

internal traversal 452

interned strings 358, 359

interned values 351

interpackage accessibility 335

interpreter 17

intraclass dependencies 336

invocation stack

see JVM stack

invoker 224

invoking garbage collection 393

IOException 235

is-a relationship 266, 267, 334

ISO Latin-1 32, 38

ISO standard 486, 487, 488

Iterable interface 366, 424

iteration 215

iteration statements 213

next iteration 223

termination 213, 222

iterators 414, 424

JJava

Native Interface see JNI

java 17

Java bytecode 16

Java Collections Framework 414

Java compiler 17

Java Development Kit (JDK) 21

Java ecosystem 21

Java EE (Enterprise Edition) 22

Java ME (Micro Edition) 22

Java Native Interface see JNI

Java Platforms 22

Java Runtime Environment (JRE) 22

Java SE (Standard Edition) 22

Java Virtual Machine see JVM

java.time package 462

java.time.format package 462

java.util package 414

java.util.function<T> package 444

javac 17

Javadoc comment 35

@param tag 49, 56

@return tag 225

@throws tag 253

javadoc utility 36

JDK 17, 508

JNI 137

just-in-time (JIT) 23

JVM 17, 22, 384, 393

JVM stack 230, 384

Kkey 69

keywords 29

abstract 120, 136, 291, 442

boolean 39

break statement 221

byte 38

case 203

catch 240

char 38

class 48, 290

const 29

continue 223

default 204, 297

do 214

double 39

else 201

extends 264

final 80, 122, 133

finally 245

float 39

for 215, 217

if 200

implements 291

import 100

instanceof 195, 320, 321

int 38

interface 290

long 38

native 137

new see new operator

null 149, 183, 320

package 98

private 128

protected 126

public 124

reserved words 29

return 224

short 38

static 17, 101, 132, 300, 402

strictfp 166

super 54, 272, 276, 285, 299

switch 203

synchronized 136

this 50

throw 249

PGJC4_JSE8_OCA.book Page 629 Monday, June 20, 2016 2:31 PM

630 INDEX

throws 251transient 138try 240unused words 29void 17, 347volatile 139while 213, 214

Llabeled break statement 222labels 220, 222

break 222case 203default 204expressions 205labeled statement 220switch statement 203

lambda body 439, 444, 445lambda expressions 433, 438, 444

access class members 446anonymous functions 439arrow -> 439, 444as values 439blocks

scope 448declared-type parameters 445deferred execution 451expression 445expression statements 446function 451inferred-type parameters 445lambda body 439, 444, 445lambda parameters 445non-void return 445parameter list 439, 444single expression 439, 445statement block 439, 446target type 450target typing 451type checking 450variable capture 449void return 445

lambda parameters 445late binding

see dynamic method lookupleast significant bit 155left associativity 152legal assignments 314length method 361letter pattern 495lexical scope

see blocks: scopelexical tokens 28lexicographical ordering 363, 425LF see linefeedlibraries 403lifetime 385

see scope 44line separator 19line terminator 35linear implementation inheritance 266linefeed 33LinkageError 237LinkedList 417List 414lists

see ArrayListliterals 30

boolean 32character 32default type 30, 31double 31escape sequences 33false 32float 31floating-point 31integer 30null 30predefined 29prefix 30quoting 32scientific notation 31string 34suffix 30, 31true 32

litmus testdesign by inheritance 266

local 43chaining of constructors 283, 406variables 44, 117

local declarations 49, 50local variables 53

blocksscope 448

LocalDate classsee temporal objects

LocalDateTime classsee temporal objects

locale 364, 490, 492localizing information 335LocalTime class

see temporal objectslocations

PGJC4_JSE8_OCA.book Page 630 Monday, June 20, 2016 2:31 PM

INDEX 631

see class pathlogical AND

& 184logical complement

! 184logical exclusive OR

^ 184logical inclusive OR

| 184logical XOR

^ 184long 30, 38

suffix 30loop body 213, 215loop condition 213, 215loops see iteration statementsloose coupling 336loss of precision 144

Mmagnitude 144main method 17, 18, 85

arguments 86modifiers 85

manifest constant 134marker interfaces 291Math class 52MAX_VALUE constant 351member declarations 48, 290members 3, 114

access 50accessibility 120, 123default values 42final 133inheritance 264instance 48modified 264modifiers 131of objects 7scope 114short-hand 51static 7, 48, 132terminology 9variables see fields

memory management 384memory organization 384message

receiver 7method call 7, 49, 72

chaining 376, 378fixed arity 84

variable arity 84method chaining 471, 474, 479method declaration 48method header 136, 137method invocation conversions 148, 315method modifiers 49method overloading 52, 273method overriding 268, 273, 407method signature 49, 269method type 450methods 3

@Override 270abstract 136, 291, 442abstract method declarations 291accessibility 49ambiguous call 316automatic variables see local variablesbehavior 433blocks 49body 49, 117call chaining 72call see method callcalling variable arity method 82chained 365clone 343concrete 134declaration 49, 72default 297dynamic lookup 330equals 183, 342exceptions 49final 134finalize 343, 390fixed arity 81functional 442getClass 343header 49implementation 136invocation see method calllocal declarations 49local variablesmain see main methodmethod invocation conversions 315method type 450modifiers 49most specific 316, 422name 72native 137, 251objects 50overloaded resolution 316overloading see method overloadingoverriding see method overriding

PGJC4_JSE8_OCA.book Page 631 Monday, June 20, 2016 2:31 PM

632 INDEX

overriding vs. overloading 273parameters 49recursive 237return 224return value 49signature 49, 52, 273static 132, 300synchronized 136termination 224throws clause 251toString 343variable arity 81

MIN_VALUE constant 351minimizing overhead 386mobile applications 22modifiers

abstract 120, 136, 291accessibility 118, 123classes 120default 297final 133members 131native 137static 132, 300strictfp 166synchronized 136transient 138volatile 139

Month enum type 465most specific method 316, 422multicore 441multicore architectures 24multidimensional arrays 63, 65multiple assignments 159multiple catch clauses 239multiple implementation inheritance 290multiple inheritance 298multiple interface inheritance 290multiple-line comment 35multiplication operator

* 167multiplicative operators 167multithreaded 24mutable character sequences 374mutually comparable 68, 69mutually exclusive

actions 202MVC 335

Nname 28

named constants 134namespaces 53NaN 166, 349narrower range 144narrowing conversions

primitive 144reference 145

narrowing reference conversions 320native libraries 403native methods 137, 251

header 137natural ordering 68, 69, 425negative zero 165nested lists 417nested loops 66new operator 5, 53, 59, 195, 406newline see linefeedNL see newlineno-argument constructor 53, 54, 283, 287non-associativity 151non-static code 48see non-static context 48

non-static context 48non-static field 9non-static field initializers 48non-static initializer block 48non-varargs callsee fixed arity call

non-void return 445non-zero argument constructor 55, 287,

288normal class 121normal execution 232notifying threads 344null reference 30

casting 320null reference literal

casting 149equality comparison 183

nulling references 387NullPointerException 236Number class 351number systems

base 30converting 157decimal 30hexadecimal 30octal 30radix 30

NumberFormatException 236, 347, 348numeric promotions 149

assignment 160

PGJC4_JSE8_OCA.book Page 632 Monday, June 20, 2016 2:31 PM

INDEX 633

binary 150unary 149

numeric wrapper classes 351numerical literals

using underscore 32

Oobject 4Object class 266, 342object hierarchy 267object references 4, 40object state 6, 53, 77, 406object-oriented design 334

cohesion 335object-oriented paradigm 22object-oriented programming 2objects 13

aggregate 12alive 385arrays 58callee 72caller 72Class class 343cleaning up 386cloning 343communication 72comparing 342composite 385constituent 12, 385constructing 406contract 335decoupling 330destroying 390eligible 387equality 183, 342exchanging information 72finalization 385garbage collection 384identity 5immutable 346implementation 335initial state 406initialization 5, 53initializer block 404internals 335lifetime 385members 7methods 50Object class 342persistence 138reachable 384, 385

resurrection 385services 335state 133see object state

value equality 183OCAJP8 507

exam objectives 515exam question assumptions 511

OCPJP8 507one-dimensional arrays 59operands 148

evaluation order 152operations 2operators 150

- 163, 169-- 176^ 184, 189^= 185, 192! 184!= 181, 182? : 194. 7, 97[] 61, 195* 163, 167*= 172/ 163, 167/= 172& 184, 189&& 186&= 185, 192% 163, 167, 168%= 172+ 163, 169, 174++ 176+= 172< 180<= 180-= 172= 158== 181, 182-> 195> 180>= 180| 184, 189|= 185, 192|| 186~ 189arithmetic compound assignment 172assignment 151, 158associativity 150binary 151bitwise 189

PGJC4_JSE8_OCA.book Page 633 Monday, June 20, 2016 2:31 PM

634 INDEX

boolean 180, 181, 184cast 151comparisons 180compound assignment 185, 192conditional 186, 194decrement 176dot 7equality 181execution order 152floating-point 165floating-point division 167floating-point remainder 169increment 176instanceof 195, 320, 321integer 189integer arithmetic 165integer division 167integer remainder 168logical 184multiplicative 167new see new operatoroverflow 165overloaded 164, 167postfix 151precedence 150relational 180short-circuited 186string concatenation 174ternary 151unary 150, 151, 167unary - 167unary + 167

optimizations 24or operator 189Oracle University 509ordinal value 90, 209OutOfMemoryException 395output 18overflow 155, 165overloaded 164overloaded method resolution 316overloading

constructors 56method resolution 316methods 52, 273

overloading vs. overriding 273overriding 253

equals 183finalizers 390methods 268, 273toString 175

overriding methods

covariant return 273overriding vs. overloading 273ownership 12

Ppackage accessibility 118, 124package directory 106package statement 96, 98packages 97

accessibility see package accessibilitydeclaration 96definition 98destination directory 106hierarchy 97java.lang 342members 97naming scheme 98package directory 106running code from 106short-hand 100statement see package statementsubpackages 97unnamed 98using 99

palindromes 382, 434parallel code 441parameter

variable arity 81parameter list 439, 444parameter list see formal parametersparameter passing

by value 72variable arity 81

parameters 49actual 72array elements 78final 80fixed arity 81formal see formal parametersimplicit 50main method 86passing 72primitives 73program 86references 75this 50variable arity 81

parent class 264parentheses 150parseType method 352parsing 462, 486

PGJC4_JSE8_OCA.book Page 634 Monday, June 20, 2016 2:31 PM

INDEX 635

parsing numeric values 352partial implementation 293pass by value 72passing

parameters 72references 75variable arity parameter 81

pathssee class path

path-separator character 110pattern letters 486, 495, 496Pearson VUE 509performance 24period 462, 476

creating 476date-based 476equality 478get methods 478immutable 476normalization 479parsing 477period-based loop 481plus/minus methods 479querying 478temporal arithmetic 479textual representation 477thread-safe 476with methods 479

Period classsee period

persistent objects 138polymorphism 311, 329, 334portability 23positional order 414positive zero 165postfix operators 151precedence rules 151precision 160predefined identifiers 29predefined literals 29predicate 436Predicate<T> 440, 451prefix 30

0 300x 30

primitive data typessee primitive types

primitive types 13, 144autoboxing 348unboxing 350see also primitive values

primitive values

assignment 159equality 181passing 73

printing values 18private 11private members 128process of elimination 510program

application 16arguments 86command line 86compiling 17formatting 35running 17

program arguments 86program output 18programming to an interface 417proleptic year 464promotion 149properties 2

see also class membersprotected 11protected members 126public 17public members 124punctuators 29

Qquotation mark 33, 34quotient 168

Rradix

prefix 30see base 349

ragged arrays 65range

character values 38floating-point values 39integer values 38

range of date-based values 464range of time-based values 464ranking criteria 414realization 296reclaiming memory 384reducing complexity 335reference types 41, 267

classes 48enum types 87

reference values 4

PGJC4_JSE8_OCA.book Page 635 Monday, June 20, 2016 2:31 PM

636 INDEX

reference variables 40

references 4, 9, 40, 41, 72

abstract types 121

aliases 75, 183

array 59, 62, 311

assignment 159

casting 149, 320

dangling 384

declared type 268

downcasting 145

dynamic type 268

equality 182

field 385

interface type 296

local 384

narrowing conversions 145

null see null reference

passing 75

reachable 384, 385

super 276

this 50

upcasting 145

widening conversions 145

relational operators 180

relative adjusters 474

reliability 24

remainder 168

remainder operator

% 168

remove whitespace 369

replacing characters 367

reserved identifiers 29

reserved keywords 29

const 29

goto 220

reserved literals

false 32

null see null reference

true 32

resources 387

resurrecting objects 385, 391

return statement 224

@return tag 225

return type

covariant

return value 7reuse of code 264, 334

right associativity 152

rightmost bit 155

ripple effect 334

robustness 24, 254

role relationship 334

root

see inheritance hierarchy

running a Java application 17

runtime

bounds checking 61

runtime checks 148, 418

Runtime class 342, 393

runtime class 343

runtime environment 384

runtime stack

see JVM stack

RuntimeException 236

Sscientific notation 31

scope 114

block 117

catch clause 244

class 114

disjoint 118

searching

arrays 69

searching in string 367

secure 24

SecurityManager class 342

selection statements 200

semantic definition 28

semicolon 50

separators 29, 151

serialization 138

services 335

shadowing 446

shallow copying 343

short 30, 38

short-circuit 186

evaluation 187

signature 52, 273

simple

assignment operator 158

if 200

statement 50

simple type name 97

simplicity 23

single expression 439

single implementation inheritance 266, 290, 296

single quote (') 32, 33

single static import 101

single-line comment 3, 35

skeletal source file 96

sorting arrays 68

PGJC4_JSE8_OCA.book Page 636 Monday, June 20, 2016 2:31 PM

INDEX 637

sourcefile 15, 98file name 96file structure 96

spaces 35special character values 33specialization 10specialized classes 266stack 3stack frame

see method executionstack trace 232, 235

see method executionStackOverflowError 237standard error stream 235standard out 18starts with characters 368state see object statestatement block 439, 446statements 50

break 221compound 50conditional 200continue 223control flow 50, 200control transfer 219declaration 171, 177, 187declarations 50do-while 214empty 50expression 50, 177for(;;) 215for(:) 217if 200if-else 201iteration 213labeled 220return 224selection 200simple 50simple if 200switch 203throw 249transfer 219try 240while 213

staticmembers see static membersmethods 7, 10, 49variable initialization 42variables see static variables

static 101, 132, 300

static codesee static context 48

static context 48static field 10static field initializers 48static import 101

conflicts 104on demand 101shadow static members 103single static import 101

static initializer block 48, 137, 402static keyword 402static members 7, 9, 10, 48static type

see declared typestatic variables 7, 10, 44storing objects 138strictfp 166string builders 176

appending 376capacity 374, 378constructing 374deleting 376differences with strings 376individual characters 375inserting 376joining 366length 375thread-safety 374

String classsee strings

string conversion 146, 175string conversions 370string literal pool 358

interned 358string literals 357

case labels 208hash value 208interned 358

StringBuffer class 374see string buildersthread-safe 374

StringBuilder class 374, 434see string builders

stringsappending 376buffers 374builders 374capacity 378changing case 364compareTo 363comparing 363

PGJC4_JSE8_OCA.book Page 637 Monday, June 20, 2016 2:31 PM

638 INDEX

concatenation 174, 364concatenation operator + 176constructing 374contains 368conversions 370convert to character array 361copying characters 361creating 357deleting 376differences with string builders 376empty 358ends with 368equals 363extracting substrings 369finding index 367formatted 370ignoring case in comparison 363immutable 357individual characters 361, 375initializing 357inserting 376interned 358joining 365, 366length 361, 375lexicographical ordering 363literals 34, 357mutable 374read character at index 361replacing 367searching 367starts with 368string literal pool 358substrings 369trimming 369

strongly typed language 148subclass 10, 11, 264subinterface 294subpackages 97subsequence 361substring searching 367substrings 367, 369subtype covariance 309, 310subtype relationship 418subtypes 293subtype–supertype relationship 145suffix

D 31F 31L 30

super 299construct 285keyword 272, 276

reference 276superclass 10, 11, 264superclass constructor 54superclass–subclass relationship 266superinterfaces 294supertypes 293supertype–subtype relationship 267supplementary characters 357suppressed exceptions 235switch statement 203

break 205, 206default clause 204enum types 209using strings 208

synchronizedmethods 136

syntactically legal 28System

out 18System class 342system clock 466

TTAB see horizontal tabtabs 35tabulators 35tags 36target type 450target typing 451telephone directory order 363temporal arithmetic 474, 479temporal objects

before/after methods 469combining date and time 466common method prefix 463comparing 470creating with factory methods 464date 462date units 474date-based values 462date-time 462formatting 486get methods 468immutable 462method naming convention 463parsing 486plus/minus methods 474querying 468range of date-based values 464range of time-based values 464temporal arithmetic 474, 479, 480

PGJC4_JSE8_OCA.book Page 638 Monday, June 20, 2016 2:31 PM

INDEX 639

temporal values 464thread-safe 462time 462time units 474time-based values 462with methods 470

temporal values 464TemporalAmount interface 479terminating loops 221ternary conditional expressions

see also conditional expressions 194ternary conditional operator 151, 194textual representation 343this

reference 50this() constructor call 282, 406ThreadDeath 237threads 24, 342, 384

death 232exception propagation 232JVM stack 385live 384notifying 344synchronization 136waiting 344

thread-safe 357, 374, 415, 462throw statement 249Throwable 233, 342throw-and-catch paradigm 230throwing exceptions 230throws clause 251time

see temporal objectstime units 474time-based values 462tokens 28toString method 343, 349transfer statements 219transient variables 138transitive relation 267trim method 369true literal 32truth-values 32, 39try block 240try-catch-finally construct 238two’s complement 154type

declared 274dynamic 274

type cast 148type cast expression 320type checking 450

type declarations 96type hierarchy 145, 267type import

see importtype parameter 290, 414, 441types

boolean 37, 39byte 30, 38casting 148char 38classes see classescomparing 321compatibility 148double 39exceptions 233float 39floating-point 37, 38int 30, 38integers 38integral types 37interface 290long 30, 38parsing 352short 30, 38wrappers 346see also classes

type-safe 315type-safety 416, 417, 418typeValue method 350, 352

UUML 2

accessibility 124aggregation 12associations 12classes 3composition 12inheritance 10see also diagrams

unary arithmetic operators 167unary numeric promotion 149unary operators 150, 151unboxing 350

do-while statement 214for(;;) statement 215for(:) statement 218if statement 200if-else statement 202switch statement 204while statement 213

unboxing conversions 145, 146

PGJC4_JSE8_OCA.book Page 639 Monday, June 20, 2016 2:31 PM

640 INDEX

uncaught exceptions 232unchangeable variables 134unchecked conversion warning 416unchecked conversions 146unchecked exceptions 237unchecked warnings 145underflow 155, 165uni-catch clause 239Unicode 32, 38, 354, 357, 363, 434Unified Modeling Language see UMLunreachable code 244unsafe casts 321unsigned integer 353UnsupportedTemporalTypeException 480, 490unused keywords 29upcasting 145update expression 215using arrays 61using packages 99using variables 41UTF-16 357

supplementary characters 357

VvalueOf method 348, 349, 369values 155

constants 30overflow 155underflow 155wrap-around 155see also variables

varargs 81variable arity call 84variable arity method 81variable arity parameter 81variable capture 449variable declarations 41, 117variable initialization 8, 43variables 4, 41

blank final 80, 134constant values 133default values 42effectively final 448final 133identifiers 40in interfaces 302initialization see variable initializationlifetime 44local 117parameters 49, 72reference variable 41

references 41static 7storing 138transient 138volatile 139

virtual method invocationsee dynamic method lookup

VirtualMachineError 237void 17, 224, 347void return 445Void wrapper class 346volatile variables 139voucher 509

Wwaiting threads 344while statement 213whitespace 35, 369whole–part relationship 267widening conversions

primitive 144references 145

widening reference conversions 267, 320wider range 144withers 470wrapper classes 38, 342, 343, 346, 347

interned values 351wrapper type 146, 164, 177

Xxor 189

Zzero

negative 165positive 165

zero-based index 414

PGJC4_JSE8_OCA.book Page 640 Monday, June 20, 2016 2:31 PM