Hello Everyone. In the process of my studying for
SCJP, I compiled these FEW rules from JLS (
Java rules bible). Published here for the benefit of all SCJP candidates. Print and Study them. Will be useful definately. If you have compiled such a list from authenticate source , please let me know. It makes learning easy. I have ommitted few simple rules from here like the expression of if statement must be boolean type.
�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.
�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.
[This message has been edited by kishor kotecha (edited October 09, 2000).]
[This message has been edited by kishor kotecha (edited October 09, 2000).]
[This message has been edited by kishor kotecha (edited October 09, 2000).]
[This message has been edited by kishor kotecha (edited October 10, 2000).]