Java Reference
In-Depth Information
Chapter 4. Types, Values, and Variables
The Java programming language is a statically typed language, which means that every vari-
able and every expression has a type that is known at compile time.
The Java programming language is also a strongly typed language, because types limit the
values that a variable (§ 4.12 ) can hold or that an expression can produce, limit the opera-
tions supported on those values, and determine the meaning of the operations. Strong static
typing helps detect errors at compile time.
The types of the Java programming language are divided into two categories: primitive types
and reference types. The primitive types (§ 4.2 ) are the boolean type and the numeric types.
The numeric types are the integral types byte , short , int , long , and char , and the floating-point
types float and double . The reference types (§ 4.3 ) are class types, interface types, and array
types. There is also a special null type. An object (§ 4.3.1 ) is a dynamically created instance
of a class type or a dynamically created array. The values of a reference type are references
to objects. All objects, including arrays, support the methods of class Object 4.3.2 ) . String
literals are represented by String objects (§ 4.3.3 ) .
4.1. The Kinds of Types and Values
There are two kinds of types in the Java programming language: primitive types (§ 4.2 ) and
reference types (§ 4.3 ). There are, correspondingly, two kinds of data values that can be
stored in variables, passed as arguments, returned by methods, and operated on: primitive
values (§ 4.2 ) and reference values (§ 4.3 ).
Type:
PrimitiveType
ReferenceType
There is also a special null type , the type of the expression null 3.10.7 , § 15.8.1 ), which has
no name.
Because the null type has no name, it is impossible to declare a variable of the null type or
to cast to the null type.
The null reference is the only possible value of an expression of null type.
The null reference can always undergo a widening reference conversion to any reference
type.
Search WWH ::




Custom Search