`Virtual Machine
`
`Specification
`
`Tim Lindholm
`
`Frank Yellin
`
`A
`VV
`
`ADDISON-WESLEY
`
`An imprint of Addison Wesley Longman, Inc.
`Reading, Massachusetts - Harlow, England - Menlo Park, California
`Berkeley, California - Don Mills, Ontario v Sydney
`Bonn - Amsterdam - Tokyo - Mexico City
`
`Page 1 of 27
`
`GOOGLE EXHIBIT 1025
`
`Page 1 of 27
`
`GOOGLE EXHIBIT 1025
`
`
`
` Copyright © 1997 Sun Microsystems, Inc.
`
`1:
`-' "m """'_I
`2550 Garcia Avenue, Mountain View, California 94043-1100 U S. A.
`All rights reserved.
`
`g
`
`Max:553 '
`
`DukeTM 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 252227-7013 (c)(1)(ii) and
`FAR 52.227519.
`
`The release described in this manual may be protected by one or more US. patents, foreign
`patents, or pending applications.
`
`Sun Microsystems, Inc. (SUN) hereby grants to you a fully-paid, nonexclusive, nontransfer—
`able, 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 implementations of this specifi—
`cation that: (i) include a complete implementation of the current version of this specification
`without subsetting or supersetting; (ii) implement all the interfaces and functionality of the
`standard java. * packages as defined by SUN, without subsetting or supersetting; (iii) do
`not add any additional packages, classes or methods to the java. * packages; (iv) pass all
`test suites relating to the most recent published version of this specification 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 binary materials without an appropriate and separate license from SUN.
`
`Sun, Sun Microsystems, Sun Microsystems Computer Corporation, the Sun logo, the Sun
`Nficrosystems Computer Corporation logo, Java, JavaSoft, JavaScript, and HotJava are
`trademarks or registered trademarks of Sun Microsystems, Inc. UNIX® is a registered trade—
`mark in the United States and other countries, exclusively licensed through XfOpen Com-
`pany, Ltd. All other product names mentioned herein are the trademarks of their respective
`owners.
`
`THIS PUBLICATION IS PROVIDED “AS IS” WITHOUT WARRANTY OFANY KIND,
`EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
`IMPLIED WARRANTIES OF NIERCHANTABILITY, FTI'NESS FOR A PARTICULAR
`PURPOSE, OR NONAINFRINGEMENT.
`
`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) ANDJ'OR THE PRO-
`GRAB/1(5) DESCRIBED IN THIS PUBLICATION AT ANY TIME.
`
`Text printed on recycled and acid—free paper
`
`ISBN 0—201—63452-X
`I 2 3 4-5 6 7 8 9-MA-00999897
`First printing, September 1996
`
`Page 2 of 27
`
`Page 2 of 27
`
`
`
` CHAPTE 1
`
`
`
`Introduction
`
`A Bit of History
`
`JAVA is a general-purpose concurrent object-oriented programming language. Its
`syntax is similar to C and C++, but it omits many of the features that make C and
`C++ complex, confusing, and unsafe. Java was initially developed to address the
`problems of building software for networked consumer devices. It was designed to
`support multiple host architectures and to allow secure delivery of software compow
`nents. To meet these requirements, compiled Java code had to survive transport
`
`across networks, operate on any client, and assure the client that it was safe to run.
`The popularization of the World Wide Web made these attributes of Java
`much more interesting. The Internet demonstrated how media-rich content could
`be made accessible in simple ways. Web browsers such as Mosaic enabled mil—
`[ions of people to roam the Net and made Web surfing part of popular culture. At
`last there was a medium where what you saw and heard was essentially the same
`whether you were using a Mac, PC, or UNIX machine, and whether you were
`connected to a high—speed network or a slow modem.
`Web enthusiasts soon discovered that the content supported by the Web’s
`HTML document format was too limited. HTML extensions, such as forms, only
`
`highlighted those limitations, while making it clear that no browser could include
`all the features users wanted. Extensibility was the answer.
`Sun‘s HotJava browser showcases Java‘s interesting properties by making it
`
`possibie to embed Java programs inside HTML pages. These programs, known as
`applets, are transparently downloaded into the HotJava browser along with the
`HTML pages in which they appear. Before being accepted by the browser, applets
`are carefully checked to make sure they are safe. Like HTML pages, compiled
`Java programs are network“ and platform-independent. Applets behave the same
`
`Page 3 of 27
`
`Page 3 of 27
`
`
`
`THE M VAT” errUAL MACHINE SPECIFICATION
`
`way regardless of where they come from, or what kind of machine they are being
`loaded into and run on.
`
`With Java as the extension language, a Web browser is no longer limited to a
`fixed set of capabilities. Programmers can write an applet once and it will run on
`any machine, anywhere. Visitors to Java-powered Web pages can use content
`found there with confidence that it will not damage their machine.
`Java has demonstrated a new way to use the Internet to distribute software.
`This new paradigm goes beyond browsers. We think it is an innovation with the
`
`potential to change the course of computing.
`
`The Java Virtual Machine
`
`The Java Virtual Machine is the cornerstone of Sun ’s Java programming language. It
`is the component of the Java technology resPonsible for Java’s cross—platform deliv»
`ery, the small size of its compiled code, and Java’s ability to protect users from mali-
`cious programs.
`
`The Java Virtual Machine is an abstract computing machine. Like a real com-
`puting machine, it has an instruction set and uses various memory areas. It is rea-
`sonably common 'to implement a programming language using a virtual machine;
`the best-known virtual machine may be the P—Code machine of UCSD Pascal.
`
`The first prototype implementation of the J ava- Virtual Machine, done at Sun
`Microsystems, Inc., emulated its instruction set in software on a handheld
`
`device that resembled a contemporary Personal Digital Assistant (PDA). Sun’s
`current Java release, the Java Developer’s Kit (JDK) version 1.0.2, emulates the
`Java Virtual Machine on Win32, MacOS, and Solaris platforms. However, the
`Java Virtual machine does not assume any particular implementation technology
`or host platform. It is not inherently interpreted, and it may just as well be
`implemented by compiling its instruction set to that of a real CPU, as for a con-
`ventional programming language. It may also be implemented in microcode, or
`directly in silicon.
`Eelaxalfirtual Maghiaglmowengthingcfitheiavaprcgranunjnglangggg,
`only of a particularfilejnmlat,.1hc..cla§imeiqrmat. A class file contains Java
`
`Virtual Machine instructions (or byrecodes) and a symbol table, as well as other
`ancillary information.
`
`Page 4 of 27
`
`Page 4 of 27
`
`
`
`INTRODUCTION
`
`For'the sake of security, the Java Virtual Machine imposes strong format and
`structural constraints on the code in a class file. However, any language with
`
`functionality that can be expressed in terms of a valid class file can be hosted by
`
`the Java Virtual Machine. Attracted by a. generally available, machine-indepen-
`
`dent platform, irnplementors of other languages are turning to the Java Virtual
`Machine as a delivery vehicle for their languages. In the future, we Will consider
`bounded extensions to the Java Virtual Machine to provide better Support for other
`
`languages.
`
`Summary of Chapters
`
`The rest of this book is structured as follows:
`
`Chapter 2 gives an overview of Java concepts and terminology necessary for
`the rest of the book.
`I
`
`Chapter 3 gives an overview of the Java Virtual Machine.
`
`Chapter 4 defines the C1 ass file format, a platform- and implementation-
`
`independent file format for compiled Java code.
`
`Chapter 5 describes runtime management of the constant pool.
`
`Chapter 6 describes the instruction set of the Java Virtual Machine, presenting
`the instructions in alphabetical order of opcode mnemonics.
`
`Chapter 7 gives examples of compiling Java code into the instruction set of the
`Java Virtual Machine.
`
`Chapter 8 describes Java Virtual Machine threads and their interaction with
`memory.
`
`Chapter 9 describes an optimization used by Sun’s implementation of the Java
`
`Virtual Machine. While not strictly part of the specification. it is a useful tech-
`nique in itself, as well as an example of the sort of implementation technique
`
`that may be employed within a Java Virtual Machine implementation.
`
`Chapter 10 gives a table of Java Virtual Machine opcode mnemonjcs indexed
`
`by opcode value.
`
`Page 5 of 27
`
`Page 5 of 27
`
`
`
`4
`
`THE M. 1m“ VIRTUAL MACHINE SPECIFICATION
`
`Use of Fonts
`
`In this book, fonts are used as follows:
`
`- A 'F'i xed width font is used for code examples written in Java, Java Virtual
`Machine data types, exceptions, and errors.
`
`- Italic is used for Java Virtual Machine “assembly language,” its opcodes and
`operands, as well as items in the Java Virtual Machine’s runtime data areas. It
`
`is also used to introduce new terms, and simply for emphasis.
`
`Page 6 of 27
`
`Page 6 of 27
`
`
`
`CHAPTER 2
`
`
`
`Java Concepts
`
`THE Java Virtual Machine was designed to support the Java programming lan—
`guage. Some concepts and vocabulary from the Java language are thus necessary
`to understand the virtual machine. This chapter gives enough of an overview of
`Java to support the discussion of the Java Virtual Machine to follow. Its material
`
`has been condensed from The Java Language Specification, by James Gosling,
`
`Bill Joy, and Guy Steele. For a complete discussion of the Java language, or for
`details and examples of the material in this chapter, refer to that book. Readers
`familiar with that book may wish to skip this chapter. Readers familiar with Java,
`
`but not with The Java Language Specification, should at least skim this chapter
`for the terminology it introduces.
`
`This chapter does not attempt to provide an introduction to or a full treatment of
`the Java language. For an introduction to Java, see The Java Programming Lan-
`
`guage, by Ken Arnold and James Gosling.
`
`2.1 Unicode
`
`Java programs are written using the Unicode character encoding, version 1.1.5, as
`specified in The Unicode Standard: Worldwide Character Encoding. Version 1.0,
`Volume 1, ISBN 0—201—56788—1, and Volume 2, ISBN 0—201—60845—6, and the
`
`update information about Unicode 1.1.5 available at ftp : //un1' code . org. There
`
`are a few minor errors in this update information; refer to The Java Language
`Specification for corrections. Updates to the Unicode information published there
`will be posted under the URL. http : //j ava. sun . com/Seri es.
`Except for comments and identifiers (§2_.2) and the contents of character
`
`and string literals (§2.3), all input elements in a Java program are formed from
`only ASCII characters. ASCII (ANSI X3.4) is the American Standard Code for
`
`Page 7 of 27
`
`Page 7 of 27
`
`
`
`THE JAVATM VIRTUAL MACHINE SPECIFICATION
`
`Information Interchange. The first 128 characters of the Unicode Character
`encoding are the ASCII characters.
`
`2.2
`
`Identifiers
`
`An identifier is an unlimited-length sequence of Unicode letters and digits, the
`first of which must be a letter. Letters and digits may be drawn from the entire
`Unicode character set, which supports most writing scripts in use in the world
`today. This allows Java programmers to use identifiers in their programs that are
`written in their native languages.
`The Java method Character.is]avaLetter returns true when passed a
`Unicode character that is considered to be a letter in Java identifiers. The Java
`
`'
`
`method Character.isJavaLetter‘OrDigit returns true when passed a Uni-
`code character that is considered to be a letter or digit in Java identifiers.
`Two identifiers are the same only if they have the same Unicode character for
`each letter or chgit; identifiers that have the same external appearance may still be
`different. An identifier must not be the same as a Java keyword or a boolean literal
`(true or Fal 5e).
`
`2.3
`
`Literals
`
`A literal is the source code representation of a value of a primitive type (§2.4.1),
`the St rfi ng type (§2.4.7), or the null type (§2.4). String literals and, more gener— _
`ally, strings that are the values of constant expressions, are “interned” so as to
`share unique instances, using the method String. 1' ntern.
`The null type has one value, the null reference, denoted by the literal null.
`The bool ean type has two values, denoted by the literals true and fal SE.
`
`2.4
`
`Types and Values
`
`Java is a strongly typed language, which means that every variable and every
`expression has a type that is known at compile time. Types limit the values that a
`variable (§2.S) can hold or that an expression can produce, limit the operations
`supported on those values, and determine the meaning of those operations. Strong
`typing helps detect errors at compile time.
`
`Page 8 of 27
`
`Page 8 of 27
`
`
`
`JAVA CONCEPTS
`
`The types of the Java language are divided into two categories: primitive types
`(§2.4.1) and reference types (§2.4.5). There is also a special rial! type, the type of
`the expression null , which has no name. The null reference is the only possible
`
`value of an expression of null type, and can always be converted to any reference
`type. In practice, the Java programmer can ignore the null type and just pretend
`that null is a special literal that can be of any reference type.
`Corresponding to the primitive types and reference types, there are two catev
`gories of data values that can be stored in variables, passed as arguments, returned
`by methods, and operated upon: primitive voices (§2.4.l) and reference values
`(§2.4.5).
`
`2.4.1
`
`Primitive Types and Values
`
`A primitive type is a type that is predefined by the Java language and named by a
`
`reserved keyword. Primitive values do not share state with other primitive values.
`A variable whose type is a primitive type always holds a primitive value of that
`type.1
`The primitive types are the bool ean type and the numeric types. The numeric
`types are the integral types and the floating-point types.
`The integral types are byte, short, int, and long, whose values are 8-bit,
`16-bit, 32-bit, and 64—bit signed two’s-complement integers, respectively, and
`
`char, whose values are 16-bit unsigned integers representing Unicode characters
`(§2-1)-
`'
`
`The floating-point types are ‘Float, whose values are 32-bit IEEE 754 float~
`ing-point numbers, and double, whoSe values are 64-bit IEEE 754 floating—point
`
`numbers as specified in IEEE Standard for Binary Floating—Point Arithmetic,
`ANSIIIEEE Standard 754-1985 (IBEE, New York). The IEEE 754 standard
`
`includes not only positive and negative Signwmagnitude numbers, but also positive
`
`and negative zeroes, positive and negative infinities, and a special Not~a~Number
`(hereafter abbreviated NaN) value. The NaN value is used to represent'the result
`
`of certain operations such as dividing zero by zero.
`The bool ean type has the truth values true and fal 5e.
`
`1' Note that a local variable is not initialized on its creation, and is only considered to hold a value
`once it is assigned to (§2.5.1).
`
`Page 9 of 27
`
`Page 9 of 27
`
`
`
`THE JAVAT“ VIRTUAL MACHINE SPECIFICATION
`
`2.4.2 Operators on Integral Values
`
`lava provides a number of operators that act on integral values, including numerical
`comparison (which results in a value of type bool ean), arithmetic operators, incre-
`ment and decrement, bitvvise logical and shift operators, and numeric cast (§2.6.8).
`Operands of certain unary and binary operators are subject to numeric promo-
`tion @269).
`_
`The built—in integer operators do not indicate overflow or underflow in any
`way; they wrap around on overflow or underflow. The only integer operators that
`can throw an exception are the integer divide and integer remainder operators,
`which can throw an Arithmet'i cExcepti on if the right-hand operand is zero.
`Any value of any integral type may be cast to or from any numeric type. There
`' are no casts between integral types and the type 13001 ean.
`
`2.4.3 Operators on Floating-Point Values
`
`Java provides a number of operators that act on floating-point values, including
`numerical comparison (which results in a value of type boo'l ean), arithmetic
`operators, increment and decrement, and numeric cast (§2.6.8).
`If at least one of the operands to a binary operator is of floating-point type,
`then the operation is a floating-point operation, even if the other operand is inte-
`gral. Operands of certain unary and binary operators are subject to numeric pro~
`motion_(§2.6.9).
`
`Operators on floating—point numbers behave exactly as specified by IEEE
`754. In particular, Java requires support of IEEE 754 denormah’zed floating-point
`numbers and gradual underflow, which make it easier to prove desirable proper-
`ties of particular numerical algorithms.
`'
`,
`Java requires that floating—point arithmetic behave as if every floating-point
`operator rounded its floating-point result to the result precision. Inexact results
`must be rounded to the representable value nearest to the infinitely precise result;
`if the two nearest representable values are equally near, the one with its least Sig-
`nificant bit zero is chosen. This is the IEEE 754 standard’s default rounding mode
`known as mandate-nearest.
`
`Java uses round-towards-zero mode when converting a floating-point value to
`an integer (§2.6.3). Round-towardsqero mode acts as though the number were mine
`cated, discarding the mantissa bits. Round-towards—zero chooses as its result the for
`' mat ’5' value closest to and no greater in magnitude than the infinitely precise result.
`
`Page 10 of 27
`
`Page 10 of 27
`
`
`
`JAVA CONCEPTS
`
`Java floating—point operators produce no exceptions (§2.15). An operation that
`
`overflows produces a signed infinity; an operation that underflows produces a
`signed zero; and an operation that has no mathematically definite result produces
`NaN. All numeric operations (except for numeric comparison) with NaN as an '
`operand produce NaN as a result.
`
`Any value of any floating-point type may be cast (§2.6.8) to or from any
`numeric type. There are no casts between floating-point types and the type
`bool e an.
`
`2.4.4 Operators on bool ean Values
`
`The boolean operators include relational operators and logical operators. Only
`bool ean expressions can be used in Java’s control flow statements and as the first
`
`operand of the conditional operator ? :. An integral value x can be converted to a
`value of type boolean, following the C language convention that any nonzero
`value is true, by the expression x ! =0. An object reference ob j can be converted
`to a value of type boolean, following the C language convention that any refer-
`ence other than null is true, by the expression obj !=nul 1.
`
`There are no casts between the type bool can and any other type.
`
`2.4.5 Reference Types, Objects, and Reference Values
`
`There are three kinds of reference types: the class types (§2.8), the interface types
`(§2.13), and the array types (§2.14). An object is a dynamically created class
`instance or an array. The reference values (often just references) are pointers to
`these objects and a special null reference, which refers to no object.
`
`A class instance is explicitly created by a class instance creation expression,
`
`or by invoking the newInstance method of class Cl ass. An array is explicitly
`created by an array creation expression. An object is created in the Java beep, and
`is garbage collected after there are no more references to it. Objects are never
`
`reclaimed or freed by explicit Java language directives.
`There may be many references to the same object. Most objects have state,
`
`stored in the fields of objects that are instances of classes or in the variables that
`are the components of an array object. If two variables contain references to the
`
`same object. the state of the object can be modified using one variable’s reference
`to the object, and then the altered state can be observed through the other vari-
`able’s reference.
`
`Page 11 of 27
`
`Page 11 of 27
`
`
`
`10
`
`THE M. VAT“ VIRTUAL MACHINE SPECIFICATION _
`
`Each object has an associated lock (§2.17, §8.13) that is used by synch roni zed
`methods and by the synchronized statement to provide control over concurrent
`access to state by multiple threads (§2..17, §8.12).
`'
`
`Reference types form a hierarchy. Each class type is a subclass of another
`class type, except for the class Object (§2.4.6), which is the superclass (§2.8.3)
`of all other class types. All objects, including arrays, support the methods of class
`Object. String literals -(§2.3) are references to instances of class String (§2.4.7).
`
`2.4.6
`
`The Class Object
`
`The standard class Object is the superclass (§2.8.3) of all other classes. A vari-
`
`able of type Object can hold a reference to any object, whether it is an instance of
`a class or an array. All class and array types inherit the methods of class Object.
`
`2.4.7
`
`The Class 51: ring
`
`Instances of class String represent sequences of Unicode characters (§2.1). A
`
`String object has a constant, unchanging value. String literals (§2.3) are refer»
`ences to instances ofclass String.
`
`2.4.8 Operators on Objects
`
`The operators on objects include field access, method invocation, cast, suing con-
`catenation, comparison for equality, instanceof, and the conditional operator ? z.
`
`2.5 Variables
`
`A variable is a storage location. It has an associated type, sometimes called its
`compile-time type, that is either a primitive type (§2.4.1) or a reference type
`{§2.4.5). A variable always contains a value that
`is assignment compatible
`(§2.6.6) with its type. A variable of a primitive type always holds a value of that
`exact primitive type. A variable of reference type can hold either a null reference
`or a reference to any object whose class is assignment compatible (§2.6.6) with
`the type of the variable.
`
`Compatibility of the value of a variable with its type is guaranteed by the
`design of the Java language because default values (§2.5.1) are compatible and
`
`all assignments to a variable are checked, at compile time, for assignment com-
`patibility.
`
`Page 12 of 27
`
`Page 12 of 27
`
`
`
`JAVA CONCEPTS
`
`There are seven kinds of variables:
`
`11
`
`. A class variable is a field of a class type declared using the keyword static
`(§2.9.1) within a class declaration, or with or without the keyword start c in
`an interface declaration. Class variables are created when the class or interface
`
`is loaded (§2.16.2) and are initialized on creation to default values (§2.5.l).
`The class variable effectively ceases to exist when its class or interface is
`
`unloaded @2168) after any necessary finalization of the class (§2.l6.8) has
`been completed.
`
`. An instance variable is a field declared within a class declaration without using
`the keyword static (§2.9.1). If a class Thas a field a that is an instance vari—
`able, then a new instance variable a is created and initialized to a default value
`
`(§2.5. l) as part of each newly created object-of class Tor of any class that is a
`subclass of T. The instance variable effectively ceases to exist when the object
`of which it is a field is no longer referenced, after any necessary finalization of
`
`the object (§2.16.7) has been completed.
`
`. Array components are unnamed variables that are created and initialized to
`
`default values (§2.5 .1) whenever a new object that is an array is created
`
`(§2.16.6). The array components effectively cease to exist when the array is no
`longer referenced.
`
`. Methoa’parameters name argument values passed to a method. For every param—
`eter declared in a method declaration, a new parameter variable is created each
`time that method is invoked. The new variable is initialized with the correspond—
`ing argument value from the method invocation. The method parameter effec—
`tively ceases to exist when the execution of the body of the method is complete.
`
`_ Constructor parameters name argument values passed to a constructor. For
`every parameter declared in a constructor declaration, a new parameter vari-
`able is created each time a class instance creation expression or eXplicit con-
`structor invocation is evaluated. The new variable is initialized with the
`corresponding argument value from the creation expression or constructor
`invocation. The constructor parameter effectively ceases to exist when the exe—
`
`cution of the body of the constructor is complete.
`
`'
`
`. An exception-handler parameter variable is created each time an exception is
`caught by a catch clause of a t r'y statement (§2. 15.2). The new variable is ini-
`tialized with the actual object associated with the exception (§2.15.3). The
`exception—handler parameter effectively ceases to exist when execution of the
`block associated with the catch clause (§2.15.2) is complete.
`
`Page 13 of 27
`
`Page 13 of 27
`
`
`
`12
`
`THE M. VAT” VIRTUAL MACHINE SPECIFICATION
`
`7. Local variables are declared by local variable declaration statements. When—
`ever the flow'of control enters ablock or a for statement, a new variable is cre—
`
`ated for each local variable declared in a local variable declaration statement
`
`immediately contained within that block or for statement. The local variable
`is not initialized, however, until the local variable declaration statement that
`
`declares it is executed. The local variable effectively ceases to exist when the
`execution of the block or fo r' statement is complete.
`
`2.5.1
`
`Initial Values of Variables
`
`Every variable in a Java program must have a value before it is used:
`
`- Each class variable, instance variable, and array component is initialized with
`a default value when it is created:
`
`I For type byte, the default value is zero, that is, the value of (byte)@.
`
`I For type short, the default value is zero, that is, the value of (short) 0.
`
`I For type int, the default value is zero, that is, B.
`
`I For type long, the default value is zero, that is, fit.
`
`. For type float, the default value is positive zero, that is, 0.01:.
`
`. For type double, the default value is positive zero, that is, 0 . @d.
`
`I For type char, the default value is the null character, that is,
`
`'\u000@ '.
`
`I For type bool ean, the default value is false.
`
`I For all reference types (§2.4.5), the default value is null (§2.3).
`
`. Each method parameter [§2.5) is initialized to the corresponding argument
`value provided by the invoker of the method.
`
`. Each constructor parameter (§2.5) is initialized to the corresponding argument
`value provided by an object creation expression or explicit constructor invoca~
`tion.
`
`- An exception-handler parameter (§2.15.2) is initialized to the thrown object
`representing the exception (§2.15.3)_
`
`- A local variable must be explicitly given a value before it is used, by either ini—
`tialization or assignment.
`
`Page 14 of 27
`
`Page 14 of 27
`
`
`
`JAVA CONCEPTS
`
`13
`
`2.5.2 Variables Have Types, Objects Have Classes
`
`Every objectbelongs to some particular class. This is the class that was mentioned
`
`in the class instance creation expression that produced the object, or the class
`whose class object was used to invoke the newInstance method to produce the
`
`object. This class is called the class of the object. An object is said to be an
`instance of its class and of all superclasses of its class. Sometimes the class of an
`object is called its “runtiine type," but “class” is the more accurate term.
`(Sometimes a variable or expression is said to have a “runtime type,” but that
`
`is an abuse of terminology; it refers to the class of the object referred to by the
`value of the variable or expression at run time, assuming that the value is not
`ml 1. Properly speaking, type is a compile—time notion. A variable or expression
`
`has a type; an object or array has no type, but belongs to a class.)
`' The type of a variable is always declared, and the type of an expression can be
`
`deduced at compile time. The type limits the possible values that the variable can
`hold or the expression can produce at run time. If a runtime value is a reference
`
`that is not ml 1 , it refers to an object or array that has a class (not a type), and that
`class will necessarily be compatible with the compile-time type.
`Even though a variable or expression .may have a compile-time type that is an
`
`interface type, there are no instances of interfaces (§2.13). A variable or expres-
`sion whose type is an interface type can reference any object whose class imple-
`ments that interface.
`'
`
`Every array also has a class. The classes for arrays have strange names that
`
`are not valid .Tava identifiers; for example, the class for an array of in compo-
`nents has the name “ [1".
`
`2.6 Conversions and Promotions
`
`Conversions implicitly change the type, and sometimes the value, of an expres-
`sion to a type acceptable for its surrounding context. In some cases this will
`
`require a corresponding action at run tirne to check the validity of the conversion
`or to translate the runtime value of the expression into a form appropriate for the
`
`new type.
`
`Numeric promotions are conversions that change an operand of a numeric
`operation to a wider type, or both operands of a numeric operation to a common
`
`type, so that an operation can be performed.
`
`Page 15 of 27
`
`Page 15 of 27
`
`
`
`14
`
`THE .IAVAT“ VIRTUAL MACHINE SPECIFICATION
`
`In Java, there are six broad kinds of conversions:
`
`Identity conversions
`
`Widening primitive conversions
`
`Narrowing primitive conversions
`
`Widening reference conversions
`
`Narrowing reference conversions
`
`String conversions
`
`There are five conversion contexts in which conversion expressions can occur.
`Each context allows conversions in some of the above-named categories but not
`others. The conversion contexts are:
`
`Assignment conversion (§2.6.6), which converts the type of an expression to
`the type of a specified variable. The conversions permitted for assignment
`
`are limited in such a way that assignment conversion never causes an excep-
`tion.
`
`Method invocation conversion (§2.6.7), which is applied to each argument in
`a method or constructor invocation, and, except in one case, performs the same
`conversions that assignment conversion does. Method invocation conversion
`never causes an exception.
`
`Casting conversion (§2.6.8), which converts the type of an expression to a type
`explicitly specified by a cast operator. It is more inclusive than assignment or
`method invocation conversion, allowing any specific conversion other than a
`
`string conversion, but certain casts to a reference type may cause an exception
`at run time.
`
`String conversion, which allows any type to be converted to type St r'i ng (§2.4.7).
`
`Numeric promotion, which brings the operands of a numeric operator to a
`common type so that an operation can be performed.
`
`String conversion only applies to operands of the binary + operator when one
`of the arguments is a St r"i ng; it will not be covered further.
`
`2.6.1
`
`Identity Conversions
`
`A conversion from a type to that same type is permitted for any type.
`
`Page 16 of 27
`
`Page 16 of 27
`
`
`
`JAVA CONCEPTS
`
`2.6.2 Widening Primitive Conversions
`
`The following conversions on primitive types are called the widening primitive
`conversions:
`
`- byte to short, int, long, float, or double
`
`0 short to “int, long, float, or double-
`
`« char to int, long, 'Fl oat, or double
`
`0 int to long, float, or double
`
`0
`
`long to fl oat or double
`
`' Float to double
`
`Widening conversions do not lose information about the sign or order of mag—
`nitude of a numeric value. Conversions widening from an integral type to another
`integral type and from 'Fl oat to double do not lose any information at all; the
`numeric value is preserved exactly. Conversion of an int or a long value to
`
`fl cat, or of a long value to double, may lose precision, that is, the result may
`
`lose some of the least significant bits of the value; the resulting floating-point
`value is a correctly rounded version of the integer value, using IEEE 754 round—
`to~nearest mode (§2.4.3).
`
`According to this rule, a widening conversion of a signed integer value to an
`integral type simply sign—extends the two‘s-complement representation of the
`integer value to fill the wider format. A widening conversion of 'a value of type
`char to an integral type zero~extends the representation of the character value to
`fi