The Java Language Specification Third Edition James Gosling 2024 Scribd Download

Download as pdf or txt
Download as pdf or txt
You are on page 1of 81

Visit https://ebookgate.

com to download the full version and


explore more ebooks

The Java Language Specification Third Edition James


Gosling

_____ Click the link below to download _____


https://ebookgate.com/product/the-java-language-
specification-third-edition-james-gosling/

Explore and download more ebooks at ebookgate.com


Here are some recommended products that might interest you.
You can download now and explore!

The Java Language Specification Java SE 8 Edition James


Gosling & Bill Joy & Guy L. Steele

https://ebookgate.com/product/the-java-language-specification-java-
se-8-edition-james-gosling-bill-joy-guy-l-steele/

ebookgate.com

Volere Requirements Specification Template 16th Edition


James Robertson

https://ebookgate.com/product/volere-requirements-specification-
template-16th-edition-james-robertson/

ebookgate.com

Java 2 micro edition Java in small things James White

https://ebookgate.com/product/java-2-micro-edition-java-in-small-
things-james-white/

ebookgate.com

Developing Java Servlets 2nd Edition James Goodwill

https://ebookgate.com/product/developing-java-servlets-2nd-edition-
james-goodwill/

ebookgate.com
Algorithms in Java THIRD EDITION pdf Robert Sedgewick

https://ebookgate.com/product/algorithms-in-java-third-edition-pdf-
robert-sedgewick/

ebookgate.com

Java Network Programming Third Edition Elliotte Rusty


Harold

https://ebookgate.com/product/java-network-programming-third-edition-
elliotte-rusty-harold/

ebookgate.com

The Leadership Challenge Workbook Third Edition James M.


Kouzes

https://ebookgate.com/product/the-leadership-challenge-workbook-third-
edition-james-m-kouzes/

ebookgate.com

Java 2 Core Language Little Black Book 1st Edition Alain


Trottier

https://ebookgate.com/product/java-2-core-language-little-black-
book-1st-edition-alain-trottier/

ebookgate.com

Persuasive Communication Third Edition James B. Stiff

https://ebookgate.com/product/persuasive-communication-third-edition-
james-b-stiff/

ebookgate.com
The Java™
Language Specification
Third Edition
The Java™ Series

The Java™ Programming Language


Ken Arnold, James Gosling and David Holmes
ISBN 0-201-70433-1

The Java™ Language Specification Third Edition


James Gosling, Bill Joy, Guy Steele and Gilad Bracha
ISBN 0-321-24678-0

The Java™ Virtual Machine Specification Second Edition


Tim Lindholm and Frank Yellin
ISBN 0-201-43294-3

The Java™ Application Programming Interface,


Volume 1: Core Packages
James Gosling, Frank Yellin, and the Java Team
ISBN 0-201-63452-X

The Java™ Application Programming Interface,


Volume 2: Window Toolkit and Applets
James Gosling, Frank Yellin, and the Java Team
ISBN 0-201-63459-7

The Java™ Tutorial: Object-Oriented Programming for the Internet


Mary Campione and Kathy Walrath
ISBN 0-201-63454-6

The Java™ Class Libraries: An Annotated Reference


Patrick Chan and Rosanna Lee
ISBN 0-201-63458-9

The Java™ FAQ: Frequently Asked Questions


Jonni Kanerva
ISBN 0-201-63456-2
The Java™
Language Specification
Third Edition
James Gosling
Bill Joy
Guy Steele
Gilad Bracha

ADDISON-WESLEY
Boston San Francisco New York Toronto Montreal
● ● ● ●

London Munich Paris Madrid


● ● ●

Capetown Sydney Tokyo Singapore Mexico City


● ● ● ●
The Java Language Specification
iv
Copyright  1996-2005 Sun Microsystems, Inc.
4150 Network Circle, Santa Clara, California 95054 U.S.A.
All rights reserved.
Duke logo™ designed by Joe Palrang.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States
Government is subject to the restrictions set forth in DFARS 252.227-7013 (c)(1)(ii) and
FAR 52.227-19.
The release described in this manual may be protected by one or more U.S. patents,
foreign patents, or pending applications.

