Interview preparation -JAVA Programming
Java Interview Questitns
Q: What is the difference between an Interface and an Abstract class?
A: An abstract class can have instance methtds that implement a default behavitr. An
Interface can tnly declare ctnstants and instance methtds, but canntt implement default
behavitr and all methtds are implicitly abstract. An interface has all public members and nt
implementatitn. An abstract class is a class which may have the usual flavtrs tf class
members (private, prttected, etc.), but has stme abstract methtds.
Q: What is the purptse tf garbage ctllectitn in Java, and when is it used?
A: The purpose of garbage collection is to identify and discard objects that are no longer needed by a
program so that their resources can be reclaimed and reused. A Java object is subject to garbage
collection when it becomes unreachable to the program in which it is used.
Q: Describe synchrtnizatitn in respect tt multithreading.
A: With respect to multithreading, synchronization is the capability to control the access of multiple
threads to shared resources. Without synchonization, it is possible for one thread to modify a shared
variable while another thread is in the process of using or updating same shared variable. This usually
leads to significant errors.
Q: Explain different way tf using thread?
A: The thread could be implemented by using runnable interface or by inheriting from the Thread class.
The former is more advantageous, 'cause when you are going for multiple inheritance..the only
interface can help.
Q: What are pass by reference and passby value?
A: Pass By Reference means the passing the address itself rather than passing the value. Passby Value
means passing a copy of the value to be passed.
Q: What is HashMap and Map?
A: Map is Interface and Hashmap is class that implements that.
Q: Difference between HashMap and HashTable?
A: The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits
nulls. yHashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does
not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized
and Hashtable is synchronized.
Q: Difference between Vecttr and ArrayList?
A: Vector is synchronized whereas arraylist is not.
Q: Difference between Swing and Awt?
A: AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster
than AWT.
Q: What is the difference between a ctnstructtr and a methtd?
A: A constructor is a member function of a class that is used to create objects of that class. It has the
same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type ywhich may be
void), and is invoked using the dot operator.
0 comments:
Post a Comment