The Java Language Specification. Java SE 8 Edition

Size: px
Start display at page:

Download "The Java Language Specification. Java SE 8 Edition"

Transcription

1

2 The Java Language Specification Java SE 8 Edition

3 This page intentionally left blank

4 The Java Language Specification Java SE 8 Edition James Gosling Bill Joy Guy Steele Gilad Bracha Alex Buckley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sydney Tokyo Singapore Mexico City

5 Copyright 1997, 2014, Oracle and/or its affiliates. All rights reserved. 500 Oracle Parkway, Redwood City, California 94065, U.S.A. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. This document is provided for information purposes only and the contents hereof are subject to change without notice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or implied in law, including implied warranties and conditions of merchantability or fitness for a particular purpose. We specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly or indirectly by this document, except as specified in the Limited License Grant herein at Appendix A. This document is subject to the Limited License Grant included herein as Appendix A, and may otherwise not be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without our prior written permission. The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact U.S. Corporate and Government Sales, (800) , corpsales@pearsontechgroup.com. For sales outside the United States, please contact International Sales, international@pearson.com. Visit us on the Web: informit.com/aw Library of Congress Control Number: ISBN-13: ISBN-10: X Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) The Specification provided herein is provided to you only under the Limited License Grant included herein as Appendix A. Please see Appendix A. Text printed in the United States on recycled paper at Edwards Brothers Malloy in Ann Arbor, Michigan. First printing, May 2014.

6 To Maurizio, with deepest thanks.

7 This page intentionally left blank

8 Table of Contents Preface to the Java SE 8 Edition xxi 1 Introduction Organization of the Specification Example Programs Notation Relationship to Predefined Classes and Interfaces Feedback References 7 2 Grammars Context-Free Grammars The Lexical Grammar The Syntactic Grammar Grammar Notation 10 3 Lexical Structure Unicode Lexical Translations Unicode Escapes Line Terminators Input Elements and Tokens White Space Comments Identifiers Keywords Literals Integer Literals Floating-Point Literals Boolean Literals Character Literals String Literals Escape Sequences for Character and String Literals The Null Literal Separators Operators 38 vii

9 The Java Language Specification 4 Types, Values, and Variables The Kinds of Types and Values Primitive Types and Values Integral Types and Values Integer Operations Floating-Point Types, Formats, and Values Floating-Point Operations The boolean Type and boolean Values Reference Types and Values Objects The Class Object The Class String When Reference Types Are the Same Type Variables Parameterized Types Type Arguments of Parameterized Types Members and Constructors of Parameterized Types Type Erasure Reifiable Types Raw Types Intersection Types Subtyping Subtyping among Primitive Types Subtyping among Class and Interface Types Subtyping among Array Types Least Upper Bound Where Types Are Used Variables Variables of Primitive Type Variables of Reference Type Kinds of Variables final Variables Initial Values of Variables Types, Classes, and Interfaces 88 5 Conversions and Contexts Kinds of Conversion Identity Conversion Widening Primitive Conversion Narrowing Primitive Conversion Widening and Narrowing Primitive Conversion Widening Reference Conversion Narrowing Reference Conversion Boxing Conversion Unboxing Conversion Unchecked Conversion Capture Conversion 103 viii

10 The Java Language Specification String Conversion Forbidden Conversions Value Set Conversion Assignment Contexts Invocation Contexts String Contexts Casting Contexts Reference Type Casting Checked Casts and Unchecked Casts Checked Casts at Run Time Numeric Contexts Unary Numeric Promotion Binary Numeric Promotion Names Declarations Names and Identifiers Scope of a Declaration Shadowing and Obscuring Shadowing Obscuring Determining the Meaning of a Name Syntactic Classification of a Name According to Context Reclassification of Contextually Ambiguous Names Meaning of Package Names Simple Package Names Qualified Package Names Meaning of PackageOrTypeNames Simple PackageOrTypeNames Qualified PackageOrTypeNames Meaning of Type Names Simple Type Names Qualified Type Names Meaning of Expression Names Simple Expression Names Qualified Expression Names Meaning of Method Names Simple Method Names Access Control Determining Accessibility Details on protected Access Access to a protected Member Qualified Access to a protected Constructor Fully Qualified Names and Canonical Names Packages Package Members 173 ix

11 The Java Language Specification 7.2 Host Support for Packages Compilation Units Package Declarations Named Packages Unnamed Packages Observability of a Package Import Declarations Single-Type-Import Declarations Type-Import-on-Demand Declarations Single-Static-Import Declarations Static-Import-on-Demand Declarations Top Level Type Declarations Classes Class Declarations Class Modifiers abstract Classes final Classes strictfp Classes Generic Classes and Type Parameters Inner Classes and Enclosing Instances Superclasses and Subclasses Superinterfaces Class Body and Member Declarations Class Members Field Declarations Field Modifiers static Fields final Fields transient Fields volatile Fields Field Initialization Forward References During Field Initialization Method Declarations Formal Parameters Method Signature Method Modifiers abstract Methods static Methods final Methods native Methods strictfp Methods synchronized Methods Generic Methods Method Result Method Throws Method Body 240 x

12 The Java Language Specification Inheritance, Overriding, and Hiding Overriding (by Instance Methods) Hiding (by Class Methods) Requirements in Overriding and Hiding Inheriting Methods with Override-Equivalent Signatures Overloading Member Type Declarations Static Member Type Declarations Instance Initializers Static Initializers Constructor Declarations Formal Parameters Constructor Signature Constructor Modifiers Generic Constructors Constructor Throws The Type of a Constructor Constructor Body Explicit Constructor Invocations Constructor Overloading Default Constructor Preventing Instantiation of a Class Enum Types Enum Constants Enum Body Declarations Enum Members Interfaces Interface Declarations Interface Modifiers abstract Interfaces strictfp Interfaces Generic Interfaces and Type Parameters Superinterfaces and Subinterfaces Interface Body and Member Declarations Interface Members Field (Constant) Declarations Initialization of Fields in Interfaces Method Declarations Inheritance and Overriding Overriding (by Instance Methods) Requirements in Overriding Inheriting Methods with Override-Equivalent Signatures Overloading Interface Method Body 291 xi

13 The Java Language Specification 9.5 Member Type Declarations Annotation Types Annotation Type Elements Defaults for Annotation Type Elements Repeatable Annotation Types Predefined Annotation Types Annotations Normal Annotations Marker Annotations Single-Element Annotations Where Annotations May Appear Multiple Annotations of the Same Type Functional Interfaces Function Types Arrays Array Types Array Variables Array Creation Array Access Array Store Exception Array Initializers Array Members Class Objects for Arrays An Array of Characters Is Not a String Exceptions The Kinds and Causes of Exceptions The Kinds of Exceptions The Causes of Exceptions Asynchronous Exceptions Compile-Time Checking of Exceptions Exception Analysis of Expressions Exception Analysis of Statements Exception Checking Run-Time Handling of an Exception 349 xii

14 The Java Language Specification 12 Execution Java Virtual Machine Startup Load the Class Test Link Test: Verify, Prepare, (Optionally) Resolve Initialize Test: Execute Initializers Invoke Test.main Loading of Classes and Interfaces The Loading Process Linking of Classes and Interfaces Verification of the Binary Representation Preparation of a Class or Interface Type Resolution of Symbolic References Initialization of Classes and Interfaces When Initialization Occurs Detailed Initialization Procedure Creation of New Class Instances Finalization of Class Instances Implementing Finalization Interaction with the Memory Model Unloading of Classes and Interfaces Program Exit Binary Compatibility The Form of a Binary What Binary Compatibility Is and Is Not Evolution of Packages Evolution of Classes abstract Classes final Classes public Classes Superclasses and Superinterfaces Class Type Parameters Class Body and Member Declarations Access to Members and Constructors Field Declarations final Fields and static Constant Variables static Fields transient Fields Method and Constructor Declarations Method and Constructor Type Parameters Method and Constructor Formal Parameters Method Result Type abstract Methods final Methods native Methods static Methods synchronized Methods 398 xiii

15 The Java Language Specification Method and Constructor Throws Method and Constructor Body Method and Constructor Overloading Method Overriding Static Initializers Evolution of Enums Evolution of Interfaces public Interfaces Superinterfaces Interface Members Interface Type Parameters Field Declarations Interface Method Declarations Evolution of Annotation Types Blocks and Statements Normal and Abrupt Completion of Statements Blocks Local Class Declarations Local Variable Declaration Statements Local Variable Declarators and Types Execution of Local Variable Declarations Statements The Empty Statement Labeled Statements Expression Statements The if Statement The if-then Statement The if-then-else Statement The assert Statement The switch Statement The while Statement Abrupt Completion of while Statement The do Statement Abrupt Completion of do Statement The for Statement The basic for Statement Initialization of for Statement Iteration of for Statement Abrupt Completion of for Statement The enhanced for statement The break Statement The continue Statement The return Statement The throw Statement The synchronized Statement The try statement 440 xiv

16 The Java Language Specification Execution of try-catch Execution of try-finally and try-catch-finally try-with-resources Basic try-with-resources Extended try-with-resources Unreachable Statements Expressions Evaluation, Denotation, and Result Forms of Expressions Type of an Expression FP-strict Expressions Expressions and Run-Time Checks Normal and Abrupt Completion of Evaluation Evaluation Order Evaluate Left-Hand Operand First Evaluate Operands before Operation Evaluation Respects Parentheses and Precedence Argument Lists are Evaluated Left-to-Right Evaluation Order for Other Expressions Primary Expressions Lexical Literals Class Literals this Qualified this Parenthesized Expressions Class Instance Creation Expressions Determining the Class being Instantiated Determining Enclosing Instances Choosing the Constructor and its Arguments Run-Time Evaluation of Class Instance Creation Expressions Anonymous Class Declarations Anonymous Constructors Array Creation and Access Expressions Array Creation Expressions Run-Time Evaluation of Array Creation Expressions Array Access Expressions Run-Time Evaluation of Array Access Expressions Field Access Expressions Field Access Using a Primary Accessing Superclass Members using super Method Invocation Expressions Compile-Time Step 1: Determine Class or Interface to Search Compile-Time Step 2: Determine Method Signature Identify Potentially Applicable Methods 509 xv