Sun Microsystems, Inc. (SUN) hereby grants to you a fully paid, nonexclusive, nontrans-
ferable, perpetual, worldwide limited license (without the right to sublicense) under
SUN’s intellectual property rights that are essential to practice this specification. This
license allows and is limited to the creation and distribution of clean room implementa-
tions of this specification that: (i) include a complete implementation of the current ver-
sion of this specification without subsetting or supersetting; (ii) implement all the
interfaces and functionality of the required packages of the Java™ 2 Platform, Standard
Edition, as defined by SUN, without subsetting or supersetting; (iii) do not add any addi-
tional packages, classes, or interfaces to the java.* or javax.* packages or their subpack-
ages; (iv) pass all test suites relating to the most recent published version of the
specification of the Java™ 2 Platform, Standard Edition, that are available from SUN six
(6) months prior to any beta release of the clean room implementation or upgrade thereto;
(v) do not derive from SUN source code or binary materials; and (vi) do not include any
SUN source code or binary materials without an appropriate and separate license from
SUN.
Sun, Sun Microsystems, the Sun logo, Solaris, Java, JavaScript, JDK, and all Java-based
trademarks or logos are trademarks or registered trademarks of Sun Microsystems, Inc.
UNIX® is a registered trademark of The Open Group in the United States and other coun-
tries. Apple and Dylan are trademarks of Apple Computer, Inc. All other product names
mentioned herein are the trademarks of their respective owners.
THIS PUBLICATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT.
THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPO-
GRAPHICAL ERRORS. CHANGES ARE PERIODICALLY ADDED TO THE INFOR-
MATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW
EDITIONS OF THE PUBLICATION. SUN MICROSYSTEMS, INC. MAY MAKE
IMPROVEMENTS AND/OR CHANGES IN THE PRODUCT(S) AND/OR THE PRO-
GRAM(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME.
Credits and permissions for quoted material appear in a separate section on page 649.
/

Text printed on recycled and acid-free paper


ISBN 0-321-24678-0
1 2 3 4 5 6 7 8 9-MA-99989796
First printing, May 2005

FT
RA
D

vi
FT
“When I use a word,” Humpty Dumpty said,
in rather a scornful tone, “it means just what I
choose it to mean—neither more nor less.”
“The question is,” said Alice, “whether you
can make words mean so many different things.”
“The question is,” said Humpty Dumpty,
“which is to be master—that’s all.”
RA
—Lewis Carroll, Through the Looking Glass
D
D
RA
FT
ix

Preface X X I I I

Preface to the Second Edition X X V I I

Preface to the Third Edition X X X I

1 Introduction 1
1.1 Example Programs 5
1.2 Notation 6
1.3 Relationship to Predefined Classes and Interfaces 6
1.4 References 6

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

3 Lexical Structure 13
3.1 Unicode 13
3.2 Lexical Translations 14
3.3 Unicode Escapes 15
3.4 Line Terminators 16
3.5 Input Elements and Tokens 17
3.6 White Space 18
3.7 Comments 18
3.8 Identifiers 19
3.9 Keywords 21
3.10 Literals 21
3.10.1 Integer Literals 22
3.10.2 Floating-Point Literals 24
3.10.3 Boolean Literals 26
3.10.4 Character Literals 26
3.10.5 String Literals 28
3.10.6 Escape Sequences for Character and String Literals 30
3.10.7 The Null Literal 30
3.11 Separators 31
3.12 Operators 31

4 Types, Values, and Variables 33


4.1 The Kinds of Types and Values 34
4.2 Primitive Types and Values 34
4.2.1 Integral Types and Values 35
4.2.2 Integer Operations 36
The Java Language Specification
x
4.2.3 Floating-Point Types, Formats, and Values 37
4.2.4 Floating-Point Operations 40
4.2.5 The boolean Type and boolean Values 43
4.3 Reference Types and Values 44
4.3.1 Objects 45
4.3.2 The Class Object 47
4.3.3 The Class String 48
4.3.4 When Reference Types Are the Same 49
4.4 Type Variables 49
4.5 Parameterized Types 51
4.5.1 Type Arguments and Wildcards 52
4.5.1.1 Type Argument Containment and Equivalence 55
4.5.2 Members and Constructors of Parameterized Types 55
4.6 Type Erasure 56
4.7 Reifiable Types 56
4.8 Raw Types 57
4.9 Intersection Types 62
4.10 Subtyping 63
4.10.1 Subtyping among Primitive Types 63
4.10.2 Subtyping among Class and Interface Types 63
4.10.3 Subtyping among Array Types 64
4.11 Where Types Are Used 65
4.12 Variables 67
4.12.1 Variables of Primitive Type 67
4.12.2 Variables of Reference Type 67
4.12.2.1 Heap Pollution 68
4.12.3 Kinds of Variables 69
4.12.4 final Variables 71
4.12.5 Initial Values of Variables 71
4.12.6 Types, Classes, and Interfaces 73

5 Conversions and Promotions 77


5.1 Kinds of Conversion 80
5.1.1 Identity Conversions 80
5.1.2 Widening Primitive Conversion 80
5.1.3 Narrowing Primitive Conversions 82
5.1.4 Widening and Narrowing Primitive Conversions 84
5.1.5 Widening Reference Conversions 85
5.1.6 Narrowing Reference Conversions 85
5.1.7 Boxing Conversion 86
5.1.8 Unboxing Conversion 88
5.1.9 Unchecked Conversion 89
5.1.10 Capture Conversion 89
5.1.11 String Conversions 92
5.1.12 Forbidden Conversions 92
5.1.13 Value Set Conversion 92
5.2 Assignment Conversion 93
5.3 Method Invocation Conversion 99
xi
5.4 String Conversion 101
5.5 Casting Conversion 101
5.6 Numeric Promotions 108
5.6.1 Unary Numeric Promotion 108
5.6.2 Binary Numeric Promotion 110

6 Names 113
6.1 Declarations 114
6.2 Names and Identifiers 115
6.3 Scope of a Declaration 117
6.3.1 Shadowing Declarations 119
6.3.2 Obscured Declarations 122
6.4 Members and Inheritance 122
6.4.1 The Members of Type Variables, Parameterized Types, Raw Types and
Intersection Types 122
6.4.2 The Members of a Package 122
6.4.3 The Members of a Class Type 123
6.4.4 The Members of an Interface Type 124
6.4.5 The Members of an Array Type 125
6.5 Determining the Meaning of a Name 126
6.5.1 Syntactic Classification of a Name According to Context 127
6.5.2 Reclassification of Contextually Ambiguous Names 129
6.5.3 Meaning of Package Names 131
6.5.3.1 Simple Package Names 131
6.5.3.2 Qualified Package Names 132
6.5.4 Meaning of PackageOrTypeNames 132
6.5.4.1 Simple PackageOrTypeNames 132
6.5.4.2 Qualified PackageOrTypeNames 132
6.5.5 Meaning of Type Names 132
6.5.5.1 Simple Type Names 132
6.5.5.2 Qualified Type Names 132
6.5.6 Meaning of Expression Names 134
6.5.6.1 Simple Expression Names 134
6.5.6.2 Qualified Expression Names 135
6.5.7 Meaning of Method Names 137
6.5.7.1 Simple Method Names 137
6.5.7.2 Qualified Method Names 137
6.6 Access Control 138
6.6.1 Determining Accessibility 138
6.6.2 Details on protected Access 139
6.6.2.1 Access to a protected Member 139
6.6.2.2 Qualified Access to a protected Constructor 140
6.6.3 An Example of Access Control 140
6.6.4 Example: Access to public and Non-public Classes 141
6.6.5 Example: Default-Access Fields, Methods, and Constructors 142
6.6.6 Example: public Fields, Methods, and Constructors 143
6.6.7 Example: protected Fields, Methods, and Constructors 143
6.6.8 Example: private Fields, Methods, and Constructors 144
The Java Language Specification
xii
6.7 Fully Qualified Names and Canonical Names 145
6.8 Naming Conventions 146
6.8.1 Package Names 147
6.8.2 Class and Interface Type Names 147
6.8.3 Type Variable Names 148
6.8.4 Method Names 149
6.8.5 Field Names 150
6.8.6 Constant Names 150
6.8.7 Local Variable and Parameter Names 151

7 Packages 153
7.1 Package Members 154
7.2 Host Support for Packages 155
7.2.1 Storing Packages in a File System 155
7.2.2 Storing Packages in a Database 157
7.3 Compilation Units 157
7.4 Package Declarations 158
7.4.1 Named Packages 158
7.4.1.1 Package Annotations 158
7.4.2 Unnamed Packages 159
7.4.3 Observability of a Package 160
7.4.4 Scope of a Package Declaration 160
7.5 Import Declarations 160
7.5.1 Single-Type-Import Declaration 161
7.5.2 Type-Import-on-Demand Declaration 163
7.5.3 Single Static Import Declaration 164
7.5.4 Static-Import-on-Demand Declaration 165
7.5.5 Automatic Imports 165
7.5.6 A Strange Example 165
7.6 Top Level Type Declarations 166
7.7 Unique Package Names 169

8 Classes 173
8.1 Class Declaration 175
8.1.1 Class Modifiers 175
8.1.1.1 abstract Classes 176
8.1.1.2 final Classes 178
8.1.1.3 strictfp Classes 178
8.1.2 Generic Classes and Type Parameters 178
8.1.3 Inner Classes and Enclosing Instances 181
8.1.4 Superclasses and Subclasses 184
8.1.5 Superinterfaces 186
8.1.6 Class Body and Member Declarations 189
8.2 Class Members 190
8.2.1 Examples of Inheritance 192
8.2.1.1 Example: Inheritance with Default Access 192
8.2.1.2 Inheritance with public and protected 193
xiii
8.2.1.3 Inheritance with private 193
8.2.1.4 Accessing Members of Inaccessible Classes 194
8.3 Field Declarations 196
8.3.1 Field Modifiers 197
8.3.1.1 static Fields 198
8.3.1.2 final Fields 199
8.3.1.3 transient Fields 199
8.3.1.4 volatile Fields 199
8.3.2 Initialization of Fields 201
8.3.2.1 Initializers for Class Variables 202
8.3.2.2 Initializers for Instance Variables 202
8.3.2.3 Restrictions on the use of Fields during Initialization 203
8.3.3 Examples of Field Declarations 205
8.3.3.1 Example: Hiding of Class Variables 205
8.3.3.2 Example: Hiding of Instance Variables 206
8.3.3.3 Example: Multiply Inherited Fields 207
8.3.3.4 Example: Re-inheritance of Fields 209
8.4 Method Declarations 209
8.4.1 Formal Parameters 210
8.4.2 Method Signature 212
8.4.3 Method Modifiers 214
8.4.3.1 abstract Methods 214
8.4.3.2 static Methods 216
8.4.3.3 final Methods 217
8.4.3.4 native Methods 218
8.4.3.5 strictfp Methods 218
8.4.3.6 synchronized Methods 218
8.4.4 Generic Methods 220
8.4.5 Method Return Type 220
8.4.6 Method Throws 221
8.4.7 Method Body 223
8.4.8 Inheritance, Overriding, and Hiding 224
8.4.8.1 Overriding (by Instance Methods) 224
8.4.8.2 Hiding (by Class Methods) 225
8.4.8.3 Requirements in Overriding and Hiding 225
8.4.8.4 Inheriting Methods with Override-Equivalent Signatures 228
8.4.9 Overloading 229
8.4.10 Examples of Method Declarations 230
8.4.10.1 Example: Overriding 230
8.4.10.2 Example: Overloading, Overriding, and Hiding 231
8.4.10.3 Example: Incorrect Overriding 231
8.4.10.4 Example: Overriding versus Hiding 232
8.4.10.5 Example: Invocation of Hidden Class Methods 234
8.4.10.6 Large Example of Overriding 234
8.4.10.7 Example: Incorrect Overriding because of Throws 236
8.5 Member Type Declarations 237
8.5.1 Modifiers 238
8.5.2 Static Member Type Declarations 238
The Java Language Specification
xiv
8.6 Instance Initializers 238
8.7 Static Initializers 239
8.8 Constructor Declarations 240
8.8.1 Formal Parameters and Formal Type Parameter 240
8.8.2 Constructor Signature 241
8.8.3 Constructor Modifiers 241
8.8.4 Generic Constructors 242
8.8.5 Constructor Throws 242
8.8.6 The Type of a Constructor 242
8.8.7 Constructor Body 242
8.8.7.1 Explicit Constructor Invocations 243
8.8.8 Constructor Overloading 246
8.8.9 Default Constructor 247
8.8.10 Preventing Instantiation of a Class 248
8.9 Enums 249

9 Interfaces 259
9.1 Interface Declarations 260
9.1.1 Interface Modifiers 260
9.1.1.1 abstract Interfaces 261
9.1.1.2 strictfp Interfaces 261
9.1.2 Generic Interfaces and Type Parameters 261
9.1.3 Superinterfaces and Subinterfaces 261
9.1.4 Interface Body and Member Declarations 263
9.1.5 Access to Interface Member Names 263
9.2 Interface Members 263
9.3 Field (Constant) Declarations 264
9.3.1 Initialization of Fields in Interfaces 265
9.3.2 Examples of Field Declarations 265
9.3.2.1 Ambiguous Inherited Fields 265
9.3.2.2 Multiply Inherited Fields 266
9.4 Abstract Method Declarations 266
9.4.1 Inheritance and Overriding 267
9.4.2 Overloading 268
9.4.3 Examples of Abstract Method Declarations 269
9.4.3.1 Example: Overriding 269
9.4.3.2 Example: Overloading 269
9.5 Member Type Declarations 270
9.6 Annotation Types 270
9.6.1 Predefined Annotation Types 277
9.6.1.1 Target 278
9.6.1.2 Retention 278
9.6.1.3 Inherited 279
9.6.1.4 Override 279
9.6.1.5 SuppressWarnings 280
9.6.1.6 Deprecated 280
9.7 Annotations 281
xv

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

11 Exceptions 297
11.1 The Causes of Exceptions 298
11.2 Compile-Time Checking of Exceptions 299
11.2.1 Exception Analysis of Expressions 299
11.2.2 Exception Analysis of Statements 300
11.2.3 Exception Checking 301
11.2.4 Why Errors are Not Checked 301
11.2.5 Why Runtime Exceptions are Not Checked 301
11.3 Handling of an Exception 302
11.3.1 Exceptions are Precise 303
11.3.2 Handling Asynchronous Exceptions 303
11.4 An Example of Exceptions 304
11.5 The Exception Hierarchy 306
11.5.1 Loading and Linkage Errors 307
11.5.2 Virtual Machine Errors 307

12 Execution 309
12.1 Virtual Machine Start-Up 309
12.1.1 Load the Class Test 310
12.1.2 Link Test: Verify, Prepare, (Optionally) Resolve 310
12.1.3 Initialize Test: Execute Initializers 311
12.1.4 Invoke Test.main 312
12.2 Loading of Classes and Interfaces 312
12.2.1 The Loading Process 313
12.3 Linking of Classes and Interfaces 314
12.3.1 Verification of the Binary Representation 314
12.3.2 Preparation of a Class or Interface Type 315
12.3.3 Resolution of Symbolic References 315
12.4 Initialization of Classes and Interfaces 316
12.4.1 When Initialization Occurs 316
12.4.2 Detailed Initialization Procedure 319
12.4.3 Initialization: Implications for Code Generation 321
12.5 Creation of New Class Instances 322
12.6 Finalization of Class Instances 325
The Java Language Specification
xvi
12.6.1 Implementing Finalization 326
12.6.1.1 Interaction with the Memory Model 328
12.6.2 Finalizer Invocations are Not Ordered 329
12.7 Unloading of Classes and Interfaces 330
12.8 Program Exit 331

13 Binary Compatibility 333


13.1 The Form of a Binary 334
13.2 What Binary Compatibility Is and Is Not 339
13.3 Evolution of Packages 340
13.4 Evolution of Classes 340
13.4.1 abstract Classes 340
13.4.2 final Classes 341
13.4.3 public Classes 341
13.4.4 Superclasses and Superinterfaces 341
13.4.5 Class Formal Type Parameters 342
13.4.6 Class Body and Member Declarations 343
13.4.7 Access to Members and Constructors 344
13.4.8 Field Declarations 345
13.4.9 final Fields and Constants 347
13.4.10 static Fields 349
13.4.11 transient Fields 350
13.4.12 Method and Constructor Declarations 350
13.4.13 Method and Constructor Formal Type Parameters 351
13.4.14 Method and Constructor Parameters 352
13.4.15 Method Result Type 352
13.4.16 abstract Methods 352
13.4.17 final Methods 353
13.4.18 native Methods 354
13.4.19 static Methods 354
13.4.20 synchronized Methods 354
13.4.21 Method and Constructor Throws 354
13.4.22 Method and Constructor Body 354
13.4.23 Method and Constructor Overloading 355
13.4.24 Method Overriding 356
13.4.25 Static Initializers 356
13.4.26 Evolution of Enums 356
13.5 Evolution of Interfaces 356
13.5.1 public Interfaces 356
13.5.2 Superinterfaces 357
13.5.3 The Interface Members 357
13.5.4 Interface Formal Type Parameters 357
13.5.5 Field Declarations 358
13.5.6 Abstract Method Declarations 358
13.5.7 Evolution of Annotation Types 358
xvii

14 Blocks and Statements 359


14.1 Normal and Abrupt Completion of Statements 360
14.2 Blocks 361
14.3 Local Class Declarations 361
14.4 Local Variable Declaration Statements 363
14.4.1 Local Variable Declarators and Types 364
14.4.2 Scope of Local Variable Declarations 364
14.4.3 Shadowing of Names by Local Variables 367
14.4.4 Execution of Local Variable Declarations 367
14.5 Statements 368
14.6 The Empty Statement 370
14.7 Labeled Statements 370
14.8 Expression Statements 371
14.9 The if Statement 372
14.9.1 The if–then Statement 372
14.9.2 The if–then–else Statement 372
14.10 The assert Statement 373
14.11 The switch Statement 377
14.12 The while Statement 380
14.12.1 Abrupt Completion 381
14.13 The do Statement 382
14.13.1 Abrupt Completion 383
14.13.2 Example of do statement 383
14.14 The for Statement 384
14.14.1 The basic for Statement 384
14.14.1.1 Initialization of for statement 385
14.14.1.2 Iteration of for statement 385
14.14.1.3 Abrupt Completion of for statement 386
14.14.2 The enhanced for statement 387
14.15 The break Statement 388
14.16 The continue Statement 390
14.17 The return Statement 392
14.18 The throw Statement 393
14.19 The synchronized Statement 395
14.20 The try statement 396
14.20.1 Execution of try–catch 398
14.20.2 Execution of try–catch–finally 399
14.21 Unreachable Statements 402

15 Expressions 409
15.1 Evaluation, Denotation, and Result 409
15.2 Variables as Values 410
15.3 Type of an Expression 410
15.4 FP-strict Expressions 411
15.5 Expressions and Run-Time Checks 411
15.6 Normal and Abrupt Completion of Evaluation 413
15.7 Evaluation Order 414
The Java Language Specification
xviii
15.7.1 Evaluate Left-Hand Operand First 415
15.7.2 Evaluate Operands before Operation 416
15.7.3 Evaluation Respects Parentheses and Precedence 417
15.7.4 Argument Lists are Evaluated Left-to-Right 418
15.7.5 Evaluation Order for Other Expressions 419
15.8 Primary Expressions 420
15.8.1 Lexical Literals 420
15.8.2 Class Literals 421
15.8.3 this 421
15.8.4 Qualified this 422
15.8.5 Parenthesized Expressions 422
15.9 Class Instance Creation Expressions 423
15.9.1 Determining the Class being Instantiated 424
15.9.2 Determining Enclosing Instances 425
15.9.3 Choosing the Constructor and its Arguments 427
15.9.4 Run-time Evaluation of Class Instance Creation Expressions 428
15.9.5 Anonymous Class Declarations 429
15.9.5.1 Anonymous Constructors 429
15.9.6 Example: Evaluation Order and Out-of-Memory Detection 430
15.10 Array Creation Expressions 431
15.10.1 Run-time Evaluation of Array Creation Expressions 432
15.10.2 Example: Array Creation Evaluation Order 433
15.10.3 Example: Array Creation and Out-of-Memory Detection 434
15.11 Field Access Expressions 435
15.11.1 Field Access Using a Primary 435
15.11.2 Accessing Superclass Members using super 438
15.12 Method Invocation Expressions 440
15.12.1 Compile-Time Step 1: Determine Class or Interface to Search 440
15.12.2 Compile-Time Step 2: Determine Method Signature 442
15.12.2.1 Identify Potentially Applicable Methods 443
15.12.2.2 Phase 1: Identify Matching Arity Methods Applicable by Sub-
typing 445
15.12.2.3 Phase 2: Identify Matching Arity Methods Applicable by
Method Invocation Conversion 446
15.12.2.4 Phase 3: Identify Applicable Variable Arity Methods 446
15.12.2.5 Choosing the Most Specific Method 447
15.12.2.6 Method Result and Throws Types 450
15.12.2.7 Inferring Type Arguments Based on Actual Arguments 451
15.12.2.8 Inferring Unresolved Type Arguments 466
15.12.2.9 Examples 466
15.12.2.10 Example: Overloading Ambiguity 468
15.12.2.11 Example: Return Type Not Considered 468
15.12.2.12 Example: Compile-Time Resolution 469
15.12.3 Compile-Time Step 3: Is the Chosen Method Appropriate? 471
15.12.4 Runtime Evaluation of Method Invocation 473
15.12.4.1 Compute Target Reference (If Necessary) 473
15.12.4.2 Evaluate Arguments 474
15.12.4.3 Check Accessibility of Type and Method 475
xix
15.12.4.4 Locate Method to Invoke 476
15.12.4.5 Create Frame, Synchronize, Transfer Control 477
15.12.4.6 Example: Target Reference and Static Methods 479
15.12.4.7 Example: Evaluation Order 479
15.12.4.8 Example: Overriding 480
15.12.4.9 Example: Method Invocation using super 481
15.13 Array Access Expressions 482
15.13.1 Runtime Evaluation of Array Access 483
15.13.2 Examples: Array Access Evaluation Order 483
15.14 Postfix Expressions 485
15.14.1 Expression Names 485
15.14.2 Postfix Increment Operator ++ 485
15.14.3 Postfix Decrement Operator -- 486
15.15 Unary Operators 487
15.15.1 Prefix Increment Operator ++ 487
15.15.2 Prefix Decrement Operator -- 488
15.15.3 Unary Plus Operator + 489
15.15.4 Unary Minus Operator - 489
15.15.5 Bitwise Complement Operator ~ 490
15.15.6 Logical Complement Operator ! 490
15.16 Cast Expressions 490
15.17 Multiplicative Operators 491
15.17.1 Multiplication Operator * 492
15.17.2 Division Operator / 493
15.17.3 Remainder Operator % 495
15.18 Additive Operators 496
15.18.1 String Concatenation Operator + 497
15.18.1.1 String Conversion 497
15.18.1.2 Optimization of String Concatenation 498
15.18.1.3 Examples of String Concatenation 498
15.18.2 Additive Operators (+ and -) for Numeric Types 500
15.19 Shift Operators 502
15.20 Relational Operators 503
15.20.1 Numerical Comparison Operators <, <=, >, and >= 503
15.20.2 Type Comparison Operator instanceof 504
15.21 Equality Operators 505
15.21.1 Numerical Equality Operators == and != 506
15.21.2 Boolean Equality Operators == and != 507
15.21.3 Reference Equality Operators == and != 507
15.22 Bitwise and Logical Operators 508
15.22.1 Integer Bitwise Operators &, ^, and | 508
15.22.2 Boolean Logical Operators &, ^, and | 508
15.23 Conditional-And Operator && 509
15.24 Conditional-Or Operator || 509
15.25 Conditional Operator ? : 510
15.26 Assignment Operators 512
15.26.1 Simple Assignment Operator = 513
15.26.2 Compound Assignment Operators 518
The Java Language Specification
xx
15.27 Expression 525
15.28 Constant Expression 525

16 Definite Assignment 527


16.1 Definite Assignment and Expressions 533
16.1.1 Boolean Constant Expressions 533
16.1.2 The Boolean Operator && 533
16.1.3 The Boolean Operator || 534
16.1.4 The Boolean Operator ! 534
16.1.5 The Boolean Operator ? : 534
16.1.6 The Conditional Operator ? : 535
16.1.7 Other Expressions of Type boolean 535
16.1.8 Assignment Expressions 535
16.1.9 Operators ++ and -- 536
16.1.10 Other Expressions 536
16.2 Definite Assignment and Statements 538
16.2.1 Empty Statements 538
16.2.2 Blocks 538
16.2.3 Local Class Declaration Statements 539
16.2.4 Local Variable Declaration Statements 539
16.2.5 Labeled Statements 540
16.2.6 Expression Statements 540
16.2.7 if Statements 541
16.2.8 assert Statements 541
16.2.9 switch Statements 541
16.2.10 while Statements 542
16.2.11 do Statements 543
16.2.12 for Statements 543
16.2.12.1 Initialization Part 544
16.2.12.2 Incrementation Part 544
16.2.13 break, continue, return, and throw Statements 545
16.2.14 synchronized Statements 545
16.2.15 try Statements 545
16.3 Definite Assignment and Parameters 547
16.4 Definite Assignment and Array Initializers 547
16.5 Definite Assignment and Enum Constants 548
16.6 Definite Assignment and Anonymous Classes 548
16.7 Definite Assignment and Member Types 549
16.8 Definite Assignment and Static Initializers 549
16.9 Definite Assignment, Constructors, and Instance Initializers 550

17 Threads and Locks 553


17.1 Locks 554
17.2 Notation in Examples 554
17.3 Incorrectly Synchronized Programs Exhibit Surprising Behaviors 555
17.4 Memory Model 557
17.4.1 Shared Variables 558
xxi
17.4.2 Actions 558
17.4.3 Programs and Program Order 560
17.4.4 Synchronization Order 561
17.4.5 Happens-before Order 561
17.4.6 Executions 567
17.4.7 Well-Formed Executions 568
17.4.8 Executions and Causality Requirements 568
17.4.9 Observable Behavior and Nonterminating Executions 571
17.5 Final Field Semantics 573
17.5.1 Semantics of Final Fields 575
17.5.2 Reading Final Fields During Construction 576
17.5.3 Subsequent Modification of Final Fields 576
17.5.4 Write Protected Fields 578
17.6 Word Tearing 578
17.7 Non-atomic Treatment of double and long 579
17.8 Wait Sets and Notification 580
17.8.1 Wait 580
17.8.2 Notification 581
17.8.3 Interruptions 582
17.8.4 Interactions of Waits, Notification and Interruption 582
17.9 Sleep and Yield 583

18 Syntax 585
18.1 The Grammar of the Java Programming Language 585

Index 597

Credits 649

Colophon 651
The Java Language Specification
xxii
Preface

THE Java ™
programming language was originally called Oak, and was designed

FT
for use in embedded consumer-electronic applications by James Gosling. After
several years of experience with the language, and significant contributions by Ed
Frank, Patrick Naughton, Jonathan Payne, and Chris Warth it was retargeted to the
Internet, renamed, and substantially revised to be the language specified here. The
final form of the language was defined by James Gosling, Bill Joy, Guy Steele,
Richard Tuck, Frank Yellin, and Arthur van Hoff, with help from Graham Hamil-
ton, Tim Lindholm, and many other friends and colleagues.
The Java programming language is a general-purpose concurrent class-based
object-oriented programming language, specifically designed to have as few
RA
implementation dependencies as possible. It allows application developers to
write a program once and then be able to run it everywhere on the Internet.
This book attempts a complete specification of the syntax and semantics of
the language. We intend that the behavior of every language construct is specified
here, so that all implementations will accept the same programs. Except for timing
dependencies or other non-determinisms and given sufficient time and sufficient
memory space, a program written in the Java programming language should com-
pute the same result on all machines and in all implementations.

We believe that the Java programming language is a mature language, ready


for widespread use. Nevertheless, we expect some evolution of the language in the
years to come. We intend to manage this evolution in a way that is completely
D

compatible with existing applications. To do this, we intend to make relatively few


new versions of the language. Compilers and systems will be able to support the
several versions simultaneously, with complete compatibility.
Much research and experimentation with the Java platform is already under-
way. We encourage this work, and will continue to cooperate with external groups
to explore improvements to the language and platform. For example, we have
already received several interesting proposals for parameterized types. In techni-
cally difficult areas, near the state of the art, this kind of research collaboration is
essential.

xxiii
PREFACE

We acknowledge and thank the many people who have contributed to this
book through their excellent feedback, assistance and encouragement:
Particularly thorough, careful, and thoughtful reviews of drafts were provided
by Tom Cargill, Peter Deutsch, Paul Hilfinger, Masayuki Ida, David Moon, Steven
Muchnick, Charles L. Perkins, Chris Van Wyk, Steve Vinoski, Philip Wadler,
Daniel Weinreb, and Kenneth Zadeck. We are very grateful for their extraordinary
volunteer efforts.
We are also grateful for reviews, questions, comments, and suggestions from
Stephen Adams, Bowen Alpern, Glenn Ammons, Leonid Arbuzov, Kim Bruce,

FT
Edwin Chan, David Chase, Pavel Curtis, Drew Dean, William Dietz, David Dill,
Patrick Dussud, Ed Felten, John Giannandrea, John Gilmore, Charles Gust,
Warren Harris, Lee Hasiuk, Mike Hendrickson, Mark Hill, Urs Hoelzle, Roger
Hoover, Susan Flynn Hummel, Christopher Jang, Mick Jordan, Mukesh Kacker,
Peter Kessler, James Larus, Derek Lieber, Bill McKeeman, Steve Naroff,
Evi Nemeth, Robert O’Callahan, Dave Papay, Craig Partridge, Scott Pfeffer,
Eric Raymond, Jim Roskind, Jim Russell, William Scherlis, Edith Schonberg,
Anthony Scian, Matthew Self, Janice Shepherd, Kathy Stark, Barbara Steele, Rob
Strom, William Waite, Greg Weeks, and Bob Wilson. (This list was generated
semi-automatically from our E-mail records. We apologize if we have omitted
RA
anyone.)
The feedback from all these reviewers was invaluable to us in improving the
definition of the language as well as the form of the presentation in this book. We
thank them for their diligence. Any remaining errors in this book—we hope they
are few—are our responsibility and not theirs.
We thank Francesca Freedman and Doug Kramer for assistance with matters
of typography and layout. We thank Dan Mills of Adobe Systems Incorporated for
assistance in exploring possible choices of typefaces.
Many of our colleagues at Sun Microsystems have helped us in one way or
another. Lisa Friendly, our series editor, managed our relationship with Addison-
Wesley. Susan Stambaugh managed the distribution of many hundreds of copies
D

of drafts to reviewers. We received valuable assistance and technical advice from


Ben Adida, Ole Agesen, Ken Arnold, Rick Cattell, Asmus Freytag, Norm Hardy,
Steve Heller, David Hough, Doug Kramer, Nancy Lee, Marianne Mueller, Akira
Tanaka, Greg Tarsy, David Ungar, Jim Waldo, Ann Wollrath, Geoff Wyant, and
Derek White. We thank Alan Baratz, David Bowen, Mike Clary, John Doerr, Jon
Kannegaard, Eric Schmidt, Bob Sproull, Bert Sutherland, and Scott McNealy for
leadership and encouragement.
The on-line Bartleby Library of Columbia University, at URL:
http://www.cc.columbia.edu/acis/bartleby/

xxiv
PREFACE

was invaluable to us during the process of researching and verifying many of the
quotations that are scattered throughout this book. Here is one example:
They lard their lean books with the fat of others’ works.
—Robert Burton (1576–1640)
We are grateful to those who have toiled on Project Bartleby, for saving us a great
deal of effort and reawakening our appreciation for the works of Walt Whitman.
We are thankful for the tools and services we had at our disposal in writing
this book: telephones, overnight delivery, desktop workstations, laser printers,

FT
photocopiers, text formatting and page layout software, fonts, electronic mail, the
World Wide Web, and, of course, the Internet. We live in three different states,
scattered across a continent, but collaboration with each other and with our
reviewers has seemed almost effortless. Kudos to the thousands of people who
have worked over the years to make these excellent tools and services work
quickly and reliably.
Mike Hendrickson, Katie Duffy, Simone Payment, and Rosa Aimée González
of Addison-Wesley were very helpful, encouraging, and patient during the long
process of bringing this book to print. We also thank the copy editors.
Rosemary Simpson worked hard, on a very tight schedule, to create the index.
RA
We got into the act at the last minute, however; blame us and not her for any jokes
you may find hidden therein.
Finally, we are grateful to our families and friends for their love and support
during this last, crazy, year.

In their book The C Programming Language, Brian Kernighan and Dennis


Ritchie said that they felt that the C language “wears well as one’s experience with
it grows.” If you like C, we think you will like the Java programming language.
We hope that it, too, wears well for you.

James Gosling
D

Cupertino, California
Bill Joy
Aspen, Colorado
Guy Steele
Chelmsford, Massachusetts
July, 1996

xxv
D
RA
FT
Preface to the Second Edition

... the pyramid must stand unchanged for a millennium;

FT
the organism must evolve or perish.
Alan Perlis, Foreword to Structure and Interpretation of Computer Programs
RA
OVER the past few years, the Java ™ programming language has enjoyed
unprecedented success. This success has brought a challenge: along with explo-
sive growth in popularity, there has been explosive growth in the demands made
on the language and its libraries. To meet this challenge, the language has grown
as well (fortunately, not explosively) and so have the libraries.
This second edition of The Java™ Language Specification reflects these devel-
opments. It integrates all the changes made to the Java programming language
since the publication of the first edition in 1996. The bulk of these changes were
made in the 1.1 release of the Java platform in 1997, and revolve around the addi-
D

tion of nested type declarations. Later modifications pertained to floating-point


operations. In addition, this edition incorporates important clarifications and
amendments involving method lookup and binary compatibility.
This specification defines the language as it exists today. The Java program-
ming language is likely to continue to evolve. At this writing, there are ongoing
initiatives through the Java Community Process to extend the language with
generic types and assertions, refine the memory model, etc. However, it would be
inappropriate to delay the publication of the second edition until these efforts are
concluded.

xxvii
PREFACE TO THE SECOND EDITION

The specifications of the libraries are now far too large to fit into this volume,
and they continue to evolve. Consequently, API specifications have been removed
from this book. The library specifications can be found on the java.sun.com
Web site (see below); this specification now concentrates solely on the Java pro-
gramming language proper.
Readers may send comments on this specification to: [email protected]. To
learn the latest about the Java 2 platform, or to download the latest Java 2 SDK
release, visit http://java.sun.com. Updated information about the Java Series,
including errata for The Java™ Language Specification, Second Edition, and pre-

FT
views of forthcoming books, may be found at http://java.sun.com/Series.
Many people contributed to this book, directly and indirectly. Tim Lindholm
brought extraordinary dedication to his role as technical editor. He also made
invaluable technical contributions, especially on floating-point issues. The book
would likely not see the light of day without him. Lisa Friendly, the Series editor,
provided encouragement and advice for which I am very thankful.
David Bowen first suggested that I get involved in the specifications of the
Java platform. I am grateful to him for introducing me to this uncommonly rich
area.
John Rose, the father of nested types in the Java programming language, has
RA
been unfailingly gracious and supportive of my attempts to specify them accu-
rately.
Many people have provided valuable comments on this edition. Special
thanks go to Roly Perera at Ergnosis and to Leonid Arbouzov and his colleagues
on Sun’s Java platform conformance team in Novosibirsk: Konstantin Bobrovsky,
Natalia Golovleva, Vladimir Ivanov, Alexei Kaigorodov, Serguei Katkov, Dmitri
Khukhro, Eugene Latkin, Ilya Neverov, Pavel Ozhdikhin, Igor Pyankov,
Viatcheslav Rybalov, Serguei Samoilidi, Maxim Sokolnikov, and Vitaly Tchaiko.
Their thorough reading of earlier drafts has greatly improved the accuracy of this
specification.
I am indebted to Martin Odersky and to Andrew Bennett and the members of
D

Sun’s javac compiler team, past and present: Iris Garcia, Bill Maddox, David
Stoutamire, and Todd Turnidge. They all worked hard to make sure the reference
implementation conformed to the specification. For many enjoyable technical
exchanges, I thank them and my other colleagues at Sun: Lars Bak, Joshua Bloch,
Cliff Click, Robert Field, Mohammad Gharahgouzloo, Ben Gomes, Steffen
Grarup, Robert Griesemer, Graham Hamilton, Gordon Hirsch, Peter Kessler,
Sheng Liang, James McIlree, Philip Milne, Srdjan Mitrovic, Anand Palaniswamy,
Mike Paleczny, Mark Reinhold, Kenneth Russell, Rene Schmidt, David Ungar,
Chris Vick, and Hong Zhang.

xxviii
PREFACE TO THE SECOND EDITION

Tricia Jordan, my manager, has been a model of patience, consideration and


understanding. Thanks are also due to Larry Abrahams, director of Java 2 Stan-
dard Edition, for supporting this work.
The following individuals all provided useful comments that have contributed
to this specification: Godmar Bak, Hans Boehm, Philippe Charles, David Chase,
Joe Darcy, Jim des Rivieres, Sophia Drossopoulou, Susan Eisenbach, Paul Haahr,
Urs Hoelzle, Bart Jacobs, Kent Johnson, Mark Lillibridge, Norbert Lindenberg,
Phillipe Mulet, Kelly O’Hair, Bill Pugh, Cameron Purdy, Anthony Scian, Janice
Shepherd, David Shields, John Spicer, Lee Worall, and David Wragg.

FT
Suzette Pelouch provided invaluable assistance with the index and, together
with Doug Kramer and Atul Dambalkar, assisted with FrameMaker expertise;
Mike Hendrickson and Julie Dinicola at Addison-Wesley were gracious, helpful
and ultimately made this book a reality.
On a personal note, I thank my wife Weihong for her love and support.
Finally, I’d like to thank my coauthors, James Gosling, Bill Joy, and Guy
Steele for inviting me to participate in this work. It has been a pleasure and a priv-
ilege.

Gilad Bracha
RA
Los Altos, California
April, 2000
D

This is the FEMALE EDITION of the Dictionary.

The MALE edition is almost identical. But NOT quite.


Be warned that ONE PARAGRAPH is crucially different.

The choice is yours.Milorad Pavic, Dictionary of the Khazars, Female Edition

xxix
D
RA
FT
Preface to the Third Edition

FT
This edition of the Java ™ Programming Language Specification represents the
largest set of changes in the language’s history. Generics, annotations, asserts,
autoboxing and unboxing, enum types, foreach loops, variable arity methods and
static imports have all been added to the language recently. All but asserts are new
to the 5.0 release of autumn 2004.
This third edition of The Java™ Language Specification reflects these develop-
ments. It integrates all the changes made to the Java programming language since
RA
the publication of the second edition in 2000.
The language has grown a great deal in these past four years. Unfortunately, it
is unrealistic to shrink a commercially successful programming language - only to
grow it more and more. The challenge of managing this growth under the con-
straints of compatibility and the conflicting demands of a wide variety of uses and
users is non-trivial. I can only hope that we have met this challenge successfully
with this specification; time will tell.
Readers may send comments on this specification to: [email protected]. To
learn the latest about the Java platform, or to download the latest J2SE release,
visit http://java.sun.com. Updated information about the Java Series, includ-
ing errata for The Java™ Language Specification, Third Edition, and previews of
D

forthcoming books, may be found at http://java.sun.com/Series.


This specification builds on the efforts of many people, both at Sun Microsys-
tems and outside it.
The most crucial contribution is that of the people who actually turn the spec-
ification into real software. Chief among these are the maintainers of javac, the
reference compiler for the Java programming language.
Neal Gafter was “Mr. javac” during the crucial period in which the large
changes described here were integrated and productized. Neal’s dedication and
productivity can honestly be described as heroic. We literally could not have com-
pleted the task without him. In addition, his insight and skill made a huge contri-
bution to the design of the new language features across the board. No one

xxxi
PREFACE TO THE THIRD EDITION

deserves more credit for this version of the language than he - but any blame for
its deficiencies should be directed at myself and the members of the many JSR
expert groups!
Neal has gone on in search of new challenges, and has been succeeded by
Peter von der Ahé, who continues to improve and stengthen the implementation.
Before Neal’s involvement, Bill Maddox was in charge of javac when the previous
edition was completed, and he nursed features such as generics and asserts
through their early days.
Another individual who deserves to be singled out is Joshua Bloch. Josh par-

FT
ticipated in endless language design discussions, chaired several expert groups
and was a key contributor to the Java platform. It is fair to say that Josh and Neal
care more about this book than I do myself!
Many parts of the specification were developed by various expert groups in
the framework of the Java community process.
The most pervasive set of language changes is the result of JSR-014: Adding
Generics to the Java Programming Language. The members of the JSR-014
expert group were: Norman Cohen, Christian Kemper, Martin Odersky, Kresten
Krab Thorup, Philip Wadler and myself. In the early stages, Sven-Eric Panitz and
Steve Marx were members as well. All deserve thanks for their participation.
RA
JSR-014 represents an unprecedented effort to fundamentally extend the type
system of a widely used programming language under very stringent compatibil-
ity requirements. A prolonged and arduous process of design and implementation
led us to the current language extension. Long before the JSR for generics was ini-
tiated, Martin Odersky and Philip Wadler had created an experimental language
called Pizza to explore the ideas involved. In the spring of 1998, David Stoutamire
and myself began a collaboration with Martin and Phil based on those ideas, that
resulted in GJ. When the JSR-014 expert group was convened, GJ was chosen as
the basis for extending the Java programming language. Martin Odersky imple-
mented the GJ compiler, and his implementation became the basis for javac (start-
ing with JDK 1.3, even though generics were disabled until 1.5).
D

The theoretical basis for the core of the generic type system owes a great debt
to the expertise of Martin Odersky and Phil Wadler. Later, the system was
extended with wildcards. These were based on the work of Atsushi Igarashi and
Mirko Viroli, which itself built on earlier work by Kresten Thorup and Mads
Torgersen. Wildcards were initially designed and implemented as part of a collab-
oration between Sun and Aarhus University. Neal Gafter and myself participated
on Sun’s behalf, and Erik Ernst and Mads Torgersen, together with Peter von der
Ahé and Christian Plesner-Hansen, represented Aarhus. Thanks to Ole Lehrmann-
Madsen for enabling and supporting that work.

xxxii
PREFACE TO THE THIRD EDITION

Joe Darcy and Ken Russell implemented much of the specific support for
reflection of generics. Neal Gafter, Josh Bloch and Mark Reinhold did a huge
amount of work generifying the JDK libraries.
Honorable mention must go to individuals whose comments on the generics
design made a significant difference. Alan Jeffrey made crucial contributions to
JSR-14 by pointing out subtle flaws in the original type system. Bob Deen sug-
gested the “? super T” syntax for lower bounded wildcards
JSR-201 included a series of changes: autoboxing, enums, foreach loops, vari-
able arity methods and static import. The members of the JSR-201 expert group

FT
were: Cédric Beust, David Biesack, Joshua Bloch (co-chair), Corky Cartwright,
Jim des Rivieres, David Flanagan, Christian Kemper, Doug Lea, Changshin Lee,
Tim Peierls, Michel Trudeau and myself (co-chair). Enums and the foreach loop
were primarily designed by Josh Bloch and Neal Gafter. Variable arity methods
would never have made it into the language without Neal’s special efforts design-
ing them (not to mention the small matter of implementing them).
Josh Bloch bravely took upon himself the responsibility for JSR-175, which
added annotations to the language. The members of JSR-175 expert group were
Cédric Beust, Joshua Bloch (chair), Ted Farrell, Mike French, Gregor Kiczales,
Doug Lea, Deeptendu Majunder, Simon Nash, Ted Neward, Roly Perera, Manfred
RA
Schneider, Blake Stone and Josh Street. Neal Gafter, as usual, was a major con-
tributer on this front as well.
Another change in this edition is a complete revision of the Java memory
model, undertaken by JSR-133. The members of the JSR-133 expert group were
Hans Boehm, Doug Lea, Tim Lindholm (co-chair), Bill Pugh (co-chair), Martin
Trotter and Jerry Schwarz. The primary technical authors of the memory model
are Sarita Adve, Jeremy Manson and Bill Pugh. The Java memory model chapter
in this book is in fact almost entirely their work, with only editorial revisions.
Joseph Bowbeer, David Holmes, Victor Luchangco and Jan-Willem Maessen
made significant contributions as well. Key sections dealing with finalization in
chapter 12 owe much to this work as well, and especially to Doug Lea.
D

Many people have provided valuable comments on this edition.


I’d like to express my gratitude to Archibald Putt, who provided insight and
encouragement. His writings are always an inspiration. Thanks once again to Joe
Darcy for introducing us, as well as for many useful comments, and his specific
contributions on numerical issues and the design of hexadecimal literals.
Many colleagues at Sun (past or present) have provided useful feedback and
discussion, and helped produce this work in myriad ways: Andrew Bennett, Mar-
tin Buchholz, Jerry Driscoll, Robert Field, Jonathan Gibbons, Graham Hamilton,
Mimi Hills, Jim Holmlund, Janet Koenig, Jeff Norton, Scott Seligman, Wei Tao
and David Ungar.

xxxiii
PREFACE TO THE THIRD EDITION

Special thanks to Laurie Tolson, my manager, for her support throughout the
long process of deriving these specifications.
The following individuals all provided many valuable comments that have
contributed to this specification: Scott Annanian, Martin Bravenboer, Bruce Chap-
man, Lawrence Gonsalves, Tim Hanson, David Holmes, Angelika Langer, Pat
Lavarre, Phillipe Mulet and Cal Varnson.
Ann Sellers, Greg Doench and John Fuller at Addison-Wesley were exceed-
ingly patient and ensured that the book materialized, despite the many missed
deadlines for this text.

FT
As always, I thank my wife Weihong and my son Teva for their support and
cooperation.

Gilad Bracha
Los Altos, California
January, 2005
RA
D

xxxiv
C H A P T E R 1
Introduction

FT
1.0 If I have seen further it is by standing upon the shoulders of Giants.

The Java ™ programming language is a general-purpose, concurrent, class-based,


object-oriented language. It is designed to be simple enough that many program-
mers can achieve fluency in the language. The Java programming language is
related to C and C++ but is organized rather differently, with a number of aspects
of C and C++ omitted and a few ideas from other languages included. It is
RA
intended to be a production language, not a research language, and so, as C. A. R.
Hoare suggested in his classic paper on language design, the design has avoided
including new and untested features.
The Java programming language is strongly typed. This specification clearly
distinguishes between the compile-time errors that can and must be detected at
compile time, and those that occur at run time. Compile time normally consists of
translating programs into a machine-independent byte code representation. Run-
time activities include loading and linking of the classes needed to execute a pro-
gram, optional machine code generation and dynamic optimization of the pro-
gram, and actual program execution.
The Java programming language is a relatively high-level language, in that
D

details of the machine representation are not available through the language. It
includes automatic storage management, typically using a garbage collector, to
avoid the safety problems of explicit deallocation (as in C’s free or C++’s
delete). High-performance garbage-collected implementations can have
bounded pauses to support systems programming and real-time applications. The
language does not include any unsafe constructs, such as array accesses without
index checking, since such unsafe constructs would cause a program to behave in
an unspecified way.
The Java programming language is normally compiled to the bytecoded
instruction set and binary format defined in The Java™ Virtual Machine Specifica-
tion, Second Edition (Addison-Wesley, 1999).

1
1 Introduction INTRODUCTION

This specification is organized as follows:


Chapter 2 describes grammars and the notation used to present the lexical and
syntactic grammars for the language.
Chapter 3 describes the lexical structure of the Java programming language,
which is based on C and C++. The language is written in the Unicode character
set. It supports the writing of Unicode characters on systems that support only
ASCII.
Chapter 4 describes types, values, and variables. Types are subdivided into
primitive types and reference types.

FT
The primitive types are defined to be the same on all machines and in all
implementations, and are various sizes of two’s-complement integers, single- and
double-precision IEEE 754 standard floating-point numbers, a boolean type, and
a Unicode character char type. Values of the primitive types do not share state.
Reference types are the class types, the interface types, and the array types.
The reference types are implemented by dynamically created objects that are
either instances of classes or arrays. Many references to each object can exist. All
objects (including arrays) support the methods of the class Object, which is the
(single) root of the class hierarchy. A predefined String class supports Unicode
character strings. Classes exist for wrapping primitive values inside of objects. In
RA
many cases, wrapping and unwrapping is performed automatically by the com-
piler (in which case, wrapping is called boxing, and unwrapping is called unbox-
ing). Class and interface declarations may be generic, that is, they may be
parameterized by other reference types. Such declarations may then be invoked
with specific type arguments.
Variables are typed storage locations. A variable of a primitive type holds a
value of that exact primitive type. A variable of a class type can hold a null refer-
ence or a reference to an object whose type is that class type or any subclass of
that class type. A variable of an interface type can hold a null reference or a refer-
ence to an instance of any class that implements the interface. A variable of an
array type can hold a null reference or a reference to an array. A variable of class
D

type Object can hold a null reference or a reference to any object, whether class
instance or array.
Chapter 5 describes conversions and numeric promotions. Conversions
change the compile-time type and, sometimes, the value of an expression. These
conversions include the boxing and unboxing conversions between primitive types
and reference types. Numeric promotions are used to convert the operands of a
numeric operator to a common type where an operation can be performed. There
are no loopholes in the language; casts on reference types are checked at run time
to ensure type safety.
Chapter 6 describes declarations and names, and how to determine what
names mean (denote). The language does not require types or their members to be

2
INTRODUCTION Introduction 1

declared before they are used. Declaration order is significant only for local vari-
ables, local classes, and the order of initializers of fields in a class or interface.
The Java programming language provides control over the scope of names
and supports limitations on external access to members of packages, classes, and
interfaces. This helps in writing large programs by distinguishing the implementa-
tion of a type from its users and those who extend it. Recommended naming con-
ventions that make for more readable programs are described here.
Chapter 7 describes the structure of a program, which is organized into pack-
ages similar to the modules of Modula. The members of a package are classes,

FT
interfaces, and subpackages. Packages are divided into compilation units. Compi-
lation units contain type declarations and can import types from other packages to
give them short names. Packages have names in a hierarchical name space, and
the Internet domain name system can usually be used to form unique package
names.
Chapter 8 describes classes. The members of classes are classes, interfaces,
fields (variables) and methods. Class variables exist once per class. Class methods
operate without reference to a specific object. Instance variables are dynamically
created in objects that are instances of classes. Instance methods are invoked on
instances of classes; such instances become the current object this during their
RA
execution, supporting the object-oriented programming style.
Classes support single implementation inheritance, in which the implementa-
tion of each class is derived from that of a single superclass, and ultimately from
the class Object. Variables of a class type can reference an instance of that class
or of any subclass of that class, allowing new types to be used with existing meth-
ods, polymorphically.
Classes support concurrent programming with synchronized methods.
Methods declare the checked exceptions that can arise from their execution, which
allows compile-time checking to ensure that exceptional conditions are handled.
Objects can declare a finalize method that will be invoked before the objects
are discarded by the garbage collector, allowing the objects to clean up their state.
D

For simplicity, the language has neither declaration “headers” separate from
the implementation of a class nor separate type and class hierarchies.
A special form of classes, enums, support the definition of small sets of values
and their manipulation in a type safe manner. Unlike enumerations in other lan-
guages, enums are objects and may have their own methods.
Chapter 9 describes interface types, which declare a set of abstract methods,
member types, and constants. Classes that are otherwise unrelated can implement
the same interface type. A variable of an interface type can contain a reference to
any object that implements the interface. Multiple interface inheritance is sup-
ported.

3
1 Introduction INTRODUCTION

Annotation types are specialized interfaces used to annotate declarations.


Such annotations are not permitted to affect the semantics of programs in the Java
programming language in any way. However, they provide useful input to various
tools.
Chapter 10 describes arrays. Array accesses include bounds checking. Arrays
are dynamically created objects and may be assigned to variables of type Object.
The language supports arrays of arrays, rather than multidimensional arrays.
Chapter 11 describes exceptions, which are nonresuming and fully integrated
with the language semantics and concurrency mechanisms. There are three kinds

FT
of exceptions: checked exceptions, run-time exceptions, and errors. The compiler
ensures that checked exceptions are properly handled by requiring that a method
or constructor can result in a checked exception only if the method or constructor
declares it. This provides compile-time checking that exception handlers exist,
and aids programming in the large. Most user-defined exceptions should be
checked exceptions. Invalid operations in the program detected by the Java virtual
machine result in run-time exceptions, such as NullPointerException. Errors
result from failures detected by the virtual machine, such as OutOfMemoryError.
Most simple programs do not try to handle errors.
Chapter 12 describes activities that occur during execution of a program. A
RA
program is normally stored as binary files representing compiled classes and inter-
faces. These binary files can be loaded into a Java virtual machine, linked to other
classes and interfaces, and initialized.
After initialization, class methods and class variables may be used. Some
classes may be instantiated to create new objects of the class type. Objects that are
class instances also contain an instance of each superclass of the class, and object
creation involves recursive creation of these superclass instances.
When an object is no longer referenced, it may be reclaimed by the garbage
collector. If an object declares a finalizer, the finalizer is executed before the
object is reclaimed to give the object a last chance to clean up resources that
would not otherwise be released. When a class is no longer needed, it may be
D

unloaded.
Chapter 13 describes binary compatibility, specifying the impact of changes
to types on other types that use the changed types but have not been recompiled.
These considerations are of interest to developers of types that are to be widely
distributed, in a continuing series of versions, often through the Internet. Good
program development environments automatically recompile dependent code
whenever a type is changed, so most programmers need not be concerned about
these details.
Chapter 14 describes blocks and statements, which are based on C and C++.
The language has no goto statement, but includes labeled break and continue
statements. Unlike C, the Java programming language requires boolean (or

4
INTRODUCTION Example Programs 1.1

Boolean) expressions in control-flow statements, and does not convert types to


boolean implicitly (except through unboxing), in the hope of catching more
errors at compile time. A synchronized statement provides basic object-level
monitor locking. A try statement can include catch and finally clauses to pro-
tect against non-local control transfers.
Chapter 15 describes expressions. This document fully specifies the (appar-
ent) order of evaluation of expressions, for increased determinism and portability.
Overloaded methods and constructors are resolved at compile time by picking the
most specific method or constructor from those which are applicable.

FT
Chapter 16 describes the precise way in which the language ensures that local
variables are definitely set before use. While all other variables are automatically
initialized to a default value, the Java programming language does not automati-
cally initialize local variables in order to avoid masking programming errors.
Chapter 17 describes the semantics of threads and locks, which are based on
the monitor-based concurrency originally introduced with the Mesa programming
language. The Java programming language specifies a memory model for shared-
memory multiprocessors that supports high-performance implementations.
Chapter 18 presents a syntactic grammar for the language.
The book concludes with an index, credits for quotations used in the book,
RA
and a colophon describing how the book was created.

1.1 Example Programs

Most of the example programs given in the text are ready to be executed and are
similar in form to:
class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++)
System.out.print(i == 0 ? args[i] : " " + args[i]);
System.out.println();
D

}
}
On a Sun workstation using Sun’s Java 2 Platform Standard Edition Develp-
ment Kit software, this class, stored in the file Test.java, can be compiled and
executed by giving the commands:
javac Test.java
java Test Hello, world.
producing the output:
Hello, world.

