Java Interview Questions (3 Years Experience)
🧠 1. Core Java (Most Important)
- What are the main features of Java?
- Difference between JDK, JRE, and JVM?
- What is OOPs? Explain its principles.
- Difference between method overloading and overriding?
- What is String vs StringBuffer vs StringBuilder?
- Why is Java called platform-independent?
- What is final, finally, and finalize?
🧩 2. Object-Oriented Programming
- Explain encapsulation with example.
- What is abstraction in Java?
- Difference between abstraction and encapsulation?
- What is inheritance and its types?
- Can Java support multiple inheritance? Why not?
📦 3. Collections Framework
- Difference between ArrayList and LinkedList?
- HashMap vs Hashtable?
- How does HashMap work internally?
- What is the difference between Set and List?
- What is ConcurrentHashMap?
- What is fail-fast vs fail-safe iterator?
⚡ 4. Multithreading & Concurrency
- What is multithreading?
- Difference between process and thread?
- How to create a thread in Java?
- What is synchronization?
- What is deadlock?
- What is volatile keyword?
- Difference between wait(), notify(), notifyAll()?
🗄️ 5. Exception Handling
- What is exception handling?
- Checked vs unchecked exceptions?
- Difference between throw and throws?
- What is custom exception?
- What is try-catch-finally?
🧱 6. Java 8 Features
- What are Java 8 features?
- What is lambda expression?
- What is Stream API?
- Difference between map() and flatMap()?
- What is Optional class?
- What are functional interfaces?
🌐 7. Spring / Spring Boot (Very Important for 3 Years)
- What is Spring Boot?
- What is dependency injection?
- Difference between Spring and Spring Boot?
- What is @Autowired?
- What is REST API in Spring Boot?
- What is microservices architecture?
- What is application.properties used for?
🗄️ 8. Database & Hibernate
- What is JDBC?
- What is Hibernate?
- Difference between JDBC and Hibernate?
- What is ORM?
- What is lazy loading and eager loading?
- What is HQL?
💻 9. Coding Questions (Very Common)
- Reverse a string without using built-in function
- Find duplicate elements in array
- Check palindrome number/string
- Find second highest number in array
- Fibonacci series
- Factorial program
- Remove duplicates from ArrayList
🧠 10. Scenario-Based Questions (Important for Experience)
- How did you handle production issues in your project?
- Explain your current project architecture.
- How do you optimize performance in Java applications?
- How do you handle memory leaks?
- How do you debug application failures?
- What challenges did you face in microservices?
⚡ Interview Tip (3 Years Experience)
Interviewers expect:
- Strong Core Java + Collections + Multithreading
- Basic Spring Boot + REST API knowledge
- Real project explanation (very important)
- Some coding ability (not very hard, but logic-based)
Java Mock Interview (3 Years Experience)
👨💼 Round 1: HR + Introduction
Interviewer: Tell me about yourself.
👉 What you should cover:
- Current role
- Tech stack (Java, Spring Boot, REST APIs, DB)
- 1–2 key projects
- Your responsibilities
👉 Sample answer:
“I am a Java developer with 3 years of experience working on backend development using Java, Spring Boot, and REST APIs. I have worked on building scalable microservices and integrating databases like MySQL. In my current project, I am responsible for developing APIs, optimizing performance, and handling production issues.”
Interviewer: Why are you looking for a change?
👉 Good answer approach:
- Growth
- Better opportunities
- Learning new technologies
💻 Round 2: Core Java
Interviewer: What is the difference between HashMap and Hashtable?
👉 Answer:
- HashMap is not synchronized, Hashtable is synchronized
- HashMap allows null keys/values, Hashtable does not
- HashMap is faster
Interviewer: How does HashMap work internally?
👉 Answer:
- Uses hashing
- Stores data in buckets
- Uses equals() and hashCode()
- Handles collisions using linked list / tree (Java 8+)
Interviewer: What is the difference between String, StringBuilder, StringBuffer?
👉 Answer:
- String → immutable
- StringBuilder → mutable, not thread-safe
- StringBuffer → mutable, thread-safe
🧩 Round 3: OOPs Concepts
Interviewer: Explain polymorphism.
👉 Answer:
Polymorphism means “many forms”. It allows method overloading (compile-time) and overriding (runtime).
Interviewer: Why Java does not support multiple inheritance?
👉 Answer:
To avoid ambiguity and complexity caused by diamond problem.
⚡ Round 4: Multithreading
Interviewer: What is synchronization?
👉 Answer:
It ensures that only one thread can access a resource at a time to avoid data inconsistency.
Interviewer: What is deadlock?
👉 Answer:
A situation where two or more threads are waiting for each other to release resources, causing infinite blocking.
🗄️ Round 5: Spring Boot
Interviewer: What is dependency injection?
👉 Answer:
It is a design pattern where objects are provided their dependencies by Spring container instead of creating them manually.
Interviewer: What is REST API?
👉 Answer:
REST API is a web service that uses HTTP methods (GET, POST, PUT, DELETE) for communication.
Interviewer: Difference between @Component, @Service, @Repository?
👉 Answer:
- @Component → generic bean
- @Service → business logic layer
- @Repository → database layer
💻 Round 6: Coding Round
Q1: Reverse a String
👉 Input: “Java” → Output: “avaJ”
public class Main {
public static void main(String[] args) {
String s = "Java";
String rev = ""; for(int i = s.length()-1; i >= 0; i--) {
rev += s.charAt(i);
} System.out.println(rev);
}
}
Q2: Find Second Largest Element
👉 Logic:
- Track largest and second largest
🧠 Round 7: Scenario-Based
Interviewer: What will you do if production issue occurs?
👉 Answer:
- Check logs
- Identify root cause
- Fix issue quickly (hotfix if needed)
- Deploy patch
- Write RCA (Root Cause Analysis)
Interviewer: How do you optimize performance?
👉 Answer:
- Proper indexing in DB
- Use caching
- Optimize queries
- Avoid unnecessary object creation
🎯 Final HR Question
Interviewer: Do you have any questions for us?
👉 Good questions:
- What is the project architecture?
- What technologies will I work on?
- Is there any training for new tools?
⚡ Interview Tips (Important)
- Speak confidently, even if unsure
- Always connect answers to your project
- Don’t memorize—understand logic
- Keep answers short and structured
- Coding = logic first, syntax second
op 50 Java Coding Questions with Solutions
🧠 1–10: Basic Logic
1. Reverse a String
String rev = new StringBuilder(s).reverse().toString();
2. Palindrome String
return s.equals(new StringBuilder(s).reverse().toString());
3. Factorial
int fact = 1;
for(int i=1;i<=n;i++) fact*=i;
4. Fibonacci Series
int a=0,b=1;
for(int i=0;i<n;i++){
System.out.print(a+" ");
int c=a+b;
a=b;b=c;
}
5. Sum of digits
while(n>0){ sum+=n%10; n/=10; }
6. Count digits
while(n>0){ count++; n/=10; }
7. Swap two numbers
a=a+b; b=a-b; a=a-b;
8. Prime number check
boolean isPrime=true;
for(int i=2;i<=Math.sqrt(n);i++)
if(n%i==0) isPrime=false;
9. Largest in array
int max=arr[0];
for(int i:arr) if(i>max) max=i;
10. Smallest in array
int min=arr[0];
for(int i:arr) if(i<min) min=i;
🔄 11–20: Arrays
11. Second largest
int max=Integer.MIN_VALUE, second=max;
12. Remove duplicates (array)
Set<Integer> set=new HashSet<>();
13. Sort array
Arrays.sort(arr);
14. Reverse array
int i=0,j=n-1;
while(i<j){ swap; }
15. Frequency of elements
Map<Integer,Integer> map=new HashMap<>();
16. Missing number in array
sumExpected - sumActual
17. Move zeros to end
Use two pointers
18. Find duplicate elements
Use HashSet
19. Union of arrays
Set.addAll()
20. Intersection of arrays
retainAll()
🧩 21–30: Strings Advanced
21. Count vowels
if("aeiou".contains(c)) count++;
22. Remove spaces
s.replace(" ","");
23. Character frequency
HashMap<Character,Integer>
24. Anagram check
sort both strings and compare
25. First non-repeating char
use LinkedHashMap
26. Reverse words in sentence
split + reverse
27. Uppercase to lowercase
s.toLowerCase();
28. Remove duplicates in string
LinkedHashSet
29. Longest word
split and compare length
30. Palindrome sentence
remove spaces + check reverse
⚡ 31–40: Collections
31. ArrayList example
List<Integer> list=new ArrayList<>();
32. HashMap iteration
for(Map.Entry e:map.entrySet())
33. LinkedList usage
addFirst(), addLast()
34. Sort list
Collections.sort(list);
35. Reverse list
Collections.reverse(list);
36. PriorityQueue
Queue<Integer> pq=new PriorityQueue<>();
37. Stack operations
push(), pop()
38. HashSet usage
Set<Integer> set=new HashSet<>();
39. Remove duplicates (list)
new HashSet<>(list)
40. Frequency count map
map.put(key, map.getOrDefault(key,0)+1);
🔥 41–50: Advanced Logic
41. Find missing number (1 to N)
n*(n+1)/2 - sum
42. Check Armstrong number
sum of digits^power
43. Binary search
while(low<=high)
44. Linear search
simple loop
45. Merge two arrays
System.arraycopy()
46. Matrix addition
nested loops
47. Transpose matrix
swap rows and columns
48. Count even/odd
if(n%2==0)
49. GCD of two numbers
Euclid algorithm
50. LCM of two numbers
(a*b)/gcd
⚡ Interview Tip
For 3 years experience, interviewers focus on:
- Arrays + Strings (VERY IMPORTANT)
- HashMap + Collections
- Basic DSA logic
- Real project coding problems
- Clean, optimized code (not just working code)