Top 17 Java coding interview questions for SDET

Hi all, I’m working as an instructor at Tech Lead Academy. We teach programming for Software Development Engineer in Test(SDET) position. I have gathered the most asked interview coding questions from my own interview experience and from our student's interviews. I’m sure if you work through these coding questions, you can nail most of the coding interview questions for SDET. For Big O notation time complexity, please read this article.

1. String reverse. Write a method that will take one string as an argument and will return the reverse version of this string.

2. Array reverse. Write a method that will take an array as an argument and reverse it.

3. Reverse words. Write a method that will take a string as an argument. The method will reverse the position of words and return it.

4. String palindrome. A palindrome is a word, phrase, number, or sequence of words that reads the same backward as forward.

5. Number palindrome. A palindrome is a word, phrase, number, or sequence of words that reads the same backward as forward. The straight forward solution would be to convert number to string and use the above approach. Some interviewers will not allow to do it. So let’s take a look at what we can do here.

6. Max/min number from an array. Write a method that will accept an array of int as an argument and it will return the max/min number from a given array.

7. Find the second min/max number from an array. Write a method that will accept int array as an argument and return second or n min/max number from the given array. I will go with the sorting algorithm. Arrays.sort() is using mergesort and it’s the time complexity is logarithmic (n log n). Some interviewers don’t like it when sorting is used. It’s possible to do without sorting, using nested loops and we will end up having O(n²).

8. Static keyword in Java. The static keyword is a very popular question in the interviews.

What’s a static keyword in Java?
- Static variables and methods belong to the class, not to a specific object. We need to use static members by class name.

Let’s see an example, what’s output from the below program? Why this output?

9. String Pool and == operator to compare references in Java. Let’s see an example, what’s output from the below program? Why this output?

10. Swap values of two variables without direct reassignment and without creating any extra variables.

11. Two string anagram. An anagram is when all the letters in one string exist in another but the order of letters does not matter. Write a method that will accept two string arguments and will return true if they are anagram and false if they are not.

12. Remove duplicates from a string. Write a method that will accept one string argument and return it without duplicates. We will see two versions of this method.

13. Count letters(Map). Write a method that will accept a string as an argument. The method will count the number of appearances of each char and return map. The key will be a letter and the value will be a number of appearances in the string. See input and output in the example.

14. FizzBuzz. Print numbers from 1 to 100
- if a number is divisible by 3 print Fizz
-
if a number is divisible by 5 print Buzz
- if a number is divisible by both 3 and 5 print FizzBuzz

15. Even or Odd. Write a method that will accept one int as an argument. The method will print Even if the number is even and Odd if the number is odd.

16. Sum. Write a method that accepts int[] array and an int number, find 2 elements in the array that sum is equal to the given int. Assume that an input array will have only one pair of numbers that sum equal to our given number. It will always have this pair. See input and output examples. I will use the Brute Force algorithm. If you have a better algorithm, please put it in the comments. I will be happy to see it.

17. The Fibonacci. It is a series of numbers where the next number is the sum of the previous two numbers. The first two numbers of the Fibonacci is 0 followed by 1. Write a method that will accept one int number n. The method will print n number of Fibonacci numbers.

17.1 Balanced String. This question became very popular lately. The program should find out if an input string is balanced or not.

Congrats! You made it. It was a long list. Thank you!

Software Developer, Java Instructor https://www.techleadacademy.io/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store