5
1.2 Notation INTRODUCTION

1.2 Notation

Throughout this book we refer to classes and interfaces drawn from the Java and
Java 2 platforms. Whenever we refer to a class or interface which is not defined in
an example in this book using a single identifier N, the intended reference is to the
class or interface named N in the package java.lang. We use the canonical name
(§6.7) for classes or interfaces from packages other than java.lang.
Whenever we refer to the The Java™ Virtual Machine Specification in this
book, we mean the second edition, as amended by JSR 924.

FT
1.3 Relationship to Predefined Classes and Interfaces

As noted above, this specification often refers to classes of the Java and Java 2
platforms. In particular, some classes have a special relationship with the Java
programming language. Examples include classes such as Object, Class,
ClassLoader, String, Thread, and the classes and interfaces in package
java.lang.reflect, among others. The language definition constrains the
behavior of these classes and interfaces, but this document does not provide a
RA
complete specification for them. The reader is referred to other parts of the Java
platform specification for such detailed API specifications.
Thus this document does not describe reflection in any detail. Many linguistic
constructs have analogues in the reflection API, but these are generally not dis-
cussed here. So, for example, when we list the ways in which an object can be cre-
ated, we generally do not include the ways in which the reflective API can
accomplish this. Readers should be aware of these additional mechanisms even
though they are not mentioned in this text.
D

