165 java interview questions | Core Java Interview Questions

Java is an Object Oriented Programming Language, First Learn Some Basics of Java and then Try to Solve Given Java Interview Questions Frequently Asked During Viva or by Recruiters. We Selected Top List of Interview Questions Asked now a days in Java Interview. Learning of java from basic questions like what is java tutorial, core java, where it is used, what type of applications are created in java and why use java Help You to Answer these Interview Questions Easily.We are Sharing Top 165 Java Interview Questions, these Interview Questions are frequently asked in Viva or by Recruiters. Java Questions can be asked from any Java Topic, Soon we list Questions topic wise. So try to answer these Java Interview Questions before facing Java Questions in Technical Interview or Aptitude Test.

Tip for Java Interview : How Interviewer Start Asking Questions
Normally Questions Start with Some Basic Concept (as we mentioned above) of the Subject and Later they Continue Based on further Discussion and what you answer.
Our Questions on These Topics So Better to Read All Before Answering these Question

  1. Basics of Java Interview Questions
  2. OOPs : Polymorphism Interview Questions
  3. Exception Handling Interview Questions
  4. Interview Questions of Object Oriented Programming and Design
  5. Questions on Programming Basics
  6. Questions on Object Oriented Concepts
  7. Java Data Structures and Advanced Topics Questions
  8. Garbage Collection Interview Questions
  9. Java Multi threading Interview Questions
  10. JDBC Interview Questions
  11. Override Interview Questions
  12. Object characteristics (Defining Objects) Interview Questions
  13. Constructors Java Interview Questions
  14. Overloading Interview Questions Java
  15. Inheritance Interview Questions of Java
  16. Java Constructor Questions
  17. Java Access Modifier(Static, Final, Volatile) Interview Questions
  18. Java Abstract Class Interview Questions
  19. Java Interface Interview Questions
  20. Java Package Interview Questions
  21. Java Thread Interview Questions
  22. Interview Questions of File I/O in Java
  23. Miscellaneous Interview Questions
Top 165 Most Frequently Asked Java Interview Questions
1) Can you override a private or static method in Java?

2) What do the expression 1.0 / 0.0 will return? will it throw Exception? any compile time error?

3) What are practical uses of volatile modifier?

4) What guarantee volatile variable provides?

5) Which one would be easy to write? synchronization code for 10 threads or 2 threads?

6) How do you call wait() method? using if block or loop? Why?

7)  What is false sharing in the context of multi-threading?

8) What is busy spin? Why should you use it?

9) How do you take thread dump in Java?

10) is Swing thread-safe?

11) What is a thread local variable in Java?

12) Write wait-notify code for producer-consumer problem?

13) Write code for thread-safe Singleton in Java?

14) What is an immutable object? How do you create an Immutable object in Java?

15) The difference between sleep and wait in Java?

16) Can we create an Immutable object, which contains a mutable object?

17) What is the right data type to represent a price in Java?

18) How do you convert bytes to String?

19) How do you convert bytes to long in Java?

20) Can we cast an int value into byte variable? what will happen if the value of int is larger than byte?

21) There are two classes B extends A and C extends B, Can we cast B into C e.g. C = (C) B;

22) Which class contains clone method? Cloneable or Object?

23) Is ++ operator is thread-safe in Java?

24) Difference between a = a + b and a += b ?

25) Can I store a double value in a long variable without casting?

26) What will this return 3*0.1 == 0.3? true or false?

27) Which one will take more memory, an int or Integer?

28) Why is String Immutable in Java?

29) Can we use String in the switch case?

30) What is constructor chaining in Java?

31) What is the size of int in 64-bit JVM?

32) The difference between Serial and Parallel Garbage Collector?

33) What is the size of an int variable in 32-bit and 64-bit JVM?

34) A difference between WeakReference and SoftReference in Java?

35) How do WeakHashMap works?

36) What is -XX:+UseCompressedOops JVM option? Why use it?

37) How do you find if JVM is 32-bit or 64-bit from Java Program?

38) What is the maximum heap size of 32-bit and 64-bit JVM?

39) What is the difference between JRE, JDK, JVM and JIT?

40) Explain Java Heap space and Garbage collection?

41) Can you guarantee the garbage collection process?

42) How do you find memory usage from Java program? How much percent of the heap is used?

43) What is the difference between stack and heap in Java?

45) What is a.hashCode() used for? How is it related to a.equals(b)?

46) Difference between final, finalize and finally?

47) What is a compile time constant in Java? What is the risk of using it?

48) The difference between List, Set, Map, and Queue in Java?

49) Difference between poll() and remove() method?

50) The difference between LinkedHashMap and PriorityQueue in Java?

51) Difference between ArrayList and LinkedList in Java?

52) What is a couple of ways that you could sort a collection?

53) How do you print Array in Java?

54) LinkedList in Java is doubly or singly linked list?

55) Which kind of tree is used to implement TreeMap in Java?

56) What is the difference between Hashtable and HashMap?

57) How HashSet works internally in Java?

58) Write code to remove elements from ArrayList while iterating?

59) Can I write my own container class and use it in the for-each loop?

60) What is default size of ArrayList and HashMap in Java?

61) Is it possible for two unequal objects to have the same hashcode?

62) Can two equal object have the different hash code?

63) Can we use random numbers in the hashcode() method?

