Core Java Interview Questions
Core Java Interview Questions
void InterviewbitTest() {
counter = 20;
InterviewbitTest(int x){
counter = x;
System.out.println(counter);
static{
class Y extends X{
static{
}
}
Y y = new Y();
System.out.println(y.i); //L5
System.out.println(num1 == num2);//1
System.out.println(num3 == num4);//2
System.out.println(Math.min(Double.MIN_VALUE, 0.0d));
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 {
someMethod(null);
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?
43. How many objects are created in Strings using string literals and new
operator?
44. How string constant pool works?
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?
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()
89. What is the Internal Datastructure in TreeMap? How the elements are sorted?
118. Explain few Thread class methods?is Sleep() a method in Thread class or
Object class?
119. Producer Consumer Problem in Java?
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