• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

my notes on JLS for any1 who needs them !!

 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Notes from JLS & Thinking in Java
Chapter : Types, Values and Variables
�Types of Java programming language are divided into 2 categories : primitives and references.
�Primitives are : boolean and numeric types (byte, short, int, long, char, float and double)
�Reference types : classes, interfaces, arrays
�Null is a special type
�Variable is a storage location
�Variable of primitive type always holds a value of that exact type
�A variable of class type T can hold a null reference or a reference to an instance of T or a reference to an instance of any subclass of T.
�Variable of interface I can hold a null reference or a reference to an instance of any class that implements I.
�Variable of array type A can hold a null reference or a reference to any array of type S that is assignable to A
�Variable of type Object can hold a null reference, or a reference to any object, whether class or array
�The value of a variable of primitive type can only be changed by assignment operations on that variable.
�boolean has exactly 2 values : true and false.
�The values of the integral types are integers in the following ranges:
�For byte, from -128 to 127, inclusive
�For short, from -32768 to 32767, inclusive
�For int, from -2147483648 to 2147483647, inclusive
�For long, from -9223372036854775808 to 9223372036854775807, inclusive
�For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535
�If an integer operator other than shift operator has at least 1 operand of type long, then the smaller is widened to long and operation is performed.
�If an integer operator other than shift operator has at least 1 operand of type int, then the smaller is widened to int and operation is performed.
�If both operands are smaller than int, both are promoted to int before operation is carried out.
�String concatenation operator implicitly creates a new string
Seven types of variables
�Class variables : field declared using the keyword static within a class declaration, with or without the keyword static in an interface declaration.
A class variable is created when it�s class or interface is prepared and initialized to a default value. It ceases to exist when it�s class or interface is unloaded
�Instance variables : declared within a class declaration without using the keyword static. It is created and initialized to a default value for every new object created of the class that contains it. It ceases to exist when the object of which it is a field is no longer referenced.
�Array Components : unnamed variables that are created and initialized to default values whenever a new array is created. They cease to exist when the array is no longer referenced.
�Method Parameters : argument values passed to a method. For every parameter declared in a method, a new parameter variable is created each time the method is invoked. This new variable is initialized with the corresponding argument value from the method invocation. It ceases to exist when the execution of the method body is complete.
�Constructor Parameters : argument values passed to a constructor. For every parameter declared in a constructor, a new parameter variable is created each time a class is created or that constructor is explicitly invoked. This new variable is initialized with the corresponding argument value from the constructor invocation. It ceases to exist when the execution of the constructor body is complete.
�Exception Handler Parameter : created each time an exception is caught by a catch clause of a try statement. Variable is initialized with the actual object associated with the exception. It ceases to exist when the execution of the block associated with the catch clause completes execution.
�Local Variables : whenever the flow of control enters a block, a for statement, a new variable is created for each local variable declared in a local variable declaration statement. It may contain an expression that initializes that variable. The variable is not initialized till its initialization statement is executed. It ceases to exist when the execution of the block or for statement is complete
�Final variable : value can be assigned to it only once.
�Once a final variable has been assigned, it always contains the same value. If a final variable holds a reference to an object, then the state of the object may be changed by operations on the object, but the variable will always refer to the same object. This applies also to arrays, because arrays are objects; if a final variable holds a reference to an array, then the components of the array may be changed by operations on the array, but the variable will always refer to the same array.

Chapter : Expressions
�When an expression in a program is evaluated, the result denotes one of three things :
�A variable
�A value
�Nothing (void)
�An expression denotes nothing if and only if it is a method invocation that invokes a void method.
�Each expression occurs in the declaration of some type that is being declared: in a field initializer, in a static initializer, in a constructor declaration or the code for a method.
�If an expression denotes a variable or a value, then the expression has a type known at compile time.
�An expression whose type is a final class F is guaranteed to have a value that is either null or an object whose class is F itself, because final types have no sub classes
�If the type of an expression is a reference type, then the class of the referenced object, is not necessarily known at compile time. There are a few places in the Java programming language where the actual class of a referenced object affects program execution in a manner that cannot be deduced from the type of the expression. They are as follows:
�Method invocation. The particular method used for an invocation o.m(...) is chosen based on the methods that are part of the class or interface that is the type of o. For instance methods, the class of the object referenced by the run-time value of o participates because a subclass may override a specific method already declared in a parent class so that this overriding method is invoked. (The overriding method may or may not choose to further invoke the original overridden m method.)
�The instanceof operator. An expression whose type is a reference type may be tested using instanceof to find out whether the class of the object referenced by the run-time value of the expression is assignment compatible with some other reference type.
�Casting. The class of the object referenced by the run-time value of the operand expression might not be compatible with the type specified by the cast. For reference types, this may require a run-time check that throws an exception if the class of the referenced object, as determined at run time, is not assignment compatible with the target type.
�Assignment to an array component of reference type. The type-checking rules allow the array type S[] to be treated as a subtype of T[] if S is a subtype of T, but this requires a run-time check for assignment to an array component, similar to the check performed for a cast.
�Exception handling. An exception is caught by a catch clause only if the class of the thrown exception object is an instanceof the type of the formal parameter of the catch clause.
�The first two of the cases just listed ought never to result in detecting a type error. Thus, a run-time type error can occur only in these situations:
�In a cast, when the actual class of the object referenced by the value of the operand expression is not compatible with the target type specified by the cast operator; in this case a ClassCastException is thrown.
�In an assignment to an array component of reference type, when the actual class of the object referenced by the value to be assigned is not compatible with the actual run-time component type of the array; in this case an ArrayStoreException is thrown.
�When any catch handler does not catch an exception; in this case the thread of control that encountered the exception first invokes the method uncaughtException for its thread group and then terminates.
�Run-time exceptions are thrown by the predefined operators as follows:
�A class instance creation expression, array creation expression, or string concatenation operator expression throws an OutOfMemoryError if there is insufficient memory available.
�An array creation expression throws a NegativeArraySizeException if the value of any dimension expression is less than zero.
�A field access throws a NullPointerException if the value of the object reference expression is null.
�A method invocation expression that invokes an instance method throws a NullPointerException if the target reference is null.
�An array access throws a NullPointerException if the value of the array reference expression is null.
�An array access throws an ArrayIndexOutOfBoundsException if the value of the array index expression is negative or greater than or equal to the length of the array.
�A cast throws a ClassCastException if a cast is found to be impermissible at run time.
�An integer division or integer remainder operator throws an ArithmeticException if the value of the right-hand operand expression is zero.
�An assignment to an array component of reference type throws an ArrayStoreException when the value to be assigned is not compatible with the component type of the array.
�A method invocation expression can also result in an exception being thrown if an exception occurs that causes execution of the method body to complete abruptly.
�A class instance creation expression can also result in an exception being thrown if an exception occurs that causes execution of the constructor to complete abruptly.
�Various linkage and virtual machine errors may also occur during the evaluation of an expression. By their nature, such errors are difficult to predict and difficult to handle.
�The this keyword may only be used in the body of an instance method, instance initializer or constructor. If it appears anywhere else, a compile time error occurs.
�An anonymous class declaration is automatically derived from a class instance creation expression by the compiler
�A final variable cannot have prefix or postfix operators in an expression
�In ternary condition, the 1st expression has to return a boolean. It is not permitted for either the second or third expressions to be the invocation of a void method

Chapter : Names
�Names are used to refer to entities in a program
�A declared entity is a package, class type, interface type, member of a reference type, parameter or a local variable
�Every declaration that introduces a name has a scope

Chapter : Packages
�A package may not contain 2 members of the same name, else a compile time error occurs
�A compilation unit consists of 3 parts, each of which is optional :
�Package declaration
�Import declarations
�Top level type declarations (class or interface)

Chapter : Conversions and Promotions
�A conversion from type Object to type Thread requires a run-time check to make sure that the run-time value is actually an instance of class Thread or one of its subclasses; if it is not, an exception is thrown.
�A conversion from type Thread to type Object requires no run-time action; Thread is a subclass of Object, so any reference produced by an expression of type Thread is a valid reference value of type Object.
�A conversion from type int to type long requires run-time sign-extension of a 32-bit integer value to the 64-bit long representation. No information is lost.
�A conversion from type double to type long requires a nontrivial translation from a 64-bit floating-point value to the 64-bit integer representation. Depending on the actual run-time value, information may be lost.
Types of Conversions
�Identity Conversion : a conversion from a type to the same type, is the only permitted conversion type for boolean.
�Widening Primitive :
The following conversions are widening primitive conversions:
�byte to short, int, long, float, or double
�short to int, long, float, or double
�char to int, long, float, or double
�int to long, float, or double
�long to float or double
�float to double
no information is lost, precision may be lost while converting int to float, never result in run-time exceptions
�Narrowing Primitive :
The following conversions are narrowing primitive conversions:
�byte to char
�short to byte or char
�char to byte or short
�int to byte, short, or char
�long to byte, short, char, or int
�float to byte, short, char, int, or long
�double to byte, short, char, int, long, or float
loss of information and precision may take place, higher order bits are discarded, never results in run-time exception
�Widening Reference :
The following conversions are widening reference conversions:
�From any class type S to any class type T, provided that S is a subclass of T. (An important special case is that there is a widening conversion to the class type Object from any other class type.)
�From any class type S to any interface type K, provided that S implements K.
�From the null type to any class type, interface type, or array type.
�From any interface type J to any interface type K, provided that J is a subinterface of K.
�From any interface type to type Object.
�From any array type to type Object.
�From any array type to type Cloneable.
�From any array type to type java.io.Serializable
�From any array type SC[] to any array type TC[], provided that SC and TC are reference types and there is a widening conversion from SC to TC.
Never throw a run-time exception, they consist simply in regarding a reference as having some other type in a manner that can be proved correct at compile time.
�Narrowing Reference:
The following conversions are called narrowing reference conversions:
�From any class type S to any class type T, provided that S is a superclass of T. (An important special case is that there is a narrowing conversion from the class type Object to any other class type.)
�From any class type S to any interface type K, provided that S is not final and does not implement K. (An important special case is that there is a narrowing conversion from the class type Object to any interface type.)
�From type Object to any array type.
�From type Object to any interface type.
�From any interface type J to any class type T that is not final.
�From any interface type J to any class type T that is final, provided that T implements J.
�From any interface type J to any interface type K, provided that J is not a subinterface of K and there is no method name m such that J and K both contain a method named m with the same signature but different return types.
�From any array type SC[] to any array type TC[], provided that SC and TC are reference types and there is a narrowing conversion from SC to TC.
Such conversions require a test at run-time to find out whether the actual reference value is a legitimate value of the new type. If not, a ClassCastException is thrown.
�String Conversion:
There is a string conversion to type String from every other type, including the null type
�Forbidden Conversions
�There is no permitted conversion from any reference type to any primitive type.
Except for the string conversions, there is no permitted conversion from any primitive type to any reference type.
�There is no permitted conversion from the null type to any primitive type.
�There is no permitted conversion to the null type other than the identity conversion.
�There is no permitted conversion to the type boolean other than the identity conversion.
�There is no permitted conversion from the type boolean other than the identity conversion and string conversion.
�There is no permitted conversion other than string conversion from class type S to a different class type T if S is not a subclass of T and T is not a subclass of S.
�There is no permitted conversion from class type S to interface type K if S is final and does not implement K.
�There is no permitted conversion from class type S to any array type if S is not Object.
�There is no permitted conversion other than string conversion from interface type J to class type T if T is final and does not implement J.
�There is no permitted conversion from interface type J to interface type K if J and K contain methods with the same signature but different return types.
�There is no permitted conversion from any array type to any class type other than Object or String.
�There is no permitted conversion from any array type to any interface type, except to the interface types java.io.Serializable and Cloneable, which are implemented by all arrays.
�There is no permitted conversion from array type SC[] to array type TC[] if there is no permitted conversion other than a string conversion from SC to TC.
�Value Set Conversion :
The process of mapping a floating point value from one value-set to another without changing its type.
�Numeric Promotion
The conversion chosen for one operand in a binary operation may partly depend on the other operand. There are different types of numeric promotions.
�Assignment Conversion : occurs when the value of the expression is assigned to a variable; the type of the expression must be converted to the type of the variable.
This allows the use of an Identity Conversion, Widening Primitive Conversion or Widening Reference Conversion.
�A Narrowing Primitive Conversion may be used if all of the following conditions are satisfied : a) expression is a constant expression of type byte, char, short or int.
b) type of variable is byte, short or int
c) the value of the expression is representable in the type of the variable
�If the type of the expression cannot be converted to the type of the variable, then a compile time error occurs.
�Assignment Conversion never causes an exception
�Compile time narrowing of constants is allowed e.g byte a = 42
�A value of a primitive type must not be assigned to a variable of reference type, this will result in a compile time error
�A value of type boolean can only be assigned to a boolean variable
�A value of null may be assigned to a reference type
�Assignment of a value of compile-time reference type S (source) to a variable of compile-time reference type T (target) is checked as follows:
�If S is a class type:
�If T is a class type, then S must either be the same class as T, or S must be a subclass of T, or a compile-time error occurs.
�If T is an interface type, then S must implement interface T, or a compile-time error occurs.
�If T is an array type, then a compile-time error occurs.
�If S is an interface type:
�If T is a class type, then T must be Object, or a compile-time error occurs.
�If T is an interface type, then T must be either the same interface as S or a superinterface of S, or a compile-time error occurs.
�If T is an array type, then a compile-time error occurs.
�If S is an array type SC[], that is, an array of components of type SC:
�If T is a class type, then T must be Object, or a compile-time error occurs.
�If T is an interface type, then a compile-time error occurs unless T is the type java.io.Serializable or the type Cloneable, the only interfaces implemented by arrays.
�If T is an array type TC[], that is, an array of components of type TC, then a compile-time error occurs unless one of the following is true:
�TC and SC are the same primitive type.
�TC and SC are both reference types and type SC is assignable to TC, as determined by a recursive application of these compile-time rules for assignability.
�Method Invocation Conversion
�Applied to each argument value in a method or constructor invocation; the type of argument must be converted to the type of the corresponding parameter. Method Invocation allows the use of Identity Conversion, Widening Primitive Conversion or Widening Reference Conversion.
�Does not include implicit narrowing of integer constants.
class Test {
static int m(byte a, int b) { return a+b; }
static int m(short a, short b) { return a-b; }
public static void main(String[] args) {
System.out.println(m(12, 2));// compile-time error
}
}
causes a compile-time error because the integer literals 12 and 2 have type int, so neither method m matches.
�String Conversion
Applies only to the operands of the binary + operator when one of the arguments is a String.
�Casting Conversion
Applied to the operand of a cast operator; the type of the operand expression must be converted to the type explicitly named by the cast operator.
Allows the use of Identity Conversion, Widening Primitive Conversion, Narrowing Primitive Conversion, Widening Reference Conversion or a Narrowing Primitive Conversion.
�Some casts can be proved incorrect at compile time and cause a compile time error.
�Value of primitive type can be cast to another primitive type using identity conversion.
�Value of primitive type cannot be cast to a reference type and vice versa
�The remaining cases involve conversion between reference types. The detailed rules for compile-time correctness checking of a casting conversion of a value of compile-time reference type S (source) to a compile-time reference type T (target) are as follows:
�If S is a class type:
�If T is a class type, then S and T must be related classes-that is, S and T must be the same class, or S a subclass of T, or T a subclass of S; otherwise a compile-time error occurs.
�If T is an interface type:
�If S is not a final class, then the cast is always correct at compile time (because even if S does not implement T, a subclass of S might).
�If S is a final class, then S must implement T, or a compile-time error occurs.
�If T is an array type, then S must be the class Object, or a compile-time error occurs.
�If S is an interface type:
�If T is an array type, then T must implement S, or a compile-time error occurs.
�If T is a class type that is not final, then the cast is always correct at compile time (because even if T does not implement S, a subclass of T might).
�If T is an interface type and if T and S contain methods with the same signature but different return types, then a compile-time error occurs.
�If S is an array type SC[], that is, an array of components of type SC:
�If T is a class type, then if T is not Object, then a compile-time error occurs (because Object is the only class type to which arrays can be assigned).
�If T is an interface type, then a compile-time error occurs unless T is the type java.io.Serializable or the type Cloneable, the only interfaces implemented by arrays.
�If T is an array type TC[], that is, an array of components of type TC, then a compile-time error occurs unless one of the following is true:
�TC and SC are the same primitive type.
�TC and SC are reference types and type SC can be cast to TC by a recursive application of these compile-time rules for casting.
�If a cast to a reference type is not a compile-time error, there are two cases:
�The cast can be determined to be correct at compile time. A cast from the compile-time type S to compile-time type T is correct at compile time if and only if S can be converted to T by assignment conversion.
�The cast requires a run-time validity check. If the value at run time is null, then the cast is allowed. Otherwise, let R be the class of the object referred to by the run-time reference value, and let T be the type named in the cast operator. A cast conversion must check, at run time, that the class R is assignment compatible with the type T, using the algorithm specified in but using the class R instead of the compile-time type S as specified there. (Note that R cannot be an interface when these rules are first applied for any given cast, but R may be an interface if the rules are applied recursively because the run-time reference value may refer to an array whose element type is an interface type.) The modified algorithm is shown here:
�If R is an ordinary class (not an array class):
�If T is a class type, then R must be either the same class as T or a subclass of T, or a run-time exception is thrown.
�If T is an interface type, then R must implement interface T, or a run-time exception is thrown.
�If T is an array type, then a run-time exception is thrown.
�If R is an interface:
�If T is a class type, then T must be Object or a run-time exception is thrown.
�If T is an interface type, then R must be either the same interface as T or a subinterface of T, or a run-time exception is thrown.
�If T is an array type, then a run-time exception is thrown.
�If R is a class representing an array type RC[]-that is, an array of components of type RC:
�If T is a class type, then T must be Object, or a run-time exception is thrown.
�If T is an interface type, then a run-time exception is thrown unless T is the type java.io.Serializable or the type Cloneable, the only interfaces implemented by arrays (this case could slip past the compile-time checking if, for example, a reference to an array were stored in a variable of type Object).
�If T is an array type TC[], that is, an array of components of type TC, then a run-time exception is thrown unless one of the following is true:
�TC and RC are the same primitive type.
�TC and RC are reference types and type RC can be cast to TC by a recursive application of these run-time rules for casting.
�If a run-time exception is thrown, it is a ClassCastException.
�Numeric promotion is applied to the operands of an arithmetic operator. It allows the use of Identity Conversion or Widening Primitive Conversion.
�Unary Numeric Promotion
Some operators apply unary numeric promotion to a single operand, which must produce a value of numeric type:
a)if the operand is of compile type byte, short or char, it is promoted to int
b)otherwise it remains as it is and it not promoted
�Unary numeric promotion is performed on expressions in the following situations:
�Each dimension expression in an array creation expression
�The index expression in an array access expression
�The operand of a unary plus operator +
�The operand of a unary minus operator �
�The operand of a bitwise complement operator ~
�Each operand, separately, of a shift operator >>, >>>, or <<; therefore a long shift distance (right operand) does not promote the value being shifted (left operand) to long
�Binary Numeric Promotion
When an operator applies binary numeric promotion to a pair of operands, each of which must denote a value of a numeric type, the following rules apply, in order, using widening conversion to convert operands as necessary:
�If either operand is of type double, the other is converted to double.
�Otherwise, if either operand is of type float, the other is converted to float.
�Otherwise, if either operand is of type long, the other is converted to long.
�Otherwise, both operands are converted to type int.
�Binary numeric promotion is performed on the operands of certain operators:
�The multiplicative operators *, / and %
�The addition and subtraction operators for numeric types + and -
�The numerical comparison operators <, <=, >, and >=
�The numerical equality operators == and !=
�The integer bitwise operators &, ^, and |
�In certain cases, the conditional operator ? :

Chapter : Arrays
�Arrays are objects, are dynamically created, may be assigned to variables of type Object, all methods of class Object may be invoked on arrays.
�Array may contain 0 components � empty array
�All components of an array have same type � component type of array
�Component type of array can itself be an array, a primitive type or a reference type
�Arrays with an interface type as the component type are allowed. The elements of such an array may have as their value a null reference or instances of any type that implements the interface.
�Arrays with an abstract class type as the component type are allowed. The elements of such an array may have as their value a null reference or instances of any subclass of the abstract class that is not itself abstract.
�Array types are used in declarations and in cast expressions
�A variable of array type holds a reference to an object
�A single variable of array type may contain references to arrays of different lengths
�Once an array object is created, it�s length never changes
�Arrays must be indexed with int values. Short, byte and char may also be used since they are subjected to unary numeric promotion
�Any attempt to access an array component with a long index value results in a compile time error
�All array accesses are checked at runtime, at attempt to use and index that is less than 0 or greater than or equal to the length of the array results in an ArrayIndexOutOfBoundsException.
�A trailing comma may appear after the last element in an array initializing statement and is ignored
�Members of an array type are :
�Public final field length � no of components of the array
�Public method clone � overrides the clone method in Object class, and throws no checked exceptions
�All members inherited from Object class, except clone
�Every array implements Cloneable and Serializable interfaces
�A clone of a multidimensional array is shallow � it only creates a single new array; sub arrays are shared
class Test {
public static void main(String[] args) throws Throwable {
int ia[][] = { { 1 , 2}, null };
int ja[][] = (int[][])ia.clone();
System.out.print((ia == ja) + " ");
System.out.println(ia[0] == ja[0] && ia[1] == ja[1]);
}
}
which prints:
false true
showing that the int[] array that is ia[0] and the int[] array that is ja[0] are the same array.
�An array of characters is not a String
�A String is immutable, while a char array has mutable elements
�ArrayStoreException :
class Point { int x, y; }
class ColoredPoint extends Point { int color; }
class Test {
public static void main(String[] args) {
ColoredPoint[] cpa = new ColoredPoint[10];
Point[] pa = cpa;
System.out.println(pa[1] == null);
try {
pa[0] = new Point();
} catch (ArrayStoreException e) {
System.out.println(e);
}
}
}
produces the output:
true
java.lang.ArrayStoreException
Here the variable pa has type Point[] and the variable cpa has as its value a reference to an object of type ColoredPoint[]. A ColoredPoint can be assigned to a Point; therefore, the value of cpa can be assigned to pa.
A reference to this array pa, for example, testing whether pa[1] is null, will not result in a run-time type error. This is because the element of the array of type ColoredPoint[] is a ColoredPoint, and every ColoredPoint can stand in for a Point, since Point is the superclass of ColoredPoint.
On the other hand, an assignment to the array pa can result in a run-time error. At compile time, an assignment to an element of pa is checked to make sure that the value assigned is a Point. But since pa holds a reference to an array of ColoredPoint, the assignment is valid only if the type of the value assigned at run-time is, more specifically, a ColoredPoint.
The Java virtual machine checks for such a situation at run-time to ensure that the assignment is valid; if not, an ArrayStoreException is thrown. More formally: an assignment to an element of an array whose type is A[], where A is a reference type, is checked at run-time to ensure that the value assigned can be assigned to the actual element type of the array, where the actual element type may be any reference type that is assignable to A.

