Java Coding Interview Questions

     Are you looking for the most frequently asked Java coding interview questions for your preparation? If yes, you are at the right place! This website (blog post site) javaicebreakers.com, provides most of the top Java coding interview questions along with more than two solutions for each coding question. You see a table below for each question with headers ‘Using Java Features’ , ‘Happy path Solution’ and ‘Combo Happy path Solutions‘; each row contains a link to the Happy path solution using that respective Java version features. This Happy path solution is easily understood by novice or intermediate programmers. The idea is to ensure that you can revise most of the Java language features for each Java coding question. The existing code solutions provided under the header ‘Happy path Solution’ covers Java features till ‘Java 7’. The code solutions provided under the header ‘Combo Happy path Solutions‘ covers maximum features of ‘Java 8’ along with Unit test scripts for the same ‘Java 8’ solution written in ‘JUnit5‘. The code solutions for ‘Java8 :: JUnit5’ are in still in progress. I wish you all the best and Good luck.        

  • How to check whether the given strings or sentences are Anagram or not?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using String’s ClassSolution Code :: Junit5 Code
StringBuilder’s ClassSolution
HashMapSolution
Lambda expressionSolution
All SolutionsAll
  • How to find 1st & the 2nd biggest numbers in an Array or an ArrayList of Integers?
Using Java Features Happy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Arrays core logicSolution Code :: Junit5 Code
SortSolution
streamSolution
ArrayListSolution
All SolutionsAll
  • How to find duplicate words in a given sentence?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using String’s ClassSolution Code :: Junit5 Code
HashMapSolution
CollectionsSolution
All SolutionsAll
  • How to remove duplicate numbers from an array of integers?
Using Java FeaturesHappy path Solution
Using ArraysSolution
HashSetSolution
StreamSolution
All SolutionsAll
  • How to reverse each word in a given sentence?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using StringBufferSolution Code :: Junit5 Code
StringsSolution
Lambda expressionSolution
streamSolution
  • How to reverse an Integer value?
Using Java FeaturesHappy path Solution
Using CorelogicSolution
Using StringBufferSolution
StringsSolution
GenericsSolution
  • How to find the sum of integers in an Array or Array List?
Using Java FeaturesHappy path Solution
Using simple ArraySolution
ArrayList (Iterator & listIterator)Solution
streamSolution
  • How to find the sum of digits in an alphanumeric value ?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using String’s classSolution Code :: Junit5 Code
Lambda expressionSolution
streamSolution
  • How to find the sum of digits in an Integer?
Using Java FeaturesHappy path SolutionCombo Happy path Solutions
( Java 8 ) :: JUnit
Using Core logicSolutionCode :: Junit5 Code
Lambda expressionSolution
streamSolution
  • How to move all Zeros to the end of an array?
Using Java FeaturesHappy path Solution
Using Arrays (Original)Solution
Additional temp ArraySolution
streamSolution
  • How to find min & max length strings in a given sentence of strings?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Core logicSolution Code :: Junit5 Code
HashmapsSolution
streamSolution
  • How to find pairs of numbers whose sum is divisible by 9 in an array?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Arrays, ListsSolution Code :: Junit5 Code
Arrays, PredicateSolution
StreamSolution
  • How to find triplets of numbers whose sum is divisible by 9 in an array?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Arrays, ListsSolution Code :: Junit5 Code
Arrays, PredicateSolution
StreamSolution
  • How to find the factorial of a number?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Core logicSolution Code :: Junit5 Code
Big IntegerSolution
RecursionSolution
StreamSolution
MultithreadsSolution
All SolutionsAll
  • How to check whether a given integer is a Prime number or not?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using CorelogicSolution Code :: Junit5 Code
Core logic, PredicateSolution
Lambda expressionSolution
All SolutionsSolution
  • How to reverse the numbers at even positions in an array of integers?
Using Java FeaturesHappy path Solution
Using Same ArraySolution
  • How to check whether a given number is Disarium or not?
Using Java FeaturesHappy path Solution
Using Core logicSolution
Using streamSolution
  • How to find subsets or substrings of a given String?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using StringsSolution Code :: Junit5 Code
String BuilderSolution
Lambda expressionSolution
MultithreadsSolution
All SolutionsAll
  • How to find the Nth largest number from an array of integers?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Arrays SortSolution Code :: Junit5 Code
Lambda expression, Arrays SortSolution
Generic functional interface, Lambda expressions, Arrays SortSolution
StreamSolution
  • How to extract characters and numbers from an Alphanumeric value?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Character ClassSolution Code :: JUnit5 Code
ASCII range checkSolution
predicates & chain of predicatesSolution
All SolutionsAll
  • How to find array triplets where the sum of two numbers equals the other number of an array?
Using Java FeaturesHappy path Solution
Using ArraysSolution
Lambda expression, ArraysSolution
streamSolution
All SolutionsSolution
  • How to check whether a given number is Armstrong or not?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using String, and Character classSolution Code :: JUnit5 Code
Core logicSolution
StreamsSolution
  • How to print Floyd’s Triangle?
Using Java FeaturesHappy path Solution
Using Core logicSolution
  • How to find the nTh value in the Fibonacci series?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Core logicSolution Code :: JUnit5 Code
RecursionSolution
MultithreadsSolution
StreamSolution
All SolutionsSolution
  • How to check whether a string can be eligible to form a palindrome?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using Core logicSolution Code :: JUnit5 Code
HashmapSolution
StringBufferSolution
All SolutionsAll
  • How to count the number of occurrences of a given word in a file?
Using Java FeaturesHappy path Solution
Using FileReader, and StringBuffer classSolution
FileReader, and String classSolution
  • How to reverse all the numbers in an array of integers?
Using Java FeaturesHappy path Solution
Using Arrays, Core logicSolution
GenericsSolution
StreamSolution
  • How do you find and replace the given string with a new one in a given file?
Using Java FeaturesHappy path Solution
Using Files, and StringBuffer classSolution
Files, and String classSolution
  • How to find strings with no Vowels in a file?
Using Java FeaturesHappy path Solution
Using Files, StringTokenizer and StringBuffer classSolution
Files, and Regex classSolution
  • How to count lines, words, and characters in a file?
Using Java FeaturesHappy path Solution
Using Files, String Tokenizer, and StringSolution
  • How to check whether a String is a Palindrome or not?
Using Java FeaturesHappy path SolutionCombo Happy path Solutions
( Java 8 ) :: JUnit
Using Lambda expression, and StringBufferSolutionCode :: Junit5 Code
Lambda expression, and StringSolution
All SolutionsSolution
  • How to check whether any number in an array is repeated twice or thrice?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using HashMapSolutionCode :: Junit5 Code
CollectionsSolution
Lambda expressionSolution
All SolutionsAll
  • How to find the intersection values of two Arrays?
Using Java FeaturesHappy path Solution
Using Arrays, StringBuilderSolution
Generics, Arrays, StringBuilderSolution
Lambda expression, Arrays, StringBuilderSolution
  • How to find Missing prime numbers from any given sequence of integers?
Using Java FeaturesHappy path Solution
Using Array Lists, Lambda expressionSolution
StreamSolution
  • How to find leader numbers from any given array of integers?
Using Java FeaturesHappy path Solution
(Till Java 7)
Combo Happy path Solutions
( Java 8 ) :: JUnit
Using ArraysSolution Code :: Junit5 Code
Using ArraysSolution
streamSolution

Having more questions for which you need solutions? Please let us know using the form below.

Go back

Your message has been sent

Warning
Warning
Warning
Warning.