1.4 References

Apple Computer. Dylan™ Reference Manual. Apple Computer Inc., Cupertino, California.
September 29, 1995. See also http://www.cambridge.apple.com.
Bobrow, Daniel G., Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor
Kiczales, and David A. Moon. Common Lisp Object System Specification, X3J13
Document 88-002R, June 1988; appears as Chapter 28 of Steele, Guy. Common Lisp:
The Language, 2nd ed. Digital Press, 1990, ISBN 1-55558-041-6, 770–864.
Ellis, Margaret A., and Bjarne Stroustrup. The Annotated C++ Reference Manual.
Addison-Wesley, Reading, Massachusetts, 1990, reprinted with corrections October
1992, ISBN 0-201-51459-1.

6
INTRODUCTION References 1.4

Goldberg, Adele and Robson, David. Smalltalk-80: The Language. Addison-Wesley,


Reading, Massachusetts, 1989, ISBN 0-201-13688-0.
Harbison, Samuel. Modula-3. Prentice Hall, Englewood Cliffs, New Jersey, 1992, ISBN
0-13-596396.
Hoare, C. A. R. Hints on Programming Language Design. Stanford University Computer
Science Department Technical Report No. CS-73-403, December 1973. Reprinted in
SIGACT/SIGPLAN Symposium on Principles of Programming Languages. Associa-
tion for Computing Machinery, New York, October 1973.
IEEE Standard for Binary Floating-Point Arithmetic. ANSI/IEEE Std. 754-1985. Avail-
able from Global Engineering Documents, 15 Inverness Way East, Englewood, Colo-

