Java Interview Programs for Freshers

Previous
Next

In this tutorial, we will see Java interview programs for freshers. This interview programs will help freshers to crack Java interview.

Here is the list of Top 10 Java interview Programs for Freshers.

Question 1: Check if number is odd or even?

Answer:

It is a very basic question. You need to check remainder value when you divide number by 2. If it is 1 then it is odd else it is even.

When you run above program, you will get below output:

Number is odd.

Question 2: How to check number is prime or not?

Answer:
If any number which is not divisible by any other number which is less than or equal to square root of that number, then it is prime number.

When you run above program, you will get below output:

17 is prime number?: true
2 is prime number?: true
91 is prime number?: false
29 is prime number?: true
81 is prime number?: false

If you can go through check if number is prime for more details.

Question 3: Reverse a String:

Answer:

When you run above program, you will get below output:

Reverse of Happy is:yppaH
 You can go through How to reverse a String for more approaches.

Question 4: Check If String is palindrome.

Answer:
Reverse a String and check it with input String.

When you run above program and you will get below output:

Enter string : 12121
String is palindrome
Enter a string : Apple
String is not palindrome

You can go through Check if String is palindrome for more details.

Question 5: Search a number in sorted array in o(logn) time?

Answer:
You need to use binary search to search an element in array in o(logn) time.
Code for binary search

When you run above program, you will get below output:

Index of 67 in array is: 2
Index of 7 in array is: -1

Question 6: Find missing number in array.

Answer:

When you run above program, you will get below output:

Missing number from array arr1: 3
Missing number from array arr2: 4

You can go through find missing number in array for more details.

Question 7: Java program to find duplicate characters in the String?

Answer:

When you run above program, you will get below output:

You can go through find duplicate characters in String for more details.

Question 8: Java program to find number of words in String?

Answer:

WHen you run above program, you will get below output:

Number of words in the string = 4
Words are:
My
Name
is
John

Question 9: Write a program to find factorial of number?

Answer:

When you run above program, you will get below output:

Enter the number to calculate Factorial:
5
Factorial of 5 is 120

Question 10: Write a program to print fibonacci series?

Answer:

When you run above program, you will get below output:

Printing Fibonacci series:
0 1 1 2 3 5 8 13 21 34

You can go through Fibonacci series program for more details

that’s all about Java Interview programs for freshers.

You may also like:

Java Interview programs

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog