Table of Contents

From JavaSpec.org

Jump to: navigation, search

Welcome to JavaSpec.org!

Chapter 1, Lexical Structure

1.1 Introduction to Lexical Structure
1.2 White Space
1.3 Comments
1.4 Identifiers
1.4.1 Java Naming Conventions
1.4.2 The Syntactic Classification of Names According to Context
1.4.3 Special Naming Restrictions
1.4.4 Obscuring
1.4.4.1 The Problem of Reversed Domain Names
1.4.5 Subpackages are Non-Entities
1.5 Keywords
1.6 Literals
1.6.1 Character Literals
1.6.2 Escape Sequences
1.6.2.1 Octal Escape Sequences
1.6.2.2 The NULL Character
1.6.2.3 Escape Sequences for C0 Control Characters
1.6.2.4 Line, Paragraph and Page Separator Characters
1.6.2.5 Escape Sequences for Special Characters
1.6.2.6 Unicode Escape Sequences
1.6.3 String Literals
1.6.3.1 The Empty String
1.6.4 Numeric Literals
1.6.4.1 Positional Notation Systems, Digits and Radices
1.6.4.2 Scientific Notation
1.6.5 Class Literals
1.7 Separators
1.8 Operators

Chapter 2, Compilation Units

2.1 Introduction to Compilation Units
2.2 The Terminology of Class Body Declarations
2.2.1 The Definition of Fields in Java
2.2.2 What Makes Constructors Different?
2.3 Anatomy of a Compilation Unit
2.3.1 Special Initialization Methods
2.3.1.1 Explicit Constructor Invocations
2.3.1.2 Default Constructors and Constructor Chaining
2.3.2 The Significance of Textual Order
2.4 Package Declarations
2.4.1 The Members of a Package
2.4.2 The Unnamed Package
2.5 Import Declarations
2.5.1 Automatic Imports
2.5.2 Redundant Imports
2.5.3 The Efficiency of Type-Import-on-Demand Declarations
2.5.4 The Simple and Complex Classpath Formulas
2.5.5 Importing Nested Classes
2.5.6 import static
2.6 Type Declarations
2.6.1 The Members of Class, Interface and Array Types
2.6.2 Immutable Types
2.7 Helper Classes
2.8 The Definition of Top-Level Classes
2.9 The Five Kinds of Classes and Interfaces
2.9.1 Package Members
2.9.2 Nested Top-Level Classes and Interfaces
2.9.3 Inner Classes
2.9.3.1 Inner Member Classes
2.9.3.2 Local Classes
2.9.3.3 Anonymous Classes
2.10 Containment and Inner Class Hierarchies
2.10.1 Containment Hierarchies
2.10.2 Inner Class Hierarchies
2.10.2.1 Orphaned Local and Anonymous Classes

Chapter 3, The static Modifier, this and super

3.1 Introduction to the static Modifier, this and super
3.2 The static Modifier
3.2.1 static Fields
3.2.2 static Methods
3.2.3 static Classes
3.2.4 The static Keyword and Inner Classes
3.2.4.1 Declaring Inlined Constants in Inner Classes
3.3 The Definition of static Context
3.3.1 The static Context in an Inner Class Hierarchy
3.4 The this and super Keywords
3.4.1 The Current Object (this)
3.4.2 The Direct Superclass (super)
3.4.2.1 Using super to Reference Members in Different Packages
3.4.3 this is Polymorphic, super is Not
3.4.4 Practical Uses of the this and super Keywords
3.5 Multiple Current Instances or Levels
3.5.1 Special Note About Deeply Nested Types
3.5.2 Qualifying the this and super Keywords

Chapter 4, Primitive Data Types and Object