Chapter : Classes
�Class declarations define new reference types and describe how they are implemented
�Top Level Class
Any class that is not nested
Can be : a + b where
a) public default
b) Abstract finalstatic strictfp
�It is a compile-time error if a top level type declaration contains any one of the following access modifiers: protected, private or static
�Inner Class
�Can�t be static
�Can inherit static member variables
�Can�t declare static member variables unless they are compile-time constants (final??)
�Can�t declare static initializers or member interfaces
�Any local variable, formal method parameter or exception handler parameter used but not declared in an inner class must be declared final and must be definitely assigned before the body of the inner class.
�Inner classes include local, anonymous and non-static member classes
�Nested Class
�Class whose declaration occurs within the body of another class
�Can be static
�If static, they cannot access instance variables of the surrounding class
�Anonymous Class
�No name
�Cannot have constructors
�Can never be abstract, is always an inner class, is never static and is implicitly final
�Member Interfaces
�Implicitly static
�Local Class (inside a Method)
�Can access only final variables of the enclosing method
�Can access all member variables of the enclosing class (including private)
�Abstract Class
�Cannot be final or private
�May contain final members
�A compile time error occurs if an attempt is made to create an instance of an abstract class
�A subclass of an abstract class that is not abstract may be instantiated, resulting in the execution of the constructors of the abstract class
�It is a compile time error to declare an abstract class such that it is not possible to create a subclass that implements all of it�s abstract methods
E.g if a class has as it�s members two abstract methods that have the same method signature but different return types
�If Super is an abstract class and Sub is a non-abstract subclass of Super, then
Super sup = new Sub(); // allowed
Super sup = new Super();// compile-time error
�Final Class
�Cannot be abstract
�Cannot contain abstract methods
�It is a compile time error to declare a class as both final and abstract
�A compile time error occurs if the name of a final class occurs in the extends clause
Public abstract final ClassA{// compile-time error
Public class SubFinal extends FinalClass {// compile-time error
�To prevent a class from being instantiated, declare it�s constructor to be private, never invoke it and don�t declare any other constructors.
e.g see constructor for Math class.
�A Class C directly depends on a type T if T is mentioned in the extends or implements clause of C either as a superclass or superinterface, or as a qualifier within a superclass or superinterface name. It is a compile time error if a class depends on itself
For example:
class Point extends ColoredPoint { int x, y; }
class ColoredPoint extends Point { int color; }
causes a compile-time error.
If circularly declared classes are detected at run time, as classes are loaded, then a ClassCircularityError is thrown.
�Each interface type in an implements clause must be an accessible interface type, or a compile type error occurs
�If the same interface name is mentioned more than once in the same implements clause, a compile-time error occurs.
e.g Class A implements java.lang.Cloneable, Cloneable {
�It is possible for a single method of a class to implement methods of more than one superinterface.
Eg. Interface Fish { public void swim();}
Interface Dolphin { public void swim();}
Class Porpoise implements Fish, Dolphin
{
public void swim() {����.}
}
But the following is not possible :
Eg. Interface Fish { public int fins();}
Interface Dolphin { public double fins();}
Class Porpoise implements Fish, Dolphin
{
public ??? swim() {����.}
}

In such a situation, Porpoise cannot implement both Fish and Dolphin.
�Field, method, member class, member interface and constructor declarations may include the access modifiers public, private and protected
�Newly declared fields can hide fields declared in a superclass or superinterface
�Newly declared class members can hide those declared in a superclass or superinterface
�Newly declared methods can hide, implement or override methods declared in a superclass or superinterface
�Method declarations describe code that may be invoked
�A class method is invoked relative to the class type
�An instance method is invoked relative to some particular object of that class type
�A method whose declaration does not indicate how it is implemented must be declared abstract
�A final method cannot be hidden or overridden
�A synchronized method automatically locks an object before executing it�s body and automatically unlocks the object before returning, thus allowing it�s activities to be synchronized with those of other threads
�Method names may be overloaded
�Instance initializers are blocks of executable code that may be used to help initialize an instance when it is created
�Static initializers are blocks of executable code that may be used to help initialize a class when it is first loaded
�Constructors are like methods, but cannot be directly invoked, they may be overloaded

Chapter : Blocks and Statements
�A block is a sequence of statements, local class declarations and local variable declarations within braces.
�A local class is a nested class that is not a member of any class and that has a name
�All local classes are inner classes
�The scope of a local class declared in a block is the rest of the immediately enclosing block, including it�s own class declarations
�The name of a local class C may not be redeclared as a local class of the directly enclosing method, constructor or initializer block within the scope of C or a compile time error occurs
�It is a compile time error if a local class declaration contains any one of the following access modifiers : public, protected, private or static
�If a declaration of an identifier as a local variable of the same method, constructor, or initializer block appears within the scope of a parameter or local variable of the same name, a compile-time error occurs.
Thus the following example does not compile:
class Test {
public static void main(String[] args) {
int i;
for (int i = 0; i < 10; i++)
System.out.println(i);
}
}
�A similar restriction on shadowing of members by local variables was judged impractical, because the addition of a member in a superclass could cause subclasses to have to rename local variables. Related considerations make restrictions on shadowing of local variables by members of nested classes, or on shadowing of local variables by local variables declared within nested classes unattractive as well. Hence, the following example compiles without error:
class Test {
public static void main(String[] args) {
int i;
class Local {
{
for (int i = 0; i < 10; i++)
System.out.println(i);
}
}
new Local();
}
}
�On the other hand, local variables with the same name may be declared in two separate blocks or for statements neither of which contains the other. Thus:
class Test {
public static void main(String[] args) {
for (int i = 0; i < 10; i++)
System.out.print(i + " ");
for (int i = 10; i > 0; i--)
System.out.print(i + " ");
System.out.println();
}
}
compiles without error
�The scope of a label declared by a labeled statement is the statement immediately enclosed by the labeled statement
�For statement : the 3 parts are optional
If the init part is missing, no action is taken
If the condition part is missing, the loop can only be exited using a break statement
If the condition part is false the 1st time, the loop is not entered or executed
�If no swtich, while, do or for encloses a break statement, a compile time error occurs
�A break statement must refer to a label within the immediately enclosing method or initializer block
�A continue statement may occur only in a while, do or for statement (iteration statements)
�A continue statement must refer to a label within the immediately enclosing method or initializer block
�A compile time error occurs if a return statement appears within an instance initializer or a static initializer.
�A throw statement causes an exception to be thrown
�The Expression in a throw statement must denote a variable or value of a reference type, which is assignable to the type Throwable, or a compile-time error occurs. Moreover, at least one of the following three conditions must be true, or a compile-time error occurs:
�The exception is not a checked exception -specifically, one of the following situations is true:
�The type of the Expression is the class RuntimeException or a subclass of RuntimeException.
�The type of the Expression is the class Error or a subclass of Error.
�The throw statement is contained in the try block of a try statement and the type of the Expression is assignable to the type of the parameter of at least one catch clause of the try statement. (In this case we say the thrown value is caught by the try statement.)
�The throw statement is contained in a method or constructor declaration and the type of the Expression is assignable to at least one type listed in the throws clause of the declaration.
�A synchronized statement acquires a mutual exclusion lock on behalf of the executing thread, executes a block and then releases the lock. While the executing thread owns the lock, no other thread may acquire the lock
Synchronized (expression) block
�Expression must be a reference type, else a compile time error occurs
�If expression is null, a NullPointerException is thrown
�If in a catch clause, the type of exception parameter must be class Throwable or a subclass of Throwable or a compile time error occurs
�It is a compile time error if an exception parameter that is declared final is assigned within the body of the catch clause
�It is a compile time error if a statement cannot be executed because it is unreachable

Chapter : Interfaces
�An interface declaration introduces a new reference type whose members are classes, interfaces, constants and abstract methods. This type has no implementation
�A nested interface is any interface whose body occurs within the body of another class or interface
�Programs can use interfaces to make it unnecessary for unrelated classes to share a common abstract superclass or to add methods to Object
�An interface may extend one or more interfaces
�A class may implement one or more interfaces
�A variable whose declared type is an interface type may have as its value a reference to any instance of a class which implements the specified interface. It is not sufficient that the class happens to implement all the abstract methods of the interface; the class or one of its superclasses must actually be declared to implement the interface, or else the class is not considered to implement the interface.
�Interface modifiers
Public protectedprivate
Abstractstaticstrictfp
�Every interface is abstract
�Each interface type in the extends clause must be an accessible interface type, else a compile time error occurs
�A compile time error occurs if an interface depends on itself
�All interface members are implicitly public
�It is a compile time error if the interface declares a method with the same signature and different return type or incompatible throws clause
�Every field declaration in the body of an interface is implicitly static, public and final
�It is a compile time error for the body of an interface to declare 2 variables of the same name
�Every field in the body of an interface must have an initialization expression
�A compile-time error occurs if an initialization expression for an interface field contains a reference by simple name to the same field or to another field whose declaration occurs textually later in the same interface.
Thus:
interface Test {
float f = j;
int j = 1;
int k = k+1;
}
causes two compile-time errors, because j is referred to in the initialization of f before j is declared and because the initialization of k refers to k itself.
�If the keyword this or the keyword super occurs in an initialization expression for a field of an interface, then unless the occurrence is within the body of an anonymous class, a compile-time error occurs.
�A compile time error occurs if the same modifier appears more than once in an abstract method declaration
�Every method in the body of an interface is implicitly abstract, public
�If an interface method is declared static, a compile time error occurs
�If an interface method is declared final, a compile time error occurs
�If a method declaration in an interface overrides the declaration of a method in another interface, a compile-time error occurs if the methods have different return types or if one has a return type and the other is void. Moreover, a method declaration must not have a throws clause that conflicts with that of any method that it overrides; otherwise, a compile-time error occurs.

Chapter : Definite Assignment
�Each local variable and every blank final variable must have a definitely assigned value when any access to its value occurs. If a value is not assigned, a compile time error occurs.
�Every blank final variable must be assigned at most once, else a compile time error occurs.
�If a final instance variable is defined, it must be assigned in an initializer block or every constructor that is defined for the class, a local final variable has to be assigned before it is first accessed.
�The values of expressions are not taken into account in the flow analysis.
For example, a Java compiler must produce a compile-time error for the code:
{
int k;
int n = 5;
if (n > 2)
k = 3;
System.out.println(k);// k is not "definitely assigned" before this
}
even though the value of n is known at compile time, and in principle it can be known at compile time that the assignment to k will always be executed (more properly, evaluated).
�Example 2
void flow(boolean flag) {
int k;
if (flag)
k = 3;
if (!flag)
k = 4;
System.out.println(k);// k is not "definitely assigned" before here
}
and so compiling this program must cause a compile-time error to occur.

Chapter : Exceptions
�When a program violates the semantic constraints of the Java programming language, the JVM signals this error to the program
�An exception is said to be thrown from the point where it occurred and caught at the point to which control is transferred
�Programs can also throw exceptions explicitly, using the throw statement
�Every exception is represented by an instance of the class Throwable or one of it�s subclasses, such an object can be used to carry information from the point at which an exception occurs to the handler that catches it
�Handlers are established by catch clauses of try statements
�The exception mechanism of the Java platform is integrated with its synchronization model, so that locks are released as synchronized statements and invocations of synchronized methods complete abruptly.
�The causes of exceptions
�An exception is throws for one of three reasons :
�An abnormal execution condition was synchronously detected by the Java virtual machine. Such conditions arise because:
�Evaluation of an expression violates the normal semantics of the language, such as an integer divide by zero, etc.
�an error occurs in loading or linking part of the program
�some limitation on a resource is exceeded, such as using too much memory
�These exceptions are not thrown at an arbitrary point in the program, but rather at a point where they are specified as a possible result of an expression evaluation or statement execution.
�A throw statement was executed.
�An asynchronous exception occurred either because:
�the method stop of class Thread was invoked
�an internal error has occurred in the virtual machine
�Exceptions are represented by instances of the class Throwable and instances of its subclasses. These classes are, collectively, the exception classes.
�For each checked exception which is a possible result, the throws clause for the method or constructor must mention the class of that exception or one of the superclasses of that exception.
�The unchecked exception classes are the class RuntimeException and it�s subclasses, and the class Error and it�s subclasses
�All other exception classes are checked exception classes
�The throws clause of an overriding method may not specify that this method will result in throwing any checked exception which the overridden method is not permitted, by it�s throws clause, to throw
�When interfaces are involved, more than one method may be overridden by a single overriding declaration. In this case, the overriding declaration must have a throws clause that is compatible with all the overridden declarations
�Static initializers, class variable initializers, and instance variable initializers within named classes must not result in checked exceptions ; if one does, a compile time error occurs
�No such restriction applies to initializers in anonymous classes
�A statement or expression is dynamically enclosed by a catch clause if it appears within the try block of the try statement of which the catch clause is a part, or if the caller of that statement or expression is dynamically enclosed within the catch clause
�The caller of a statement or expression depends on where it occurs:
�If within a method, then the caller is the method invocation expression that was executed to cause the method to be invoked.
�If within a constructor or an instance initializer or the initializer for an instance variable, then the caller is the class instance creation expression or the method invocation of newInstance that was executed to cause an object to be created.
�If within a static initializer or an initializer for a static variable, then the caller is the expression that used the class or interface so as to cause it to be initialized.
�Whether a particular catch clause handles an exception is determined by comparing the class of the object that was thrown to the declared type of the parameter of the catch clause. The catch clause handles the exception if the type of its parameter is the class of the exception or a superclass of the class of the exception. Equivalently, a catch clause will catch any exception object that is an instanceof the declared parameter type.
�The control transfer that occurs when an exception is thrown causes abrupt completion of expressions and statements until a catch clause is encountered that can handle the exception; execution then continues by executing the block of that catch clause. The code that caused the exception is never resumed.
�If no catch clause handling an exception can be found, then the current thread (the thread that encountered the exception) is terminated, but only after all finally clauses have been executed and the method uncaughtException has been invoked for the ThreadGroup that is the parent of the current thread.
�In situations where it is desirable to ensure that one block of code is always executed after another, even if that other block of code completes abruptly, a try statement with a finally clause may be used.
�If a try or catch block in a try-finally or try-catch-finally statement completes abruptly, then the finally clause is executed during propagation of the exception, even if no matching catch clause is ultimately found. If a finally clause is executed because of abrupt completion of a try block and the finally clause itself completes abruptly, then the reason for the abrupt completion of the try block is discarded and the new reason for abrupt completion is propagated from there.
�Exception hierarchy :
The possible exceptions in a program are organized in a hierarchy of classes, rooted at class Throwable, a direct subclass of Object. The classes Exception and Error are direct subclasses of Throwable. The class RuntimeException is a direct subclass of Exception.

Chapter : Threads and Locks (JLS)
�Each JVM can support many threads of execution at once
�Threads may be supported by having many hardware processors or by time slicing a single/multiple processor(s).
�The Java programming language provides mechanisms for synchronizing the current activity of threads
�To synchronize threads, Java uses monitors, which are a high level mechanism for allowing only one thread at a time to execute a region of code protected by the monitor.
�The synchronized statement performs 2 special functions relevant to multithreaded operation :
a)after computing a reference to an object before executing it�s body, it locks a lock associated with the object
b)after execution of the body has completed, either normally or abruptly, it unlocks that same lock
�The methods wait, notify and notifyAll of class Object support an efficient transfer of control from one thread to another
�Variable is a location within a program, variables are stored in main memory that is shared by all threads
�Every thread has it�s own memory where it keeps a working copy of the variables it must use or assign
�The main memory also contains locks, there is one associated with each object. Threads may compete to acquire a lock
�Threads are created and managed by the built in classes Thread and ThreadGroup
�Creating a Thread object is the only way to create a thread
�When a thread is created, it is not yet active; it begins to run when it�s start method is called
�Every thread has a priority, threads with higher priority are generally executed in preference to threads with lower priority
�The synchronized statement computes a reference to an object, attempts to perform a lock on it and does not proceed till that action is completed.
�After the lock is performed, the body of the synchronized statement is executed. After execution, the lock is unlocked
�The method wait for an object should only be called when the current thread (T) has locked the object�s lock
�The thread (T) then lies dormant till one of the following things happen :
�Some other thread invokes the notify method for that object and T happens to be the one chosen to notify
�Some other thread invokes notifyAll on the object
�If the call by thread T to the wait method specified a timeout interval, the specified amount of time elapsed
�The thread T is then re-scheduled for execution

Threads (Thinking in Java � Bruce Eckels)
�Objects provide a way to divide a program up into independent sections. Often you also need to turn a program into separate independent subtasks, each of these independent subtasks is called a thread
�A process is a self-contained program running in its own address space
�A multitasking operating system is capable of running more than one process at a time
�A thread is a single sequential flow of control within a process
�A single process can thus have multiple concurrently executing threads
�The simplest way to create a thread is to inherit from class Thread
�The most important method is run() which must be overridden, and which contains the code that the thread will execute. A run() method always has a kind of loop that continues until the thread is no longer necessary
�The start() performs initialization for the thread and then calls the run(). If you don�t call start, the thread will never be started
�Sleep() relies on the existence of a thread to execute
�Threads register themselves, and there is always a reference to them so they cant be garbage collected
�Thread class implements Runnable

Compile Time Errors
�A compile-time error occurs if a class has the same simple name as any of its enclosing classes or interfaces.
�A compile-time error occurs if the same modifier appears more than once in a class declaration.
�If a class that is not abstract contains an abstract method, then a compile-time error occurs.
�A compile-time error occurs if an attempt is made to create an instance of an abstract class using a class instance creation expression
�A compile-time error occurs if the name of a final class appears in the extends clause of another class declaration; this implies that a final class cannot have any subclasses.
�A compile-time error occurs if a class is declared both final and abstract, because the implementation of such a class could never be completed.
�Because a final class never has any subclasses, the methods of a final class are never overridden
�It is a compile-time error if a class depends on itself.
�A compile-time error occurs if the same interface is mentioned two or more times in a single implements clause.
�It is a compile-time error for the body of a class declaration to declare two fields with the same name.
�A compile-time error occurs if the same modifier appears more than once in a field declaration, or if a field declaration has more than one of the access modifiers public, protected, and private.
�It is a compile-time error if a blank final class variable is not definitely assigned by a static initializer of the class in which it is declared.
�A blank final instance variable must be definitely assigned at the end of every constructor of the class in which it is declared; otherwise a compile-time error occurs.
�A compile-time error occurs if a final variable is also declared volatile.
�It is a compile-time error for the body of a class to have as members two methods with the same signature.
�If two formal parameters of the same method or constructor are declared to have the same name (that is, their declarations mention the same Identifier), then a compile-time error occurs.
�A compile-time error occurs if the same modifier appears more than once in a method declaration, or if a method declaration has more than one of the access modifiers public, protected, and private.
�A compile-time error occurs if a method declaration that contains the keyword abstract also contains any one of the keywords private, static, final, native, strictfp, or synchronized.
�A compile-time error occurs if a method declaration that contains the keyword native also contains strictfp.
�It is a compile-time error for a private method to be declared abstract.
�It is a compile-time error for a static method to be declared abstract.
�It is a compile-time error for a final method to be declared abstract.
�It is a compile-time error to attempt to override or hide a final method.
�It is a compile-time error for a final method to be declared abstract.
�A compile-time error occurs if a native method is declared abstract.
�A compile-time error occurs if any ClassType mentioned in a throws clause is not the class Throwable or a subclass of Throwable. It is permitted but not required to mention other (unchecked) exceptions in a throws clause.
�A compile-time error occurs if a method declaration is either abstract or native and has a block for its body.
�A compile-time error occurs if a method declaration is neither abstract nor native and has a semicolon for its body.
�If a method is declared void, then its body must not contain any return statement that has an Expression.
�A compile-time error occurs if an instance method attempts to override a static method to be non-static.
�A compile-time error occurs if a static method hides an instance method.
�If a method declaration overrides or hides the declaration of another method, then a compile-time error occurs if they have different return types or if one has a return type and the other is void. Moreover, a method declaration must not have a throws clause that conflicts with that of any method that it overrides or hides; otherwise, a compile-time error occurs.
�If the overridden or hidden method is public, then the overriding or hiding method must be public; otherwise, a compile-time error occurs.
�If the overridden or hidden method is protected, then the overriding or hiding method must be protected or public; otherwise, a compile-time error occurs.
�If the overridden or hidden method has default (package) access, then the overriding or hiding method must not be private; otherwise, a compile-time error occurs.
�If a return statement appears anywhere within a static initializer, then a compile-time error occurs.
�If the keyword this or the keyword super appears anywhere within a static initializer, then a compile-time error occurs.
�A class may not declare two constructors with the same signature, or a compile-time error occurs.
�It is a compile-time error for a constructor to directly or indirectly invoke itself through a series of one or more explicit constructor invocations involving this.
�A compile-time error occurs if a default constructor is provided by the compiler but the superclass does not have an accessible constructor that takes no arguments.
a method declared in an interface must not be declared final or a compile-time error occurs. However, a method declared in an interface may be implemented by a method that is declared final in a class that implements the interface.
�A component of an array is accessed by an array access expression that consists of an expression whose value is an array reference followed by an indexing expression enclosed by [ and ], as in A[i]. All arrays are 0-origin. An array with length n can be indexed by the integers 0 to n-1.
�Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion and become int values. An attempt to access an array component with a long index value results in a compile-time error.
�The type of the Switch Expression must be char, byte, short, or int, or a compile-time error occurs.
�Every case constant expression associated with a switch statement must be assignable to the type of the switch Expression.
�No two of the case constant expressions associated with a switch statement may have the same value.
�Only one default label may be associated with the same switch statement.
�If a break statement is not enclosed by a switch, while, do, or for statement , a compile-time error occurs.
�If no labeled statement with Identifier as its label encloses the break statement, a compile-time error occurs.
�If a continue statement is not enclosed by a while, do, or for statement, a compile-time error occurs.
�If no labeled statement with Identifier as its label encloses the continue statement, a compile-time error occurs.
�A continue statement with label Identifier attempts to transfer control to the enclosing labeled statement that has the same Identifier as its label; that statement, which is called the continue target, then immediately ends the current iteration and begins a new one. The continue target must be a while, do, or for statement or a compile-time error occurs.
�If a label of continue statement is not assigned to while, do, or for statement, a compile-time error occurs.
�A compile-time error occurs if a return statement appears within an instance initializer or a static initializer.
�A return statement with an Expression must be contained in a method declaration that is declared to return a value (�8.4) or a compile-time error occurs. The Expression must denote a variable or value of some type T or a compile-time error occurs. The type T must be assignable (�5.2) to the declared result type of the method, or a compile-time error occurs.
�It is a compile-time error if a statement cannot be executed because it is unreachable.
�The keyword this may be used only in the body of an instance method, instance initializer or constructor, or in the initializer of an instance variable of a class. If it appears anywhere else, a compile-time error occurs.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Archana .... The notes will be very useful to us.
All the best.
Shrikrishna
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Archana,
What a great way to put up the notes! Thank you very much...
I hope that rest follow the same path now instead of creating a "me too... this is my email.."
Thanks again..
Shubhangi
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Archana,
Thank you very much. That is wonderful way to share the knowledge.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Archana.
Your notes will help all of us to become more knowledgable.
Parag
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Archana,
wow, Greate help.Thank you very much,
regards
Prasad
[This message has been edited by Prasad Ballari (edited November 16, 2000).]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Hi arch correa
This is jason, thanks for the notes. If you have a any other notes & questions and answers or web links please send to my email address.
email-id: jason_jp@usa.net
Thanks..
Bye

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are some notes I made it is mainly based on syntax operators and stuff. its just the basics but i am adding on everyday. I have the varible tye info but i have it aranged into a table if you need that let me know.
Relational Operators.
Generate a boolean result. They evaluate the
relationship between the values of the operands.
<Less than.Tests to see if a value is less than.<br /> >Greater than.Tests to see if a value is greater than.
<=Less than or equal to.Tests to see if value is less than or equal to. <br /> >=Greater than or equal to.Tests to see if value is greater than or
equal to.
= =Equal too.Tests to see if value is equal to.
!=Not equal too.Tests to see if value is not equal to
Logical Operators.
Produces a boolean value of true or false based on the logical relationship of
its arguments.
&&AND.
| |OR.
!NOT.
Bitwise Operators.
The bitwise operators allow you to manipulate individual bits in an
integral primitive data type. Bitwise operators perform boolean algebra on
the corresponding bits in the two arguments to produce the result.

&AND.Produces a one in the output bit if both input bits are one
otherwise zero
|OR.Produces a one if in the output bit if either one or zero if
both input bits are zero
^Exclusive XOR.Produces a one in the output bit if
one or the other input bit is a one,
but not both.
~Not.produces the opposite of the input bit�a one if the input
bit is zero, a zero if the input bit is one.
Shift Operators.
The shift operators also manipulate bits. They can be used solely with
primitive, integral types.
<< Left shift.<br /> >>Right shift.
Ternary if-else Operator.
boolean-exp ? value0 : value 1States that if boolean-exp is
evaluated to true, value0 is evaluated and its results becomes the produced by the operator
if boolean-exp is false, value1 is evaluated and its results becomes the value produced by
the operator.
String Operator.
Used to link stings together.

+String Operator.Used to connect strings together.
Math Operators.
Simple Mathimatical operators to return values.

+ Addition.Adds 2 values.
-Subtraction.Subtracts 2 values.
*Multiplication.Multiplies 2 values.
/Division.Divides 2 values.
%Modulus.Takes the remainder of integer division.
Auto increment Operators.
Used to increment/decrement a varible by 1.
i++ *Postfix ++Adds 1 to a variable after the operation.
++i *Prefix ++Adds 1 to a variable before the operation.
i-- *Postfix --Subtracts 1 from a variable after the operation.
--i *Prefix --Subtracts 1 from a variable before the operation.
* �i� can be any variable name.
Assignment Operator.
=Assignment Operator.Assigns a value to a variable, object, etc.
Access Modifiers.
- Access modifiers are public, protected, private.
If nothing is provided,
default - 'friendly' - package level -
permissions are given for class/members.
public permissions are given for interface members
note : friendly is not a keyword
- Accessibitlity is different in each of the following
- within the class,
- another class in the same package,
- sub class in same package,
- another class in the another package,
- sub class in another package.
- Therefore, there are
- four types of access permissions and
- five places to test the accessibility.
- Totally 20 combinations.
- Accessibility with in the class :
- private - available
- friendly - available
- protected - available
- public - available
- Accessibility with in sub class in same package :
- private - not available
- friendly - available
- protected - available
- public - available
- Accessibility with in another class in same package :
- private - not available
- friendly - available
- protected - available
- public - available
- Accessibility with in sub class in another package :
- private - not available
- friendly - not available
- protected - available
- public - available
- Accessibility with in another class in another package :
- private - not available
- friendly - not available
- protected - not available
- public - available
- Important :
- public is more visible than protected,friendly,private
- proctected is more visible than friendly,private
- friendly is more visible than private
- private is no more visible than anything.
- while overriding,
- narrowing accessibility is not allowed.
- windening accessibility is legal.
- narrowing accessibility is
public -> protected -> friendly -> private
- widening accessibility is
private -> friendly -> protected -> public
- Access Modifier Applicability :
- Access modifiers are only applicable to
classes and class members and not method variables.
- classes :
- package level class should only be public or friendly.
- inner classes can be public, protected, friendly, and private.
- constructors :
public, protected, friendly, and private
- methods
public, protected, friendly, and private
- variables
public, protected, friendly, and private
- Class with only private constructor(s)
- this class can not be instantiated.
Thanks to Krishnaraj Kalimuthu Javaranch.com forums.
General Notes.
= = and != compare references not values, use the equals( ) method to compare
values. prototype : object.
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
 
Brett Knapik
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh yeah I have this in a word document formatted indented and such for easy reading so if you want a copy let me know ok?
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
 
arch correa
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Brett !!
that's a nice summing up of all the info that span pages and pages in any book !!
Good work !!
and everyone : i'll hunt about for more stuff to post. hang on !!
:-)
Arch
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u Ms Archana & Mr Breet,
Can u pl send me Excercises on each objective.
General note prepared for SCJP.
For Threading, can u pl suggest a good mat'l.
My Mail-id is subbubs@yahoo.com
Thanks and regards
B S Subbu

