Custom Search

What is reflection ?

Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.

What is the basic difference between string and stringbuffer object ?

String is an immutable object. StringBuffer is a mutable object.

What is mutable object and immutable object ?

If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)

What is a daemon thread ?

These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.

What is garbage collection ? What is the process that is responsible for doing that in java ?

Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process.

What is the purpose of Void class ?

The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.

What if the main method is declared as private ?

The program compiles properly but at runtime it will give "Main method not public." message.

What is meant by pass by reference and pass by value in Java ?

Pass by reference means, passing the address itself rather than passing the value. Pass by value means passing a copy of the value.

What if the main method is declared as private ?

The program compiles properly but at runtime it will give "Main method not public." message.

What if I do not provide the String array as the argument to the method ?

Program compiles. But at runtime throws an error "NoSuchMethodError".

What does it mean that a class or member is final ?

o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection

Variables defined in an interface are implicitly final. A final class can't be extended i.e., final class may not be subclassed. This is done for security reasons with basic classes like String and Integer. It also allows the compiler to make some optimizations, and makes thread safety a little easier to achieve. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant). finalize() method is used just before an object is destroyed and garbage collected. finally, a key word used in exception handling and will be executed whether or not an exception is thrown. For example, closing of open connections is done in the finally method.