4.1 Introduction to Primitive Data Types and Object
4.2 The Seven Kinds of Variables
4.2.1 What are Stack Variables?
4.3 The Definition of Data Types
4.4 Numeric Data Types
4.4.1 Integral Types
4.4.1.1 How Long is long?
4.4.2 Floating-Point Types
4.4.2.1 The Precision of a Floating-Point Type
4.4.2.2 The Significand is Designed to be Imprecise
4.4.2.3 The Problem of Incommensurable Bases
4.5 Floating-Point Modes
4.5.1 The StrictMath Class
4.6 IEEE 754 Standard Floating-Point Arithmetic
4.6.1 Positive and Negative Zero
4.6.2 Positive and Negative Infinity
4.6.3 Not-a-Number (NaN)
4.6.5 Overflow and Underflow
4.6.5.1 Two’s Complement Overflow and Underflow
4.6.5.2 Floating-Point Overflow
4.6.5.3 Denormalized Numbers and Gradual Underflow
4.6.6 Rounding
4.6.7 Truncation
4.6.8 ArithmeticException
4.7 The char Data Type
4.8 The boolean Data Type
4.9 The null Type
4.10 The Number Class
4.11 The java.math Package
4.11.1 The BigInteger Class
4.11.2 The BigDecimal Class
4.12 Currency Calculations
4.12.1 Inexact Results and Comparison Operators
4.12.2 Rounding the Result of a Floating-Point Operation
4.12.3 Using Integral Types to Store Monetary Values
4.13 Primitive Type Wrapper Classes
4.13.1 Converting Primitive Numeric Data Types to Strings
4.13.2 Converting Strings to Primitive Numeric Data Types
4.13.3 Unicode Utility Methods
4.13.3.1 Case
4.13.3.2 Character Types
4.13.3.3 char to Digit Conversions and Vice Versa
4.13.3.4 The getNumericValue() Method
4.13.4 Accessing Primitive Type System Properties
4.13.5 Floating-Point Data Types as Binary Data
4.14 The Object Class
4.14.2 Understanding Hash Codes
4.14.3 The Five Housekeeping Methods
4.14.3.1 The toString() Method
4.14.3.2 The equals(Object o) Method
4.14.3.3 The hashCode() Method
4.14.3.4 The clone() Method
4.14.3.5 The compareTo() Method

Chapter 5, Strings and Other Common Data Types

5.1 Introduction to Strings and Other Common Data Types
5.2 Strings
5.2.1 Would-Be Mutator Methods
5.3 String Concatenation Operations
5.3.1 A Note about the Overloaded Binary + Operator
5.3.2 Implicit String Conversions
5.3.3 The Intern Mechanism
5.3.4 Shared Character Buffers
5.4 Dates and Times
5.5 Calendars
5.5.1 Date and Time Fields in the Calendar Class
5.6 Localizing Common Data Types
5.6.1 The Locale Class
5.7 Custom Pattern Strings and Format Symbols
5.7.1 The DecimalFormatSymbols Class
5.7.2 The DateFormatSymbols Class
5.7.3 Setting Format Symbols
5.8 Currency

Chapter 6, Arrays and the Collections Framework

6.1 Introduction to Arrays and the Collections Framework
6.2 Array, Component, and Element Types
6.2.1 What Is Run-Time Type?
6.3 Arrays
6.3.1 Array Classes Are Dynamically Created
6.3.2 Array Type Variable Declarations
6.3.3 Initializing Array Type Variables
6.3.3.1 Array Initializers
6.3.3.2 Array Creation Expressions
6.3.4 Array Access Expressions
6.3.5 Anonymous Arrays
6.4 Interoperability
6.5 Untyped References versus Parameterized Types
6.6 The Equivalence Relationship and Elements
6.7 The Collections Framework
6.7.1 Bulk Operations
6.7.2 The Collection Interface
6.7.2.1 The Set and SortedSet Interfaces
6.7.2.2 The List Interface
6.7.3 The Map and SortedMap Interfaces
6.8 General-Purpose Implementations
6.8.1 Choosing a General-Purpose Implementation
6.8.1.1 ArrayList versus LinkedList
6.8.1.2 Stacks, Queues and Deques
6.8.1.3 HashMap
6.8.1.4 TreeMap
6.8.2 Performance Tuning the General-Purpose Imple­mentations
6.9 Special-Purpose Implementations
6.9.1 WeakHashMap
6.10 Convenience Implementations
6.11 Views
6.11.1 Synchronized Views
6.11.2 Unmodifiable Views
6.11.3 Range Views (Sublists, Subsets, and Submaps)
6.11.4 Collection Views of a Map
6.11.5 List View of an Array
6.12 Iterators
6.12.1 List Iterators
6.12.2 Using Collection Views to Iterate over a Map
6.12.3 A Poor Man’s Collection
6.12.4 Synchronized Iterators
6.12.5 Fail-Fast Iterators
6.12.6 Iterating Backwards Through a TreeSet or TreeMap
6.13 Al-Khwarizmi Concerning the Hindu Art of Reckoning
6.14 Utility Methods for Arrays and Other Collections
6.14.1 Time Complexities (or Big-O Notation)
6.14.2 Sorting Containers
6.14.3 Searching Containers
6.14.3.1 Binary Searches
6.14.3.2 Linear Searches
6.14.4 Cloning versus Copying
6.14.4.1 Copying Arrays
6.14.5 Filling an Array or List
6.14.6 The Minimum and Maximum Elements in a Con­tainer
6.14.8 Shuffling a List
6.15 Housekeeping Methods for Containers
6.15.1 Hashing a Container
6.15.2 Equal Containers
6.15.3 The toString() Method in Container Classes
6.16 Custom Implementations
6.16.1 Abstract Implementations
6.16.2 Optional Operations
6.16.3 Restricted Containers
6.16.4 Standard Constructors
6.17 Multimaps and Multidimensional Arrays
6.17.1 Multimaps
6.17.2 Multidimensional Arrays
6.18 Legacy Containers

Chapter 7, Fields and Methods

7.1 Introduction to Fields and Methods
7.2 Fields
7.3 Field Initialization
7.3.1 Automatic Initialization using Standard Default Values
7.3.2 Initialization Blocks
7.3.2.1 Throwing Checked Exceptions During Instance Initialization
7.3.2.2 Throwing Checked Exceptions During Class Initialization
7.3.3 Constructors
7.3.3.1 Reference Constructors
7.3.3.2 Alternative Constructor Designs
7.4 Field Initialization Anomalies
7.4.1 Illegal Forward References
7.4.1.1 The Variable Initializer for a Field is Always Executed
7.4.2 Invoking Overridden Methods During Instance Initialization
7.4.2.1 Bug Id 4030374 and the -target Compiler Option
7.4.3 Inlined Constants Always Appear to Have Been Initialized
7.4.4 StackOverflowError During Instance Initialization
7.5 Constants
7.5.1 Compile-Time Constant Expressions
7.5.2 Inlined Constants
7.5.2.1 The Problem of Changeable Inlined Constants
7.5.3 Declaring Mutable Objects final
7.5.4 Declaring Local Variables and Parameters final
7.5.5 Blank Finals
7.5.6 Enum Types
7.5.7 The Constant Interface Antipattern (Update for Tiger)
7.6 Methods
7.6.1 abstract Methods
7.6.2 Result Types and the return Statement
7.6.2.1 Returning More Than One Value
7.6.2.2 Using Return Values to Indicate Failure
7.6.3 Formal Parameter Lists
7.6.3.1 Argument Checks
7.6.3.2 On const References
7.6.3.3 Making Defensive Copies
7.6.4 The throws Clause
7.7 Local Variables
7.8 “Write Once, Compile Anywhere”
7.8.1 Definite Assignment
7.8.2 Unreachable Statements
7.9 The Definition of Qualifying Type
7.10 The Five General Forms
7.10.1 Method Invocation Chaining
7.10.2 Casting a Target Reference
7.10.3 Accessing static Members using a Primary Expression
7.11 Method Signatures
7.12 Method Descriptors
7.13 The Compiler-Enforced Method Contract
7.13.1 Covariant Result Types
7.13.2 throws Clause Conflicts in abstract Methods
7.14 Overloading and Overriding
7.14.1 Overloaded Methods
7.14.2 Overriding and Dynamic Method Lookup
7.14.2.1 The invokeinterface machine instruction
7.15 Method Forwarding

Chapter 8, Scope, Shadowing and Qualified Access

8.1 Introduction to Scope, Shadowing and Qualified Access
8.2 Java Namespaces
8.3 Qualified Names
8.4 The Meaning of a Name
8.4.1 The Meaning of a Simple Field or Method Name
8.4.2 Disambiguating Type Names
8.5 The Fundamentals of Lexical Scoping
8.5.1 The Mysterious Scope Hole
8.5.2 Compilation Unit Scope
8.5.3 Members Shadow Declarations in Enclosing Scopes
8.5.4 The Scope of Types in the Unnamed Package
8.5.5 Circular Dependencies in Type Declarations
8.6 Shadowing
8.7 Observable Compilation Units and Packages
8.8 Qualified Access
8.9 Access Control
8.9.1 The protected Access Modifier
8.9.2 Full Access to the Members of an Enclosing Class
8.9.3 Members More Accessible Than Their Class Type
8.9.4 Accessing the Implementation of Same Class Objects
8.10 Encapsulation

Chapter 9, Hiding and Inheritance

9.1 Introduction to Hiding and Inheritance
9.2 Hiding
9.3 The Definition of Baseclass
9.4 The Definition of Related Class and Interface Types
9.5 Generalization in Inheritance Hierarchies
9.6 Inheritance
9.6.1 Interface Inheritance
9.6.2 Implementation Inheritance
9.6.3 Inheriting Overloaded Methods
9.7 Do Interfaces Extend the Object Class?
9.8 Inheriting Members With The Same Name
9.8.1 Re-Inheritance
9.8.2 Ambiguous Names Related to Inheritance
9.8.3 Inheriting Methods With the Same Signature
9.9 Designing Extensible Classes
9.10 Capping a Class Hierarchy

Chapter 10, Expressions, Statements and Blocks

10.1 Introduction to Expressions, Statements and Blocks
10.2 Expressions
10.2.1 Primary Expressions
10.2.2 Expression Statements and Other Top-Level Expressions
10.3 Operator Expressions
10.3.1 Numeric Promotion
10.3.2 Operator Order of Precedence and Parenthesized Expressions
10.3.3 The Associative Property of Operators
10.3.4 Nondestructive Operators
10.4 Exceptions are Precise
10.5 Unary, Binary, and Ternary Operators
10.5.1 Increment and Decrement Operators
10.5.2 Negation Operators
10.5.3 The Elementary School Operators
10.5.4 Remainder Operator
10.5.5 Boolean Logical Operators
10.5.6 Bitwise Operators
10.5.7 Ternary Conditional Operator
10.5.8 The Simple and Compound Assignment Operators
10.6 The instanceof Type Comparison Operator
10.7 A Bitwise Primer
10.7.1 Bits
10.7.2 Converting Nybbles to Hexadecimal Digits
10.7.3 General-purpose Integer to String Conversion Methods
10.7.4 Unsigned Bytes
10.7.5 Some Miscellaneous Uses of the Bitwise Operators
10.8 Statements
10.8.1 Control-flow Statements
10.8.1.1 The if-then and if-then-else Statements
10.8.1.2 The switch Statement
10.8.1.3 The for Statement
10.8.1.4 The do and while Statements
10.8.2 Labeled Statements
10.8.3 Control-transfer Statements (a.k.a. Abrupt Completion)
10.8.3.1 The continue Statement
10.8.3.2 The break Statement
10.9 Blocks

Chapter 11, Type Conversions and the Cast Operator

11.1 Introduction to Type Conversions and the Cast Operator
11.2 The Type of a Variable or Expression versus the Class of an Object
11.2.1 The Phrase “type of an object” is in Prevalent Use
11.2.2 The Term “class type” is Where Everything Goes Afoul
11.3 Java is a Strongly Typed Language
11.4 Substitution is a Higher Concept than Polymorphism
11.5 Identity Conversions
11.6 Type Conversions
11.6.1 Primitive Type Conversions
11.6.1.1 Widening Primitive Conversions
11.6.1.2 Narrowing Primitive Conversions
11.6.1.3 The Implicit Narrowing of Integer Constants
11.6.2 Reference Type Conversions
11.6.2.1 Conversions Between Class Types
11.6.2.2 Conversions Involving Interface Types
11.6.2.3 Conversions Between Array Types
11.6.3 Boxing and Unboxing
11.7 Conversion Contexts
11.7.1 Simple Assignment Conversion Context
11.7.1.1 The ArrayStoreException
11.7.2 Method Invocation Conversion Context
11.7.3 Method Return Conversion Context
11.7.4 The Cast Operator
11.7.5 The Implicit Cast in a Compound Assignment Operation
11.8 Overloaded Method Matching
11.8.1 Choosing The Most Specific Applicable Method
11.8.2 The Declaring Class of Applicable Methods
11.9 Value Set Conversions

Chapter 12, Assertions, Exceptions and Logging

12.1 Introduction to Assertions, Exceptions and Logging
12.2 Assertions
12.2.1 Preconditions, Postconditions, and Invariants
12.2.2 assert false and Logic Traps (or Control-flow Invariants)
12.2.3 Catching CloneNotSupportedException
12.2.3.1 Conditional Cloning
12.3 An Execution Stack Primer
12.4 The Exception Mechanism
12.5 The New Exception-Handling Paradigm
12.5.1 Mapping Exceptions to throw Statements
12.5.1.1 High-Level Exceptions
12.5.1.2 Low-Level Exceptions
12.5.1.3 Umbrella Exceptions
12.5.2 Exception Translation and Chaining
12.5.2.1 Converting Checked Exceptions into Unchecked Exceptions
12.6 The Throwable Class Hierarchy
12.6.1 Checked Exceptions
12.6.1.1 The Throwable Class Hierarchy
12.6.2 Unchecked Exceptions
12.6.2.1 Runtime Exceptions
12.6.2.2 Errors
12.7 Throwable Objects
12.7.1 The Loggable Interface
12.8 The throw Statement
12.9 The try Statement
12.9.1 The catch Clause
12.9.1.1 Catchall Exception Handlers
12.9.2 The finally Clause
12.9.2.1 try-finally as a Control-flow Statement
12.9.2.2 Releasing System Resources
12.10 Unspecified Runtime Exceptions and Errors
12.10.1 The Chicken Little “The Sky is Falling” Problem
12.11 Alternative Exception-Handling Strategies
12.12 Uncaught Exceptions
12.12.1 Top-level Exception Handlers
12.12.1.1 The AWTExceptionHandler Class
12.12.1.2 The UncaughtException Class
12.12.2 A Stack Trace Primer
12.13 Asynchronous Exceptions
12.14 Logging
12.14.1 The Logger Namespace
12.14.2 Logging Configuration
12.14.3 Logging Methods
12.14.4 The Cleaner Thread (A Shutdown Hook in LogManager)

 

Personal tools
points of entry