Java面试题和答案 (英文版)
Q:What isthe difference betweenan Interface and anAbstract class?
A:Anabstract class can have instance methods that implement a default behavior.An Interface canonly
declareconstants and instance methods, but cannot implement default behaviorandallmethodsare implicitly
abstract.An interface has all public members and no implementation.Anabstract class is a class which may
have the usualflavors of class members (private, protected, etc.), but has some abstract methods.
Q:What isthe purpose of garbage collection inJava, and when is it used?
A:The purpose of garbage collectionisto identify and discard objectsthat are no longerneeded by a program
so that their resources can be reclaimed and reused.A Java object is subject to garbage collectionwhen it
becomes unreachable to the program inwhich it is used.
Q:Describe synchronization in respect to multithreading.
A:With respect to multithreading,synchronizationisthe capability to controlthe access of multiplethreadsto
sharedresources.Withoutsynchonization,itispossibleforonethreadtomodifyasharedvariablewhileanother
thread is inthe process of using or updating same shared variable.This usually leads to significant errors.
Q:Explaindifferent way of using thread?
A:The thread could be implemented by using runnable interface or by inheriting fromtheThread class.The
former is more advantageous, 'cause whenyouare goingfor multiple inheritance..the only interface can help.
Q:What are pass by reference and passby value?
A:Pass By Reference meansthe passingthe address itself ratherthan passingthevalue.PassbyValue means
passing a copy of the value to be passed.
Q:What is HashMapand Map?
A:Map is Interface and Hashmap is class that implementsthat.
Q:Difference between HashMap and HashTable?
A:The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.
(HashMapallows nullvalues as key and value whereas Hashtable doesnt allow).HashMap does not guaran