FT
rado 80112-5704 USA; 800-854-7179.
Kernighan, Brian W., and Dennis M. Ritchie. The C Programming Language, 2nd ed.
Prentice Hall, Englewood Cliffs, New Jersey, 1988, ISBN 0-13-110362-8.
Madsen, Ole Lehrmann, Birger Møller-Pedersen, and Kristen Nygaard. Object-Oriented
Programming in the Beta Programming Language. Addison-Wesley, Reading, Mas-
sachusetts, 1993, ISBN 0-201-62430-3.
Mitchell, James G., William Maybury, and Richard Sweet. The Mesa Programming
Language, Version 5.0. Xerox PARC, Palo Alto, California, CSL 79-3, April 1979.
Stroustrup, Bjarne. The C++ Progamming Language, 2nd ed. Addison-Wesley, Reading,
RA
Massachusetts, 1991, reprinted with corrections January 1994, ISBN 0-201-53992-6.
Unicode Consortium, The. The Unicode Standard: Worldwide Character Encoding, Ver-
sion 1.0, Volume 1, ISBN 0-201-56788-1, and Volume 2, ISBN 0-201-60845-6.
Updates and additions necessary to bring the Unicode Standard up to version 1.1 may
be found at http://www.unicode.org.
Unicode Consortium, The. The Unicode Standard, Version 2.0, ISBN 0-201-48345-9.
Updates and additions necessary to bring the Unicode Standard up to version 2.1 may
be found at http://www.unicode.org.
Unicode Consortium, The. The Unicode Standard, Version 4.0, ISBN 0-321-18578-1.
Updates and additions may be found at http://www.unicode.org.
D

7
1.4 References INTRODUCTION

FT
RA
D

8
C H A P T E R 2
Grammars

FT
Grammar, which knows how to control even kings . . .

THIS chapter describes the context-free grammars used in this specification to


define the lexical and syntactic structure of a program.

2.1 Context-Free Grammars


RA
A context-free grammar consists of a number of productions. Each production has
an abstract symbol called a nonterminal as its left-hand side, and a sequence of
one or more nonterminal and terminal symbols as its right-hand side. For each
grammar, the terminal symbols are drawn from a specified alphabet.
Starting from a sentence consisting of a single distinguished nonterminal,
called the goal symbol, a given context-free grammar specifies a language,
namely, the set of possible sequences of terminal symbols that can result from
repeatedly replacing any nonterminal in the sequence with a right-hand side of a
production for which the nonterminal is the left-hand side.
D

2.2 The Lexical Grammar

A lexical grammar for the Java programming language is given in (§3). This
grammar has as its terminal symbols the characters of the Unicode character set. It
defines a set of productions, starting from the goal symbol Input (§3.5), that
describe how sequences of Unicode characters (§3.1) are translated into a
sequence of input elements (§3.5).
These input elements, with white space (§3.6) and comments (§3.7) dis-
carded, form the terminal symbols for the syntactic grammar for the Java pro-
gramming language and are called tokens (§3.5). These tokens are the identifiers

9
2.3 The Syntactic Grammar GRAMMARS

(§3.8), keywords (§3.9), literals (§3.10), separators (§3.11), and operators (§3.12)
of the Java programming language.

2.3 The Syntactic Grammar

The syntactic grammar for the Java programming language is given in Chapters 4,
6–10, 14, and 15. This grammar has tokens defined by the lexical grammar as its
terminal symbols. It defines a set of productions, starting from the goal symbol
CompilationUnit (§7.3), that describe how sequences of tokens can form syntacti-

FT
cally correct programs.

2.4 Grammar Notation

Terminal symbols are shown in fixed width font in the productions of the lexical
and syntactic grammars, and throughout this specification whenever the text is
directly referring to such a terminal symbol. These are to appear in a program
exactly as written.
RA
Nonterminal symbols are shown in italic type. The definition of a nonterminal
is introduced by the name of the nonterminal being defined followed by a colon.
One or more alternative right-hand sides for the nonterminal then follow on suc-
ceeding lines. For example, the syntactic definition:
IfThenStatement:
if ( Expression ) Statement

states that the nonterminal IfThenStatement represents the token if, followed by a
left parenthesis token, followed by an Expression, followed by a right parenthesis
token, followed by a Statement.
As another example, the syntactic definition:
D

ArgumentList:
Argument
ArgumentList , Argument
states that an ArgumentList may represent either a single Argument or an
ArgumentList, followed by a comma, followed by an Argument. This definition of
ArgumentList is recursive, that is to say, it is defined in terms of itself. The result
is that an ArgumentList may contain any positive number of arguments. Such
recursive definitions of nonterminals are common.
The subscripted suffix “opt”, which may appear after a terminal or nontermi-
nal, indicates an optional symbol. The alternative containing the optional symbol

10
GRAMMARS Grammar Notation 2.4

actually specifies two right-hand sides, one that omits the optional element and
one that includes it.
This means that:
BreakStatement:
break Identifieropt ;

is a convenient abbreviation for:


BreakStatement:
break ;

FT
break Identifier ;

and that:
BasicForStatement:
for ( ForInitopt ; Expressionopt ; ForUpdateopt ) Statement

is a convenient abbreviation for:


BasicForStatement:
for ( ; Expressionopt ; ForUpdateopt ) Statement
for ( ForInit ; Expressionopt ; ForUpdateopt ) Statement
RA
which in turn is an abbreviation for:
BasicForStatement:
for ( ; ; ForUpdateopt ) Statement
for ( ; Expression ; ForUpdateopt ) Statement
for ( ForInit ; ; ForUpdateopt ) Statement
for ( ForInit ; Expression ; ForUpdateopt ) Statement

which in turn is an abbreviation for:


BasicForStatement:
for ( ; ; ) Statement
for ( ; ; ForUpdate ) Statement
D

for ( ; Expression ; ) Statement


for ( ; Expression ; ForUpdate ) Statement
for ( ForInit ; ; ) Statement
for ( ForInit ; ; ForUpdate ) Statement
for ( ForInit ; Expression ; ) Statement
for ( ForInit ; Expression ; ForUpdate ) Statement

so the nonterminal BasicForStatement actually has eight alternative right-hand


sides.
A very long right-hand side may be continued on a second line by substan-
tially indenting this second line, as in:

11
Random documents with unrelated
content Scribd suggests to you:
indent their shores, and they are so connected by rivers that almost
continuous canoeing for scores of miles is sometimes practicable, with only
occasionally a mile or two of portage. In connection with such a multitude of
lakes there are some very interesting geological facts.

In the Muskoka region there are more than one hundred hotels, from the
Royal Muskoka, accommodating three hundred guests, to those of the
simplest, yet entirely comfortable order that can receive only fifteen or
twenty guests with prices often as low as six dollars a week. The month of
September in the Muskoka Lakes is particularly delightful. It is estimated
that there is an annual transient summer population of not less than thirty
thousand every year of people from both the States and the Dominion. Many
of the romantic islands in the lakes are owned by wealthy people who have
built charming summer villas upon them. There are between four and five
hundred of these islands, the largest of which consists of over eleven
hundred acres, and on many of which any one is at liberty to build. The
generous attitude of the Ontario Government is always a fact with which to
reckon. There are very beautiful places in this Muskoka district: the "River
of Shadows" (apparently a subterranean forest, so perfectly is every leaf and
branch mirrored in the water), the Moon River, and the Falls of Bala. It is of
the strange, wild beauty of Muskoka that Lampman wrote:

"When silent shadows darken from the shores,


And all thy swaying fairies over floors
Of luminous water lying strange and bright
Are spinning mists of silver in the moon;
When, out of magic bays,
The yells and demon laughter of the loon
Startle the hills and raise
The solitary echoes far away;

O Spirit of the sunset! in thine hand


This hollow of the forest brims with fire,
And piling high to westward builds a pyre
Of sombre spruces and black pines that stand,
Ragged, and grim, and eaten through with gold.
The arched east grows sweet
With rose and orange, and the night a-cold
Looms, and beneath her feet
Still waters green and purple in strange schemes,
Till twilight wakes the hoot-owl from his dreams."

All these Highlands of Ontario are a part of the vast Laurentian range and
they are characterised by a singular type of rugged and stately beauty. They
are densely wooded; and the luxuriant maples in all their golden-green, that
wonderfully vivid emerald with a hint of gold caught from the sunshine in
the summer, and their brilliant scarlet and amber in the early autumn; the
fragrant balsams; the giant hemlocks; the tall pines that almost lead one to
question George Eliot's assertion that "Care is taken that the trees do not
grow into the sky," for the Canadian pine seems almost to pierce the sky—
all this marvel of forest, with the shining lakes and sunlit glades, renders the
Highlands of Ontario one of the wonders of the world. From Buffalo and
Toronto to North Bay on Lake Nipissing, this entire region is traversed by
the Grand Trunk System carrying summer wanderers through this
enchanting scenery—hills, and lofty peaks, and woods, variegated with the
silver expanse of lakes and flowing rivers; and if, perchance, one is
travelling by night, it is rather delightful to raise the heavy curtain of the
large window of a Pullman sleeper and watch the stars, and the sky, and the
often weird effects of chiaroscuro. They not unfrequently suggest artistic
creations. By night or by day it is all a spellbinding land, the celestial
heavens glittering by night, the sunshine flooding the world with
illumination by day; and silver mists, and ethereal shadows lurk in the deep
pinewoods. To the initiate there are magic guides in all these haunts, unseen
save of him who hath the "spirit-gifted eyes." The light of all the
constellations that have ever looked down on earth since the morning-stars
sang together is in these Canadian skies. For always is it true that

"The Muse can knit


What is past, what is done,
With the web that's just begun."

Not only the romance of Canada, but the tangible realities of her prosperity
are disclosed to the eye of the traveller. Farms in a high state of cultivation;
comfortable, alluring farmhouses, with their lawns, and gardens, and
parterres of flowers, and a rustic seat here and there are in continual
evidence. The refinements of life, from the neatness and grace of rural
homes to the beautiful little railway stations with their attractive architecture,
their plots of greenery, their brilliant beds of flowers, are impressive to the
onlooker, and do more to convey to travellers a true concept of the character
of the Canadian people than can be fully estimated. The gratification of one's
sense of beauty in these charming little way stations along the route adds
immeasurably to the enjoyment of the journey.

Then, too, what can be said of that sail among the thirty thousand islands
in the Georgian Bay? In colour and idyllic charm this sail rivals the famous
cruise among the Ionian Islands:

"The Isles of Greece, the Isles of Greece,


Where burning Sappho loved and sung,"

and all the summer resorts of this region, Minnecoganashene, Sans Souci,
Rose Point, and various nooks of verdant charm are peopled by their
summer lovers.

The Great Lakes, shared alike by the Dominion and the States, offer a
delightful cruise between Sarnia (Ontario) and Duluth (Minnesota) with calls
at Fort William and Port Arthur, and a further excursion to the Falls of
Kakabeka, a cascade higher than that of Niagara, which are near Port Arthur.

Lake Nipissing and the French River are attractive grounds for the
camper and the canoeist; but they are not suited to the "tenderfoot." It is
amazing that a region which can be reached with ease is yet so absolutely a
place where the lover of Nature in her wild solitudes can absolutely secure a
vacation from relentless Time! In the Lake Nipissing land he may elude the
postman and the telephone. Doubtless by 1920, some invading airship will
drop a voluminous mail at his feet when he is out in his canoe; but at the
present time the sojourner here is immune from cables, telegrams,
Marconigrams, long-distance telephones, special deliveries, messenger boys,
and all this incubus of what we call civilisation. If radiograms fall upon him
they must needs come from the solar system alone. Emerson, even in the
prehistoric period of the nineteenth century, declared solitude a thing
impossible to find.
"When I would spend a lonely day
Sun and moon are in my way,"

