Skip to main content

Command Palette

Search for a command to run...

Most Asked Java Coding Interview Questions

In this article i have added most common coding interview questions. If some one practice these he will do better in coding round In Shaa Allah

Updated
3 min read
Most Asked Java Coding Interview Questions
S

👋 Hey there! I’m Shohanur Rahman!

I’m a backend developer with over 5.5 years of experience in building scalable and efficient web applications. My work focuses on Java, Spring Boot, and microservices architecture, where I love designing robust API solutions and creating secure middleware for complex integrations.

💼 What I Do Backend Development: Expert in Spring Boot, Spring Cloud, and Spring WebFlux, I create high-performance microservices that drive seamless user experiences. Cloud & DevOps: AWS enthusiast, skilled in using EC2, S3, RDS, and Docker to design scalable and reliable cloud infrastructures. Digital Security: Passionate about securing applications with OAuth2, Keycloak, and digital signatures for data integrity and privacy. 🚀 Current Projects I’m currently working on API integrations with Spring Cloud Gateway and designing an e-invoicing middleware. My projects often involve asynchronous processing, digital signature implementations, and ensuring high standards of security.

📝 Why I Write I enjoy sharing what I’ve learned through blog posts, covering everything from backend design to API security and cloud best practices. Check out my posts if you’re into backend dev, cloud tech, or digital security!

String

  1. How to reverse a String in java? Can you write a program without using any java inbuilt methods?

    Input: String str = "abc"

    Output: "cba"

  2. Write a java program to check if two Strings are anagrams in java.

    Input: String str1 = "RACE", str2 = "CARE"

    Output: "true"

  3. Write a program to check if String has all unique characters in java.

  4. How to check if one String is the rotation of another String in java?

  5. How to find duplicate characters in String in java?

  6. Find the first non-repeated character in String in java.

  7. Find all substrings of String in java.

  8. Find the length of a String without using any inbuilt method in java.

  9. Write a program to print all permutations of String in java.

Array

  1. Write a java Program to Find the Smallest and Largest Element in an Array.

  2. Find the missing number in the array.

  3. Search an element in a rotated and sorted array.

  4. Find the minimum element in a sorted and rotated array.

  5. Find the second largest number in an array

  6. Find the number occurring an odd number of times in an array

  7. Find the minimum number of platforms required for the railway station

  8. Find a Pair Whose Sum is Closest to zero in the Array

  9. Given a sorted array and a number x, find the pair in an array whose sum is closest to x

  10. Find all pairs of elements from an array whose sum is equal to a given number

  11. Given an array of 0’s and 1’s in random order, you need to separate 0’s and 1’s in an array.

  12. Separate odd and even numbers in an array

  13. Given an array containing zeroes, ones and twos only. Write a function to sort the given array in O(n) time complexity.

  14. Find local minima in the array

  15. Sliding window maximum in java

  16. Count the number of occurrences (or frequency) of each element in a sorted array

  17. Find subarrays with a given sum in an array.

  18. Find the peak element in the array.

  19. Find leaders in an array.

  20. Count 1’s in sorted Binary Array.

  21. Find the first repeating element in an array of integers.

  22. Check if Array Elements are Consecutive.

  23. Permutations of the array in java.

  24. Rotate an array by K positions.

  25. Stock Buy Sell to Maximize Profit.

  26. Find the maximum difference between two elements such that larger element appears after the smaller number.

    int arr[] = {14, 12, 70, 15, 95, 65, 22, 30};

    Max Difference = 95-12 = 83

  27. Search in a row-wise and column-wise sorted matrix.

    Input: mat[4][4] = {

    {10, 20, 30, 40},

    {15, 25, 35, 45},

    {27, 29, 37, 48},

    {32, 33, 39, 50}

    } x = 29 Output: Found at (2, 1)

  28. Largest sum contiguous subarray.

    Input: [-3, -4, 5, -1, 2, -4, 6, -1] Output: 8 Explanation: Subarray [5, -1, 2, -4, 6] is the max sum contiguous subarray with sum 8.

  29. Find the Contiguous Subarray with Sum to a Given Value in an array.

    Input: arr[]={14, 12, 70, 15, 99, 65, 21, 90}; X =97.

    Sum found between index 1 to 3, Elements are 12, 17 and 15

  30. Min sum in contiguous subarray

    Input: arr[] = {3, -4, 2, -3, -1, 7, -5}

    Output: -6

  31. Max product subarray

    Input: arr[] = {6, -3, -10, 0, 2}

    Output: 180 // The subarray is {6, -3, -10}

  32. Longest Common Prefix in an array of Strings in java.

    Input: arr[] = {"javaworld","javabean","javatemp"};

    Output: "java"

  33. Find all subsets of a set (power set) in java.

    Input: nums = [1,2,3]

    Output: [[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]

More from this blog

Shohanur Rahman's blog

69 posts