Contents | Prev | Next | Index Java Language Specification
Second Edition


Table of Contents

Preface
Preface to the Second Edition

1 Introduction

1.1 Example Programs
1.2 Notation
1.3 Relationship to Predefined Classes and Interfaces
1.4 References

2 Grammars

2.1 Context-Free Grammars
2.2 The Lexical Grammar
2.3 The Syntactic Grammar
2.4 Grammar Notation

3 Lexical Structure

3.1 Unicode
3.2 Lexical Translations
3.3 Unicode Escapes
3.4 Line Terminators
3.5 Input Elements and Tokens
3.6 White Space
3.7 Comments
3.8 Identifiers
3.9 Keywords
3.10 Literals
3.10.1 Integer Literals
3.10.2 Floating-Point Literals
3.10.3 Boolean Literals
3.10.4 Character Literals
3.10.5 String Literals
3.10.6 Escape Sequences for Character and String Literals
3.10.7 The Null Literal
3.11 Separators
3.12 Operators

4 Types, Values, and Variables

4.1 The Kinds of Types and Values
4.2 Primitive Types and Values
4.2.1 Integral Types and Values
4.2.2 Integer Operations
4.2.3 Floating-Point Types, Formats, and Values
4.2.4 Floating-Point Operations
4.2.5 The boolean Type and boolean Values
4.3 Reference Types and Values
4.3.1 Objects
4.3.2 The Class Object
4.3.3 The Class String
4.3.4 When Reference Types Are the Same
4.4 Where Types Are Used
4.5 Variables
4.5.1 Variables of Primitive Type
4.5.2 Variables of Reference Type
4.5.3 Kinds of Variables
4.5.4 final Variables
4.5.5 Initial Values of Variables
4.5.6 Types, Classes, and Interfaces

5 Conversions and Promotions

5.1 Kinds of Conversion
5.1.1 Identity Conversions
5.1.2 Widening Primitive Conversion
5.1.3 Narrowing Primitive Conversions
5.1.4 Widening Reference Conversions
5.1.5 Narrowing Reference Conversions
5.1.6 String Conversions
5.1.7 Forbidden Conversions
5.1.8 Value Set Conversion
5.2 Assignment Conversion
5.3 Method Invocation Conversion
5.4 String Conversion
5.5 Casting Conversion
5.6 Numeric Promotions
5.6.1 Unary Numeric Promotion
5.6.2 Binary Numeric Promotion

6 Names

6.1 Declarations
6.2 Names and Identifiers
6.3 Scope of a Declaration
6.3.1 Shadowing Declarations
6.3.2 Obscured Declarations
6.4 Members and Inheritance
6.4.1 The Members of a Package
6.4.2 The Members of a Class Type
6.4.3 The Members of an Interface Type
6.4.4 The Members of an Array Type
6.5 Determining the Meaning of a Name
6.5.1 Syntactic Classification of a Name According to Context
6.5.2 Reclassification of Contextually Ambiguous Names
6.5.3 Meaning of Package Names
6.5.3.1 Simple Package Names
6.5.3.2 Qualified Package Names
6.5.4 Meaning of PackageOrTypeNames
6.5.4.1 Simple PackageOrTypeNames
6.5.4.2 Qualified PackageOrTypeNames
6.5.5 Meaning of Type Names
6.5.5.1 Simple Type Names
6.5.5.2 Qualified Type Names
6.5.6 Meaning of Expression Names
6.5.6.1 Simple Expression Names
6.5.6.2 Qualified Expression Names
6.5.7 Meaning of Method Names
6.5.7.1 Simple Method Names
6.5.7.2 Qualified Method Names
6.6 Access Control
6.6.1 Determining Accessibility
6.6.2 Details on protected Access
6.6.2.1 Access to a protected Member
6.6.2.2 Qualified Access to a protected Constructor
6.6.3 An Example of Access Control
6.6.4 Example: Access to public and Non-public Classes
6.6.5 Example: Default-Access Fields, Methods, and Constructors
6.6.6 Example: public Fields, Methods, and Constructors
6.6.7 Example: protected Fields, Methods, and Constructors
6.6.8 Example: private Fields, Methods, and Constructors
6.7 Fully Qualified Names and Canonical Names
6.8 Naming Conventions
6.8.1 Package Names
6.8.2 Class and Interface Type Names
6.8.3 Method Names
6.8.4 Field Names
6.8.5 Constant Names
6.8.6 Local Variable and Parameter Names

