50 Java Coding Interview Questions
A. Core Basics & Logic (Simple Programs)
1 Print Fibonacci series up to n terms.
2 Check if a number is prime.
3 Find factorial of a number (iterative & recursive).
4 Reverse a number without using built-in functions.
5 Check if a string is a palindrome.
6 Count vowels and consonants in a string.
7 Find the largest of three numbers.
8 Swap two numbers without a third variable.
9 Check even or odd without using % operator.
10 Sum of digits of a number.
B. Arrays & Strings
1 Find the second largest element in an array.
2 Remove duplicates from an array.
3 Find the missing number in a sequence (1–n).
4 Sort an array without using built-in sort.
5 Merge two sorted arrays.
6 Rotate an array k times.
7 Check if two strings are anagrams.
8 Count frequency of each character in a string.
9 Reverse each word in a sentence.
10 Find the first non-repeating character in a string.
C. Collections & Data Structures
1 Implement a stack using arrays.
2 Implement a queue using linked list.
3 Find intersection of two lists.
4 Remove duplicates from an ArrayList.
5 Sort a HashMap by values.
6 Use HashSet to find unique elements in a list.
7 Count word frequency in a sentence using Map.
8 Implement a simple LRU cache using LinkedHashMap.
9 Implement a priority queue (min-heap) without library.
10 Detect a cycle in a linked list.
D. OOP Pillars
1 Encapsulation: Create a BankAccount class with private fields and public getters/setters.
2 Inheritance: Build a Shape superclass and subclasses Circle, Rectangle to calculate area.
3 Polymorphism (Compile-time): Method overloading example with Calculator class.
4 Polymorphism (Runtime): Method overriding with Animal → Dog, Cat.
5 Abstraction: Abstract class Vehicle with abstract method move().
6 Interface Payment with multiple implementations like CreditCardPayment, UPIPayment.
7 Multiple inheritance using interfaces (e.g., Printable, Scannable).
8 Use super keyword to access parent class constructor and methods.
9 Demonstrate this keyword in constructors and methods.
10 Create a custom exception class and use throw/throws.
E. File & Streams
1 Read a text file and count number of words.
2 Copy contents of one file to another.
3 Serialize and deserialize a Java object.
4 Read a CSV file and display as formatted output.
5 Write a program to list all files in a directory.
F. Advanced / Miscellaneous
1 Implement singleton design pattern (lazy & eager).
2 Producer–consumer problem using threads.
3 Implement a simple multithreading example (extend Thread vs implement Runnable).
4 Use synchronized block to avoid race conditions.
5 Build a small menu-driven library management system using OOP concepts.