java4all@1986 java. Powered by Blogger.

>> Saturday, June 25, 2011

Q).What is casting ?
A).
Casting means converting one type to another. There are mainly two types of casting. Casting between primitive types and casting between object references. Casting between primitive numeric types is used to convert larger data types to smaller data types. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

Q).What is the difference between == and equals ?
A)
.The equals method can be considered to perform a deep comparison of the value of an object, whereas the == operator performs a shallow comparison.  If we are not overriding the equals method both will give the same result. == will is used to compare the object references. It is used to check whether two objects are points to the same reference.

Q).What are the different ways in which a thread can enter into waiting state?
A).
There are three ways for a thread to enter into waiting state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method.
   
Q).What are synchronized methods and synchronized statements?
A).
Synchronized methods are methods that are declared with the keyword synchronized. A thread executes a synchronized method only after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. It is a block of code declared with synchronized keyword. A synchronized statement can be executed only after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Q).What is hashCode?
A).
The hashcode of a Java Object is simply a number (32-bit signed int) that allows an object to be managed by a hash-based data structure. A hashcode should be, equal for equal object (this is mandatory!) ,  fast to compute based on all or most of the internal state of an object, use all or most of the space of 32-bit integers in a fairly uniform way , and likely to be different even for objects that are very similar. If you are overriding hashCode you need to override equals method also.

Q).What do you mean by immutable ? How to create an immutable object ?
A).
Immutability means an object cannot be modified after it has been initialized.  There will not be any setter methods in an immutable class. And normally these classes will be final.

Q).Can we compile a java program without main?    
A).
Yes, we can. In order to compile a java program, we don't require any main method. But to execute a java program we must have a main in it (unless it is an applet or servlet). Because main is the starting point of a java program.

Q).What is daemon thread?    
A).
Theards which are running on the background are called deamon threads. daemon thread is a thread which doesn't give any chance to run other threads once it enters into the run state it doesn't give any chance to run other threads. Normally it will run forever, but when all other non-daemon threads are dead, daemon thread will be killed by JVM.

Q).What is volatile variable?    
A).
A volatile variable is not allowed to have a local copy of a variable that is different from the value currently held in "main" memory. Volatile modifier requests the JVM to always access the shared copy of the variable so the its most current value is always read.

Q).What is sandbox?    
 A)
.A sandbox is a security mechanism for safely running programs. The sandbox typically provides a tightly-controlled set of resources for guest programs to run in, such as scratch space on disk and memory.
   
Q).What is the difference between throw and throws clause?    
A).
throw is used to throw an exception manually, where as throws is used in the case of checked exceptions, to tell the compiler that we haven't  handled the exception, so that the exception will be handled by the calling function.

Q).What are the different inner classes types?    
A).
There are mainly four types available. They are Member classes, Nested top-level classes,  Local classes,  Anonymous classes.

Q).Can a top level class be private or protected?    
A).
No. A top level class can not be private or protected. It can have either "public" or no modifier.

Q).What is the use of assert keyword    
A).
Assert keyword validates certain expressions. It replaces the if block effectively and throws an AssertionError on failure. The assert keyword should be used only for critical arguments (means without that the method does nothing).

Q).What are the methods in Object?    
 A).
clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString .


   
   
   

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP