Java coding interview questions for experienced

For experienced Java developers (8–12+ years), interviewers usually focus on advanced Java concepts, system design, performance, concurrency, and real-world problem solving rather than basic syntax.

Below is a structured list of common Java coding interview questions frequently asked in senior-level interviews.


1. String Coding Questions (Very Common)

Reverse a String without using built-in methods

public static String reverse(String str){
    char[] arr = str.toCharArray();
    int left = 0;
    int right = arr.length - 1;

    while(left < right){
        char temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        left++;
        right--;
    }
    return new String(arr);
}

Check if a String is Palindrome

public static boolean isPalindrome(String str){
    int left = 0;
    int right = str.length() - 1;

    while(left < right){
        if(str.charAt(left) != str.charAt(right)){
            return false;
        }
        left++;
        right--;
    }
    return true;
}

Find First Non-Repeated Character

public static Character firstNonRepeated(String str){
    Map<Character,Integer> map = new LinkedHashMap<>();

    for(char c : str.toCharArray()){
        map.put(c,map.getOrDefault(c,0)+1);
    }

    for(Map.Entry<Character,Integer> entry : map.entrySet()){
        if(entry.getValue() == 1)
            return entry.getKey();
    }
    return null;
}

2. Collection Coding Questions

Remove duplicates from List

List<Integer> list = Arrays.asList(1,2,2,3,4,4,5);

List<Integer> unique = list.stream()
        .distinct()
        .collect(Collectors.toList());

Sort Map by Value

Map<String,Integer> map = new HashMap<>();

map.entrySet()
   .stream()
   .sorted(Map.Entry.comparingByValue())
   .forEach(System.out::println);

Find Duplicate Elements in Array

public static void findDuplicates(int[] arr){
    Set<Integer> set = new HashSet<>();

    for(int num : arr){
        if(!set.add(num)){
            System.out.println("Duplicate: "+num);
        }
    }
}

3. Java 8 Coding Questions

Find Maximum Number from List

List<Integer> list = Arrays.asList(10,20,5,30);

int max = list.stream()
              .max(Integer::compare)
              .get();

Count Occurrence of Each Character

String str = "java";

Map<Character,Long> map =
str.chars()
   .mapToObj(c -> (char)c)
   .collect(Collectors.groupingBy(c -> c, Collectors.counting()));

System.out.println(map);

Sort Employees by Salary

employees.stream()
         .sorted(Comparator.comparing(Employee::getSalary))
         .forEach(System.out::println);

4. Multithreading Coding Questions

Print Odd and Even Numbers using Two Threads

class NumberPrinter{
    int number = 1;

    synchronized void printOdd() throws InterruptedException{
        while(number <= 10){
            if(number % 2 == 0){
                wait();
            }else{
                System.out.println(number++);
                notify();
            }
        }
    }

    synchronized void printEven() throws InterruptedException{
        while(number <= 10){
            if(number % 2 == 1){
                wait();
            }else{
                System.out.println(number++);
                notify();
            }
        }
    }
}

5. Data Structure Coding Questions

Find Second Largest Element

public static int secondLargest(int[] arr){
    int first = Integer.MIN_VALUE;
    int second = Integer.MIN_VALUE;

    for(int num : arr){
        if(num > first){
            second = first;
            first = num;
        }
        else if(num > second && num != first){
            second = num;
        }
    }
    return second;
}

Fibonacci Series

public static void fibonacci(int n){
    int a = 0, b = 1;

    for(int i=0;i<n;i++){
        System.out.print(a+" ");
        int temp = a + b;
        a = b;
        b = temp;
    }
}

6. Real Interview Coding Questions (Senior Level)

Implement Custom LRU Cache

Key concept:

  • HashMap + Doubly Linked List

Interviewers ask this frequently in product companies.


Implement Producer Consumer Problem

Concepts tested:

  • wait()
  • notify()
  • BlockingQueue

Implement Singleton (Thread Safe)

public class Singleton {

    private static volatile Singleton instance;

    private Singleton(){}

    public static Singleton getInstance(){
        if(instance == null){
            synchronized (Singleton.class){
                if(instance == null){
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}

7. Frequently Asked Algorithm Questions

Experienced developers are often asked these:

  1. Two Sum problem
  2. Longest substring without repeating characters
  3. Merge two sorted arrays
  4. Rotate array
  5. Detect cycle in linked list
  6. Reverse linked list
  7. Binary search implementation
  8. Top K frequent elements
  9. Implement Stack using Queue
  10. Implement Queue using Stack

8. Real-World Coding Problems (Very Common for 10+ Years)

These test problem solving + architecture thinking.

Examples:

• Design a Rate Limiter
• Implement API Retry Mechanism
• Implement Circuit Breaker pattern
• Design URL Shortener (like TinyURL)
• Implement Cache with Expiry


9. Advanced Java Coding Questions

Senior interviews may also include:

  • Custom Thread Pool implementation
  • Implement CompletableFuture pipeline
  • Implement Immutable class
  • Implement Custom Comparator
  • Write Deadlock example

Other Quetions

1️⃣ Top 50 Java coding questions for 10+ years experience
2️⃣ Java + Spring Boot coding interview questions
3️⃣ Real coding questions asked in product companies (Amazon, Walmart, Adobe)
4️⃣ Java 8 Stream coding questions (most asked)
5️⃣ Microservices coding interview questions

Share with