17 The Java Language Specification Phase 1: Identify Matching Arity Methods Applicable by Strict Invocation Phase 2: Identify Matching Arity Methods Applicable by Loose Invocation Phase 3: Identify Methods Applicable by Variable Arity Invocation Choosing the Most Specific Method Method Invocation Type Compile-Time Step 3: Is the Chosen Method Appropriate? Run-Time Evaluation of Method Invocation Compute Target Reference (If Necessary) Evaluate Arguments Check Accessibility of Type and Method Locate Method to Invoke Create Frame, Synchronize, Transfer Control Method Reference Expressions Compile-Time Declaration of a Method Reference Type of a Method Reference Run-Time Evaluation of Method References Postfix Expressions Expression Names Postfix Increment Operator Postfix Decrement Operator Unary Operators Prefix Increment Operator Prefix Decrement Operator Unary Plus Operator Unary Minus Operator Bitwise Complement Operator ~ Logical Complement Operator! Cast Expressions Multiplicative Operators Multiplication Operator * Division Operator / Remainder Operator % Additive Operators String Concatenation Operator Additive Operators (+ and -) for Numeric Types Shift Operators Relational Operators Numerical Comparison Operators <, <=, >, and >= Type Comparison Operator instanceof Equality Operators Numerical Equality Operators == and!= Boolean Equality Operators == and!= Reference Equality Operators == and!= Bitwise and Logical Operators Integer Bitwise Operators &, ^, and 568 xvi

18 The Java Language Specification Boolean Logical Operators &, ^, and Conditional-And Operator && Conditional-Or Operator Conditional Operator? : Boolean Conditional Expressions Numeric Conditional Expressions Reference Conditional Expressions Assignment Operators Simple Assignment Operator = Compound Assignment Operators Lambda Expressions Lambda Parameters Lambda Body Type of a Lambda Expression Run-Time Evaluation of Lambda Expressions Constant Expressions Definite Assignment Definite Assignment and Expressions Boolean Constant Expressions Conditional-And Operator && Conditional-Or Operator Logical Complement Operator! Conditional Operator? : Conditional Operator? : Other Expressions of Type boolean Assignment Expressions Operators ++ and Other Expressions Definite Assignment and Statements Empty Statements Blocks Local Class Declaration Statements Local Variable Declaration Statements Labeled Statements Expression Statements if Statements assert Statements switch Statements while Statements do Statements for Statements Initialization Part of for Statement Incrementation Part of for Statement break, continue, return, and throw Statements synchronized Statements try Statements 624 xvii

19 The Java Language Specification 16.3 Definite Assignment and Parameters Definite Assignment and Array Initializers Definite Assignment and Enum Constants Definite Assignment and Anonymous Classes Definite Assignment and Member Types Definite Assignment and Static Initializers Definite Assignment, Constructors, and Instance Initializers Threads and Locks Synchronization Wait Sets and Notification Wait Notification Interruptions Interactions of Waits, Notification, and Interruption Sleep and Yield Memory Model Shared Variables Actions Programs and Program Order Synchronization Order Happens-before Order Executions Well-Formed Executions Executions and Causality Requirements Observable Behavior and Nonterminating Executions final Field Semantics Semantics of final Fields Reading final Fields During Construction Subsequent Modification of final Fields Write-Protected Fields Word Tearing Non-Atomic Treatment of double and long Type Inference Concepts and Notation Inference Variables Constraint Formulas Bounds Reduction Expression Compatibility Constraints Type Compatibility Constraints Subtyping Constraints Type Equality Constraints Checked Exception Constraints Incorporation Complementary Pairs of Bounds 674 xviii

20 The Java Language Specification Bounds Involving Capture Conversion Resolution Uses of Inference Invocation Applicability Inference Invocation Type Inference Functional Interface Parameterization Inference More Specific Method Inference Syntax 689 Index 715 A Limited License Grant 755 xix

21 This page intentionally left blank

22 Preface to the Java SE 8 Edition IN 1996, James Gosling, Bill Joy, and Guy Steele wrote for the First Edition of The Java Language Specification: "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 compatible with existing applications." Java SE 8 represents the single largest evolution of the Java language in its history. A relatively small number of features - lambda expressions, method references, and functional interfaces - combine to offer a programming model that fuses the objectoriented and functional styles. Under the leadership of Brian Goetz, this fusion has been accomplished in a way that encourages best practices - immutability, statelessness, compositionality - while preserving "the feel of Java" - readability, simplicity, universality. Crucially, the libraries of the Java SE platform have co-evolved with the Java language. This means that using lambda expressions and method references to represent behavior - for example, an operation to be applied to each element in a list - is productive and performant "out of the box". In a similar fashion, the Java Virtual Machine has co-evolved with the Java language to ensure that default methods support library evolution as consistently as possible across compile time and run time, given the constraints of separate compilation. Initiatives to add first-class functions to the Java language have been around since the 1990s. The BGGA and CICE proposals circa 2007 brought new energy to the topic, while the creation of Project Lambda in OpenJDK circa 2009 attracted unprecedented levels of interest. The addition of method handles to the JVM in Java SE 7 opened the door to new implementation techniques while retaining "write once, run anywhere." In time, language changes were overseen by JSR 335, Lambda Expressions for the Java Programming Language, whose Expert Group consisted of Joshua Bloch, Kevin Bourrillion, Andrey Breslav, Rémi Forax, Dan Heidinga, Doug Lea, Bob Lee, David Lloyd, Sam Pullara, Srikanth Sankaran, and Vladimir Zakharov. Programming language design typically involves grappling with degrees of complexity utterly hidden from the language's users. (For this reason, it is often compared to an iceberg: 90% of it is invisible.) In JSR 335, the greatest complexity xxi