7 Packages

7.1 Package Members
7.2 Host Support for Packages
7.2.1 Storing Packages in a File System
7.2.2 Storing Packages in a Database
7.3 Compilation Units
7.4 Package Declarations
7.4.1 Named Packages
7.4.2 Unnamed Packages
7.4.3 Observability of a Package
7.4.4 Scope of a Package Declaration
7.5 Import Declarations
7.5.1 Single-Type-Import Declaration
7.5.2 Type-Import-on-Demand Declaration
7.5.3 Automatic Imports
7.5.4 A Strange Example
7.6 Top Level Type Declarations
7.7 Unique Package Names

8 Classes

8.1 Class Declaration
8.1.1 Class Modifiers
8.1.1.1 abstract Classes
8.1.1.2 final Classes
8.1.1.3 strictfp Classes
8.1.2 Inner Classes and Enclosing Instances
8.1.3 Superclasses and Subclasses
8.1.4 Superinterfaces
8.1.5 Class Body and Member Declarations
8.2 Class Members
8.2.1 Examples of Inheritance
8.2.1.1 Example: Inheritance with Default Access
8.2.1.2 Inheritance with public and protected
8.2.1.3 Inheritance with private
8.2.1.4 Accessing Members of Inaccessible Classes
8.3 Field Declarations
8.3.1 Field Modifiers
8.3.1.1 static Fields
8.3.1.2 final Fields
8.3.1.3 transient Fields
8.3.1.4 volatile Fields
8.3.2 Initialization of Fields
8.3.2.1 Initializers for Class Variables
8.3.2.2 Initializers for Instance Variables
8.3.2.3 Restrictions on the use of Fields during Initialization
8.3.3 Examples of Field Declarations
8.3.3.1 Example: Hiding of Class Variables
8.3.3.2 Example: Hiding of Instance Variables
8.3.3.3 Example: Multiply Inherited Fields
8.3.3.4 Example: Re-inheritance of Fields
8.4 Method Declarations
8.4.1 Formal Parameters
8.4.2 Method Signature
8.4.3 Method Modifiers
8.4.3.1 abstract Methods
8.4.3.2 static Methods
8.4.3.3 final Methods
8.4.3.4 native Methods
8.4.3.5 strictfp Methods
8.4.3.6 synchronized Methods
8.4.4 Method Throws
8.4.5 Method Body
8.4.6 Inheritance, Overriding, and Hiding
8.4.6.1 Overriding (by Instance Methods)
8.4.6.2 Hiding (by Class Methods)
8.4.6.3 Requirements in Overriding and Hiding
8.4.6.4 Inheriting Methods with the Same Signature
8.4.7 Overloading
8.4.8 Examples of Method Declarations
8.4.8.1 Example: Overriding
8.4.8.2 Example: Overloading, Overriding, and Hiding
8.4.8.3 Example: Incorrect Overriding
8.4.8.4 Example: Overriding versus Hiding
8.4.8.5 Example: Invocation of Hidden Class Methods
8.4.8.6 Large Example of Overriding
8.4.8.7 Example: Incorrect Overriding because of Throws
8.5 Member Type Declarations
8.5.1 Access Modifiers
8.5.2 Static Member Type Declarations
8.6 Instance Initializers
8.7 Static Initializers
8.8 Constructor Declarations
8.8.1 Formal Parameters
8.8.2 Constructor Signature
8.8.3 Constructor Modifiers
8.8.4 Constructor Throws
8.8.5 Constructor Body
8.8.5.1 Explicit Constructor Invocations
8.8.6 Constructor Overloading
8.8.7 Default Constructor
8.8.8 Preventing Instantiation of a Class

9 Interfaces

9.1 Interface Declarations
9.1.1 Interface Modifiers
9.1.1.1 abstract Interfaces
9.1.1.2 strictfp Interfaces
9.1.2 Superinterfaces and Subinterfaces
9.1.3 Interface Body and Member Declarations
9.1.4 Access to Interface Member Names
9.2 Interface Members
9.3 Field (Constant) Declarations
9.3.1 Initialization of Fields in Interfaces
9.3.2 Examples of Field Declarations
9.3.2.1 Ambiguous Inherited Fields
9.3.2.2 Multiply Inherited Fields
9.4 Abstract Method Declarations
9.4.1 Inheritance and Overriding
9.4.2 Overloading
9.4.3 Examples of Abstract Method Declarations
9.4.3.1 Example: Overriding
9.4.3.2 Example: Overloading
9.5 Member Type Declarations

10 Arrays

10.1 Array Types
10.2 Array Variables
10.3 Array Creation
10.4 Array Access
10.5 Arrays: A Simple Example
10.6 Array Initializers
10.7 Array Members
10.8 Class Objects for Arrays
10.9 An Array of Characters is Not a String
10.10 Array Store Exception

11 Exceptions

11.1 The Causes of Exceptions
11.2 Compile-Time Checking of Exceptions
11.2.1 Why Errors are Not Checked
11.2.2 Why Runtime Exceptions are Not Checked
11.3 Handling of an Exception
11.3.1 Exceptions are Precise
11.3.2 Handling Asynchronous Exceptions
11.4 An Example of Exceptions
11.5 The Exception Hierarchy
11.5.1 Loading and Linkage Errors
11.5.2 Virtual Machine Errors

12 Execution

12.1 Virtual Machine Start-Up
12.1.1 Load the Class Test
12.1.2 Link Test: Verify, Prepare, (Optionally) Resolve
12.1.3 Initialize Test: Execute Initializers
12.1.4 Invoke Test.main
12.2 Loading of Classes and Interfaces
12.2.1 The Loading Process
12.3 Linking of Classes and Interfaces
12.3.1 Verification of the Binary Representation
12.3.2 Preparation of a Class or Interface Type
12.3.3 Resolution of Symbolic References
12.4 Initialization of Classes and Interfaces
12.4.1 When Initialization Occurs
12.4.2 Detailed Initialization Procedure
12.4.3 Initialization: Implications for Code Generation
12.5 Creation of New Class Instances
12.6 Finalization of Class Instances
12.6.1 Implementing Finalization
12.6.2 Finalizer Invocations are Not Ordered
12.7 Unloading of Classes and Interfaces
12.8 Program Exit

13 Binary Compatibility

13.1 The Form of a Binary
13.2 What Binary Compatibility Is and Is Not
13.3 Evolution of Packages
13.4 Evolution of Classes
13.4.1 abstract Classes
13.4.2 final Classes
13.4.3 publicClasses
13.4.4 Superclasses and Superinterfaces
13.4.5 Class Body and Member Declarations
13.4.6 Access to Members and Constructors
13.4.7 Field Declarations
13.4.8 final Fields and Constants
13.4.9 static Fields
13.4.10 transient Fields
13.4.11 Method and Constructor Declarations
13.4.12 Method and Constructor Parameters
13.4.13 Method Result Type
13.4.14 abstract Methods
13.4.15 final Methods
13.4.16 native Methods
13.4.17 static Methods
13.4.18 synchronized Methods
13.4.19 Method and Constructor Throws
13.4.20 Method and Constructor Body
13.4.21 Method and Constructor Overloading
13.4.22 Method Overriding
13.4.23 Static Initializers
13.5 Evolution of Interfaces
13.5.1 public Interfaces
13.5.2 Superinterfaces
13.5.3 The Interface Members
13.5.4 Field Declarations
13.5.5 Abstract Method Declarations

14 Blocks and Statements

14.1 Normal and Abrupt Completion of Statements
14.2 Blocks
14.3 Local Class Declarations
14.4 Local Variable Declaration Statements
14.4.1 Local Variable Declarators and Types
14.4.2 Scope of Local Variable Declarations
14.4.3 Shadowing of Names by Local Variables
14.4.4 Execution of Local Variable Declarations
14.5 Statements
14.6 The Empty Statement
14.7 Labeled Statements
14.8 Expression Statements
14.9 The if Statement
14.9.1 The if-then Statement
14.9.2 The if-then-else Statement
14.10 The switch Statement
14.11 The while Statement
14.11.1 Abrupt Completion
14.12 The do Statement
14.12.1 Abrupt Completion
14.12.2 Example of do statement
14.13 The for Statement
14.13.1 Initialization of for statement
14.13.2 Iteration of for statement
14.13.3 Abrupt Completion of for statement
14.14 The break Statement
14.15 The continue Statement
14.16 The return Statement
14.17 The throw Statement
14.18 The synchronized Statement
14.19 The try statement
14.19.1 Execution of try-catch
14.19.2 Execution of try-catch-finally
14.20 Unreachable Statements

15 Expressions

15.1 Evaluation, Denotation, and Result
15.2 Variables as Values
15.3 Type of an Expression
15.4 FP-strict Expressions
15.5 Expressions and Run-Time Checks
15.6 Normal and Abrupt Completion of Evaluation
15.7 Evaluation Order
15.7.1 Evaluate Left-Hand Operand First
15.7.2 Evaluate Operands before Operation
15.7.3 Evaluation Respects Parentheses and Precedence
15.7.4 Argument Lists are Evaluated Left-to-Right
15.7.5 Evaluation Order for Other Expressions
15.8 Primary Expressions
15.8.1 Lexical Literals
15.8.2 Class Literals
15.8.3 this
15.8.4 Qualified this
15.8.5 Parenthesized Expressions
15.9 Class Instance Creation Expressions
15.9.1 Determining the Class being Instantiated
15.9.2 Determining Enclosing Instances
15.9.3 Choosing the Constructor and its Arguments
15.9.4 Run-time Evaluation of Class Instance Creation Expressions
15.9.5 Anonymous Class Declarations
15.9.5.1 Anonymous Constructors
15.9.6 Example: Evaluation Order and Out-of-Memory Detection
15.10 Array Creation Expressions
15.10.1 Run-time Evaluation of Array Creation Expressions
15.10.2 Example: Array Creation Evaluation Order
15.10.3 Example: Array Creation and Out-of-Memory Detection
15.11 Field Access Expressions
15.11.1 Field Access Using a Primary
15.11.2 Accessing Superclass Members using super
15.12 Method Invocation Expressions
15.12.1 Compile-Time Step 1: Determine Class or Interface to Search
15.12.2 Compile-Time Step 2: Determine Method Signature
15.12.2.1 Find Methods that are Applicable and Accessible
15.12.2.2 Choose the Most Specific Method
15.12.2.3 Example: Overloading Ambiguity
15.12.2.4 Example: Return Type Not Considered
15.12.2.5 Example: Compile-Time Resolution
15.12.3 Compile-Time Step 3: Is the Chosen Method Appropriate?
15.12.4 Runtime Evaluation of Method Invocation
15.12.4.1 Compute Target Reference (If Necessary)
15.12.4.2 Evaluate Arguments
15.12.4.3 Check Accessibility of Type and Method
15.12.4.4 Locate Method to Invoke
15.12.4.5 Create Frame, Synchronize, Transfer Control
15.12.4.6 Example: Target Reference and Static Methods
15.12.4.7 Example: Evaluation Order
15.12.4.8 Example: Overriding
15.12.4.9 Example: Method Invocation using super
15.13 Array Access Expressions
15.13.1 Runtime Evaluation of Array Access
15.13.2 Examples: Array Access Evaluation Order
15.14 Postfix Expressions
15.14.1 Postfix Increment Operator ++
15.14.2 Postfix Decrement Operator --
15.15 Unary Operators
15.15.1 Prefix Increment Operator ++
15.15.2 Prefix Decrement Operator --
15.15.3 Unary Plus Operator +
15.15.4 Unary Minus Operator -
15.15.5 Bitwise Complement Operator ~
15.15.6 Logical Complement Operator !
15.16 Cast Expressions
15.17 Multiplicative Operators
15.17.1 Multiplication Operator *
15.17.2 Division Operator /
15.17.3 Remainder Operator %
15.18 Additive Operators
15.18.1 String Concatenation Operator +
15.18.1.1 String Conversion
15.18.1.2 Optimization of String Concatenation
15.18.1.3 Examples of String Concatenation
15.18.2 Additive Operators (+ and -) for Numeric Types
15.19 Shift Operators
15.20 Relational Operators
15.20.1 Numerical Comparison Operators <, <=, >, and >=
15.20.2 Type Comparison Operator instanceof
15.21 Equality Operators
15.21.1 Numerical Equality Operators == and !=
15.21.2 Boolean Equality Operators == and !=
15.21.3 Reference Equality Operators == and !=
15.22 Bitwise and Logical Operators
15.22.1 Integer Bitwise Operators &, ^, and |
15.22.2 Boolean Logical Operators &, ^, and |
15.23 Conditional-And Operator &&
15.24 Conditional-Or Operator ||
15.25 Conditional Operator ? :
15.26 Assignment Operators
15.26.1 Simple Assignment Operator =
15.26.2 Compound Assignment Operators
15.27 Expression
15.28 Constant Expression

16 Definite Assignment

16.1 Definite Assignment and Expressions
16.1.1 Boolean Constant Expressions
16.1.2 The Boolean Operator &&
16.1.3 The Boolean Operator ||
16.1.4 The Boolean Operator !
16.1.5 The Boolean Operator ? :
16.1.6 The Conditional Operator ? :
16.1.7 Assignment Expressions
16.1.8 Operators ++ and --
16.1.9 Other Expressions
16.2 Definite Assignment and Statements
16.2.1 Empty Statements
16.2.2 Blocks
16.2.3 Local Class Declaration Statements
16.2.4 Local Variable Declaration Statements
16.2.5 Labeled Statements
16.2.6 Expression Statements
16.2.7 if Statements
16.2.8 switch Statements
16.2.9 while Statements
16.2.10 do Statements
16.2.11 for Statements
16.2.11.1 Initialization Part
16.2.11.2 Incrementation Part
16.2.12 break, continue, return, and throw Statements
16.2.13 synchronized Statements
16.2.14 try Statements
16.3 Definite Assignment and Parameters
16.4 Definite Assignment and Array Initializers
16.5 Definite Assignment and Anonymous Classes
16.6 Definite Assignment and Member Types
16.7 Definite Assignment and Static Initializers
16.8 Definite Assignment, Constructors, and Instance Initializers

17 Threads and Locks

17.1 Terminology and Framework
17.2 Execution Order
17.3 Rules about Variables
17.4 Nonatomic Treatment of double and long
17.5 Rules about Locks
17.6 Rules about the Interaction of Locks and Variables
17.7 Rules for Volatile Variables
17.8 Prescient Store Actions
17.9 Discussion
17.10 Example: Possible Swap
17.11 Example: Out-of-Order Writes
17.12 Threads
17.13 Locks and Synchronization
17.14 Wait Sets and Notification

18 Syntax

18.1 The Grammar of the Java Programming Language

Index


Contents | Prev | Next | Index Java Language Specification
Second Edition
Copyright © 2000 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to [email protected]