Skip to content

Instantly share code, notes, and snippets.

@vengateshm
Last active May 16, 2024 11:48
Show Gist options
  • Save vengateshm/b39d39526fcf25c447469cbb66b725da to your computer and use it in GitHub Desktop.
Save vengateshm/b39d39526fcf25c447469cbb66b725da to your computer and use it in GitHub Desktop.
Core Java Interview questions
  1. OOPs concepts Encapsulation, Abstraction, Inheritance, Polymorphism and explain

  2. Exception hierarchy in inheritance

  3. Parent child override scenario

  4. Can we override static and private method?

  5. Difference between Java 7 and Java 8 interface (static methods and default methods introduced)

  6. Final, Finally, Finalize

  7. Equals and hashcode

  8. Why checked exception also called compile time exception, is it occurs in compile time?

  9. How to write custom exception?

  10. Throw and throws exception

  11. Exception order

  12. return usage in try, catch and finally block

  13. Is finally block always executed?

  14. How many ways we can create string object?

  15. String constant pool and working of it

  16. Why string is immutable?

  17. String vs StringBuffer vs StringBUilder

  18. How to write your own custom immutable class?

  19. Which is good to store passwords char array or string?

  20. What is marker interface? (Serializable, Cloneable, Remote) and how and when it works?

  21. Collections - List(ArrayList, LinkedList), Set(HashSet, LinkedHashSet, TreeSet), Map(HashMap, LinkedHashMap, TreeMap)

  22. Concurrent - CopyOnWriteArrayList, CopyOnWriteArraySet, ConcurrentHashMap

  23. List vs Set

  24. ArrayList vs LinkedList

  25. Custom array list without duplicates (extend array list and override add method)

  26. ArrayList al = new ArrayList(); vs List l = new ArrayList<>();

  27. Declaring list with final keyword

  28. Why set does not allow duplicates?

  29. Comparable vs Comparator

  30. Fail fast vs fail safe iterator

  31. HashMap (can store null keys / values) vs ConcurrentHashMap (cannot store null keys / values)

  32. HashTable vs ConcurrentHashMap

  33. Collections.synchronizedMap() - HashTable implementation - Entired data structure is locked

  34. Internal working of HashMap - hash, bucket index, equals check, Linked List, Load factor, Balanced tree

  35. Null key hashmap - 0th index bucket

  36. TreeMap working

  37. Why wait and notify is declared in Object class instead of Thread?

  38. Why are multiple inheritances not supported in Java?

  39. Why Java does not support operator overloading?

  40. Why String is immutable in Java?

    Java runtime saves lot of heap space because different string variables can refer to same variable in the pool. If it is mutable then there is a chance database password, username passed as String can be modified by hackers. It is safe for multi threading which avoids synchronizing for thread safety. Hashcode cached at creation time and makes a great candidate for key in Map and faster than other HashMap key objects.

  41. Why character array is preferred to store passwords instead String in Java?

    Any change in string will create new string as they are immutable. Whereas in char[] we can set elements to blank or zero. With string there is always risk of printing plain text to log or file, on the other hand if we print char[] it just
    prints memory address.

    String resides in SCP and JVM needs to be restarted to clean up SCP by GC and it will remain in memory for long time.

    Memory dump will have string passwords in clear text so passwords should be encrypted.

  42. String intern() method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment