1) The final keyword on a method means that the method cannot be overridden in a subclass. But since the main() method is a static method, it can't be overridden anyway. So making the main() method final makes no sense.
2) main method can be final.
3) A class without a main method can be run by JVM, if its ancestor class has a main method. (main is just a method and is inherited)
4) We can set the reference variables to null, hinting the gc to garbage collect the objects referred by the variables. Even if we do that, the object may not be gc-ed if it's attached to a listener. (Typical in case of AWT components) Remember to remove the listener first.
5) protected void finalize() throws Throwable { }
In the descendents this method can be protected or public. Descendents can restrict the exception list that can be thrown by this method.
6) finalize is not implicitly chained. A finalize method in sub-class should call finalize in super class explicitly as its last action for proper functioning. But compiler doesn't enforce this check.
7) NAN's are non ordinal and INFINITIES are ordinal.
x == Float.NaN won't work.
X == Double.POSITIVE_INFINITY will give expected result.
8) If x instanceof Y is not allowed by compiler, then Y y = (Y) x is not a valid cast expression. If x instanceof Y is allowed and returns false, the above cast is valid but throws a ClassCastException at runtime. If x instanceof Y returns true, the above cast is valid and runs fine.
9) Extended assignment operators do an implicit cast. (Useful when applied to byte, short or char)
10)
The output of the above program is:
value of name in parent object Base class
value of name in child object Base class
11) Always keep in mind that operands are evaluated from left to right, and the operations are executed in the order of precedence and associativity.
12) Member variables marked final are not initialized by default.
13) avoid overloading a varargs method because it can be difficult to discern which overloading gets called
14) Same thread if started twice throws IllegalThreadStateException.
2) main method can be final.
3) A class without a main method can be run by JVM, if its ancestor class has a main method. (main is just a method and is inherited)
4) We can set the reference variables to null, hinting the gc to garbage collect the objects referred by the variables. Even if we do that, the object may not be gc-ed if it's attached to a listener. (Typical in case of AWT components) Remember to remove the listener first.
5) protected void finalize() throws Throwable { }
In the descendents this method can be protected or public. Descendents can restrict the exception list that can be thrown by this method.
6) finalize is not implicitly chained. A finalize method in sub-class should call finalize in super class explicitly as its last action for proper functioning. But compiler doesn't enforce this check.
7) NAN's are non ordinal and INFINITIES are ordinal.
x == Float.NaN won't work.
X == Double.POSITIVE_INFINITY will give expected result.
8) If x instanceof Y is not allowed by compiler, then Y y = (Y) x is not a valid cast expression. If x instanceof Y is allowed and returns false, the above cast is valid but throws a ClassCastException at runtime. If x instanceof Y returns true, the above cast is valid and runs fine.
9) Extended assignment operators do an implicit cast. (Useful when applied to byte, short or char)
byte b = 10; b = b + 10; // Won't compile, explicit cast required since the expression evaluates to an int b += 10; // OK, += does an implicit cast from int to byte
10)
class Base
{
String name;
Base()
{
name = "Base class";
}
public String getName()
{
return name;
}
}
public class Sub extends Base
{
String name;
Sub()
{
name="Sub class";
}
public static void main(String args[])
{
Base parent = new Base();
Sub child = new Sub();
System.out.println("value of name in parent object "
+parent.getName()+
" \n value of name in child object "
+child.getName());
}
}
The output of the above program is:
value of name in parent object Base class
value of name in child object Base class
11) Always keep in mind that operands are evaluated from left to right, and the operations are executed in the order of precedence and associativity.
int i = 0; i = i++; i = i++; i = i++; System.out.println(i); // prints 0, since = operator has the lowest precedence.
12) Member variables marked final are not initialized by default.
13) avoid overloading a varargs method because it can be difficult to discern which overloading gets called
14) Same thread if started twice throws IllegalThreadStateException.
0 Comments On This Entry
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 |
My Blog Links
Recent Entries
-
SCJP Notes - Part 8on Apr 04 2008 01:22 AM
-
SCJP Notes - Part 7on Mar 31 2008 05:06 AM
-
SCJP Notes - Part 6on Mar 27 2008 08:19 AM
-
SCJP Notes - Part 5on Mar 27 2008 08:05 AM
-
SCJP Notes - Part 4on Mar 27 2008 07:31 AM
Recent Comments
Search My Blog
12 user(s) viewing
12 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



Leave Comment








|