64) What is the difference between Comparator and Comparable in Java?

65) Why you need to override hashcode, when you override equals in Java?

66) In my Java program, I have three sockets? How many threads I will need to handle that?

67) How do you create ByteBuffer in Java?

68) How do you write and read from ByteBuffer in Java?

69) Is Java BIG endian or LITTLE endian?

70) What is the byte order of ByteBuffer?

71) The difference between direct buffer and non-direct buffer in Java?

72) What is the memory mapped buffer in Java?

73) What is TCP NO DELAY socket option?

74) What is the difference between TCP and UDP protocol?

75) The difference between ByteBuffer and StringBuffer in Java?

76) What best practices you follow while writing multi-threaded code in Java?

77) Tell me few best practices you apply while using Collections in Java?

78) Can you tell us at least 5 best practice you use while using threads in Java?

79) Name 5 IO best practices?

80) Name 5 JDBC best practices your follow?

81) Name couple of method overloading best practices in Java?

82) Does SimpleDateFormat is safe to use in the multi-threaded program?

83) How do you format a date in Java? e.g. in the ddMMyyyy format?

84) How do you show timezone in formatted date in Java?

85) The difference between java.util.Date and java.sql.Date in Java?

86) How to you calculate the difference between two dates in Java?

87) How do you convert a String(YYYYMMDD) to date in Java?

89) How do you test static method?

90) How to do you test a method for an exception using JUnit?

91) Which unit testing libraries you have used for testing Java programs?

92) What is the difference between @Before and @BeforeClass annotation?

93) How to check if a String contains only numeric digits?

94) How to write LRU cache in Java using Generics?

95) Write a Java program to convert bytes to long?

96) How to reverse a String in Java without using StringBuffer?

97) How to find the word with the highest frequency from a file in Java?

98) How do you check if two given String are anagrams?

99) How to print all permutation of a String in Java?

100) How do you print duplicate elements from an array in Java?

101) How to convert String to int in Java?

102) How to swap two integers without using temp variable?

103) What is the interface? Why you use it if you cannot write anything concrete on it?

104) The difference between abstract class and interface in Java?

105) Which design pattern have you used in your production code? apart from Singleton?

106) Can you explain Liskov Substitution principle?

107) What is Law of Demeter violation? Why it matters?

108) What is Adapter pattern? When to use it?

109) What is "dependency injection" and "inversion of control"? Why would someone use it?

110) What is an abstract class? How is it different from an interface?

111) Which one is better constructor injection or setter dependency injection?

112) What is difference between dependency injection and factory design pattern?

113) Difference between Adapter and Decorator pattern?

114) Difference between Adapter and Proxy Pattern? .

115) What is Template method pattern?

116) When do you use Visitor design pattern?

117) When do you use Composite design pattern?

118) The difference between Inheritance and Composition?

119) Describe overloading and overriding in Java?

120) The difference between nested public static class and a top level class in Java?

121) Difference between Composition, Aggregation and Association in OOP?

122) Give me an example of design pattern which is based upon open closed principle?

123) Difference between Abstract factory and Prototype design pattern?

124) When do you use Flyweight pattern?

125) The difference between nested static class and top level class?

126) Can you write a regular expression to check if String is a number?

127) The difference between checked and unchecked Exception in Java?

128) The difference between throw and throws in Java?

129) The difference between Serializable and Externalizable in Java?

130) The difference between DOM and SAX parser in Java?

131) Tell me 3 features introduced on JDK 1.7?

132) Tell me 5 features introduced in JDK 1.8?

133) What is the difference between Maven and ANT in Java?

134) Can we make array volatile in Java?

135) Can volatile make a non-atomic operation to atomic?

136) Does Java support multiple inheritances?

137) What will happen if we put a key object in a HashMap which is already there?

138) If a method throws NullPointerException in the superclass, can we override it with a method which throws RuntimeException?

139) How do you ensure that N thread can access N resources without deadlock?

140) What is difference between CyclicBarrier and CountDownLatch in Java?

141) What is the difference between StringBuffer and StringBuilder in Java?

142) Can you access a non-static variable in the static context?

143) When Singleton doesn't remain Singleton in Java?

144) is it possible to load a class by two ClassLoader?

145) is it possible for equals() to return false, even if contents of two Objects are same?

146) Why compareTo() should be consistent to equals() method in Java?

147) When do Double and BigDecimal give different answers for equals() and compareTo() == 0.

148) How does "has before" apply to volatile work?

149) Why is 0.1 * 3 != 0.3,

150) Why is (Integer) 1 == (Integer) 1 but (Integer) 222 != (Integer) 222 and which command arguments change this.

151) What happens when exception is thrown by a Thread?

152) Difference between notify() and notifyAll() call?

153) Difference between System.exit() and System.halt() method?

154) Does following code legal in Java? is it example of method overloading or overriding?

155) What is the most important feature of Java?

156) What is the difference between a JDK and a JVM?

157) Can you declare the main method as final?

158) Can we intialize blank final variable?

159) What is blank final variable?

160) Can you have virtual functions in Java?

161) Can we overload main() method?

162)  Why Java does not support pointers?

163) Can we execute a program without main() method?

164) Does constructor return any value?

165) What is classloader?

Hope These Interview Questions Helps You to Perform Better in Interview Exams Taken by Various Companies, in Viva, Aptitude Exams. 

Related Posts