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