Originally posted by Brett Knapik:
These are some notes I made it is mainly based on syntax operators and stuff. its just the basics but i am adding on everyday. I have the varible tye info but i have it aranged into a table if you need that let me know.
Relational Operators.
Generate a boolean result. They evaluate the
relationship between the values of the operands.
<Less than.Tests to see if a value is less than.<br /> >Greater than.Tests to see if a value is greater than.
<=Less than or equal to.Tests to see if value is less than or equal to. <br /> >=Greater than or equal to.Tests to see if value is greater than or
equal to.
= =Equal too.Tests to see if value is equal to.
!=Not equal too.Tests to see if value is not equal to
Logical Operators.
Produces a boolean value of true or false based on the logical relationship of
its arguments.
&&AND.
| |OR.
!NOT.
Bitwise Operators.
The bitwise operators allow you to manipulate individual bits in an
integral primitive data type. Bitwise operators perform boolean algebra on
the corresponding bits in the two arguments to produce the result.

&AND.Produces a one in the output bit if both input bits are one
otherwise zero
|OR.Produces a one if in the output bit if either one or zero if
both input bits are zero
^Exclusive XOR.Produces a one in the output bit if
one or the other input bit is a one,
but not both.
~Not.produces the opposite of the input bit�a one if the input
bit is zero, a zero if the input bit is one.
Shift Operators.
The shift operators also manipulate bits. They can be used solely with
primitive, integral types.
<< Left shift.<br /> >>Right shift.
Ternary if-else Operator.
boolean-exp ? value0 : value 1States that if boolean-exp is
evaluated to true, value0 is evaluated and its results becomes the produced by the operator
if boolean-exp is false, value1 is evaluated and its results becomes the value produced by
the operator.
String Operator.
Used to link stings together.

