Top 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 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 returns the max/min number from a given array.
7. Find the second min/max number from an array. Write a method that accepts int array as an argument and returns second or n min/max number from the given array.
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 this program? Why this output?
9. String Pool and == operator to compare references in Java. Let’s see an example, what’s output from this 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 accepts two string arguments and returns true if they are anagram and false if they are not.
12. Remove duplicates from a string. Write a method that accepts one string argument and returns it without duplicates. We will see two versions of this method.
13. Count letters(Map). Write a method that accepts a string as an argument. The method counts 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 prints Even if the number is even and Odd if the number is odd.
16. Sum of two. 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 use the Brute Force algorithm.
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.
18. Balanced String. This question became very popular lately. The program should find out if an input string is balanced or not.
19. Sort array without built in sort methods. In this example, we will use selection sort and bubble sort algorithms to sort our array.
In selection sort, we select smallest and swapped with current array and we will keep doing it for each element. Please watch this video for visual explanation.
In bubble sort, we bubble out the biggest values to the right side by looping over our array and switching two pairs of elements if they are not in correct order. Please watch this video for visual explanation.
Congrats! You made it. It was a long list. Thank you!
Please take my Java Course for video lectures.This article is part of the series of articles to learn Java programming language from Tech Lead Academy:Introduction to programming
OS, File, and File System
Working with terminal
Welcome to Java Programming Language
Variables and Primitives in Java
Convert String to numeric data type
Input from the terminal in Java
Methods with Java
Java Math Operators and special operators
Conditional branching in Java
Switch statement in Java
Ternary operator in Java
Enum in Java
String class and its methods in Java
Loops in Java
Access modifiers in Java
Static keyword in Java
The final keyword in Java
Class and Object in Java
Object-Oriented Programming in Java
OOP: Encapsulation in Java
OOP: Inheritance in Java
OOP: Abstraction in Java
OOP: Polymorphism in Java
The method Overriding vs Overloading in Java
Array in Java
Data Structures with Java
Collection framework in Java
ArrayList in Java
Set in Java
Map in Java
Date and Time in Java
Exception in Java
How to work with files in Java
Design Patterns
Generics in Java
Multithreading in java
Annotations in Java
Reflection in Java
Reflection & Annotations - The Powerful Combination
Run terminal commands from Java
Lambda in Java
Unit Testing in Java
Big O Notation for coding interviews
Top Java coding interview questions for SDET