Java Question Bank | Rajat Varyani

In quest of the interview preparation, I became fond of Java. Hence I created this personalised question bank which I used to revise. The question bank is very extensive and covers many critical aspects of Java Programming. Use this to full effect and I can say you will never get it wrong when it comes to Java questions. These questions have been collected from various sources.

 General Questions

  • Is Java pass by value or pass by reference? 
  • Does Java support multiple inheritance? Why/Why not?
  • Why the main method is public void and static?
  • Difference Deep copy and shallow copy? 
  • What is marker interface? What does it do? (Explain annotations as well)
  • How to create an immutable object in Java? Count all benefits. (Tough)
  • Explain keywords in Java? eg static native transient volatile final.
  • Why static should be avoided?
  • Difference btw jdk jre and jvm. 


Object orientation

  • Explain the principles of OOPS.
  • What is the difference between Encapsulation and abstraction?
  • State difference between abstract class and Interface?
  • State difference between association, composition, and aggregation?
  • Can abstract class have constructors in Java? If yes why?
  • Can abstract class implement interface? Do they require to implement all the methods?
  • Can an abstract class be final?
  • Can abstract class have static methods(main)?
  • Can you create an instance of an abstract class?
  • Is it mandatory for an abstract class to have an abstract method?
  • When do you favor abstract class over the interface?
  • Can you overload and override static methods in Java?Explain the reason behind it.


Collections

  • Explain Collection Framework hierarchy
  • Difference between ArrayList and Vector
  • How to get synchronized version of ArrayList
  • State difference between HashSet and LinkedHashSet
  • Compare 3 cursors present in Java
  • State Difference between Comparable and Comparator
  • State Difference between HaahMap and HashTable
  • State importance of Hashcode and equals and explain the contract between them?


General questions

  • What is the Java Collections API? List down its advantages?
  • Explain Collections hierarchy?
  • Why Collection interface does not extend Cloneable and Serializable interface?
  • Why Map interface does not extend Collection interface?


List interface related

  • Why we use List interface? What are main classes implementing List interface?
  • How to convert an array of String to ArrayList?
  • How to reverse the list?


Set interface related

  • Why we use Set interface? What are main classes implementing Set interface?
  • How HashSet store elements?
  • Can a null element be added to a TreeSet or HashSet?


Map interface related

  • Why we use Map interface? What are main classes implementing Map interface?
  • What are IdentityHashMap and WeakHashMap?
  • Explain ConcurrentHashMap? How it works?
  • How hashmap works?
  • How to design a good key for hashmap?
  • What are different Collection views provided by Map interface?
  • When to use HashMap or TreeMap?


Tell the difference questions

  •  State difference between Set and List.
  •  State difference between List and Map.
  •  State difference between HashMap and HashTable.
  •  State difference between Vector and ArrayList and Array.
  •  State difference between Iterator and Enumeration.
  •  State difference between HashMap and HashSet.
  •  State difference between Iterator and ListIterator.
  •  State difference between TreeSet and SortedSet.
  •  State difference between ArrayList and LinkedList.


More questions

  •  How to make a collection read only?
  •  How to make a collection thread safe?
  •  Why there is no method like Iterator.add() to add elements to the collection?
  •  What are different ways to iterate over a list?
  •  What do you understand by iterator fail-fast property?
  •  What is the difference between fail-fast and fail-safe?
  •  How to avoid ConcurrentModificationException while iterating a collection?
  •  What is UnsupportedOperationException?
  •  Which collection classes provide random access of its elements?
  •  What is BlockingQueue?
  •  What are Queue and Stack, list their differences?
  •  What is Comparable and Comparator interface?
  •  What are Collections and Arrays class?


Garbage collection

  • Explain garbage collection in Java?
  • Mark and Sweep, Reference count, Stop and Wait, Generational Stop and wait.
  • When does an Object become eligible for Garbage collection in Java?
  • What is finalize method in Java? When does Garbage collector calls finalize method in Java?
  • If Object A has reference to Object B and Object B refer to Object A, apart from that there is no live reference to either object A or B, Does they are eligible to Garbage collection?


Exception handling

  • State difference between and checked and unchecked exceptions.
  • State difference between final, finally and finalize.
  • State difference between throw and throws.


Multithreading

  • State difference between notify and notifyall.
  • Why methods notify,notifyall and wait are in object class and not in Thread class?
  • Explain about synchronized keyword and what are its advantages and disadvantages
  • What is object lock and when it is required?
  • While a thread is executing an instance synchronized method then is it possible to execute any other synchronized method?
  • What is class level lock and when is it required?
  • What is the difference between class level lock and object level lock?
  • What is the advantage of sync block over sync keyword?
  • How to declare sync block to class level block?
  • What is race condition? and how to avoid it?
  • What is synchronized statements?
  • Number of ways to create threads in Java and which one is the better one?
  • State difference between Sleep yield and wait().


Serialization

  • What is Serialization and declare-serialization and which streams are involved in both of them?
  • State the example for above?
  • What is transient variable and its effects on instance variable, static variable and final variables?
  • What is object graph in serialization?
  • What is Externalization and its need?
  • Difference between Serialization and Externalization?
  • What is serialVersionUID?


String class

  • State difference between StringBuilder, String, and StringBuffer in Java?
  • Why String is immutable in Java.
  • Explain the concept of StringPool.
  • How does substring inside string works?
  • Object equality vs reference equality in terms of Wrapper classes and Strings.



Comments

Popular posts from this blog

ThoughtWorks | Eaton | Sujata Regoti

Nvidia | Ramesh Nagargoje

Veritas | Mahesh Bhosale