he complains. The lingerer camping out on the French River has no green-
shaded electric reading-lamp at his elbow; no electric bell summons his
servitor. He "catches" his breakfast in the deep waters of the lake; he
concocts his matutinal coffee over a camp-fire. No ingenious victrola
enchants his evening with the lyric melody of Melba or Caruso; but instead,
the strange cry of the loon echoes startlingly through the silences. And so it
falls out that the hardy devotees of the chase and the camp hail this region as
their El Dorado.

Unlike the Nipissing, Timagami, as before noted, may be considered to


be the earthly paradise of those to whom the necessities of life consist in the
modern luxuries; those who would quite sympathise with John Lothrop
Motley; who remarked that if he had the luxuries of life he could get on very
well without the necessities.

Nibigami, "country of lakes," is a new outing ground in Canada now


made accessible by the Canadian Government Railways; and all this hitherto
unknown wilderness is enlisting the devotion of thousands of hunters, of
fishermen, and hardly less of the artist and student.

Three hours east of Winnipeg is Minaki, the "Beautiful Country" of the


Indians, at which station passengers may disembark to step into a steam
launch for a sail of twenty minutes to Minaki Inn. This is a large and
charmingly appointed hotel, accommodating three hundred and fifty guests,
with its annex, Minaki Lodge, affording rooms for seventy-five in addition,
located in a natural park of fourteen acres, every room having its own
outlook over lakes or woodlands. With its spacious piazzas, its artistic
furnishing, its admirable management, it is little wonder that the Minaki Inn
has leapt into popular favour, not only for season guests, but also for
travellers en route for the Canadian Rockies, for Jasper and Mount Robson
Parks, or Prince Rupert, and for all those who find the Minaki a restful place
at which to break the journey. The hotel is woodland embowered and lake
mirrored. It is supremely comfortable.
Around the lakes on which the Inn is placed is a large and constantly
increasing number of cottages, very artistic in architectural detail, built by
wealthy people of Winnipeg and elsewhere for their summer homes. They
are by no means primitive in construction; the latest devices in heating,
lighting, and household conveniences as well as luxurious furnishings are in
evidence; and at night from the piazzas and balconies of the hotel the circle
of these friendly illuminations around the lakes is fascinating to the gazer.

View in Jasper Park

Jasper Park, lying west of Edmonton, in the foothills of the Rockies, is


another National reservation included among the Playgrounds of Canada;
and it has an area half as large as that of the kingdom of Belgium,
comprising some 4400 square miles. The Government will keep this in its
natural state for all future time, so that, as the country becomes more settled,
and the features peculiarly Canadian become obliterated, Jasper Park may
reveal to coming generations the nature of the primæval wilderness. Jasper
Park is invested with historic interest, as it was the scene of the fierce
commercial conflicts between the Hudson's Bay and the North-West Trading
Companies. It is also rich in Indian legend and tradition.

Jasper Park is, however, not filled with game as is Algonquin. It is said
that a century ago it teemed with bear, mink, beaver, elk, and caribou—but
since that time the resident Indians have devastated the animal life; and
when they learned that the Dominion was about to take over the entire tract
for a permanent reservation, they embarked upon a wholesale slaughter of
the animals. The Park is now made by Government decree a safe and
friendly region for the wild game, and it is thus confidently hoped to
gradually increase the animal life of the preserve.

The flora of the Park is so varied and so unusual as to make it an


important locality to the botanist. Not only is there an infinite variety of
flowers, many of which are not found elsewhere on the continent, the
aquilegia, the mampanula, the moon-daisy, and endless variations on the
chrysanthemum; but also the strange grasses, mosses, lichens, and curious
shrubs, all combine to enlist and hold the curiosity of the student of nature.

The steel highway has brought this Alpine region, on the western border
of Alberta, into easy and swift connection with the travelling world. Already
the Grand Trunk Pacific is projecting hotels of the same exceptional
character as those with which Algonquin Park is so well provided. At present
there is the unique feature of a "tent city," which renders a sojourn of any
length one that is entirely comfortable and provisioned with the amenities of
life. It is one to rather enhance, indeed, the ordinary experiences of travel.
The sleeping tents (as separate as rooms in an hotel) are all fitted with board
floors and are equipped with comfortable beds and every convenience. There
is a large central marquee for the dining-room, and all this comfort, to say
nothing of glories of scenery undreamed of, is offered at the almost nominal
rate of two and a half dollars a day. The town site commands a magnificent
view of Athabasca Valley. The Athabasca river expands, at intervals, into
lakes, of which Brule Lake, Jasper Lake, and Fish Lake are notable. At the
juncture of the Athabasca and the Maligne rivers stood formerly the
headquarters of the North-Western Fur Company; while the old Jasper
House, the Hudson's Bay Company's post, now in ruins, was in close
proximity. The site is now defined only by a pile of stones and by several
graves, with mouldering crosses, that suggest the close of the drama of
earthly life for those who lived and toiled here, unconsciously aiding to build
up the future. The very atmosphere is pervaded by a sense of heroic effort.

One of the delightful excursions for sylvan wanderers is that of the trail to
Maligne Lake, a beautiful sheet of water some thirty miles distant; and in
Maligne Canyon, only eight miles from Jasper, are two comfortable shelter-
houses for the free use of all tourists; each house divided into three parts,
with one large room for ladies, one for gentlemen, and a central hall fitted
with a range and other conveniences, where impromptu cooking may be
conducted with successful results. These shelter-houses provide one more
illustration of the way in which the tourist is safe-guarded all over the
Dominion, even in what would seem her most impenetrable localities. So
swiftly are modern conditions of comfort on their winged way that the
refinements of life fairly spring up in the wilderness and almost every
conceivable need or requirement of the traveller is anticipated.

The Canadian summer resorts are destined to play an important part in


sociology. They attract sojourners from widely separated localities and
promote interchange of views, of valuable knowledge, of ideas, of
sympathies, that form an interchange of the utmost significance in its
influence and determining effect upon the general international life. The
summer allurements of the Dominion are to be increasingly appreciated by
the civilised world, as they open up new realms teeming with new
inspirations.

The beauty of Banff and Lake Louise is already known to the tourist, but
it is, rather especially, the wonderful region opened to travel by the
extensions of the Grand Trunk System that is so unusually spellbinding. The
grandeur of these majestic mountain-peaks; the valleys and plateaus amid
the gleam of lake and river; the brilliant foliage; the rich scheme of colour of
purple and vermilion cliffs; the glint of blue waters through overarching
trees—Ah! Land of the Maple Leaf, how fair is thy heritage!
CHAPTER VI

COBALT AND THE SILVER MINES

The famous Cobalt Silver Mines naturally focus the interest of the
capitalist and the financier in any tour across the great Dominion. While
British Columbia and the Yukon have been called the "Wonderland" of
Canada, not alone for their mineral possibilities, but for a great wealth of
other natural resources besides, and because many millions of dollars have
been extracted by placer miners from rivers and streams, yet Ontario is
found to exceed all other provinces, so far as yet developed, in the volume of
mineral production. The Klondyke gold discoveries in the Canadian Yukon
became a romance which has fairly rivalled the Tale of the Golden Fleece.
Yet when in the year 1903 the copious and apparently unmeasurable deposits
of silver-cobalt ores containing an extraordinarily high percentage of silver
were discovered in the district of Cobalt (not far to the west from Lake
Temiskaming), this event sent a thrill of sensation through the world of
mining and mineral interests that left little to exceed, in romantic ardour, in
the poetic legends of the Yukon:

"Steeped in eternal beauty, crystalline waters and woods."


Cobalt, Ontario

Since the discovery of silver in 1903, Cobalt has produced $130,000,000


worth of the white metal. Dividends totalling over $60,000,000 have been
paid to shareholders of twenty-four mines. One company alone has
distributed among its shareholders in dividends nearly $15,000,000.

In some of the Cobalt mines the ores that contained such phenomenal
quantities of silver have been depleted, and ores of lower grade are now
being worked, so that a much larger mass of ore, more machinery, and a
larger force of working-men are now required to produce the same amount
of silver.

The geological intervention of radioactivity is believed by physicists to


have a determining influence upon the development of subterranean
resources as well as upon the surface features of the earth and the formation
of mountain chains. Vitality is another ever-increasing phenomenon, but the
bewildering abundance of life that confronts the student of nature is no more
inciting to research than the mystery of metals deposited far in the ground.
The natural resources of Canada are so vast that even yet, as Dr. W. J. A.
Donald asserts, "the greater part of three million six hundred thousand
square miles of the Dominion is still terra incognita as regards its mineral
resources, or even its geological features."

During the present war all enterprises are, more or less, and, indeed,
largely, in abeyance in the Dominion; but the present is always compact of
the future, nor can any strictly dividing line be drawn. "Even in the midst of
the greatest tragedies," said Sir Clifford Sifton in his address before the
Canadian Club of Montreal on January 25, 1915, "while we are trying to do
our duty in the greatest crisis of life, we still must speak, act, think, and do in
reference to the ordinary affairs of life; and the better we think and act and
do in regard to these affairs, the better we shall act in these crises and the
better we shall discharge our duty." Canada will never be numbered with
those nations regarding whom the words were said of old, "Where there is
no vision the people perish."

There is no lack of vision in the Dominion. The splendid loyalty of


Canada, not only to the Empire, but to the cause of righteousness, is beyond
all estimate in words; as the Right Honourable Sir Robert L. Borden has so
finely expressed, there can be only one conclusion regarding the present
tragedy of conflict. "To overthrow the most powerful and highly organised
system of militarism that ever existed must necessarily entail terrible war
and perhaps a protracted struggle. We have not glorified war or sought to
depart from the paths of peace; but our hearts are firm and united in an
inflexible determination that the cause for which we have drawn the sword
shall be maintained to an honourable and triumphant issue."

This is the spirit of the Dominion. But all conflicts must have an end, and
when the end of this struggle comes there is a marvellous future awaiting the
Dominion. The future of a nation as well as that of an individual is not
merely, nor even mostly, to be mechanically surveyed. It is not a definite
geographical region with boundaries that can be located and crossed with a
clear knowledge of the line of demarcation. The future is something that is
created by men's thoughts. It is made, not found; it is constructed, not
discovered. And thus, even while all internal industries are somewhat in the
grasp of an enforced pause, yet new plans and projects for the future are in
order. The mineral resources of Canada are incalculable. But that they will
form one of the most remarkable factors in her future prosperity and
importance is a practicable certainty.

It was somewhere as early as 1846 that the veins of silver were


discovered in the region adjacent to Port Arthur on Lake Superior; and
twenty years later that ore was actively producing silver which it continued
to do until 1903. On a small island, near Thunder Cape (known as the Silver
Islet), was the most famous and the richest of these mines, and the ore,
interlined with veins of quartz and carbonates, was found in a wide area. It
traversed a large belt of diabase, and only where the vein transversed the
diabase was it richly infused with silver. Otherwise, it bore galena alone. As
early as 1884 the mine had carried to a level of nearly two thousand feet, and
it was estimated that not less than three million two hundred and fifty
thousand dollars worth of silver had been extracted from it.

When the Cobalt silver mines began to be worked, Canada took her place
as the third silver-producing country in the world; and this distinction must
be largely attributed to the richness and copious output of these particular
veins.

Cobalt is about 330 miles north of Toronto, on the Ontario Government


Railway, and four hours south of Cochrane. At Cobalt the mines are
clustered all around and beneath the town, a lake in the centre having been
drained to facilitate the search for ore. To the south-east these mines are
distributed over a distance of four miles. While the Cobalt silver district
proper is comprised within this area, other mines, and productive ones too,
have been found in the farther outlying country. London is the chief silver
market of the world. Much of the bullion shipped from Cobalt is sent
directly there, and London is also the basing point of prices.

The vast mills of Cobalt, transforming the crude ore into bullion, and the
hydraulic plant on the top of a hill, where one man manipulates power
sufficient to wash down huge rocks and to uproot and send down large trees
and stumps, open out to the uninitiate a new idea of the way in which man
contrives to control Nature and force her to do his bidding.
At Cobalt the "silver sidewalk" is not only an actual and visible spectacle,
a solid surface on the level ground of shining silver from one to three feet in
extent, but it is an indication of untold possibilities. Still, up to this time, the
richness of the veins has been found to be rather in their number than their
depth. These deposits are found in association with the pre-Cambrian rocks
which, according to the geologists, belong to the Huronian and the Keewatin
formations, through which a later diabase has been intruded in the form of a
sill. This is not held to be necessarily the source of the ore deposits, but
rather the means of opening the way for their introduction from other
sources. A large majority of the productive veins, some eighty per cent., in
fact, occur solely in the Huronian formation. The remaining twenty per cent.
is divided between the Keewatin and the later diabase. As has been said
above, these deposits are not especially deep, most of them being found
below the sill within a depth of two hundred feet. The ores from all the
Cobalt region include white arsenic, cobalt oxide, and nickel oxide, as well
as the fine silver, and not infrequently a semi-refined mixture of the cobalt
and nickel oxides.

If silver were the magnet that first drew the attention of the miner, the
prospector, or the capitalist to Cobalt, it is not the only encouragement to the
settlement of all this beautiful region. A few miles out from Cobalt is the
pretty suburb of New Liskeard on a sheet of the bluest water, sparkling in the
sunshine and the transparent air; where numbers of artistically designed
cottages have sprung up; where the business street reveals a thriving trade;
where one or two newspapers are published; and where the seeker after the
occult may find his palmist and his mental healer as well as his dentist and
his physician. Electric cars connect this idyllic little village with Cobalt, and
motor cars dart about in a way which suggests that this region is by no
means outside of the cosmopolitan luxuries of life. The country is one of
great scientific interest. The geologist may find new data; the botanist and
ornithologist new fields for observation.

Cobalt is recognised as a permanent silver camp, and as one of the richest


on the entire American continent. At first the stories told of silver paths,
brilliant and shining in the sunshine, were regarded as part and parcel of the
usual myths that spring up in mining camps. But the "silver sidewalks" were
there. They were the most palpable of facts. A hundred miles to the north of
the town of Cobalt, on Porcupine Creek, the prospectors found gold.
Specimens of the alluring yellow ore may be seen in glass cases in the
corridor of the King Edward Hotel, Toronto. In that city many of the miners
may be met, for mining is now a scientific pursuit rather than merely an
industry, and whether the miner takes his ease in cosmopolitan centres and
gives his mines "absent treatment," after the convenient fashion of Christian
Scientists, or whether he is less remote from his interests, does not seem to
affect the results in a vital manner.

During the year 1915 thirteen mines in Northern Ontario produced gold,
and many of these are now making alterations and additions to their plants
which will enable them to largely increase their output.

The following table shows the steady advance of the Porcupine gold
camp since its discovery in 1910:—

