Skip to content

Java _ Revision

October 11, 2011

Varargs argument – if no implicit array creation takes place then it is called as non-varargs call. but if array is cast to object then varargs call takes place. Enum cannot be made final or static.

overloaded methods, which method implementation will be executed at runtime is determined at compile time , but for overridden methods, the method implementation to be executed is determined at runtime.As the return type is not a part of the method signature, just having different return types is not enough to overload methods.

All arrays of reference types are also subtypes of the array type Object[], but arrays of primitive data types are not. Note that the array type Object[] is also a subtype of the Object type
covariant return types means subclass overrides method and return is subclass of the super class’s return.

Child class cannot reduce visibility of overriden methods , cannot increase count of checked exception, can only have covariant return type for methods.

Static methods if hidden are called based on the class of the reference.

Top t = new Bottom();
t.staticMethod – Top’s static method called. !.
If super class has non default constructor subclass must define the constructor on it’s own. Secondly, super has to be the first statement in the constructor.

conversion of int[] array to
Object array – since int[] is not subtype of Object[] – it is enapsulated as an object and passed. But String[] etc are subtypes of Object[]. []… is treated like a 2d array
All arrays of reference types are also subtypes of the array type Object[], but arrays of primitive data types are not. Note that the array type Object[] is also a subtype of the Object type

If a non-generic reference type is a subtype of another non-generic reference type, the corresponding array types also have an analogous subtype-supertype relationship. This is called the subtype covariance relationship. This relationship however does not hold for parameterized types .There is no subtype-supertype relationship between a type and its corresponding array type.

Method call for overloading rules – calls most specific method. Rules are:
1. It first performs overload resolution without permitting boxing, unboxing, or the use of a varargs call.
2. If phase (1) fails, it performs overload resolution allowing boxing and unboxing, but excluding the use of a varargs call.
3. If phase (2) fails, it performs overload resolution combining a varargs call,boxing, and unboxing.

Static member class can define both static and instance members, like
any other top-level class. However, its code can only directly access static members in its enclosing context.

Instance of a non-static member class can only exist with an instance of its enclosing class. This means that an instance of a non-static member class must be created in the context of an instance of the enclosing class. This also means that a non-static member class cannot have static members. In other words, the non-static member class does not provide any services, only instances of the class do. However, final static variables are allowed, as these are constants.
• Code in a non-static member class can directly refer to any member (including nested) of any enclosing class or interface, including private members. No fully qualified reference is required.

To create a non static member class you need instance of the parent class:
MyLinkedList.Node node2 = Node(“node2”, node1); // (17)

Multiple objects of the non-static member classes can be associated with an object of an enclosing class at runtime !! 🙂
list- > node1, node2, node3 – nice 🙂

From within the non static inner class – “this” has special meaning referring to the nested class itself. The outer this can be referred with appending of class name. [class].this.outerproperty.
private fields of outer context can be accessed
MyLinkedList.this.message + ” in ” + this.nodeInfo

If you wish to extend a nested non static member class from outside you need to provide in the constructor mandatory an instance of the outer class: Unique format:
// (4) Mandatory non-default constructor:
SubclassC(OuterA outerRef) {
outerRef.super(); // (5) Explicit super() call

But if you extend outerA and innerA both – this above is not needed.
new OuterB().new InnerB(); is sufficient as subclasses.

Nested interfaces are always static

the scope of the Inner class, the doIt() method of the Outer class is hidden by the doIt() method of the Inner class

Non-static member classes, unlike top-level classes, can have any accessibility modifier.

Static member classes can only be declared in top-level or nested static
member classes and interfaces.

Local = method scoped classes. similar to non static member classes.
cannot have static members, final static fields are allowed, as these are constants.[diff] Local classes cannot have any accessibility modifier. Only finals/statics from enclosing method are accessible.
local class cannot be specified with the keyword static.

TLCWithLocalClasses.this.nsf1 – only for non static local class
static has no concept of OUTER object – so no “this” allowed in any form.

A non-static local class can access both static and non-static members defined in the enclosing class.static local class can only directly access members defined in the enclosing class that are static

instance block – forward reference of static field/method allowed.
All instances of concrete wrapper classes are immutable.
All wrapper classes except Boolean and Void have a compareTo() method. Only the numeric wrapper classes have an intValue() method.

Certain values are cached- as in only one wrapper objects exists for certain range of primitive values once created. so should not rely on object == when comparing wrappers.

equal objects must produce equal hash codes.For the sake of efficiency, a hash function should strive to produce unequal hash codes for unequal objects.

LinkedHashSet = LIFO movement.
Navigable = poll (first/last) + range operations = head/tail/sub = map/set., ceiling,floor, higher, lower , descending (map/set)

searching in hashmap/hashset faster than treemap/treeset.

Pattern.compile, p.match, greedy, reluctant, possesive qualifiers for regex.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: