2. Runtime(UnChecked) and CompileTime(Checked) exceptions
3. Deadlock and Race Condition
4. String and StringBuffer
5. List and ArrayList
6. Hashtable and Hashmap
7. Static and Non Static
Answer 1
- Abstract class is a class which atleast has one method abstract or unimplemented while Interface only has method signatures and public constants only.
- A class can implement many Interfaces but can extract only one class.
Answer 2
- For compile time exeptions, Compiler forces the Caller method to either have a try/catch or throw the exception itself , thus making sure the Exception if thrown is well handled. Examples of Compile time exceptions are the UserDefined Exceptions, or any class which Extends the Exception class.
- For Runtime exception, Compiler does not force the calling method, so potentially if a method throws an exception, the behaviour has be decided at Runtime.
Examples include, NullPointer, ArrayIndexOutOfBounds exception etc.
- Deadlock happens when two threads are holding each others resources and waiting for the other thread to release the resource first. Since each thread is waiting on the other to release the resource, both the threads will be always be in waiting condition resulting in a Deadlock.
- Race condition, happens when two threads are trying for the resource, and any once can occupy it depending on who goes first. Thus giving rise to a random output.
- String is a immutable , there is just one instance of the string. If the string is changed a new String gets created. Thus lot of objects are created
- StringBuffer is used when the String object needs to be changed , so that we work on the same instance. StringBuffer.toString() can be used to convert it back to String. StringBuffer.append("abc") can be used to append the String to the StringBuffer.
- List is an interface which is implemented by Vector, ArrayList
- ArrayList is a class which implements List interface and stores objects. All methods in ArrayList are not threadsafe.
Answer 6
- Hashtable and Hashmap have exactly same, only difference is, in Hashtable all the methods are Synchronized or ThreadSafe while Hashmap is not thread safe
- So Hashmap is faster but not ThreadSafe
- Static methods work on Class level, hence do not need an instance to call it
- Non Static methods are instance level methods , so need an instance to call it.
- Static variables are CLASS level , while instance variables work on an instance and are instance specific