Here’s a list of frequently asked Java programs in interviews, covering basic to advanced concepts.
These are commonly used to test logical thinking, coding style, and understanding of Java fundamentals.
🔹 Basic Java Programs
-
Palindrome Check
-
Check if a string or number is palindrome (same forwards and backwards).
Example: “madam” → palindrome.
-
-
Factorial of a Number
-
Using loops and recursion.
-
-
Fibonacci Series
-
Print first N Fibonacci numbers using loop or recursion.
-
-
Prime Number Check
-
Determine whether a number is prime.
-
-
Reverse a Number or String
-
Example: 12345 → 54321.
-
-
Armstrong Number
-
Example: 153 = 1³ + 5³ + 3³ → Armstrong.
-
-
Swap Two Numbers
-
With and without using a temporary variable.
-
-
Find Largest and Smallest Numbers
-
In an array.
-
-
Sum of Digits
-
Input: 1234 → Output: 10.
-
-
Count Vowels and Consonants
-
In a given string.
-
🔹 Intermediate Java Programs
-
Check for Anagrams
-
“Listen” and “Silent” → Anagrams.
-
-
Sort Elements
-
Without using built-in functions (Bubble sort, Selection sort, etc.).
-
-
Find Duplicate Elements in Array
-
Using HashSet or nested loops.
-
-
Remove Duplicates from Array or String
-
Example: “programming” → “progamin”.
-
-
Find Second Largest Number
-
In an array.
-
-
String Reversal Using Recursion
-
Without using StringBuilder reverse().
-
-
Count Occurrence of Each Character
-
Using HashMap.
-
-
Check if String Contains Only Digits
-
Without using regex.
-
-
Check for Prime Numbers in a Range
-
Example: 1–100.
-
-
Sum of Elements in Array
-
Using loops or streams.
-
🔹 Advanced / Common Logic Programs
-
Find Missing Number in Array
-
Example: {1,2,3,5} → Missing 4.
-
-
Find Pair of Numbers with Given Sum
-
Example: sum = 9 → (2,7), (4,5).
-
-
Check Balanced Parentheses
-
Example: “(a+b)*(c-d)” → Balanced.
-
-
Check if a String is Rotation of Another
-
Example: “ABCD” and “CDAB”.
-
-
Count Words in a String
-
Example: “Java is fun” → 3 words.
-
-
Find Frequency of Each Word
-
Using HashMap.
-
-
Reverse Words in a Sentence
-
Example: “Java is fun” → “fun is Java”.
-
-
Find Longest and Shortest Word in a Sentence
-
Example: “Coding is beautiful” → Longest: “beautiful”.
-
-
Check Leap Year
-
Example: 2024 → Leap year.
-
-
Find Intersection of Two Arrays
-
Using HashSet.
-
🔹 OOPs & Collections Based
-
Implement Singleton Class
-
Demonstrate Method Overloading and Overriding
-
Implement Comparable and Comparator
-
Use of HashMap, TreeMap, LinkedHashMap
-
Reverse a LinkedList
-
Find Middle Element of LinkedList
-
Detect Loop in LinkedList
-
Use Streams API to Filter and Sort
-
Count Elements Using Stream GroupingBy
-
Convert ArrayList to Array and vice versa

