Anda di halaman 1dari 5

Notes:

A continue statement can occur in and only in a for, while or do-while loop. A continue statement
means: Forget about the rest of the statements in the loop and start the next iteration.
To override a method in the subclass, the overriding method (i.e. the one in the subclass) MUST
HAVE:
same name
same return type in case of primitives (a subclass is allowed for classes, this is also known as
covariant return types).
same type and order of parameters
it may throw only those exceptions that are declared in the throws clause of the superclass's
method or exceptions that are subclasses of the declared exceptions. It may also choose NOT to
throw any exception.
The names of the parameter types do not matter. For example, void methodX(int i) is same as
void methodX(int k)
Variables can't be declared as abstract or native.
a superclass object can never be assigned to a base class reference.
Variables can't be declared as abstract or native.
The left operand of instanceof MUST be an object and not a primitive.
Right operand of instanceof MUST be a class name.
Keyword this cannot be used in static block/method
you cannot import a package statically. You can only import static members of a class statically.
A constructor that does not include an access modifier will have package-private access.
Static methods can only access static methods and static variables. They cannot access instance
variables or standard methods.
static and final are valid modifiers for both member field and method declarations within a class.
transient and volatile modifiers are only valid for member field declarations.
that String class doesn't have append (and insert) method
You can apply public, private, protected to a constructor. But not static, final, synchronized,
native and abstract.

First, static statements/blocks are called IN THE ORDER they are defined.
Next, instance initializer statements/blocks are called IN THE ORDER they are defined.
Finally, the constructor is called.
Long (or any wrapper class) does not have a no-args constructor
As a rule, fields defined in an interface are public, static, and final. The methods are public.
In case of overriding, the return type of the overriding method must match exactly to the return
type of the overridden method if the return type is a primitive.
Trying to override a static method with a non-static method (and vice-versa) in a class will result
in a compilation error.
variables are SHADOWED and methods are OVERRIDDEN. Which variable will be used
depends on the class that the variable is declared of. Which method will be used depends on the
actual class of the object that is referenced by the variable.
. operator has more precedence than the cast operator.
method length() of String class is a final method.
Trying to override a static method with a non-static method (and vice-versa) in a class will result
in a compilation error. Even in case of interfaces, a subinterface not override a default method
with a static method.
static methods can never be abstract (neither in an interface not in a class).
intern() equals(Object) equalsIgnoreCase(String) are string objects
When you use System.out.println(exception), a stack trace is not printed. Just the name of the
exception class and the message is printed.
When you use exception.printStackTrace(), a complete chain of the names of the methods called,
along with the line numbers, is printed
implicit narrowing is permitted only among byte, char, short, and int.
All interface methods have to be public.
An interface can have a static method but the method must have a body in that case.
You can apply public, private, protected to a constructor. But not static, final, synchronized,
native and abstract
a while or do/while construct takes an expression that returns a boolean.
java.lang.Number, is not final class but System and other wrapper classes are final.
append() method does not exist in String class. It exits only in StringBuffer and StringBuilder.
static member can be accessed by static and non-static methods both. Non-static can only be
accessed by non-static.

If you are throwing an exception then there should be try or catch block, or a throws clause. Else,
it will not compile.
The overriding method may opt not to declare any throws clause even if the original method has
a throws clause.
1. static methods can never be abstract (neither in an interface not in a class).
2. An interface can have a static method but the method must have a body
To call a static method of another class, you must use the name of the other class, for example
OtherClass.staticMethod();
it is the job of a constructor to initialize an instance, a constructor of the super class has to be
invoked before the constructor of the subclass can proceed.
ArrayList does not have a field named length. It does have a method named size() though.
A final variable must be initialized when an instance is constructed, or else the code will not
compile.
parseBoolean returns a primitive and not a Boolean wrapper object.
main() is a static method. It does not have 'this'!
When the return type of the overridden method (i.e. the method in the base/super class) is a
primitive, the return type of the overriding method (i.e. the method in the sub class) must match
the return type of the overridden method.
ArrayList extends java.util.AbstractList.
ArrayList allows you to access its elements in random order
ArrayList can sort elements using Collections.sort() method.
Switch declaration statement cannot be Boolean
All compound assignment operators internally do an explicit cast.
Trim() method is in String class.
an overriding method can only throw a subset of checked exceptions declared in the throws
clause of the overridden method.

ensureCapacity(int ), append(boolean), reverse() and setlength () are part of the StringBuilder


class

Objects can be instantiated but primitives can not be instantiated.

A variable will be passed by value if its a primitive and by reference if its an object.
ArrayList objects cannot store primitives like basic arrays can.
An abstract class may contain abstract methods, or methods that are not implemented.
Abstract classes can have instance variables.
An abstract class can not be instantiated.

An interface cant implement an interface or class.


Identifiers can start with a letter a $ mark or an underscore.
Constructors and static initializers are not members of class and therefore are not inherited
Interface cannot "implement" another interfaces. It can extend multiple interfaces. The following
is a valid declaration : interface I1 extends I2, I3, I4 { }
The access type of a default constructor is same as the access type of the class.
A final method cannot be overridden.
All non-static members are instance members.
A constructor is non-static, and so it can access directly both the static and non-static members of
the class.
!, && and || operate only on Booleans
super(); is automatically added if the sub class constructor doesn't call any of the super class's
constructors.
An interface can be extended by another interface.
Any class, whether abstract or concrete, can implement any interface.
Functional interface must have exactly one abstract method and may have other default or static
methods
Implicit narrowing occurs only for byte, char, short, and int. Remember that it does not occur for
long, float, or double.
String, StringBuffer and StringBuilder are also final. All Primitive wrappers are also final (i.e.
Boolean, Integer, Byte etc).
Variables can't be declared as abstract or native.
Each object of a class has its own copy of each non-static member variable
The overriding method cannot decrease the accessibility.

static member can be accessed by static and non-static methods both. Non-static can only be
accessed by non-static.
The native keyword can only be used on methods, not on classes and or variables
variables defined in methods are called local variables (also known as automatic variables)
where as instance members are defined in the class scope.
!, && and || operate only on booleans.
~ Operates only on integral types
Only String, byte, char, short, int, and enum values can be used as types of a switch variable.
(String is allowed since Java 7.) Wrapper classes Byte, Character, Short, and Integer are allowed
as well.

Anda mungkin juga menyukai