Value of
Year Production
$
1910 35,539
1911 17,187
1912 1,730,628
1913 4,284,928
1914 5,203,229
1915 7,580,766
----------
Total 18,852,277

To find this possibly incalculable wealth in the densely wooded


wilderness is a continually increasing surprise. The Porcupine district, as
well as the Cobalt region, is reached by the Temiskaming and Northern
Ontario Railway, a line of two hundred miles in length, built by the Province
of Ontario, and furnishing connection between the Transcontinental line
from Quebec to Winnipeg, north of the lakes, and the cities in the southern
portion of the provinces of Ontario and Quebec. The construction of this
connecting line led to the discovery of Lake Timagami (one of the popular
summer resorts), and about thirty miles north of the lake the first indication
of silver was accidently found by a workman who hurled his hammer at a
scampering rabbit and hit a rock instead, chipping off a layer that disclosed a
vein of almost pure silver. This initiated the famous La Rose mine, taking its
name from the man who made this fortunate throw of his hammer, and
within the succeeding four years this immediate region was capitalised at
some five hundred millions. While the Cobalt silver mines, then, owe their
discovery to this employee on the line, the engineers prospecting for the
grade of the Grand Trunk Pacific accidentally uncovered vast coal-fields in
Alberta.

This Temiskaming and Northern Ontario Railway connects the Grand


Trunk System at North Bay with the Canadian Government lines at
Cochrane. The opening up of all this country has not only resulted in the
exploiting of these famous mines, but has brought to knowledge the
existence of the largest tract of pulpwood in the world. The belt of these
forests extends from Ontario to Quebec and westward to the prairies of
Manitoba, a thousand miles of almost unbroken woodland.

The hydraulic mechanism used in prospecting for ore is one of the


marvels of inventive genius. One man can operate the powerful lever that
turns on a torrent of water against trees, huge stumps, vast rocks, and sends
them rolling down the hillside. All obstruction, indeed, the very hill itself, is
washed down. The twentieth century will always stand out as a remarkable
era for the invention of mechanism to harness and utilise power hitherto
undreamt of for practical application. These inventions are securing the
increasing spiritual liberation of man. When he is enabled to harness the
powers of the ether; to send the lightning on his errands; to bridle a force
that no man ever saw or touched; when he can cause the waves of the ether
to serve his chariot wheels, he has indeed transformed the world in which he
finds himself.

There are rumours of a recent invention made by Mr. Asa Thurston


Heydon in the Yukon that may largely revolutionise the mining industry. It
was in the middle 'eighties that Mr. Heydon began studying the primitive
divining-rod, the use of which he was inclined to believe was based upon
some germs of scientific truth. He thought it possible that some natural law
lay hidden in the garments of superstition. For thirty years he experimented
and observed. This research has led him to what he believes is a series of
discoveries, one of which is his invention called the clairoscope, which is the
diviner for substances that are in the earth. Fitted with one or another
substance attached, it turns to that which corresponds with the given thing
attached. He calls the instrument the clairoscope and the result obtained the
clairum. The clairum, Mr. Heydon explains, is the counterpart of the
spectrum. The latter is limited to the luminous, the former to the non-
luminous, rays. The spectrum exemplifies one pole of the spherical
organisation of energy, and the clairum exemplifies the opposite pole. Mr.
Heydon's researches are based on his conviction that everything, organic and
inorganic, from electrons to the mighty universe itself, is surrounded by a
sphere; that these spheres blend and combine "in accordance with the laws
of force-centres," but that in all combinations "they retain their identity as do
rays of light." This interesting speculator holds that the non-luminous rays
are constant, changing only from attraction to repulsion, and that they are the
radii of the spheres. He believes that the distinctive energy that operates the
clairoscope is a higher dynamic energy; nothing less, indeed, than that vital
force which is characteristic of all life. "A name must be found," he says,
"for this vital force which is rhythmically circulating throughout the
universe, forming the pulse of existence. The dream of the alchemist is
founded in the nature of things," continues Mr. Heydon, "and will be realised
when mankind shall have discovered the simple process of polarising and
depolarising electrons at will. This will induce the polarisation of the
correlated material sphere, and an electron of the desired element will
awaken from its slumbers."
To what degree Mr. Heydon's theories will bear the test of his future
investigations it is impossible to conjecture; but it is already true that the
clairoscope is being used to some extent to locate minerals and has proved
useful.

To descend into a mine, down to a three hundred and fifty feet level, and
see the strange panorama of life that is before one's eyes, is a novel
experience. Into the cage steps the little party, and the downward journey
begins. All is dark save for the lamps of the miners, affixed to their caps, and
the lights that are swung give a fitful and weird illumination. Through the
narrow aisles on every level push-carts are passing, and the visitor must pack
himself into as little space as possible as he stands against the wall to let the
traffic pass by. Everything is dripping; one walks in mud and water, and sees
the glisten of the wet walls. The air is cold and damp. It seems inconceivable
that men can work under such conditions, yet the visitor is assured by some
of the workmen themselves that they prefer this labour to any of the
employments open to them on the surface of the earth. This subterranean
world incites curiosity, interest, and still the onlooker is not sorry when he
finds himself again in the air and sunlight above.

On the hills about Cobalt are perched attractive cottages and bungalows,
and the quiet, pleasantly social little town bears no trace of the traditional
atmosphere of the mining-camp of that peculiar order that has been most
vividly derived from the pictures in the novels of Bret Harte.

CHAPTER VII

WINNIPEG AND EDMONTON

The traveller whose imagination had vaguely pictured Winnipeg as a fur-


trading station somewhere toward the North Pole would be aroused from
such reveries by the spectacle of this brilliant and cosmopolitan centre, with
its beautiful architecture, its broad boulevards, the magnificent Fort Garry
Hotel on the site of the ancient fort, and the civic centre in the Free
Exposition building, where specimens of all the great products of the
Canadian West are displayed. Winnipeg, which in 1870 had a population of
two hundred and fifteen people, in 1917 records its quarter of a million. It
grows at such a rate that it is unsafe to prophesy to what degree these figures
may be increased in the immediate future. A representative of Baedeker, who
had been sent to the United States to prepare a volume on its western
regions, complained to a fellow-voyager on the ocean steamer, when
returning to his own country, that it was mathematically impossible to cope
with the Far West with any accuracy. "Why, I prepare the exact population of
a town—Seattle, for instance—and before I can get my report into print the
population has doubled." This was naturally a tangible grievance, and one
which was extremely difficult for the statistician to meet. Possibly the same
baffling problem of accuracy confronts him who would record the
population of Winnipeg.

From the tower of the Fort Garry Hotel there is revealed a scene hardly to
be compared with any other on the continent. The spectator can see broad
boulevards, many of which are a hundred and thirty-two feet in width; an
electric railway, operating hundreds of cars, whose service is said to be the
most perfect of that of any city in the States or in Canada; streets paved with
asphalt and macadam; extensive parks, where equipages not less fine than
those of Hyde Park or the Bois de Boulogne, are seen rolling along the
smooth, winding roads; churches, numbering nearly two hundred; the
University of Manitoba; the art school; and the unexcelled beauty of miles of
residential regions, laid out in those graceful curves and crescents so familiar
in the West End of London—all these are indicated in this great centre of
commercial, industrial, and social life.

To those who had thought of Winnipeg as being remote, if not


inaccessible, it is rather surprising to find that this metropolis of Western
Canada is but twenty-seven hours from Chicago and but forty-five hours
from Washington. At the time of the Chicago Exposition of 1893, one of the
most popular routes between Boston and that city was through the Hoosac
tunnel, on which the passenger boarded his train in Boston at seven P.M.,
and arrived in Chicago at seven the second morning after—a journey of
thirty-six hours, which no one at that time regarded as being too long. Nor
does it require the memory of that traditional being, the "oldest inhabitant,"
to recall that when the Pennsylvania Railroad succeeded in reducing the time
between New York and Chicago to twenty-five hours, it was then held to be
much more of a marvel than is now the eighteen-hours' journey of the
Twentieth-Century Flyer. Winnipeg is forty-eight hours from Montreal, fifty-
three from Quebec, and only forty-five from New York. No city on the
western continent is more splendidly equipped than Winnipeg for business
enterprises, great conventions, and large convocations of all orders. Besides
the spacious and superb Fort Garry Hotel, she has more than fifty other
guest-houses and one of the largest departmental stores on the continent; she
has parks covering more than five hundred acres; she has more than twenty
banks; and in a single year these banks did a business of almost one billion
seven hundred million dollars. All the grain business of the Canadian West
centres in Winnipeg. In the magnificent Union Station of white marble,
costing some two millions of dollars, there are twenty-seven railway tracks,
long distance and local, all of which radiate from the city. The Winnipeg
River offers unmeasured facilities for power, a total of sixty thousand horse-
power being already developed, which is sold to manufacturers and other
consumers at the cost of production. There are over four hundred successful
factory plants in operation, employing twenty thousand factory workers.
Thus told in bald statistics alone, the story of Winnipeg is singularly
impressive; but these facts and figures are but the mere skeleton of the story
of Winnipeg. In this northern metropolis the polarity of life in general is
changed.
Union Station and Fort Garry Hotel, Winnipeg

A signal aim in this city is the culture of beauty. In the laying out of
streets and avenues the question of vista and the composition, so to speak, of
the landscape has received unfailing consideration. All the country about is
finely wooded, and with its rolling declivities offers cool and shaded nooks
and spaces for summer outings. Here and there are lofty elms, and
occasional wooded areas of many acres in extent. These are a surprise to the
traveller whose conceptions of this region have been those of a bare and
more or less desolate prairie land. The nature of the soil of the
neighbourhood is a factor of determining importance. The clay belt begins at
Cochrane, the junction of the Transcontinental line with the Ontario
Government Railway, and it extends for three hundred miles to the west,
affording a tract with plentiful water and with every productive condition.
The provision of population for this clay belt is now a foremost question in
Canada and engages the attention of both the Province of Ontario and of the
Transcontinental Railway. The generation that cleared the bush lands has
almost passed away, and the present settlers have different ideas of pioneer
life. One age does not repeat itself. The continual invention of machinery
that liberates human life has its dominating influence, and all signs of the
times point to new methods of entering on new settlements. The British
settlers who arrive are not accustomed to the clearing of timber-lands, yet
this clay belt has probably resources to sustain a population of from one to
two million people, and the climate is no more severe than that of Quebec or
of northern Maine. The transformation of this region of wilderness into a
well-populated country would provide a much-needed link between Eastern
and Western Canada. The distances, as we have seen, between Winnipeg and
other of the great centres both in the Dominion and in the United States are
by no means appalling; and with the splendid railway facilities now provided
by the new Trans-continental route between Winnipeg, Toronto, and
Montreal, by way of Cochrane, Cobalt, and North Bay, across New Ontario,
and through the Highlands of the same Province, a route that only opened on
July 13, 1915, this region is abounding in attractions for the new settler.

There are two sources of revenue which are of unmeasured value; one is
that of pulpwood which can be advantageously disposed of, and the other
that of employment in constructing government roads. Another inducement
will be that of the "ready-made farm." This scheme has been utilised to some
extent in Alberta and in New Brunswick as an inducement to colonists.
Thousands of these farms, on which buildings have been erected and a small
area placed under cultivation, with stock and farming implements furnished,
have been placed at the disposal of settlers, each for a small cash payment,
and with the conditions of subsequent payments made most liberal and
lenient. In Ontario the scheme has not yet been worked out in detail; but the
government of the Province is favourable toward adopting a similar system,
building a house and barn and clearing ten acres on a farm of a hundred and
sixty acres, as well as advancing a limited sum of money for the purchase of
stock. The Ontario government also propose arrangements for assisting the
farmer in marketing his pulpwood.

All these conditions of the surrounding country are of vital importance to


the city of Winnipeg. The settlement of wild lands, the development of
industrial resources, centres of population springing up in new sections—all
these directly contribute to the growth and importance of the metropolitan
centre. The civilisation of Canada has proceeded more rapidly in the
transformation of the wilderness into populated lands than did that of the
western part of the United States. Four years after the formation of the
Dominion (July 1, 1867) Canada had extended across the entire continent.
By the conditions of the time, both in applied inventions and in the degree of
progress achieved by man, Canada has escaped the disadvantage that the
long efforts of pioneer life entail upon a nation. The new towns and cities
begin with well-paved streets, electric lighting, and electric transit.

Winnipeg, since 1899, has owned and operated its own water system,
which is the hydro-electric power plant. The architecture is largely of a
permanent nature, the designs following the latest developments of taste,
skill, and efficient construction. Much of it compares favourably with the
best architecture of New York or Washington. The blocks of handsome
residences; the architectural taste of the public buildings; and the constant
series of lawns, with their flowers and plants, leafy shrubs and luxuriant
trees, make the city one of exceeding beauty and attractiveness. Churches,
schools (and they are among the best in Canada), theatres, and lecture halls
abound; the libraries are particularly enlightened and helpful and their
growth and extension are only comparable with the library developments of
St. Paul and Minneapolis, of Los Angeles and other young cities of the most
advanced degrees of progress. "The world of books is still the world," wrote
Mrs. Browning; and the community that renews its resources from the best
that has been thought and said in the world, as it is conserved in literature,
will be that which is the more efficient in all that makes for human
advancement. Familiarity with the best literature has the most potent of
influences for good taste, good manners, high ideals of conduct, mutual
courtesy, and self-respect.

Canada cannot afford to ignore Matthew Arnold's wise warning not to


mistake material achievement for civilisation. In its true and full
significance, civilisation means "the humanisation of man in society; his
making progress there towards his true and full humanity. We hear a nation
called highly civilised," Mr. Arnold proceeds to say, "by reason of its
industry, commerce, and wealth, or by reason of its liberty or equality, or by
reason of its numerous churches, schools, libraries, and newspapers. But
there is something in human nature, some instinct of growth, some law of
perfection, which rebels against this narrow account of the matter. Do not
tell me, says human nature, of the magnitude of your industry and
commerce; of the beneficence of your institutions, your freedom, your
equality; of the great and growing number of your churches and schools,
libraries and newspapers; tell me also if your civilisation—which is the
grand name you give to all this development—tell me if your civilisation is
interesting."

Carlyle, as Matthew Arnold reminds us, once wrote to a younger brother


who thought of emigrating to the United States: "Could you banish yourself
from all that is interesting to your mind, forget the history, the glorious
institutions, the noble principles of old Scotland—that you might eat a better
dinner, perhaps?"

Mr. Arnold hastens to disclaim any sympathy with the idea that young
men should not emigrate; it was the term "interesting" that caught his eye in
Carlyle's counsel, and it is for that element that he makes his eloquent plea.
It is that element, moreover, which the young and splendid city of Winnipeg
may well reckon as one of its fundamental characteristics. In the Journal
Intime of M. Amiel, the reader finds him saying that "the human heart is, as
it were, haunted by confused reminiscences of an age of gold; or, rather, by
aspirations toward a harmony of things which every-day reality denies to
us." In all the appointments of wealth and luxury, M. Amiel made an effort
to realise or to approach this ideal, and thus finds in this order of life one
form of poetry. Society demands distinction and beauty as a component part
of human nature's daily food.

