Java Interview Programs5 min read

This article includes a big list of java programs for interviews. This includes your coding skills different java interview questions and helps you to understand each of the questions clearly and be a better developer.

The idea behind this post is to create a list of all the frequently asked java programming interview questions and make you prepare for it. We start with simple number programs, logical, strings, the use of loop,s and many more.

Click on the solution to dive into the source code and explanation from the list mentioned below.
Let us begin


1. Armstrong number in java:

A number is said to be an Armstrong Number if even after the sum of its digits, where each digit is raised to the power of the number of digits is equal to the original number. For example 153, 371, 407, 9474, etc.
(Solution with example and explanation)


2. Reverse a String in java:

There are various ways in the java program to reverse a String. Reversing a string means displaying the string from backward. Example: reverse will be displayed as esrever.
(Solution with example and explanation)


3. How to create a Pyramid of Numbers in java?

Patterns are one of the easiest ways to improve the coding skills and one of the logical programs asked in an interview. The frequent use of loops can increase your skills and printing them in order.
(Solution with example and explanation)


4. Java Program to Swap Two Numbers without using the Third Variable.

It is easy to swap two numbers using the third variable, we assigned one to a temporary(temp) variable and swap with to others. But the main interview question asked in swapping is without using the third variable.
(Solution with example and explanation)


5. A Prime Number

A number is said to be a prime number if it is divisible by itself and 1. Example 3, 5, 7, 11, 13, 17, 19, etc. Also, learn to list the prime number between given numbers
(Solution with example and explanation)


6. Palindrome Number/String

A number is said to be a Palindrome number if it remains the same when its digits are reversed or are the same as forward. It is also applied to the word, phrase or other sequences of symbols.
For example: 14141, 777, 272 are palindrome numbers as they remain the same even if reversed
(Solution with example and explanation)


7. Fibonacci Series:

Fibonacci series is the series of numbers where the next number is achieved by the addition of the previous two numbers. The initial addition of two numbers is 0 and 1. For example: 0,1,1,2,3,5,8,13….etc. Using for loop and recursion.
(Solution with example and explanation)


8. String Anagram

Two strings are said to be in an anagram if they contain the same set of characters but in a different order.
For example: “Keep – peek”, “School Master – The Classroom”, “Debit Card – Bad Credit” etc.
(Solution with example and explanation)


9. How to remove duplicates from ArrayList in java

ArrayList is a collection type used mostly in java. It is the list interface from Java’s collection framework that allows duplicates in its list. It provides insertion order, flexibility in program and duplicates in a list. Using HashSet and LinkedHashSet.
(Solution with example and explanation)


10. How to find the duplicate characters in a string in java

We write a program to find duplicate characters in a string in java. For example, consider a string “nut cutter“, duplicate characters in it are : u: 2, t : 3.
(Solution with example and explanation)


11. Java Program to remove all white spaces from a string

In this post, we will learn how to remove white spaces from a string in java. We will learn the two ways to remove white spaces in java. First by using in-built methods called replaceAll() and second without the use of in-built methods (for-loop).
(Solution with example and explanation)


12. The Square Root of a number in java

This post shows how to find a square root of a number in java. We will learn two methods to find the square root one by an in-built math method called Math.sqrt() and the other by using a do-while loop.
(Solution with example and explanation)


13. Java Program to Count the Number of Words present in a String using HashMap.

Take the string from user input using Scanner class and store it in a string “str“. We declare the HashMap(which is a part of java’s collection that stores data in (Key, value) pairs). The Key in this program is String and the Value in an Integer.
(Solution with example and explanation)


14. Java Program to find the second-largest number in an array.

we take the user input for How many elements does a user wants in an array and what are the elements with the help of the Scanner class. Example with output.
(Solution with example and explanation)


15. Printing different Patterns in Java

Patterns are one of the easiest ways to improve the coding skills for java.
This post contains printing star patterns, alphabetic patterns, and numeric patterns.
(solution with example and explanation)


16. Java Program to find the GCD of two numbers.

GCD(Greatest Common Divisor) or we can say HCF(Highest Common Factor) of two numbers is the largest number(integer). Example using for loop and if statement.
(Solution with example and explanation).


17. How to reverse sentences in String Java?

Reversing a string in java is easy. Here we reverse the sentence of words from back to front rather than reversing each word.
Example: Let us consider a string “I am a code” and the output will be “code a am I“.
(Solution with example and explanation)


18. Java program to check whether the given number Is Binary or not

binary number is a number expressed in the base-2 numeral system that is the number that contains 2 symbols to represent all the numbers. The symbols are 0 and 1.
For example: 101011, 110011110, 10001111 are binary numbers.
(Solution with example and explanation)


19. Generate Random numbers in Java.

We can define Random as something that happens without any conscious decision. Similarly, a random number is a number that is chosen unpredictably or randomly from the set of numbers. Learn two ways two generate random numbers in java.
(Solution with example and explanation)


20. How to remove all vowels from a string in java?

This post shows, How to remove all vowels from a string in java? with the help of replaceAll() method.
(Solution with example and explanation)

More Question will be added to on upcoming months.


MORE

Java Program to find the sum of the Largest Forward Diagonal

in this tutorial, we will write a java program to find the sum of the Largest Forward Diagonal in an Arraylist (matrix). Java Program to …

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a numberĀ using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …