Comments ,Types,Variables and Scope

Comments and Program Layout:

Comments have no effect on the execution of the program but may be inserted anywhere to help
humans understand the program. There are two forms: one-line comments and delimited comments.Program layout has no effect on the computer's execution of the program but is used to help humans understand the structure of the program.

within the class we write like this:
// This is a one-line comment; it extends to the end of the line.

/* This is a delimited comment,
extending over several lines.
*/

int /* This delimited comment extends over part of a line */ x = 117;

Types:

A type is a set of values and operations on them. A type is either a primitive type or a reference type.

Primitive Types :


A primitive type is either boolean or one of the numeric types char, byte, short, int, long, float,
and double.

The integer types are exact within their range. They use signed 2's complement representation (except for char), so when the most positive number in a type is max, then the most negative number is -max-1. The floating-point types are inexact and follow IEEE754, with the number of significant digits indicated by "sigdig." For character escape sequences such as \u0000.
Integer literals (of type byte, char, short, int, or long) may be written in three different bases:

Notation Base Distinction

Decimal 10 no leading 0

Hexa Decimal 16 leading 0x

octal 8 leading 0

For all primitive types there are corresponding wrapper classes , namely Boolean and Character as well as Byte, Short, Integer, Long, Float, and Double, where the last six have the common superclass Number. To use a primitive value, such as 17, where an object is expected, use an object of its wrapper class, such as new Integer(17).

Reference Types :

A reference type is either a class type defined by a class declaration , or an interface type defined by an interface declaration , or an array type .A value of reference type is either null or a reference to an object or array. The special value null denotes "no object." The literal null, denoting the null value, can have any reference type.

Array Types :

An array type has the form t[], where t is any type. An array type t[] is a reference type. Hence a value of array type t[] is either null, or is a reference to an array whose element type is precisely t (when t is a primitive type), or is a subtype of t (when t is a reference type).

Subtypes and Compatibility :

A type t1 may be a subtype of a type t2, in which case t2 is a supertype of t1. Intuitively this means that any value v1 of type t1 can be used where a value of type t2 is expected. When t1 and t2 are reference types, t1 must provide at least the functionality (methods and fields) provided by t2. In particular, any value v1 of type t1 may be bound to a variable or field or parameter x2 of type t2, e.g., by the assignment x2 = v1 or by parameter passing. We also say that types t1 and t2 are compatible.

The following rules determine when a type t1 is a subtype of a type t2:

Every type is a subtype of itself.

If t1 is a subtype of t2, and t2 is a subtype of t3, then t1 is a subtype of t3.

char is a subtype of int, long, float, and double.

byte is a subtype of short, int, long, float, and double.

short is a subtype of int, long, float, and double.

int is a subtype of long, float, and double.

long is a subtype of float and double.

float is a subtype of double.

If t1 and t2 are classes, then t1 is a subtype of t2 if t1 is a subclass of t2.

If t1 and t2 are interfaces, then t1 is a subtype of t2 if t1 is a sub interface of t2.

If t1 is a class and t2 is an interface, then t1 is a subtype of t2 provided that t1 (is a
subclass of a class that) implements t2 or implements a subinterface of t2.

Array type t1 [] is a subtype of array type t2 [] if reference type t1 is a subtype of
reference type t2.

reference type t, including any array type, is also a subtype of predefined class Object.

No primitive type is a subtype of a reference type. No reference type is a subtype of a primitive type.

RELATED POST

RUNNING JAVA

No comments:

Post a Comment