
Here is a big list of Java programs for Job Interviews. As I said, it includes questions from problem-solving, linked list, array, string, matrix, bitwise operators, and other miscellaneous parts of programming. Once you are gone through these questions, you can handle a good number of questions in real Job interviews.
20. Reverse a number
21. The first non-repeated character of String
22. Finding Middle element of linked list in one pass (
23. Pre-order traversal
24. Pre-order traversal without recursion
25. In order traversal
26. In order traversal without recursion
27. Post-order traversal
28. Postorder traversal without recursion
29. Print all leaves of a binary tree
30. Sort array using quicksort
You need to write a Java program to sort an array of integers using a quick sort algorithm. You cannot use any library method, e.g. JDK or a third party library, which means, you need to first implement the quicksort algorithm and then sort the array.
31. Insertion sort
Write a program to implement the insertion sort algorithm in Java. The program should take an unsorted array and sort it using insertion sort algorithm Also explain the best case and worst case time and space complexity of the Insertion sort algorithm.
32. Bubble sort
Write a program to implement the bubble sort algorithm in Java. You can use basic operators and functions, but sorting functions from Java API is not allowed.
33. Transpose a matrix
34. Print all permutations of String
Write a Java program to print all permutations of a given String. For example, if given String is “GOD” then your program should print all 6 permutations of this string, e.g. “GOD,” “OGD,” “DOG,” “GDO,” “ODG,” and “DGO.”
35. Reverse a String in place
36. Adding two matrices in Java
37. Matrix multiplication
38. Removal all white space from String
39. Reverse a linked list
Write a program to reverse a singly linked list in Java. You can use iteration and recursion to solve this problem, but you should reverse a linked list in place.
40. Find the length of the linked list
Just write a program in Java to find the length of a singly linked list in one pass, i.e. in just one iteration of a singly linked list.
41. Check if a linked list has a loop
Write a program to check if given linked list has a loop or not. Sometimes a linked list get corrupt, and two nodes point to the same node, which forms the loop or cycle in the linked list.
42. Find the start of loop in a linked list
43. Find the middle element of a linked list
44. Find the 3rd element from the tail linked list
You need to write a program to find the 3rd element from the tail of a singly linked list. You need to solve this problem without iterating twice.
45. Convert a linked list to a binary tree
It’s possible to convert a doubly-linked list to a binary tree, you need to write a Java program which takes a doubly-linked list and returns a binary tree.
45. Sort a linked list
You need to given an unsorted linked list, and you need to write a program in Java to sort them in ascending order of the values in each node.
46. Iterative Quicksort
You need to write a Java program to implement quicksort sorting algorithm without recursion. You can use essential JDK classes and programming constructs, but recursion is not allowed.
46. Bucket sort
This program is increasingly getting popular on Java interview because it sorts a given array in linear time. Though there is a lot of prerequisites, e.g. you must know the maximum value present in the array, it is a very interesting problem from interview point of view. You need to write a program to implement a bucket sort algorithm in Java.
47. Counting sort
This is another problem which is similar to the previous one because counting sort is also a linear sorting algorithm. Just remember that bucket sort, and counting sort are different algorithms, so it’s also good to state how they are different.
48. Check if two string rotation of each other
Write a program which accepts two given String and checks if they are the rotation of each. If they then return true otherwise return false. A String is said to be a rotation of other string if they contain same characters and the sequence is rotated across any character, e.g. “dabc” is a rotation of “abcd” but “dbac” is not.
49. LRU cache in Java
Write a program to implement an LRU cache in Java. An LRU cache means Least Recently Used Cache which removes the least recently used element if the cache is full.
50. Merge sort
Implement the merge sort algorithm in Java. You can write a recursive or iterative solution, whichever you like. You also need to explain the time and space complexity for the best, worst, and average case.
That’s all about top 50 programs from Java interviews. You can practice these Java programs even if you are not preparing for any Job interview. They not only help you to do well on your programming job interviews but also on learning how to code and developing your programming skill and coding sense.
These small programs touch several important areas, e.g. popular data structures like an array, linked list, binary tree, binary search tree, string, etc., popular algorithms, e.g. sieve of the Eratosthenes algorithm for generating primes, the Euclidean algorithm for calculating LCM, and GCF, Fibonacci sequence, printing patterns and so on.
These programs also touch base on useful operators like bit-shift and bitwise operators, modulus operators, and others. Overall, you get a good understanding of the Java programming world by practicing these Java programs from coding interviews.
Thanks for reading this article so far, if you like these Java programs, then please share with your friends and colleagues, if you have any question or problem, then please drop a comment.