Tuesday, February 27, 2007

Can a for statement loop indefinitely?

Yes, a for statement can loop indefinitely. For example, consider the following:
for(;;) ;


SOURCE : www.referjava.com

Does garbage collection guarantee that a program will not run out of memory?

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection


SOURCE : www.referjava.com

What is the difference between the >> and >>> operators?

The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.

How does Java handle integer overflows and underflows?

It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.


SOURCE : www.referjava.com

How are Observer and Observable used?

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.


SOURCE : www.referjava.com

What is user defined exception ?

Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.


SOURCE : www.referjava.com

You can create a String object as String str = "abc"; Why cant a button object be created as Button bt = "abc";? Explain

The main reason you cannot create a button by Button bt1= "abc"; is because "abc" is a literal string (something slightly different than a String object, by-the-way) and bt1 is a Button object. The only object in Java that can be assigned a literal String is java.lang.String. Important to note that you are NOT calling a java.lang.String constuctor when you type String s = "abc";


SOURCE : www.referjava.com

What is passed by ref and what by value ?

All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references


SOURCE : www.referjava.com

What is constructor chaining and how is it achieved in Java ?

A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.


SOURCE : www.referjava.com