1. What is the difference between an Abstract class and Interface ?
|Abstract class can have abstract and non-abstract methods.||Interface can have only abstract methods. Since Java 8, it can have default and static methods also.|
|Abstract class doesn’t support multiple inheritance.||Interface supports multiple inheritance.|
|Abstract class can have final, non-final, static and non-static variables.||Interface has only static and final variables|
|An abstract class can be extended using keyword “extends”.||An interface can be implemented using keyword “implements”.|
|A Java abstract class can have class members like private, protected, etc.||Members of a Java interface are public by default.|
2. What are the basic difference Between Array and ArrayList
|Size should be given at the time of array declaration.||Size may not be required. It changes the size dynamically.|
|To put an object into array we need to specify the index.||No index required.|
|Array can contain both primitive data types as well as objects of a class depending on the definition of the array.||ArrayList only supports object entries, not the primitive data types.|
3. What is Static Keyword?
Static keyword in Java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than an instance of the class.
The static can be: Variable (also known as a class variable), Method (also known as a class method), Block, Nested class
4. What is this and super keyword?
- this can be used to refer current class instance variable.
- this can be used to invoke current class method (implicitly)
- this() can be used to invoke current class constructor.
- this can be passed as an argument in the method call.
- this can be passed as argument in the constructor call.
- this can be used to return the current class instance from the method.
The super keyword in Java is a reference variable which is used to refer immediate parent class object.
5. What is Final Keyword?
The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be: variable, method, class
6. Can we declare a constructor final?
No, because constructor is never inherited.
7. What is collections in java?
Collection is a framework that is designed to store the objects and manipulate the design to store the objects.
Collections are used to perform the following operations: Searching, Sorting, Manipulation, Insertion, Deletion
A group of objects is known as collections. All the classes and interfaces for collecting are available in Java util package.
8. What are all the Classes and Interfaces that are available in the collections?
Interfaces:Collection,List,Set,Map,Sorted Set,Sorted Map,Queue
Classes:Lists,Array List,Vector,Linked List
Sets:Hash set,Linked Hash Set,Tree Set
Maps: Hash Map,Hash Table,Tree Map,Linked Hash Map
9. What is the difference between Hashmap and Hashtable?
|Methods are not synchronized||Key methods are synchronized|
|Not thread safety||Thread safety|
|Iterator is used to iterate the values||Enumerator is used to iterate the values|
|Allows one null key and multiple null values||Doesn’t allow anything that is null|
|Performance is high than HashTable||Performance is slow|
10. What is Exception ?
An Exception is a problem that can occur during the normal flow of an execution. A method can throw an exception when something wails at runtime. If that exception couldn’t be handled, then the execution gets terminated before it completes the task.
If we handled the exception, then the normal flow gets continued. Exceptions are a subclass of java.lang.Exception.