Fwfe

Only available on StudyMode
  • Topic: C, C++, Class
  • Pages: 216 (60596 words)
  • Download(s): 47
  • Published: April 4, 2013
Open Document
Text Preview
The Java® Language Specification
Java SE 7 Edition
James Gosling Bill Joy Guy Steele Gilad Bracha Alex Buckley

2013-02-28

Specification: JSR-000901 Java® Language Specification ("Specification") Version: 7 Status: Final Release Release: July 2011 Copyright © 1997, 2013, Oracle America, Inc. and/or its affiliates. All rights reserved. 500 Oracle Parkway, Redwood City, California 94065, U.S.A. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. The Specification provided herein is provided to you only under the Limited License Grant included herein as Appendix A. Please see Appendix A, Limited License Grant.

Table of Contents
Preface to the Java SE 7 Edition xv Preface to the Third Edition xvii Preface to the Second Edition xxi Preface to the First Edition xxiii

1 Introduction 1
1.1 1.2 1.3 1.4 1.5 Organization of the Specification 2 Example Programs 5 Notation 6 Relationship to Predefined Classes and Interfaces 6 References 7

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

3 Lexical Structure 15
3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 Unicode 15 Lexical Translations 16 Unicode Escapes 17 Line Terminators 18 Input Elements and Tokens 19 White Space 21 Comments 21 Identifiers 23 Keywords 24 Literals 25 3.10.1 Integer Literals 25 3.10.2 Floating-Point Literals 32 3.10.3 Boolean Literals 35 3.10.4 Character Literals 35 3.10.5 String Literals 36 3.10.6 Escape Sequences for Character and String Literals 38

iii

The Java® Language Specification

3.11 3.12

3.10.7 The Null Literal 39 Separators 40 Operators 40

4 Types, Values, and Variables 41
4.1 4.2 The Kinds of Types and Values 41 Primitive Types and Values 42 4.2.1 Integral Types and Values 43 4.2.2 Integer Operations 43 4.2.3 Floating-Point Types, Formats, and Values 45 4.2.4 Floating-Point Operations 48 4.2.5 The boolean Type and boolean Values 51 Reference Types and Values 52 4.3.1 Objects 54 4.3.2 The Class Object 56 4.3.3 The Class String 57 4.3.4 When Reference Types Are the Same 57 Type Variables 58 Parameterized Types 60 4.5.1 Type Arguments and Wildcards 61 4.5.2 Members and Constructors of Parameterized Types 64 Type Erasure 65 Reifiable Types 66 Raw Types 67 Intersection Types 71 Subtyping 72 4.10.1 Subtyping among Primitive Types 72 4.10.2 Subtyping among Class and Interface Types 73 4.10.3 Subtyping among Array Types 73 Where Types Are Used 74 Variables 75 4.12.1 Variables of Primitive Type 76 4.12.2 Variables of Reference Type 76 4.12.3 Kinds of Variables 78 4.12.4 final Variables 80 4.12.5 Initial Values of Variables 81 4.12.6 Types, Classes, and Interfaces 82

4.3

4.4 4.5 4.6 4.7 4.8 4.9 4.10

4.11 4.12

5 Conversions and Promotions 85
5.1 Kinds of Conversion 88 5.1.1 Identity Conversion 88 5.1.2 Widening Primitive Conversion 88 5.1.3 Narrowing Primitive Conversion 90 5.1.4 Widening and Narrowing Primitive Conversion 93 5.1.5 Widening Reference Conversion 93 5.1.6 Narrowing Reference Conversion 93 5.1.7 Boxing Conversion 94

iv

The Java® Language Specification

5.2 5.3 5.4 5.5

5.6

5.1.8 Unboxing Conversion 95 5.1.9 Unchecked Conversion 97 5.1.10 Capture Conversion 97 5.1.11 String Conversion 99 5.1.12 Forbidden Conversions 100 5.1.13 Value Set Conversion 100 Assignment Conversion 101 Method Invocation Conversion 106 String Conversion 108 Casting Conversion 108 5.5.1 Reference Type Casting 111 5.5.2 Checked Casts and Unchecked Casts 115 5.5.3 Checked Casts at Run Time 116 Numeric Promotions 117 5.6.1 Unary Numeric Promotion 118 5.6.2 Binary Numeric Promotion 119

6 Names 121
6.1 6.2 6.3 6.4 6.5 Declarations 122 Names and Identifiers 127 Scope of a Declaration 130 Shadowing and Obscuring 133 6.4.1 Shadowing 135 6.4.2 Obscuring 138 Determining the Meaning of a Name 140 6.5.1 Syntactic Classification of a Name According to Context 141 6.5.2...
tracking img