If you’re trying to hire a top Java developer for your team, you need to assess several skills.
Your next new hire should have the right soft skills, technical skills, and values that align with your company culture.
Skills testing and interviewing candidates are two easy ways to evaluate your applicants’ skills. But what if you don’t have the right interview questions yet?
There’s no need to panic – below, you’ll find 100 common Java coding interview questions in this article to assess your applicants’ Java coding skills and knowledge.
Take a look at the list below to build a set of questions.
Determine whether applicants are the right fit for your open role by asking them these 15 common Java interview questions.
Which skills do developers need to code in Java?
Which soft skills do developers need to code in Java?
What are your strongest Java coding skills?
Which Java coding skills do you need to improve?
How do you keep up to date with best coding practices in Java?
Describe your experience with Scrum.
Describe your Java coding experience.
Describe your largest project that involved coding in Java.
What are your favorite Java features?
What are your least favorite Java features?
Explain some advantages of using Java for coding.
Explain what constructors are.
Explain what a class is in Java.
Explain what static loading is in Java.
Explain what dynamic loading is in Java.
Here are sample answers to five of the general Java interview questions to guide you when evaluating interviewees’ responses.
Applicants should know that three critical skills they need to code in Java include data-structure knowledge, algorithms-in-Java knowledge, and knowledge of APIs and libraries.
Do your applicants know that communication, critical thinking, and problem-solving skills are vital soft skills for developers? Can they provide examples of why these soft skills are important?
Some of the Java features that applicants may mention when responding to this interview question include:
Java’s Secure feature to guarantee a virus-free system
The fact that Java is an object-oriented programming language
The fact that Java is an independent platform, and its virtual machine interprets its code
Your applicants should understand that static loading is an object-and-instance-creation process developers carry out using new keywords.
Your candidates should be able to explain that developers can complete dynamic class loading even when the class’ name is unknown at the time of compilation.
Test your interviewees’ string-related knowledge in Java with the interview questions in this section.
How would you reverse strings in Java?
Explain what an anagram string is.
How would you write a program to check whether two strings are anagrams?
How would you determine whether a string’s characters are all unique?
Which method would you use to learn if a string is a rotation of another string?
Explain how you would find a duplicate character in a string.
Explain how you would find a string’s first non-repeated character.
How would you find all of the substrings of a string?
How would you find out the length of a string in Java?
How would you print all string permutations in Java?
How would you find out if there is a vowel in a string?
How would you determine if a number is a prime number in a string?
Explain what trim() does.
Explain what strip() does.
Explain what whitespaces are in strings.
Here are the answers to five of the above questions about strings. Use them to evaluate your developers’ responses.
Although a reverse() utility method doesn’t exist in the string class, methods your candidates may mention when answering this interview question include:
Using a stringBuffer method
Using a recursion method
Using a for loop method
Two methods your applicants may outline when explaining how to determine if a string’s characters are all unique are:
Using an indexOf and lastIndexOf method
Using a HashSet method
Applicants should mention a few steps when responding to this interview question. They may first label the two strings involved in the process (i.e., str5 and str6) and then outline the following processes:
Make a new string: str7 = str5 + str5
Check whether str7 contains str6
If str7 does contain str6, str6 is a rotation of str5
If str 7 does not contain str 6, str6 is not a rotation of str5
Can your candidates explain that whitespaces are characters that represent spaces in strings? They may also explain that whitespace characters can impact a developer’s source-code size.
Interviewees may explain that developers can find a string’s first non-repeated character using two methods:
The linkedHashMap method
The indexOf and lastIndexOf method
Ask your interviewees some of these 15 Java interview questions about arrays to learn whether their skills align with the requirements of your open role.
Explain what an array is in Java.
How would you find the smallest element in an array?
How would you find the largest element in an array?
How would you find a missing number in an array?
How would you find the minimum element in sorted, rotated arrays?
How would you sort an array in Java?
How would you write a program to determine the sum of elements in integer arrays?
Which method would you use to shuffle arrays in Java?
Explain how arrays are different from ArrayList in Java.
How would you separate 0s and 1s in an array?
How would you separate even and odd numbers in an array?
Explain what a peak element is in an array.
Explain what a leader element is in an array.
Explain what a permutation is in an array.
Explain how you would find local minima in an array in Java.
Here’s a selection of five of the above Java coding interview questions about arrays, along with sample answers to gauge the depth of your applicants’ knowledge.
Can your applicants explain that arrays are container objects with a certain number of values of a specific type? Do they know that developers can determine the length of an array when they create one, because the length doesn’t change afterwards?
Applicants should know that if a developer wants to sort a primitive array, they can implement the arrays.sort() method:
int[] array = { 1, 2, 4, -1, -2, 4 };
Arrays.sort(array);
System.out.println(Arrays.toString(array));
They may explain that when sorting an array of objects, developers must implement a comparable interface.
Your candidates may provide the following example of a program to work out the sum of elements in integer arrays:
int[] array = { 9, 8, 7, 6, 5 };
int sum = 0;
for (int i : array)
sum += i;
System.out.println(sum);
Can your applicants explain that a permutation of an array is the rearrangement of sequence members to produce a new sequence? They may give an example to explain in more detail, by using an example similar to the one below:
The total number of new sequence permutations of [w, x, y, z] is 24, some of which are: [x, w, z, y], [z, w, x, y], and [w, z, x, y]
Applicants should know that an element is a leader if the elements on its right side are all lower than it, and in an array, the element on the far-right side is always a leader.
Determine whether your candidates’ knowledge of stacks in Java stacks up to your expectations by asking them some of these 10 interview questions.
How would you implement stacks with arrays?
How would you implement linked lists with stacks?
How would you implement stacks with two queues?
Explain what LIFO means in a stack.
Explain what a stack is in Java.
What are the advantages of stacks in Java?
How would you use stacks to determine if parentheses are balanced in Java?
How would you use recursion to sort a stack?
How would you locate an expression’s duplicate parentheses?
Stacks are referred to as recursive data structures. Explain why.
Here are the answers to five of the Java coding interview questions about stacks. Use them to assess your applicants’ knowledge.
Your applicants may explain that a stack always uses the LIFO principle, which means “Last In First Out,” when developers insert or remove the objects within the container.
Java developers should know that a stack is a data structure that contains objects that programmers insert and remove. They may explain that developers can either insert, delete, or display stack items (known as a push, pop, and peek, respectively).
Stacks in Java:
Are easy to learn and implement
Don’t come with high hardware demands
Enable developers to solve recursion problems easily
Help control the allocation and deallocation of memory
Enable developers to implement efficient data-management processes
Your applicants should know that developers can use two stacks to simulate linked lists. They may explain that the first stack is called the “list” and that developers use the second for temporary storage. Developers can either add, remove, or insert items from the stack after they have completed the following steps:
Include the header files that the program uses
Declare the user-defined functions
Define node structures
Define node pointer and set the pointer to NULL
Implement main methods by displaying the menu operations list
Your candidates may explain that stacks are recursive data structures because developers use them to implement recursion, and recursion utilizes stack space. They may also mention that recursion refers to a step in which a function fetches data from itself.
How well do your candidates understand linked lists in Java? Ask them some of these 15 common Java coding interview questions below to find out.
Explain what a linked list is in Java.
How would you reverse a linked list?
How would you find a linked list’s middle element?
How would you find a linked list’s nth element from its end?
How would you detect loops in linked lists?
How would you find out whether a linked list is a palindrome?
Explain what a loop is in a linked list.
Explain what a single-linked list is.
Explain what a doubly-linked list is.
How would you find a linked list’s start node?
How would you determine if a list of integers only has odd numbers?
What is the merge sort algorithm?
Which method would you use to merge two lists?
How would you implement a doubly-linked list?
How would you find two linked lists’ intersections?
Here are the answers to five of the questions about linked lists. Use them to assess your applicants’ responses and hire a skilled software developer.
A linked list is a set of data elements that are ordered and feature a link to successors and, on occasion, predecessors. Your applicants may explain that singly- and doubly-linked lists are two examples of linked lists in Java.
If a linked list doesn’t have an end, developers label this a loop. Your candidates may mention that developers can use hashing to remove loops from linked lists, which works through traversing linked lists and entering found nodes into a hash set. If developers find that the node is already in the hash set, this means that it has already been seen.
Expert developers should know that single-linked lists are unidirectional. They may explain that developers can traverse this list type only in one direction, from the head to the tail.
Candidates familiar with linked lists should know that developers can navigate doubly-linked lists in both directions, i.e. backward and forward.
Can your applicants explain that a programmer may write a recursive solution specifically for the purposes of linked list reversal? Applicants may mention that using decendingIterator() will return an iterator that developers can use to create a different linked list with reverse ordered elements.
Learn whether your applicants have comprehensive Java binary-tree knowledge by asking them some of the interview questions below.
What is a binary tree?
Explain what binary tree traversal means.
What is pre-order binary tree traversal?
What is in-order binary tree traversal?
What is post-order binary tree traversal?
What is binary tree spiral level order traversal?
How would you print a binary tree’s leaf nodes?
How would you count a binary tree’s leaf nodes?
How would you print every path from the root to the leaf in a binary tree?
How would you find a node’s level in a binary tree?
Which method would you use to find a binary tree’s maximum element?
Which method would you use to find a binary tree’s lowest common ancestor?
Explain what a lowest common ancestor is.
Which method would you use to do binary tree boundary traversal?
How would you print a binary tree’s vertical sum?
Below, you’ll find the answers to five of the common Java coding interview questions about binary trees to help you assess your interviewees’ responses.
Skilled developers should know that the traversal of binary trees involves visiting each tree node systematically and only once. They may explain that programmers traverse binary trees to display every element or perform an operation on every element.
Applicants should know that the root of two nodes on a binary tree is called the lowest common ancestor. They may also explain that there are paths between two nodes and the root node on a binary tree.
Can your applicants explain that developers process the nodes before the sub-trees in pre-order binary tree traversal? In other words, developers visit nodes before the nodes’ children during traversal.
Can your candidates explain that in in-order binary tree traversal, developers process nodes using the Left Root Right method? Do they know that developers first traverse the left subtree before focusing on the root node, and finally the right subtree in in-order tree traversal?
Applicants should know that in post-order binary tree traversal, developers process nodes by visiting the left subtree, the right subtree, and then the node.
Ask your interviewees some of these 15 interview questions about sorting in Java to assess their knowledge in depth.
How would you implement a bubble sort algorithm?
What does bubble sort mean in Java?
How would you implement an insertion sort algorithm?
What does insertion sort mean in Java?
How would you implement a selection sort algorithm?
What does selection sort mean in Java?
Which method would you use to implement heap sort in Java?
What does heap sort mean in Java?
Which method would you use to implement quick sort in Java?
What does quick sort mean?
Which method would you use to implement shell sort?
What does shell sort mean?
Which method would you use to implement counting sort?
What does counting sort mean?
Which method would you use to locate an element in a sorted array?
Here are five common Java coding interview questions and answers related to sorting in Java. Check out the answers to evaluate your applicants’ responses.
Can your applicants explain that a bubble sort is a type of algorithm used to compare an array’s adjacent elements? Do they know that a bubble sort will swap the elements when the right-hand side element is smaller than the one on the left-hand side?
Your interviewees should know that an insertion sort is an algorithm used to sort an array’s elements one at a time. They may explain that insertion sort works using an in-place sorting method, where developers modify the original array and do not require temporary structures.
Applicants should be able to explain that a selection sort involves sorting elements in an array by switching the smallest-sized element with the first element and then the second smallest element with the second element.
Interviewees should know that heap sorting is a sorting method that developers use. It involves finding the minimum element and placing it at the beginning. The process removes the elements at the list’s “heap” part and moves them to the list’s “sorted” part.
Applicants should know that a counting sort is a type of algorithm developers use to sort elements in an array. The algorithm works by counting the unique elements’ occurrences in the array.
Before proceeding to interviews where you can ask candidates some of the Java interview questions above, we advise you to assess their Java skills with the help of a skills assessment (a combination of skills tests).
A pre-employment skills assessment will help you assess applicants’ soft skills, technical skills, and values all at once.
Each skills test is graded automatically and at the end you get objective and reliable information on each of your candidates’ skills. You can then compare them easily and invite the most skilled developers to an interview to further assess their knowledge.
It’s important to use skills assessments early on in the hiring process, before you invite applicants to an interview, because this helps you make a selection and only interview your best applicants.
Recommended reading: 29 essential hard and soft skills for Java developers
There are many skills you need to evaluate to hire top talent for a Java developer role, but don’t panic.
All you need is a top skills assessment platform like TestGorilla to build your skills assessment and the Java coding interview questions in this article.
Hire exceptional talent using the right Java interview questions and go to TestGorilla’s test library to find the most reliable, expert-crafted skills tests. Hiring doesn’t have to be difficult!
Get started for free today and start making better hiring decisions, faster and bias-free.
Why not try TestGorilla for free, and see what happens when you put skills first.
Biweekly updates. No spam. Unsubscribe any time.
Our screening tests identify the best candidates and make your hiring decisions faster, easier, and bias-free.
A step-by-step blueprint that will help you maximize the benefits of skills-based hiring from faster time-to-hire to improved employee retention.
With our onboarding email templates, you'll reduce first-day jitters, boost confidence, and create a seamless experience for your new hires.
This handbook provides actionable insights, use cases, data, and tools to help you implement skills-based hiring for optimal success
A comprehensive guide packed with detailed strategies, timelines, and best practices — to help you build a seamless onboarding plan.
This in-depth guide includes tools, metrics, and a step-by-step plan for tracking and boosting your recruitment ROI.
Get all the essentials of HR in one place! This cheat sheet covers KPIs, roles, talent acquisition, compliance, performance management, and more to boost your HR expertise.
Onboarding employees can be a challenge. This checklist provides detailed best practices broken down by days, weeks, and months after joining.
Track all the critical calculations that contribute to your recruitment process and find out how to optimize them with this cheat sheet.