Friday, October 17, 2025

Nitheen Kumar

Frequently asking interview program in Java

 

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

  1. Palindrome Check

    • Check if a string or number is palindrome (same forwards and backwards).
      Example: “madam” → palindrome.

  2. Factorial of a Number

    • Using loops and recursion.

  3. Fibonacci Series

    • Print first N Fibonacci numbers using loop or recursion.

  4. Prime Number Check

    • Determine whether a number is prime.

  5. Reverse a Number or String

    Frequently asking interview program in Java

    • Example: 12345 → 54321.

  6. Armstrong Number

    • Example: 153 = 1³ + 5³ + 3³ → Armstrong.

  7. Swap Two Numbers

    • With and without using a temporary variable.

  8. Find Largest and Smallest Numbers

    • In an array.

  9. Sum of Digits

    • Input: 1234 → Output: 10.

  10. Count Vowels and Consonants

    • In a given string.


🔹 Intermediate Java Programs

  1. Check for Anagrams

    • “Listen” and “Silent” → Anagrams.

  2. Sort Elements

    • Without using built-in functions (Bubble sort, Selection sort, etc.).

  3. Find Duplicate Elements in Array

    • Using HashSet or nested loops.

  4. Remove Duplicates from Array or String

    • Example: “programming” → “progamin”.

  5. Find Second Largest Number

    • In an array.

  6. String Reversal Using Recursion

    • Without using StringBuilder reverse().

  7. Count Occurrence of Each Character

    • Using HashMap.

  8. Check if String Contains Only Digits

    • Without using regex.

  9. Check for Prime Numbers in a Range

    • Example: 1–100.

  10. Sum of Elements in Array

    • Using loops or streams.


🔹 Advanced / Common Logic Programs

  1. Find Missing Number in Array

    • Example: {1,2,3,5} → Missing 4.

  2. Find Pair of Numbers with Given Sum

    • Example: sum = 9 → (2,7), (4,5).

  3. Check Balanced Parentheses

    • Example: “(a+b)*(c-d)” → Balanced.

  4. Check if a String is Rotation of Another

    • Example: “ABCD” and “CDAB”.

  5. Count Words in a String

    • Example: “Java is fun” → 3 words.

  6. Find Frequency of Each Word

    • Using HashMap.

  7. Reverse Words in a Sentence

    • Example: “Java is fun” → “fun is Java”.

  8. Find Longest and Shortest Word in a Sentence

    • Example: “Coding is beautiful” → Longest: “beautiful”.

  9. Check Leap Year

    • Example: 2024 → Leap year.

  10. Find Intersection of Two Arrays

    • Using HashSet.


🔹 OOPs & Collections Based

  1. Implement Singleton Class

  2. Demonstrate Method Overloading and Overriding

  3. Implement Comparable and Comparator

  4. Use of HashMap, TreeMap, LinkedHashMap

  5. Reverse a LinkedList

  6. Find Middle Element of LinkedList

  7. Detect Loop in LinkedList

  8. Use Streams API to Filter and Sort

  9. Count Elements Using Stream GroupingBy

  10. Convert ArrayList to Array and vice versa


Subscribe to get more Posts :