Obviously, a new country cannot offer archives of long centuries of


history, nor ruined castles, nor an assortment of myth and tradition. These
may and do have their part in that atmosphere of interest which is the nurture
of the intellectual powers; but the Future is no less stimulating than the Past;
prophecy is not less alluring than history. The art of life itself is the finest of
all the fine arts and to the seeing eye may invest a city with as much
fascination as is to be derived from the galleries of the Louvre or of the
Vatican. The spiritual life of all the ages is preserved in libraries, and the
youngest of cities may well be heir to the records of this life. "No matter
how poor I am," said William Ellery Channing; "no matter though the
prosperous of my own time will not enter my obscure dwelling—if the
sacred virtues will enter and take up their abode under my roof; if Milton
will sing of Paradise; and Shakespeare open to me the worlds of imagination
and the workings of the human heart; if Franklin will enrich me with his
practical wisdom—I shall not pine for intellectual companionship, and I may
become a cultivated man, though excluded from what is called the best
society in the place where I live."

It is not only noble art and beautiful architecture combined with historic
and social traditions that appeal to all that is best in life. What could more
readily appeal to the imagination than that visible expression of faith in the
future of the Great Dominion, the completion of a new great transcontinental
line making possible direct transit across Canada from ocean to ocean? What
could more appeal to the imagination than the marvellous invention of the
wireless control of moving trains as has been already described in a previous
chapter?

What can, indeed, be a feature of greater interest than the practical


creation of a new world; the power of man conquering and transforming the
domain of Nature? Do not Romance and Poetry spring up here anew?
Science and the Muses have a subtle basis of understanding. James Russell
Lowell has interpreted this mutual comprehension in the lines:

"He who first stretched his nerves of subtle wire


Over the land and through the sea-depths still,
Thought only of the flame-winged messenger
As a dull drudge that should encircle earth
With sordid messages of Trade, and tame
Blithe Ariel to a bagman. But the Muse
Not long will be defrauded. From her foe
Her misused wand she snatches; at a touch
The Age of Wonder is renewed again,
And to our disenchanted deity restores
The Shoes of Swiftness that gave odds to Thought;
The Cloak that makes invisible; and with these
I glide an airy fire from shore to shore."
Winnipeg has an interesting centre in the Industrial Bureau and
permanent Exposition and Public Service Building, located in the leading
business street and contributing in many ways to the swiftest means of
unfolding industrial opportunities and to the most liberal development of the
city. Both the Dominion and the Province of Manitoba, beside all the
railways centering in Winnipeg and thirty western Boards of Trade, have
installed attractive and extensive exhibits of the natural resources, so
extensive, indeed, as to be practically complete in their revelation to the
visitor of every variety and quality of the country. The manufacturing
interests of the city are represented by eighty-five practical exhibits of
articles "made in Winnipeg." There is also a museum with a large collection
of mounted birds and wild animals of Canada; and there are historic relics
and curios; as well as collections of economic minerals and other exhibits of
various interest. Winnipeg has also, in this building, the first Civic Art
Gallery in Canada, and it is wisely made free to all. In connection with the
Gallery is an Art School where painting and drawing are taught. In this
Public Service centre is a Convention Hall that will seat four thousand
people and a smaller lecture or banquet hall seating about four hundred.
There are also other accommodations for meetings, large or small
gatherings, as may be, that are so numerous in business, social, industrial, or
educational activities. Over seven hundred meetings were held in this
building within the first ten months after it was opened. Adjoining
Convention Hall is the Central Farmers' Market, where citizens conveniently
find the produce of farm, market, or garden. The Industrial Bureau, which
has its quarters in this building, is a thoroughly representative one,
incorporated under Provincial Government Charter, with a directorate
elected from appointed representatives of twenty-nine public bodies of the
city, grouping together the best talent, administrative, professional,
educational, and industrial, which could be brought together for the work of
public service. The Bureau organisation is non-partisan, non-sectarian, and
has no axe to grind other than that which concerns the benefit of the whole
community. It is the Civic Bureau of Information for citizens, visitors, and
outside inquirers.

The Fort Garry Hotel is a social centre of Winnipeg. Its imposing


architectural effects render it a landmark in the panoramic view of the city.
Its walls, of buff sandstone, rise to a height of fourteen stories, and the
copper roof and lofty pinnacles are transformed to molten gold when the sun
shines on them. The majestic structure is an adaptation from the period of
François I., with something reminiscent of the old chateau in Touraine and
Normandy. In the standards of elegance and beauty in all entertainments,
these Grand Trunk hostelries—the Château Laurier, the Fort Garry, the
Macdonald of Edmonton—all introduce standards of polite life that are of
incalculable benefit to the community and which have hardly before been
approached in the Dominion. In elegance and refinement, both of
appointments and of service, these hotels rival, if indeed they do not almost
excel, the choicest luxuriance and beauty of Paris and New York. One block
to the east of the Fort Garry is the magnificent Union Station in which the
Canadian Northern and Grand Trunk Pacific centre, and which has every
convenience and device up to date; and between the station and the Fort
Garry Hotel is a wide boulevard with a double row of trees in the centre, and
a little park, under the very shadow of the house, has its picturesque
approach through the ivy-clad ruins of the old gateway to the fort; an historic
reminder of the time when, a century ago, this entrance was built by the
Hudson's Bay Company in a turbulent period. The contrast between the
sense of peaceful though intense activity, under the brilliant sunshine over
the broad, beautiful streets, whose smooth pavement is a joy to motorists,
with that time when savage assaults must be defended by the forces within
Fort Garry, is a contrast to incite a train of speculative reflection. There were
"sceptred spirits" in those days whose heroic deeds shine through all the
years between their time and our own. The history of the Hudson's Bay
Company is, in itself, one of the most thrilling chronicles of the Dominion.

From the windows and balconies of the Fort Garry Hotel the view is
magnificent—St. Boniface, with its splendid cathedral group, Assiniboine
Park, and the Legislative Buildings, with two rivers winding away into the
vast spaces of the prairie—all make up a panorama never to be forgotten.
The interior of this alluring house is singularly charming to the eye. The
furnishings are rich and yet have that air of simplicity that appeals to the
artistic sense—grey marble floors with soft rugs and the main dining-room
all in cream and gold. The foyer and loggia connecting the banquet and ball
rooms suggest the ancient cloister with their vaulted ceilings and the
mediæval lanterns for electric lights. The café has marble wainscoting,
suggestive of some old baronial castle, while in the grillroom there is oak
panelling that would delight old England. There are three hundred rooms,
two hundred and thirty-five of which have private baths while the others
have easy access to bathrooms. What a contrast of living is thus revealed
between the fastidious and luxurious life of the twentieth century and that of
the primitive days of a hundred years ago when the old Fort Garry occupied
the site of this hotel!

For fully fifty miles west of Winnipeg extends a belt of land some 300
miles in width, provided with good water found at reasonable depths, which
is the marvel of the world for grain raising. This Red River Valley is the
great wheat-producing region of the continent, and the journey of nearly
eight hundred miles from Winnipeg to Edmonton reveals vast fields of
golden grain, while along the route the colossal elevators loom up in the
level expanse like some colossal fortifications.

Winnipeg has been from the first a predestined centre of commerce. It is


the metropolis of the transcontinental lines and is the one supreme gateway
through which all travellers and all traffic from ocean to ocean must pass.
No other city on the western continent has such an absolute monopoly of all
transit from the east to the west, or the reverse.

Edmonton, the capital of Alberta, most attractive in its beauty of locality,


stands on the bold bluffs of the Saskatchewan. The railway bridge spanning
this gulf is one of the finest on the continent, with its imposing piers of hewn
stone, over a hundred feet in height, with trusses of steel. Two bridges at the
level of the river provide for other traffic, with the novel arrangement that
heavy vehicles are lifted and lowered from the surface of the bluff to the
river by means of colossal elevators. The elevator is a municipal institution,
and municipal ownership is the general rule in Edmonton, the city owning
and operating the trolley lines, the electric light plant, the water-works, and
the telephone system. Edmonton would be the earthly paradise of the
disciples of Henry George, for it is a single-tax town. The University of
Alberta with its splendid campus of three hundred and fifty acres, fronts the
impressive capitol, of cream-hued sandstone, which stands on the Edmonton
side of the river.

The capitol is four stories in height, with classic portico and a dome
surmounted by a tall lantern, while the building is rendered still more
beautiful by its artistic approach; wide terraced steps, with balustrades,
ornamented with heavy bronze lamps, the effect of which, when lighted at
night, is not without reminiscences of Paris. The Hotel Macdonald has a
charming situation on the high bank of the river, within a few minutes' walk
of the centre of the town. The traveller enters by the spacious court and
covered loggia, passing thence into the great rotunda, with its floor of pink
Levantine marble and its ceiling of solid oak. Adjoining this is a lounge,
opening on a terrace 50 feet wide, overlooking the river, and the palm-room
(octagonal in form, with its dome decorated in Wedgwood designs), as well
as a beautiful dining-room, a café, and other public rooms. As one walks
through all this magnificence in the place so recently occupied by Indians,
hunters, and trappers of the frontier trading posts, he begins to realise
something of that almost incredible rapidity of growth and development that
characterises the great North-West.

The Canadian Women's Press Club in Edmonton is an organisation that


delights the heart of the modern woman, to whom her clubs are the very
breath of being; and its President, Mrs. Arthur Murphy, is well known to the
world of letters under her nom de plume, "Janey Canuck." Mrs. Murphy is
one of the most famous of Canadian writers, and has contributed much to the
general knowledge of the Dominion. Her work has received very high
praise. "She has opened a new path in Canadian literature," says an eminent
critic, "and her Open Trails and Seeds of Pine will inspire many other
writers."

Mrs. Murphy is the wife of the Rev. Arthur Murphy, D.D., who at one
time was the chaplain to the Empress Frederick. Her work has attracted
much attention in England, and The Bookman of London, in a critical review
of her books extending into several pages, said:

"The work of 'Janey Canuck' has the optimism of the true lyric; the song of the
open road. The refrain of the windswept spaces was never set to a better tune.... It
is not style that matters in the work of 'Janey Canuck' any more than it matters in
the work of Walt Whitman—a kindred philosopher. She comes scattering seeds of
gladness in our mist, and lo! our gloom is gone like a black cloud that breaks
before the April sun. She is the philosopher of gladness and content and common
sense, a philosophy as durable as Bergsonism."
Mrs. Murphy has been honoured by King George by the decoration that
entitles her to be known as a "Lady of Grace," an appropriate title, indeed,
for so gracious a lady.

Edmonton is the gateway to the Yellowhead Pass; and the beauty of its
location, the charming nature of its people, and the vastness of the territory
of which it is naturally the centre, all conspire to incite dream and prophecy
of the future of this young city of University ideals and marked intellectual
and literary quality.

CHAPTER VIII

ON THE GRAND TRUNK PACIFIC

One of the most enchanting pleasure trips that can be enjoyed on the
North American continent is that from Winnipeg to Prince Rupert through
regions of scenic glory

"Where all wonder tales come true";

where one journeys to the accompaniment of a bewildering series of


surprises that open vistas of new interests and enjoyments never dreamed of
before. It is one of the signal charms of a journey through regions of
majestic beauty and of scenic enchantment that it is not over even when it is
past. Such a trip is a treasure laid up in life for future enjoyment without
limit.

It is only some five hours from Edmonton before one begins to enter on
this wonderland of romance. It is so new that the world of travel has not yet
realised the marvel and glory of this trip. When it is stated that even the first
surveying for this transcontinental line began only in 1910, it will be readily
seen that in this region is opened up an absolutely new part of the world to
general travel. The anomaly of traversing these primeval wilds in a train so
luxuriously appointed as are the limiteds on the Grand Trunk Pacific appeals
to the comprehension of man's conquest over nature. To travel in the comfort
of these commodious coaches, equipped with a richly-furnished drawing-
room, an admirable dining-car, an observation car with a spacious balcony
platform at the rear and fitted with writing-desks, stationery in abundance,
books, magazines, and newspapers, is to enjoy a journey on a flying hotel.

"Here is a train worth while!" wrote Sir Arthur Conan Doyle after the
conclusion of the extensive trip that he and Lady Conan Doyle enjoyed over
the Dominion: "it is the latest word in comfort, in luxury, in safety, in speed.
The dining-car is never taken off. The observation car is a pleasant club. The
road is as smooth as polished marble, with heavy rails well ballasted, no
smoke or cinders.... It has the highest maintenance of track and rolling
stock.... It runs on a marvellous line, destined to a mighty future."

Mount Edith Cavell and Cavell Lake


The entrance to the Wonderland begins, as was said, some five hours
from Edmonton. The best plan is to leave this thriving young capital of
Alberta by a late evening train, and waken in the morning to find one's self
in a region where the peaks to the south of the Yellowhead Pass begin to
appear on the horizon. He who understands the romance of railroad travel
will raise the heavy blind of the windows of his lower berth or his drawing-
room, so as not to miss the strange panorama of the night. Indeed, if we
compare the romance of a night on shipboard with that of a night on a flying
railroad train, the latter is incomparably the greater. The first requisite is an
added relay of pillows—all that one wants, and all that one does not want, so
to speak—pillows on which to prop one's self up to the proper angle of
altitude that he may lie at ease and watch that marvellous moving panorama
of forest and glade, of starlit sky, or of the hills flooded with moonlight; with
flitting gleams of shining silver as the train glides past lakes, or along the
course of a winding river. It is the realm of fäery, where nothing is but what
is not. Is there a moon? There are a dozen moons! There is one in the south,
but a moment later it appears in the far east—no well-regulated moon would
career about in the heavens in so erratic a manner, therefore there must be
another; and when, at the next glimpse, it again appears at some different
point of the compass, one's conviction that the earth must have as many
moons as Jupiter is reinforced. The vast forest solitudes are all strange; to
waken suddenly and find one's self flying through these unreal regions is an
experience never to be forgotten. It is an experience entirely lost save to one
who unveils his windows to the mystic scenes rather than sleep in the
darkness of drawn blinds. The elusive fascination possible to the nights on a
railway train is a chapter of life in itself. It recalls to one the dictum of
Socrates that all exact inquiry into such matters as the movements and nature
of the sun and the moon should be excluded from too close investigation!

From Winnipeg the traveller speeds over fields of emerald or fields of


gold, according to the season; the harvest time is a world of gold and
resplendence; and ere the grain ripens it forms an infinite expanse of tender
green. The economist would see in these far-reaching fields of growing grain
a theme for his statistics and practical deductions as to their contribution to
the world's wealth; but the eye of the pleasure-traveller regards them solely
in the light of æsthetic effect. Wheat or oats, grass or anything else, it is all
one to him as long as the colour scheme enchants his eye. As he approaches
the mountain region the scene is etherealised. Away on the horizon are
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookgate.com

You might also like