Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

Core Java Interview Questions

Interview docs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Core Java Interview Questions

Interview docs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Core java Interview Questions

1. What do you know about Factory Design Pattern in Java?


2. Is it necessary to declare all immutable objects as final?

3. What is the output of the below code and why?


public class InterviewbitTest {

private static int counter = 0;

void InterviewbitTest() {

counter = 20;

InterviewbitTest(int x){

counter = x;

public static void main(String[] args) {

InterviewbitTest interviewbitTest = new InterviewbitTest();

System.out.println(counter);

4. What is the result of the below program?


class X {

static int i = 1111;

static{

i = i-- - --i; //L1

i = i++ + ++i; //L2

class Y extends X{

static{

i = --i - i--; //L3

i = ++i + i++; //L4

}
}

public class DriverClass{

public static void main(String[] args){

Y y = new Y();

System.out.println(y.i); //L5

5. What is the output of the below code?


public class InterviewbitProblem{

public static void main(String[] args) {

Integer num1 = 1000, num2 = 1000;

System.out.println(num1 == num2);//1

Integer num3 = 20, num4 = 20;

System.out.println(num3 == num4);//2

6. Is there any difference in defining or creating a String by using String literal


and by using the new() operator?

7. Is it possible to override a method to throw RuntimeException from throwing


NullPointerException in the parent class?

8. What will happen if you run 1.0/0.0?

9. What is the result of the below Java code?


public class InterviewbitProblem{

public static void main(String[] args) {

System.out.println(Math.min(Double.MIN_VALUE, 0.0d));

10. What is the result of the below code?


public class InterviewbitProblem{

public static void main(String[] arr){

System.out.println(0.1*3 == 0.3);

System.out.println(0.1*2 == 0.2);

}
11. Can we use HashMap in a multi-threaded environment?
12. What is the best possible way to call the wait() method - by using the if
construct or the loop construct?
13. How would you help a colleague with lesser Java experience who has trouble
in serializing a class?
14. What is the result of the below code and Why?
public class TestClass {

public static void main(String[] args) {

someMethod(null);

public static void someMethod(Object o) {

System.out.println("Object method Invoked");

public static void someMethod(String s) {

System.out.println("String method Invoked");

15. How is the classpath variable different from the path variables?
16. What is the importance of the hashCode() and equals() contract?
17. Can you write a code for representing thread-safe singleton patterns in Java?
18. What do you understand by the ... in the below method parameters?
19. How is Collection different from Collections in Java?
20. Differentiate between the Vector and ArrayList collections in Java.
21. What is the difference between the == operator and the equals() method in
Java?
22. Explain the concept of object-oriented programming (OOP) and its pillars.
23. What is the difference between abstract classes and interfaces in Java?
24. Can you explain the concept of method overloading and method overriding in
Java?
25. What is the purpose of the final keyword in Java? How does it affect classes,
methods, and variables?
26. What are some of the common classes in Java?
27. What are checked and unchecked exceptions in Java? Provide examples of
each.
28. How does garbage collection work in Java? Explain the different generations
of the garbage collector.
29. What is the static keyword used for in Java? How does it affect variables and
methods?
30. Can you explain the concept of multithreading in Java? How do you create
and synchronize threads?
31. What is the purpose of the synchronized keyword? How does it ensure thread
safety?
32. How does Java handle memory management? Explain the difference between
stack and heap memory.
33. What is the Java Virtual Machine (JVM)? How does it execute Java programs?
34. What are the different access modifiers in Java (e.g., public, private,
protected, default)? Explain their visibility and usage.
35. How do you handle exceptions in Java? What are the best practices for
exception handling?
36. Can you explain the concept of serialization in Java? How do you serialize and
deserialize objects?
37. What is the difference between a StringBuilder and a StringBuffer in Java?
When would you use each?
38. Explain the concept of polymorphism in Java. How does it relate to
inheritance and method overriding?
39. Can you explain the concept of Java annotations? Provide examples of built-in
annotations and their usage.
40. How do you handle concurrent modification exceptions when working with
collections in Java?
41. Why are strings immutable in java?

42. How intern() works?

43. How many objects are created in Strings using string literals and new
operator?
44. How string constant pool works?

45. Difference between equals and == operator?

46. Difference between string , string buffer and string builder.


47. Why is wrapper class required?

48. Methods of Object class?

49. Does java gives importance to primitive data types?

50. Is Java pass by value or pass by reference?

51. Types of oops

52. Composition vs Aggregation vs Association?


53. Function overloading vs overriding

54. Difference between Abstract class and Interface?

55. Can private method or static methods be overridden in Java?

56. Can main() method be overloaded?

57. Can Abstract class have main method?

58. What is Serialisation and Deserialisation?

59. Use of transient keyword?

60. Is it possible to serialise a class if its super class is not serialisable ?Can the
class be still serialised and deserialised?
61. Can Uninitialised non serialised , non transient fields still be tolerated?

62. What is marker interface?

63. What is shallow copy and Deep copy?

64. Difference between Error and Exception?

65. Checked vs Unchecked Exception?

66. Create custom Exception?

67. What is Runtime exception ?

68. How does JVM handle Exception?

69. Difference between Final, Finalise and Finally?

70. Super class of all exceptions?

71. Is throwable an interface?

72. When Finally block doesn’t get executed?

73. Can subclass throw higher checked exception than base class?

74. Can we throw an unchecked exception in child class if parent class doesn’t
throw any exception?
75. Difference between throw and throws()

76. Why to use Enum?

77. How does Garbage collection in Java works?

78. Array vs ArrayList?

79. ArrayList vs LinkedList? When to use which collection?

80. Fail Safe vs Fail Fast Iterators?

81. Fail Safe vs Fail Fast Iterators?

82. What is concurrent modification exception?


83. Internal working of HashMap

84. Java8 changes to HashMap

85. Why HashMap contains null key?

86. Is it Mandatory to have key immutable in HashMap?

87. Why to override equals() and hashcode() method?

88. HashSet vs LinkedHashSet vs TreeSet

89. What is the Internal Datastructure in TreeMap? How the elements are sorted?

90. HashMap vs ConcurrentHashMap

91. Comparable vs Comparator

92. What is blocking Queue?

93. What is Vector? When to use it?

94. MultiThreading vs MultiProcessing vs MultiProgramming vs MultiTasking?

95. Life cycle of a Thread

96. Extends vs Runnable

97. yield() vs sleep() vs join() ?

98. wait() vs sleep() ?

99. why is join() method used?

100. Can we Override start() method in Thread?

101. Can we Override run() method?

102. Can we start the thread twice?

103. What is IllegalThreadStateException?

104. What happens if run() method is called without start()?

105. Why do we use ThreadPool?

106. What is Race Condition?

107. What is Synchronisation?Types of Synchronisation?

108. Object Level Locking vs Class Level Locking?

109. If there is 2 synchronised methods m1 and m2 in a class, can 2 different


threads t1 and t2 call different methods(m1,m2) respectively on same object of
class c at same time ?
110. If a class has a synchronised method and non synchronised method, can
multiple threads execute non synchronised methods?
111. Can 2 threads call 2 different static synchronised methods of same class?

112. Does static synchronised methods block a non synchronised methods?


113. Can Constructors be synchronised?

114. What is DeadLock?

115. What is Inter thread communication?Explain wait(),notify() and notifyall()?

116. What is IllegalMonitorStateException?

117. Which class does wait(),notify() and notifyall() method belong?

118. Explain few Thread class methods?is Sleep() a method in Thread class or
Object class?
119. Producer Consumer Problem in Java?

120. Volatile vs Synchronised?

121. What are Atomic variables?

122. runnable vs callable ?

123. What is Future Object?

124. What is CompletableFuture?

125. Use of Done() , IsCancelled() and Cancel() method of Future Object?

126. Explain ThreadLocal class

127. What is CountDownLatch?

128. What is CyclicBarrier?

129. What is ReEntrant lock?

130. ExecutorService.submit() vs Executor.execute()?

131. Different types of ThreadExecutor Services?

132. Explain how FixedThreadPool executor works?

133. Interface8 changes

134. What is Functional Interface? why do we need it?

135. Difference between Collection and Stream

136. What is Terminal Operator vs Intermediate operators?

137. What is Optional?

138. Flat map vs Map?

139. Difference between Parallel sort vs sort

140. Difference between Predicate vs BiPredicate?

141. How Diamond problem is solved in Java8?

142. Difference between JDK,JRE and JVM

143. What is Immutable class?


144. What are solid principles?

145. Difference between ClassNotFound vs NoClassDefError?

146. What is Singleton Design pattern? Explain Thread Safe Singleton and Bill
Pugh Singleton ?
147. How to break Singleton?

148. Explain few features in each Java versions starting from Java8

You might also like