+String Operator.Used to connect strings together.
Math Operators.
Simple Mathimatical operators to return values.

+ Addition.Adds 2 values.
-Subtraction.Subtracts 2 values.
*Multiplication.Multiplies 2 values.
/Division.Divides 2 values.
%Modulus.Takes the remainder of integer division.
Auto increment Operators.
Used to increment/decrement a varible by 1.
i++ *Postfix ++Adds 1 to a variable after the operation.
++i *Prefix ++Adds 1 to a variable before the operation.
i-- *Postfix --Subtracts 1 from a variable after the operation.
--i *Prefix --Subtracts 1 from a variable before the operation.
* �i� can be any variable name.
Assignment Operator.
=Assignment Operator.Assigns a value to a variable, object, etc.
Access Modifiers.
- Access modifiers are public, protected, private.
If nothing is provided,
default - 'friendly' - package level -
permissions are given for class/members.
public permissions are given for interface members
note : friendly is not a keyword
- Accessibitlity is different in each of the following
- within the class,
- another class in the same package,
- sub class in same package,
- another class in the another package,
- sub class in another package.
- Therefore, there are
- four types of access permissions and
- five places to test the accessibility.
- Totally 20 combinations.
- Accessibility with in the class :
- private - available
- friendly - available
- protected - available
- public - available
- Accessibility with in sub class in same package :
- private - not available
- friendly - available
- protected - available
- public - available
- Accessibility with in another class in same package :
- private - not available
- friendly - available
- protected - available
- public - available
- Accessibility with in sub class in another package :
- private - not available
- friendly - not available
- protected - available
- public - available
- Accessibility with in another class in another package :
- private - not available
- friendly - not available
- protected - not available
- public - available
- Important :
- public is more visible than protected,friendly,private
- proctected is more visible than friendly,private
- friendly is more visible than private
- private is no more visible than anything.
- while overriding,
- narrowing accessibility is not allowed.
- windening accessibility is legal.
- narrowing accessibility is
public -> protected -> friendly -> private
- widening accessibility is
private -> friendly -> protected -> public
- Access Modifier Applicability :
- Access modifiers are only applicable to
classes and class members and not method variables.
- classes :
- package level class should only be public or friendly.
- inner classes can be public, protected, friendly, and private.
- constructors :
public, protected, friendly, and private
- methods
public, protected, friendly, and private
- variables
public, protected, friendly, and private
- Class with only private constructor(s)
- this class can not be instantiated.
Thanks to Krishnaraj Kalimuthu Javaranch.com forums.
General Notes.
= = and != compare references not values, use the equals( ) method to compare
values. prototype : object.


 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for all the notes. This is how I keep track of Operator Precedence. Got the Idea from Bruce Eckel's "Thinking in Java".
Unicode All Source Code Before Seeing The Applet.
U - Unary ++ -- + 1 ! ~ ()
A - Arithmetic * / % + -
S - Shift >> << >>>
C - Comparison < <= > => instanceof == !=
B - Bitwise & ^ |
S - Short-Circuit && | |
T - Ternary ?:
A - Assignment = "op="

[This message has been edited by Vijay, Bakshi (edited November 17, 2000).]
 
Brett Knapik
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry sub cant help you i am only studying for it making notes.
------------------
I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work
 
Paddy spent all of his days in the O'Furniture back yard with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic