Wednesday, April 3, 2019

Java interview questions part-1

1. What is singleton class in java ?
Answer :- 

2. what is difference between singleton in java and singleton in spring ?
Answer :-

3. what is immutable in java ?
Answer :-

4. How to create custom immutable class in java ?
Answer :- 

5. Difference between abstraction and encapsulation in java ?
Answer :- 

6. How to achieve abstraction in java ?
Answer :- 

7. How to achieve encapsulation in java ?
Answer :- 

8. What are the 4 basics of OOP ?

Answer :- There four principles of  oop (object-oriented programming) are encapsulation, abstraction, inheritance, and polymorphism.

9. What is solid principle in java ?

Answer :- 
S - Single Responsibility Principle (SRP)
O - Open Closed Principle
L - Liskov Substitution Principle
I - Interface Segregation Principle
D - Dependency Inversion Principle

10. What are the methods in Object class in java ?

11. Enumeration  Vs  Iterator  Vs  ListIterator ?

Enumeration Iterator  ListIterator
  Enumeration is interface.
  Use only for only legacy classes.
  Like Hashtable or Vector or Properties
  Iterator is interface.
  Use for any (all) collection                classes. Like like ArrayList, HashSet or  Hashtable
  Sub-interfaceof Iterator.
  Use to traverse the List objects only.
  Like ArrayList or LinkedList or Vector
  Enumeration has two methods:
  • hasMoreElements()
  • nextElement()
  Iterator has methods:
  •  hasNext()
  •  next()
  •  remove()
  ListIterator have methods as mention below:
  • add(E e)
  • hasNext()
  • hasPrevious()
  • next(), returns E
  • nextIndex()
  • previous(), returns E
  • previousIndex()
  • remove()
  • set(E e)
  enumerate legacy collection only in          FORWARD direction   iterate any (all) collection. only      in   FORWARD direction   ListIterator can use in  either FORWARD or  BACKWARD        directions
  It unidirectional (FORWARD) directional    cursor it unidirectional (FORWARD) directional cursor   it bi-directional (FORWARD or BACKWARD) directional          cursor
  It is Fail-Safe. we can use with thread-      safe environment.   Fail Fast   Fail Fast
  Does not Throw       ConcurrentModification Exception   Throw ConcurrentModification Exception   Throw ConcurrentModification Exception
  Present in java.util package   Present in java.util package   Present in java.util package

No comments:

Post a Comment