23 PREFACE TO THE JAVA SE 8 EDITION lurked in the interaction of implicitly typed lambda expressions with overload resolution. In this and many other areas, Dan Smith at Oracle did an outstanding job of thoroughly specifying the desired behavior. His words are to be found throughout this specification, including an entirely new chapter on type inference. Another initiative in Java SE 8 has been to enhance the utility of annotations, one of the most popular features of the Java language. First, the Java grammar has been extended to allow annotations on types in many language constructs, forming the basis for novel static analysis tools such as the Checker Framework. This feature was specified by JSR 308, Annotations on Java Types, led by Michael Ernst with an Expert Group of myself, Doug Lea, and Srikanth Sankaran. The changes involved in this specification were wide-ranging, and the unstinting efforts of Michael Ernst and Werner Dietl over many years are warmly recognized. Second, annotations may be "repeated" on a language construct, to the great benefit of APIs that model domain-specific configuration with annotation types. Michael Keith and Bill Shannon in Java EE initiated and guided this feature. Many colleagues in the Java Platform Group at Oracle have provided valuable support to this specification: Leonid Arbouzov, Mandy Chung, Joe Darcy, Robert Field, Joel Franck, Sonali Goel, Jon Gibbons, Jeannette Hung, Stuart Marks, Eric McCorkle, Matherey Nunez, Mark Reinhold, Vicente Romero, John Rose, Georges Saab, Steve Sides, Bernard Traversat, and Michel Trudeau. Perhaps the greatest acknowledgement must go to the compiler engineers who turn the specification into real software. Maurizio Cimadamore at Oracle worked heroically from the earliest days on the design of lambda expressions and their implementation in javac. Support for Java SE 8 features in Eclipse was contributed by Jayaprakash Arthanareeswaran, Shankha Banerjee, Anirban Chakraborty, Andrew Clement, Stephan Herrmann, Markus Keller, Jesper Møller, Manoj Palat, Srikanth Sankaran, and Olivier Thomann; and in IntelliJ by Anna Kozlova, Alexey Kudravtsev, and Roman Shevchenko. They deserve the thanks of the entire Java community. Java SE 8 is a renaissance for the Java language. While some search for the "next great language", we believe that programming in Java is more exciting and productive than ever. We hope that it continues to wear well for you. Alex Buckley Santa Clara, California March, 2014 xxii

24 CHAPTER1 Introduction THE Java programming language is a general-purpose, concurrent, classbased, object-oriented language. It is designed to be simple enough that many programmers 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 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 and statically 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 program, optional machine code generation and dynamic optimization of the program, and actual program execution. The Java programming language is a relatively high-level language, in that 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 bytecode instruction set and binary format defined in The Java Virtual Machine Specification, Java SE 8 Edition. 1

25 1 INTRODUCTION 1.1 Organization of the Specification 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. 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 many cases, wrapping and unwrapping is performed automatically by the compiler (in which case, wrapping is called boxing, and unwrapping is called unboxing). 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 reference 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 reference 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 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 2

26 Organization of the Specification 1.1 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 declared before they are used. Declaration order is significant only for local variables, 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 implementation of a type from its users and those who extend it. Recommended naming conventions that make for more readable programs are described here. Chapter 7 describes the structure of a program, which is organized into packages similar to the modules of Modula. The members of a package are classes, interfaces, and subpackages. Packages are divided into compilation units. Compilation 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 execution, supporting the object-oriented programming style. Classes support single implementation inheritance, in which the implementation 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 methods, 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. For simplicity, the language has neither declaration "headers" separate from the implementation of a class nor separate type and class hierarchies. 3

27 1 INTRODUCTION 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 languages, 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 supported. 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 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 Java 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 program is normally stored as binary files representing compiled classes and interfaces. 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 4

28 Organization of the Specification 1.1 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 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 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 protect against non-local control transfers. Chapter 15 describes expressions. This document fully specifies the (apparent) 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. 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 automatically 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 sharedmemory multiprocessors that supports high-performance implementations. Chapter 18 describes a variety of type inference algorithms used to test applicability of generic methods and to infer types in a generic method invocation. Chapter 19 presents a syntactic grammar for the language. 5

29 1 INTRODUCTION 1.2 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(); } } On a machine with the Oracle JDK installed, 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. 1.3 Notation Throughout this specification we refer to classes and interfaces drawn from the Java SE platform API. Whenever we refer to a class or interface (other than those declared in an example) 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. Non-normative information, designed to clarify the specification, is given in smaller, indented text. This is non-normative information. It provides intuition, rationale, advice, examples, etc. The type system of the Java programming language occasionally relies on the notion of a substitution. The notation [F 1 :=T 1,...,F n :=T n ] denotes substitution of F i by T i for 1 i n. 6

30 Relationship to Predefined Classes and Interfaces Relationship to Predefined Classes and Interfaces As noted above, this specification often refers to classes of the Java SE platform API. 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. This specification constrains the behavior of such classes and interfaces, but does not provide a complete specification for them. The reader is referred to the Java SE platform API documentation. Consequently, this specification does not describe reflection in any detail. Many linguistic constructs have analogs in the Core Reflection API (java.lang.reflect) and the Language Model API (javax.lang.model), but these are generally not discussed here. For example, when we list the ways in which an object can be created, we generally do not include the ways in which the Core Reflection API can accomplish this. Readers should be aware of these additional mechanisms even though they are not mentioned in the text. 1.5 Feedback Readers may send feedback about errors, omissions, and ambiguities in The Java Language Specification to jls-comments_ww@oracle.com. Questions concerning the behavior of javac (the reference compiler for the Java programming language), and in particular its conformance to this specification, may be sent to compiler-dev@openjdk.java.net. 1.6 References Apple Computer. Dylan Reference Manual. Apple Computer Inc., Cupertino, California. September 29, 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 R, June 1988; appears as Chapter 28 of Steele, Guy. Common Lisp: The Language, 2nd ed. Digital Press, 1990, ISBN , Ellis, Margaret A., and Bjarne Stroustrup. The Annotated C++ Reference Manual. Addison- Wesley, Reading, Massachusetts, 1990, reprinted with corrections October 1992, ISBN

31 1 INTRODUCTION Goldberg, Adele and Robson, David. Smalltalk-80: The Language. Addison-Wesley, Reading, Massachusetts, 1989, ISBN Harbison, Samuel. Modula-3. Prentice Hall, Englewood Cliffs, New Jersey, 1992, ISBN Hoare, C. A. R. Hints on Programming Language Design. Stanford University Computer Science Department Technical Report No. CS , December Reprinted in SIGACT/SIGPLAN Symposium on Principles of Programming Languages. Association for Computing Machinery, New York, October IEEE Standard for Binary Floating-Point Arithmetic. ANSI/IEEE Std Available from Global Engineering Documents, 15 Inverness Way East, Englewood, Colorado USA; Kernighan, Brian W., and Dennis M. Ritchie. The C Programming Language, 2nd ed. Prentice Hall, Englewood Cliffs, New Jersey, 1988, ISBN Madsen, Ole Lehrmann, Birger Møller-Pedersen, and Kristen Nygaard. Object-Oriented Programming in the Beta Programming Language. Addison-Wesley, Reading, Massachusetts, 1993, ISBN Mitchell, James G., William Maybury, and Richard Sweet. The Mesa Programming Language, Version 5.0. Xerox PARC, Palo Alto, California, CSL 79-3, April Stroustrup, Bjarne. The C++ Progamming Language, 2nd ed. Addison-Wesley, Reading, Massachusetts, 1991, reprinted with corrections January 1994, ISBN Unicode Consortium, The. The Unicode Standard, Version Mountain View, CA, 2011, ISBN

32 Index Symbols = operator, 582 assignment contexts, 109 expressions and run-time checks, 463, 464 normal and abrupt completion of evaluation, 465, repeatable annotation types, 303 repeatable annotation types, 307 formal parameters, 305 checked casts and unchecked casts, 121 formal parameters, 228 requirements in overriding and hiding, 246 unchecked conversion, 302 multiple annotations of the same type, 318 repeatable annotation types, 298 where annotations may appear, 313 A abrupt completion of do statement, 425 do statement, 425 abrupt completion of for statement, 428 iteration of for statement, 428 abrupt completion of while statement, 424 while statement, 423 abstract classes, 192, 383 abstract methods, 232 anonymous class declarations, 485 array creation expressions, 487 final classes, 194 superinterfaces, 204 abstract interfaces, 279 abstract methods, 232, 396 abstract classes, 192 method body, 240 method declarations, 286 access control, 161 accessing superclass members using super, 498 class literals, 474 class modifiers, 191 constructor declarations, 256 default constructor, 265 enum body declarations, 269 explicit constructor invocations, 262 field access using a primary, 495 identify potentially applicable methods, 509 import declarations, 180 interface modifiers, 278 local class declarations, 407 member type declarations, 254 method declarations, 286 normal annotations, 309 objects, 54 qualified expression names, 158, 158,

33 INDEX qualified type names, 156, 156 reference types and values, 53 requirements in overriding and hiding, 247 single-static-import declarations, 184 single-type-import declarations, 181 static-import-on-demand declarations, 184 superclasses and subclasses, 200 superinterfaces, 202 superinterfaces and subinterfaces, 280 type-import-on-demand declarations, 183 access to a protected member, 167 access to members and constructors, 387 accessing superclass members using super, 497 declarations, 132 field declarations, 213 field initialization, 221, 222 initialization of fields in interfaces, 285 instance initializers, 255 static methods, 234 to context, 150 actions, 640 synchronization order, 642 additive operators, 556 constant expressions, 605 integer operations, 43 additive operators (+ and -) for numeric types, 559 binary numeric promotion, 126 floating-point operations, 48 an array of characters is not a String, 339 annotation type elements, 303 annotation types, 293 declarations, 130, 131, 131 marker annotations, 311 normal annotations, 309 single-element annotations, 312 to context, 150 where types are used, 76 annotation types, 302 annotations, 308 declarations, 130 interface declarations, 278 annotations, 308 declarations, 132 defaults for annotation type elements, 297 to context, 150 anonymous class declarations, 485 class instance creation expressions, 477, 477 class modifiers, 191 definite assignment and anonymous classes, 627 enum constants, 268 form of a binary, 377 initialization of fields in interfaces, 285 inner classes and enclosing instances, 197 to context, 151 where types are used, 76, 77 anonymous constructors, 485 choosing the constructor and its arguments, 484 default constructor, 265 form of a binary, 381 argument lists are evaluated left-to-right, 470 array access, 332 array access expressions, 491 array access, 332 assignment operators, 582 compound assignment operators, 589 simple assignment operator =,

34 to context, 151 unary numeric promotion, 125 array creation, 332 array creation and access expressions, 487 method reference expressions, 529 array creation expressions, 487 array creation, 332 array initializers, 335 objects, 53 to context, 151 unary numeric promotion, 125 where types are used, 76, 78 array initializers, 335 array creation, 332 definite assignment and array initializers, 626 normal and abrupt completion of evaluation, 464 objects, 53 run-time evaluation of array creation expressions, 488 array members, 336 declarations, 130, 130 happens-before order, 644 qualified expression names, 159 array store exception, 333 array variables, 332 assignment contexts, 109 expressions and run-time checks, 463, 464 normal and abrupt completion of evaluation, 465 variables, 80 array types, 330 annotation type elements, 294 enhanced for statement, 430 raw types, 66 reference types and values, 52 reifiable types, 65 where types are used, 77 array variables, 330 enhanced for statement, 431 formal parameters, 228 lambda parameters, 598 arrays, 329 array creation expressions, 487 kinds of variables, 83 when reference types are the same, 57 assert statement, 416 assert statements, 620 detailed initialization procedure, 365 when initialization occurs, 361 assert statements, 620 assignment contexts, 107 array initializers, 335 array store exception, 333 array variables, 332 class instance creation expressions, 478 execution of try-catch, 444 expressions and run-time checks, 463, 463 kinds of types and values, 42 lambda expressions, 595 method invocation expressions, 500 method reference expressions, 531 normal annotations, 310 reference conditional expressions, 580 return statement, 436 run-time evaluation of method references, 540 simple assignment operator =, 582, 583 switch statement, 420 throw statement, 437, 438 type of an expression, 461 variables, 80 assignment expressions,

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

Programming Lecture 3

Programming Lecture 3 Five-Minute Review 1. What is a variable? 2. What is a class? An object? 3. What is a package? 4. What is a method? A constructor? 5. What is an object variable? 1 Programming Lecture 3 Expressions etc.

More information

Programming Lecture 3

Programming Lecture 3 Five-Minute Review 1. What is a variable? 2. What is a class? An object? 3. What is a package? 4. What is a method? A constructor? 5. What is an object variable? 1 Programming Lecture 3 Expressions etc.

More information

Programming Lecture 3

Programming Lecture 3 Five-Minute Review 1. What is a variable? 2. What is a class? An object? 3. What is a package? 4. What is a method? A constructor? 5. What is an object variable? 1 Programming Lecture 3 Expressions etc.

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

More information

The Java Tutorial. A Short Course on the Basics. Raymond Gallardo. Sowmya Kannan. AAddison-Wesley. Sharon Biocca Zakhour.

The Java Tutorial. A Short Course on the Basics. Raymond Gallardo. Sowmya Kannan. AAddison-Wesley. Sharon Biocca Zakhour. The Java Tutorial A Short Course on the Basics Fifth Edition Sharon Biocca Zakhour Sowmya Kannan Raymond Gallardo AAddison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto

More information

Operators and Expressions

Operators and Expressions Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

More information

Introduction. Assessment Test. Part I The Programmer s Exam 1

Introduction. Assessment Test. Part I The Programmer s Exam 1 4276FM.fm Page ix Thursday, October 2, 2003 11:22 AM at a Glance Introduction Assessment Test xix xxv Part I The Programmer s Exam 1 Chapter 1 Language Fundamentals 3 Chapter 2 Operators and Assignments

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple

More information

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p. Preface p. xix Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p. 5 Java Applets and Applications p. 5

More information

PYTHON. p ykos vtawynivis. Second eciitiovl. CO Ve, WESLEY J. CHUN

PYTHON. p ykos vtawynivis. Second eciitiovl. CO Ve, WESLEY J. CHUN CO Ve, PYTHON p ykos vtawynivis Second eciitiovl WESLEY J. CHUN. PRENTICE HALL Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sydney

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Microsoft Visual C# Step by Step. John Sharp

Microsoft Visual C# Step by Step. John Sharp Microsoft Visual C# 2013 Step by Step John Sharp Introduction xix PART I INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2013 Chapter 1 Welcome to C# 3 Beginning programming with the Visual

More information

Java Quick Syntax Reference. Second Edition. Mikael Olsson

Java Quick Syntax Reference. Second Edition. Mikael Olsson Java Quick Syntax Reference Second Edition Mikael Olsson Java Quick Syntax Reference Second Edition Mikael Olsson Java Quick Syntax Reference Mikael Olsson Hammarland, Länsi-Suomi, Finland ISBN-13 (pbk):

More information

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Microsoft. Microsoft Visual C# Step by Step. John Sharp Microsoft Microsoft Visual C#- 2010 Step by Step John Sharp Table of Contents Acknowledgments Introduction xvii xix Part I Introducing Microsoft Visual C# and Microsoft Visual Studio 2010 1 Welcome to

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

C++ Primer, Fifth Edition

C++ Primer, Fifth Edition C++ Primer, Fifth Edition Stanley B. Lippman Josée Lajoie Barbara E. Moo Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sidney Tokyo

More information

Fundamentals of the Java Programming Language

Fundamentals of the Java Programming Language Fundamentals of the Java Programming Language Student Guide SL-110 REV E D61798GC10 Edition 1.0 2009 D62399 Copyright 2006, 2009, Oracle and/or its affiliates. All rights reserved. Disclaimer This document

More information

Programming. Principles and Practice Using C++ Bjarne Stroustrup. / Addison-Wesley. Second Edition

Programming. Principles and Practice Using C++ Bjarne Stroustrup. / Addison-Wesley. Second Edition Programming Principles and Practice Using C++ Second Edition Bjarne Stroustrup / Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

Common Lisp Object System Specification. 1. Programmer Interface Concepts

Common Lisp Object System Specification. 1. Programmer Interface Concepts Common Lisp Object System Specification 1. Programmer Interface Concepts Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated:

More information

OracleAS 10g R3: Java Programming

OracleAS 10g R3: Java Programming OracleAS 10g R3: Java Programming Volume I Student Guide D18382GC20 Edition 2.0 April 2007 D50171 Authors Patrice Daux Kate Heap Technical Contributors and Reviewers Ken Cooper C Fuller Vasily Strelnikov

More information

IC Language Specification

IC Language Specification CS 301 Spring 2016 IC Language Specification The IC Language For the implementation project, you will build a compiler for an object-oriented language called IC (for Irish Coffee 1 ), which is essentially

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

Programming. In Ada JOHN BARNES TT ADDISON-WESLEY

Programming. In Ada JOHN BARNES TT ADDISON-WESLEY Programming In Ada 2005 JOHN BARNES... TT ADDISON-WESLEY An imprint of Pearson Education Harlow, England London New York Boston San Francisco Toronto Sydney Tokyo Singapore Hong Kong Seoul Taipei New Delhi

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Table of Contents Preface Bare Necessities... 17

Table of Contents Preface Bare Necessities... 17 Table of Contents Preface... 13 What this book is about?... 13 Who is this book for?... 14 What to read next?... 14 Personages... 14 Style conventions... 15 More information... 15 Bare Necessities... 17

More information

Annotation File Specification

Annotation File Specification Annotation File Specification Javari Team MIT Computer Science and Artificial Intelligence Lab javari@csail.mit.edu October 2, 2007 1 Purpose: External storage of annotations Java annotations are meta-data

More information

1 OBJECT-ORIENTED PROGRAMMING 1

1 OBJECT-ORIENTED PROGRAMMING 1 PREFACE xvii 1 OBJECT-ORIENTED PROGRAMMING 1 1.1 Object-Oriented and Procedural Programming 2 Top-Down Design and Procedural Programming, 3 Problems with Top-Down Design, 3 Classes and Objects, 4 Fields

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

Oracle 10g: Java Programming

Oracle 10g: Java Programming Oracle 10g: Java Programming Volume 1 Student Guide D17249GC12 Edition 1.2 July 2005 D19367 Author Kate Heap Technical Contributors and Reviewers Ken Cooper Brian Fry Jeff Gallus Glenn Maslen Gayathri

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

The Sun s Java Certification and its Possible Role in the Joint Teaching Material The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified

More information

Programming in Python 3

Programming in Python 3 Programming in Python 3 A Complete Introduction to the Python Language Mark Summerfield.4.Addison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Java TM Introduction. Renaud Florquin Isabelle Leclercq. FloConsult SPRL.

Java TM Introduction. Renaud Florquin Isabelle Leclercq. FloConsult SPRL. Java TM Introduction Renaud Florquin Isabelle Leclercq FloConsult SPRL http://www.floconsult.be mailto:info@floconsult.be Java Technical Virtues Write once, run anywhere Get started quickly Write less

More information

WA1278 Introduction to Java Using Eclipse

WA1278 Introduction to Java Using Eclipse Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA1278 Introduction to Java Using Eclipse This course introduces the Java

More information

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p. 9 Classes and Objects p. 11 Creating Objects p. 12 Static or

More information

E Oracle 10g Java Bootcamp I v1

E Oracle 10g Java Bootcamp I v1 E Oracle 10g Java Bootcamp I v1 Student Guide Volume 1 D22059GC10 Edition 1.0 October 2005 D22281 Authors Jeff Gallus Glenn Stokol Editor Gayathri Rajagopal Technical Contributors and Reviewers Kenneth

More information

Java: framework overview and in-the-small features

Java: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Types, Values and Variables (Chapter 4, JLS)

Types, Values and Variables (Chapter 4, JLS) Lecture Notes CS 141 Winter 2005 Craig A. Rich Types, Values and Variables (Chapter 4, JLS) Primitive Types Values Representation boolean {false, true} 1-bit (possibly padded to 1 byte) Numeric Types Integral

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

interface MyAnno interface str( ) val( )

interface MyAnno interface str( ) val( ) Unit 4 Annotations: basics of annotation-the Annotated element Interface. Using Default Values, Marker Annotations. Single-Member Annotations. The Built-In Annotations-Some Restrictions. 1 annotation Since

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

COMP 202 Java in one week

COMP 202 Java in one week COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1 CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Winter 2008 3/11/2008 2002-08 Hal Perkins & UW CSE V-1 Agenda Java virtual machine architecture.class files Class loading Execution engines

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107 A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

STRUCTURING OF PROGRAM

STRUCTURING OF PROGRAM Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the

More information

Peter Sestoft. Java Precisely. Third Edition. The MIT Press Cambridge, Massachusetts London, England

Peter Sestoft. Java Precisely. Third Edition. The MIT Press Cambridge, Massachusetts London, England Peter Sestoft Java Precisely Third Edition The MIT Press Cambridge, Massachusetts London, England Contents Preface Notational Conventions xi xii 1 Running Java: Compilation, Loading, and Execution 2 2

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

GUJARAT TECHNOLOGICAL UNIVERSITY

GUJARAT TECHNOLOGICAL UNIVERSITY GUJARAT TECHNOLOGICAL UNIVERSITY MASTER OF COMPUTER APPLICATIONS (COURSE CODE-6) Subject: Java Programming Subject Code: 2630002 Year II (Semester III) (W.E.F. JULY 2013) Objectives: To develop proficiency

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Java Overview An introduction to the Java Programming Language

Java Overview An introduction to the Java Programming Language Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/

More information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez

SQL Queries. for. Mere Mortals. Third Edition. A Hands-On Guide to Data Manipulation in SQL. John L. Viescas Michael J. Hernandez SQL Queries for Mere Mortals Third Edition A Hands-On Guide to Data Manipulation in SQL John L. Viescas Michael J. Hernandez r A TT TAddison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Java 8 Programming for OO Experienced Developers

Java 8 Programming for OO Experienced Developers www.peaklearningllc.com Java 8 Programming for OO Experienced Developers (5 Days) This course is geared for developers who have prior working knowledge of object-oriented programming languages such as

More information

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java Introduction Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2 Problem Solving The purpose of writing a program is to solve a problem

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Metadata Features in Java SE 8

Metadata Features in Java SE 8 Metadata Features in Java SE 8 Joel Borggrén-Franck Java Platform Group Oracle @joelbf Metadata Features in Java SE 8 Joel Borggrén-Franck Java Platform Group Oracle @joelbf First, a message from our lawyers:

More information

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

Points To Remember for SCJP

Points To Remember for SCJP Points To Remember for SCJP www.techfaq360.com The datatype in a switch statement must be convertible to int, i.e., only byte, short, char and int can be used in a switch statement, and the range of the

More information

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

Casting -Allows a narrowing assignment by asking the Java compiler to trust us Primitives Integral types: int, short, long, char, byte Floating point types: double, float Boolean types: boolean -passed by value (copied when returned or passed as actual parameters) Arithmetic Operators:

More information

C # Language Specification

C # Language Specification C # Language Specification Copyright Microsoft Corporation 1999-2001. All Rights Reserved. Please send corrections, comments, and other feedback to sharp@microsoft.com Notice 1999-2001 Microsoft Corporation.

More information

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010 IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

More information

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7) Software Development & Education Center Java Platform, Standard Edition 7 (JSE 7) Detailed Curriculum Getting Started What Is the Java Technology? Primary Goals of the Java Technology The Java Virtual

More information

The Java Programming Language

The Java Programming Language The Java Programming Language Slide by John Mitchell (http://www.stanford.edu/class/cs242/slides/) Outline Language Overview History and design goals Classes and Inheritance Object features Encapsulation

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

2 rd class Department of Programming. OOP with Java Programming

2 rd class Department of Programming. OOP with Java Programming 1. Structured Programming and Object-Oriented Programming During the 1970s and into the 80s, the primary software engineering methodology was structured programming. The structured programming approach

More information

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H JAVA COURSE DETAILS DURATION: 60 Hours With Live Hands-on Sessions J P I N F O T E C H P U D U C H E R R Y O F F I C E : # 4 5, K a m a r a j S a l a i, T h a t t a n c h a v a d y, P u d u c h e r r y

More information

Contents. iii Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1998, Revision B

Contents. iii Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1998, Revision B Contents About the Course...xv Course Overview... xvi Course Map... xvii Module-by-Module Overview... xviii Course Objectives... xxii Skills Gained by Module... xxiii Guidelines for Module Pacing... xxiv

More information

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.asp...

https://asd-pa.perfplusk12.com/admin/admin_curric_maps_display.asp... 1 of 8 8/27/2014 2:15 PM Units: Teacher: ProgIIIAPCompSci, CORE Course: ProgIIIAPCompSci Year: 2012-13 Computer Systems This unit provides an introduction to the field of computer science, and covers the

More information

Programming with POSIX Threads

Programming with POSIX Threads Programming with POSIX Threads David R. Butenhof :vaddison-wesley Boston San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sidney Tokyo Singapore Mexico City Contents List of

More information

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language Chapter 1 Getting Started Introduction To Java Most people are familiar with Java as a language for Internet applications We will study Java as a general purpose programming language The syntax of expressions

More information

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

"Charting the Course... Java Programming Language. Course Summary

Charting the Course... Java Programming Language. Course Summary Course Summary Description This course emphasizes becoming productive quickly as a Java application developer. This course quickly covers the Java language syntax and then moves into the object-oriented

More information