| |
| |
Table of Contents | |
| |
| |
Preface | |
| |
| |
Preface to the Second Edition | |
| |
| |
| |
Introduction | |
| |
| |
| |
Example Programs | |
| |
| |
| |
Notation | |
| |
| |
| |
Relationship to Predefined Classes and Interfaces | |
| |
| |
| |
References | |
| |
| |
| |
Grammars | |
| |
| |
| |
Context-Free Grammars | |
| |
| |
| |
The Lexical Grammar | |
| |
| |
| |
The Syntactic Grammar | |
| |
| |
| |
Grammar Notation | |
| |
| |
| |
Lexical Structure | |
| |
| |
| |
Unicode | |
| |
| |
| |
Lexical Translations | |
| |
| |
| |
Unicode Escapes | |
| |
| |
| |
Line Terminators | |
| |
| |
| |
Input Elements and Tokens | |
| |
| |
| |
White Space | |
| |
| |
| |
Comments | |
| |
| |
| |
Identifiers | |
| |
| |
| |
Keywords | |
| |
| |
| |
Literals | |
| |
| |
| |
Integer Literals | |
| |
| |
| |
Floating-Point Literals | |
| |
| |
| |
Boolean Literals | |
| |
| |
| |
Character Literals | |
| |
| |
| |
String Literals | |
| |
| |
| |
Escape Sequences for Character and String Literals | |
| |
| |
| |
The Null Literal | |
| |
| |
| |
Separators | |
| |
| |
| |
Operators | |
| |
| |
| |
Types, Values, and Variables | |
| |
| |
| |
The Kinds of Types and Values | |
| |
| |
| |
Primitive Types and Values | |
| |
| |
| |
Integral Types and Values | |
| |
| |
| |
Integer Operations | |
| |
| |
| |
Floating-Point Types, Formats, and Values | |
| |
| |
| |
Floating-Point Operations | |
| |
| |
| |
The boolean Type and boolean Values | |
| |
| |
| |
Reference Types and Values | |
| |
| |
| |
Objects | |
| |
| |
| |
The Class Object | |
| |
| |
| |
The Class String | |
| |
| |
| |
When Reference Types Are the Same | |
| |
| |
| |
Where Types Are Used | |
| |
| |
| |
Variables | |
| |
| |
| |
Variables of Primitive Type | |
| |
| |
| |
Variables of Reference Type | |
| |
| |
| |
Kinds of Variables | |
| |
| |
| |
Final Variables | |
| |
| |
| |
Initial Values of Variables | |
| |
| |
| |
Types, Classes, and Interfaces | |
| |
| |
| |
Conversions and Promotions | |
| |
| |
| |
Kinds of Conversion | |
| |
| |
| |
Identity Conversions | |
| |
| |
| |
Widening Primitive Conversion | |
| |
| |
| |
Narrowing Primitive Conversions | |
| |
| |
| |
Widening Reference Conversions | |
| |
| |
| |
Narrowing Reference Conversions | |
| |
| |
| |
String Conversions | |
| |
| |
| |
Forbidden Conversions | |
| |
| |
| |
Value Set Conversion | |
| |
| |
| |
Assignment Conversion | |
| |
| |
| |
Method Invocation Conversion | |
| |
| |
| |
String Conversion | |
| |
| |
| |
Casting Conversion | |
| |
| |
| |
Numeric Promotions | |
| |
| |
| |
Unary Numeric Promotion | |
| |
| |
| |
Binary Numeric Promotion | |
| |
| |
| |
Names | |
| |
| |
| |
Declarations | |
| |
| |
| |
Names and Identifiers | |
| |
| |
| |
Scope of a Declaration | |
| |
| |
| |
Shadowing Declarations | |
| |
| |
| |
Obscured Declarations | |
| |
| |
| |
Members and Inheritance | |
| |
| |
| |
The Members of a Package | |
| |
| |
| |
The Members of a Class Type | |
| |
| |
| |
The Members of an Interface Type | |
| |
| |
| |
The Members of an Array Type | |
| |
| |
| |
Determining the Meaning of a Name | |
| |
| |
| |
Syntactic Classification of a Name According to Context | |
| |
| |
| |
Reclassification of Contextually Ambiguous Names | |
| |
| |
| |
Meaning of Package Names | |
| |
| |
| |
Meaning of PackageOrTypeNames | |
| |
| |
| |
Meaning of Type Names | |
| |
| |
| |
Meaning of Expression Names | |
| |
| |
| |
Meaning of Method Names | |
| |
| |
| |
Access Control | |
| |
| |
| |
Determining Accessibility | |
| |
| |
| |
Details on protected Access | |
| |
| |
| |
An Example of Access Control | |
| |
| |
| |
Example: Access to public and Non-public Classes | |
| |
| |
| |
Example: Default-Access Fields, Methods, and Constructors | |
| |
| |
| |
Example: public Fields, Methods, and Constructors | |
| |
| |
| |
Example: protected Fields, Methods, and Constructors | |
| |
| |
| |
Example: private Fields, Methods, and Constructors | |
| |
| |
| |
Fully Qualified Names and Canonical Names | |
| |
| |
| |
Naming Conventions | |
| |
| |
| |
Package Names | |
| |
| |
| |
Class and Interface Type Names | |
| |
| |
| |
Method Names | |
| |
| |
| |
Field Names | |
| |
| |
| |
Constant Names | |
| |
| |
| |
Local Variable and Parameter Names | |
| |
| |
| |
Packages | |
| |
| |
| |
Package Members | |
| |
| |
| |
Host Support for Packages | |
| |
| |
| |
Storing Packages in a File System | |
| |
| |
| |
Storing Packages in a Database | |
| |
| |
| |
Compilation Units | |
| |
| |
| |
Package Declarations | |
| |
| |
| |
Named Packages | |
| |
| |
| |
Unnamed Packages | |
| |
| |
| |
Observability of a Package | |
| |
| |
| |
Scope of a Package Declaration | |
| |
| |
| |
Import Declarations | |
| |
| |
| |
Single-Type-Import Declaration | |
| |
| |
| |
Type-Import-on-Demand Declaration | |
| |
| |
| |
Automatic Imports | |
| |
| |
| |
A Strange Example | |
| |
| |
| |
Top Level Type Declarations | |
| |
| |
| |
Unique Package Names | |
| |
| |
| |
Classes | |
| |
| |
| |
Class Declaration | |
| |
| |
| |
Class Modifiers | |
| |
| |
| |
Inner Classes and Enclosing Instances | |
| |
| |
| |
Superclasses and Subclasses | |
| |
| |
| |
Superinterfaces | |
| |
| |
| |
Class Body and Member Declarations | |
| |
| |
| |
Class Members | |
| |
| |
| |
Examples of Inheritance | |
| |
| |
| |
Field Declarations | |
| |
| |
| |
Field Modifiers | |
| |
| |
| |
Initialization of Fields | |
| |
| |
| |
Examples of Field Declarations | |
| |
| |
| |
Method Declarations | |
| |
| |
| |
Formal Parameters | |
| |
| |
| |
Method Signature | |
| |
| |
| |
Method Modifiers | |
| |
| |
| |
Method Throws | |
| |
| |
| |
Method Body | |
| |
| |
| |
Inheritance, Overriding, and Hiding | |
| |
| |
| |
Overloading | |
| |
| |
| |
Examples of Method Declarations | |
| |
| |
| |
Member Type Declarations | |
| |
| |
| |
Access Modifiers | |
| |
| |
| |
Static Member Type Declarations | |
| |
| |
| |
Instance Initializers | |
| |
| |
| |
Static Initializers | |
| |
| |
| |
Constructor Declarations | |
| |
| |
| |
Formal Parameters | |
| |
| |
| |
Constructor Signature | |
| |
| |
| |
Constructor Modifiers | |
| |
| |
| |
Constructor Throws | |
| |
| |
| |
Constructor Body | |
| |
| |
| |
Constructor Overloading | |
| |
| |
| |
Default Constructor | |
| |
| |
| |
Preventing Instantiation of a Class | |
| |
| |
| |
Interfaces | |
| |
| |
| |
Interface Declarations | |
| |
| |
| |
Interface Modifiers | |
| |
| |
| |
Superinterfaces and Subinterfaces | |
| |
| |
| |
Interface Body and Member Declarations | |
| |
| |
| |
Access to Interface Member Names | |
| |
| |
| |
Interface Members | |
| |
| |
| |
Field (Constant) Declarations | |
| |
| |
| |
Initialization of Fields in Interfaces | |
| |
| |
| |
Examples of Field Declarations | |
| |
| |
| |
Abstract Method Declarations | |
| |
| |
| |
Inheritance and Overriding | |
| |
| |
| |
Overloading | |
| |
| |
| |
Examples of Abstract Method Declarations | |
| |
| |
| |
Member Type Declarations | |
| |
| |
| |
Arrays | |
| |
| |
| |
Array Types | |
| |
| |
| |
Array Variables | |
| |
| |
| |
Array Creation | |
| |
| |
| |
Array Access | |
| |
| |
| |
Arrays: A Simple Example | |
| |
| |
| |
Array Initializers | |
| |
| |
| |
Array Members | |
| |
| |
| |
Class Objects for Arrays | |
| |
| |
| |
An Array of Characters is Not a String | |
| |
| |
| |
Array Store Exception | |
| |
| |
| |
Exceptions | |
| |
| |
| |
The Causes of Exceptions | |
| |
| |
| |
Compile-Time Checking of Exceptions | |
| |
| |
| |
Why Errors are Not Checked | |
| |
| |
| |
Why Runtime Exceptions are Not Checked | |
| |
| |
| |
Handling of an Exception | |
| |
| |
| |
Exceptions are Precise | |
| |
| |
| |
Handling Asynchronous Exceptions | |
| |
| |
| |
An Example of Exceptions | |
| |
| |
| |
The Exception Hierarchy | |
| |
| |
| |
Loading and Linkage Errors | |
| |
| |
| |
Virtual Machine Errors | |
| |
| |
| |
Execution | |
| |
| |
| |
Virtual Machine Start-Up | |
| |
| |
| |
Load the Class Test | |
| |
| |
| |
Link Test: Verify, Prepare, (Optionally) Resolve | |
| |
| |
| |
Initialize Test: Execute Initializers | |
| |
| |
| |
Invoke Test.main | |
| |
| |
| |
Loading of Classes and Interfaces | |
| |
| |
| |
The Loading Process | |
| |
| |
| |
Linking of Classes and Interfaces | |
| |
| |
| |
Verification of the Binary Representation | |
| |
| |
| |
Preparation of a Class or Interface Type | |
| |
| |
| |
Resolution of Symbolic References | |
| |
| |
| |
Initialization of Classes and Interfaces | |
| |
| |
| |
When Initialization Occurs | |
| |
| |
| |
Detailed Initialization Procedure | |
| |
| |
| |
Initialization: Implications for Code Generation | |
| |
| |
| |
Creation of New Class Instances | |
| |
| |
| |
Finalization of Class Instances | |
| |
| |
| |
Implementing Finalization | |
| |
| |
| |
Finalizer Invocations are Not Ordered | |
| |
| |
| |
Unloading of Classes and Interfaces | |
| |
| |
| |
Program Exit | |
| |
| |
| |
Binary Compatibility | |
| |
| |
| |
The Form of a Binary | |
| |
| |
| |
What Binary Compatibility Is and Is Not | |
| |
| |
| |
Evolution of Packages | |
| |
| |
| |
Evolution of Classes | |
| |
| |
| |
Abstract Classes | |
| |
| |
| |
Final Classes | |
| |
| |
| |
Public Classes | |
| |
| |
| |
Superclasses and Superinterfaces | |
| |
| |
| |
Class Body and Member Declarations | |
| |
| |
| |
Access to Members and Constructors | |
| |
| |
| |
Field Declarations | |
| |
| |
| |
Final Fields and Constants | |
| |
| |
| |
Static Fields | |
| |
| |
| |
Transient Fields | |
| |
| |
| |
Method and Constructor Declarations | |
| |
| |
| |
Method and Constructor Parameters | |
| |
| |
| |
Method Result Type | |
| |
| |
| |
Abstract Methods | |
| |
| |
| |
Final Methods | |
| |
| |
| |
Native Methods | |
| |
| |
| |
Static Methods | |
| |
| |
| |
Synchronized Methods | |
| |
| |
| |
Method and Constructor Throws | |
| |
| |
| |
Method and Constructor Body | |
| |
| |
| |
Method and Constructor Overloading | |
| |
| |
| |
Method Overriding | |
| |
| |
| |
Static Initializers | |
| |
| |
| |
Evolution of Interfaces | |
| |
| |
| |
Public Interfaces | |
| |
| |
| |
Superinterfaces | |
| |
| |
| |
The Interface Members | |
| |
| |
| |
Field Declarations | |
| |
| |
| |
Abstract Method Declarations | |
| |
| |
| |
Blocks and Statements | |
| |
| |
| |
Normal and Abrupt Completion of Statements | |
| |
| |
| |
Blocks | |
| |
| |
| |
Local Class Declarations | |
| |
| |
| |
Local Variable Declaration Statements | |
| |
| |
| |
Local Variable Declarators and Types | |
| |
| |
| |
Scope of Local Variable Declarations | |
| |
| |
| |
Shadowing of Names by Local Variables | |
| |
| |
| |
Execution of Local Variable Declarations | |
| |
| |
| |
Statements | |
| |
| |
| |
The Empty Statement | |
| |
| |
| |
Labeled Statements | |
| |
| |
| |
Expression Statements | |
| |
| |
| |
The if Statement | |
| |
| |
| |
The if-then Statement | |
| |
| |
| |
The if-then-else Statement | |
| |
| |
| |
The switch Statement | |
| |
| |
| |
The while Statement | |
| |
| |
| |
Abrupt Completion | |
| |
| |
| |
The do Statement | |
| |
| |
| |
Abrupt Completion | |
| |
| |
| |
Example of do statement | |
| |
| |
| |
The for Statement | |
| |
| |
| |
Initialization of for statement | |
| |
| |
| |
Iteration of for statement | |
| |
| |
| |
Abrupt Completion of for statement | |
| |
| |
| |
The break Statement | |
| |
| |
| |
The continue Statement | |
| |
| |
| |
The return Statement | |
| |
| |
| |
The throw Statement | |
| |
| |
| |
The synchronized Statement | |
| |
| |
| |
The try statement | |
| |
| |
| |
Execution of try-catch | |
| |
| |
| |
Execution of try-catch-finally | |
| |
| |
| |
Unreachable Statements | |
| |
| |
| |
Expressions | |
| |
| |
| |
Evaluation, Denotation, and Result | |
| |
| |
| |
Variables as Values | |
| |
| |
| |
Type of an Expression | |
| |
| |
| |
FP-strict Expressions | |
| |
| |
| |
Expressions and Run-Time Checks | |
| |
| |
| |
Normal and Abrupt Completion of Evaluation | |
| |
| |
| |
Evaluation Order | |
| |
| |
| |
Evaluate Left-Hand Operand First | |
| |
| |
| |
Evaluate Operands before Operation | |
| |
| |
| |
Evaluation Respects Parentheses and Precedence | |
| |
| |
| |
Argument Lists are Evaluated Left-to-Right | |
| |
| |
| |
Evaluation Order for Other Expressions | |
| |
| |
| |
Primary Expressions | |
| |
| |
| |
Lexical Literals | |
| |
| |
| |
Class Literals | |
| |
| |
| |
This | |
| |
| |
| |
Qualified this | |
| |
| |
| |
Parenthesized Expressions | |
| |
| |
| |
Class Instance Creation Expressions | |
| |
| |
| |
Determining the Class being Instantiated | |
| |
| |
| |
Determining Enclosing Instances | |
| |
| |
| |
Choosing the Constructor and its Arguments | |
| |
| |
| |
Run-time Evaluation of Class Instance Creation Expressions | |
| |
| |
| |
Anonymous Class Declarations | |
| |
| |
| |
Example: Evaluation Order and Out-of-Memory Detection | |
| |
| |
| |
Array Creation Expressions | |
| |
| |
| |
Run-time Evaluation of Array Creation Expressions | |
| |
| |
| |
Example: Array Creation Evaluation Order | |
| |
| |
| |
Example: Array Creation and Out-of-Memory Detection | |
| |
| |
| |
Field Access Expressions | |
| |
| |
| |
Field Access Using a Primary | |
| |
| |
| |
Accessing Superclass Members using super | |
| |
| |
| |
Method Invocation Expressions | |
| |
| |
| |
Compile-Time Step 1: Determine Class or Interface to Search | |
| |
| |
| |
Compile-Time Step 2: Determine Method Signature | |
| |
| |
| |
Compile-Time Step 3: Is the Chosen Method Appropriate? | |
| |
| |
| |
Runtime Evaluation of Method Invocation | |
| |
| |
| |
Array Access Expressions | |
| |
| |
| |
Runtime Evaluation of Array Access | |
| |
| |
| |
Examples: Array Access Evaluation Order | |
| |
| |
| |
Postfix Expressions | |
| |
| |
| |
Postfix Increment Operator ++ | |
| |
| |
| |
Postfix Decrement Operator -- | |
| |
| |
| |
Unary Operators | |
| |
| |
| |
Prefix Increment Operator ++ | |
| |
| |
| |
Prefix Decrement Operator -- | |
| |
| |
| |
Unary Plus Operator + | |
| |
| |
| |
Unary Minus Operator - | |
| |
| |
| |
Bitwise Complement Operator ~ | |
| |
| |
| |
Logical Complement Operator ! | |
| |
| |
| |
Cast Expressions | |
| |
| |
| |
Multiplicative Operators | |
| |
| |
| |
Multiplication Operator * | |
| |
| |
| |
Division Operator / | |
| |
| |
| |
Remainder Operator % | |
| |
| |
| |
Additive Operators | |
| |
| |
| |
String Concatenation Operator + | |
| |
| |
| |
Additive Operators (+ and -) for Numeric Types | |
| |
| |
| |
Shift Operators | |
| |
| |
| |
Relational Operators | |
| |
| |
| |
Numerical Comparison Operators [, [=, ], and ]= | |
| |
| |
| |
Type Comparison Operator instanceof | |
| |
| |
| |
Equality Operators | |
| |
| |
| |
Numerical Equality Operators == and != | |
| |
| |
| |
Boolean Equality Operators == and != | |
| |
| |
| |
Reference Equality Operators == and != | |
| |
| |
| |
Bitwise and Logical Operators | |
| |
| |
| |
Integer Bitwise Operators and, ^, and | |
| |
| |
| |
Boolean Logical Operators and, ^, and | |
| |
| |
| |
Conditional-And Operator andand | |
| |
| |
| |
Conditional-Or Operator | |
| |
| |
| |
Conditional Operator ? : | |
| |
| |
| |
Assignment Operators | |
| |
| |
| |
Simple Assignment Operator = | |
| |
| |
| |
Compound Assignment Operators | |
| |
| |
| |
Expression | |
| |
| |
| |
Constant Expression | |
| |
| |
| |
Definite Assignment | |
| |
| |
| |
Definite Assignment and Expressions | |
| |
| |
| |
Boolean Constant Expressions | |
| |
| |
| |
The Boolean Operator andand | |
| |
| |
| |
The Boolean Operator | |
| |
| |
| |
The Boolean Operator ! | |
| |
| |
| |
The Boolean Operator ? : | |
| |
| |
| |
The Conditional Operator ? : | |
| |
| |
| |
Assignment Expressions | |
| |
| |
| |
Operators ++ and -- | |
| |
| |
| |
Other Expressions | |
| |
| |
| |
Definite Assignment and Statements | |
| |
| |
| |
Empty Statements | |
| |
| |
| |
Blocks | |
| |
| |
| |
Local Class Declaration Statements | |
| |
| |
| |
Local Variable Declaration Statements | |
| |
| |
| |
Labeled Statements | |
| |
| |
| |
Expression Statements | |
| |
| |
| |
if Statements | |
| |
| |
| |
switch Statements | |
| |
| |
| |
while Statements | |
| |
| |
| |
do Statements | |
| |
| |
| |
for Statements | |
| |
| |
| |
break, continue, return, and throw Statements | |
| |
| |
| |
synchronized Statements | |
| |
| |
| |
try Statements | |
| |
| |
| |
Definite Assignment and Parameters | |
| |
| |
| |
Definite Assignment and Array Initializers | |
| |
| |
| |
Definite Assignment and Anonymous Classes | |
| |
| |
| |
Definite Assignment and Member Types | |
| |
| |
| |
Definite Assignment and Static Initializers | |
| |
| |
| |
Definite Assignment, Constructors, and Instance Initializers | |
| |
| |
| |
Threads and Locks | |
| |
| |
| |
Terminology and Framework | |
| |
| |
| |
Execution Order | |
| |
| |
| |
Rules about Variables | |
| |
| |
| |
Nonatomic Treatment of double and long | |
| |
| |
| |
Rules about Locks | |
| |
| |
| |
Rules about the Interaction of Locks and Variables | |
| |
| |
| |
Rules for Volatile Variables | |
| |
| |
| |
Prescient Store Actions | |
| |
| |
| |
Discussion | |
| |
| |
| |
Example: Possible Swap | |
| |
| |
| |
Example: Out-of-Order Writes | |
| |
| |
| |
Threads | |
| |
| |
| |
Locks and Synchronization | |
| |
| |
| |
Wait Sets and Notification | |
| |
| |
| |
Syntax | |
| |
| |
| |
The Grammar of the Java Programming Language | |
| |
| |
Index | |
| |
| |
Credits | |
| |
| |
Colophon | |