Education logo

Java Coding Interview Questions For Freshers

Explore the java basic programming examples to prepare for the interviews

By OMKARPublished 29 days ago 3 min read
Java Coding Interview Questions For Freshers
Photo by Emile Perron on Unsplash

In this article, we are going to learn about some of the most commonly asked fundamental algorithm-based Java coding examples. Having knowledge of fundamental Java concepts is crucial for any Java interview. So, let's explore some of the most frequently asked basic Java coding questions and answers in interviews.

Example 1: Java program to check given number is palindrome or not

A palindrome number is a number that is same after reverse. For example: 252, 676, 77577, 1234321 etc are palindrome numbers.

OUTPUT:

Enter the number:

252

Given number is palindrome

Example 2: Java Program to check Given Number is Prime or not

Prime number is a number that is greater than 1 and divided by 1 and itself only. For example: 2, 3, 5, 7, 11, 13, 17, 19, 23... etc. are prime numbers.

OUTPUT:

Enter number:

11

Given number is prime

Example 3: Java program to calculate gross salary of an employee

We can calculate an employee's gross salary using the following method for DA and HRA. The DA is 20% of the basic salary, and the HRA is 30% of the basic salary. The gross salary is the sum of the basic salary, DA, and HRA.

OUTPUT:

Enter the basic salary of an employee: 25000

Gross salary of an employee is: 37500.0

Example 4: Write a Java Program to Calculate Factorial of Given Number

The factorial of a number is found by multiplying all the whole numbers from that number down to 1. For example, to find the factorial of 5, you multiply 5 by 4, then by 3, then by 2, and finally by 1, which equals 120. So, the factorial of 5 is 120 (5 x 4 x 3 x 2 x 1=120).

OUTPUT:

Enter a Number: 7

Factorial of 7 is: 5040

Example 5: Write a Java Program to Print Fibonacci Series

The Fibonacci series is a sequence where each number is the sum of the two numbers before it. For example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, and so on. You can see that the first two numbers in the Fibonacci series are 0 and 1.

In the above program, we first printed the values 0 and 1 manually. A for loop is used to generate and print the rest of the Fibonacci series by adding the previous two numbers and updating the values of num1, num2, and num3 for each iteration.

OUTPUT:

Enter limit: 10

0 1 1 2 3 5 8 13 21 34

Example 6: Java Program to Check whether Given Element is Present in Array or not

In the above program, we first declare an array and add some values to it. Then, we create a Scanner class object to accept the value we want to search for. Next, a for-each loop iterates over all the values present in the array until it matches the given value. If the count is greater than 0, it means the value is present in the array; otherwise, it prints that the value is not present.

OUTPUT:

Enter the value you want to find:

9

Value is present in array at position : 6

Example 7: Write a Java Program to Reverse a Given String

In above program we have used StringBuffer class reverse method to reverse a string. We can also use StringBuilder insted of StringBuffer. This is the easiest way to reverse a string in java.

OUTPUT:

Enter the String:

Coding is Easy!

Reversed String is : !ysaE si gnidoC

In conclusion, these simple Java coding questions are key for beginners entering the programming world. By understanding these basics, you'll be ready to tackle entry-level interviews and start your journey as a Java developer. Practice makes perfect, so keep coding, exploring, and challenging yourself: learning to code is an exciting adventure!

Happy coding!

degreeinterviewcoursescollege

About the Creator

OMKAR

Here I will share programming languages tutorials, latest tech updates, coding tips and tricks, Learn Java with lot of examples, interview questions, recommendations and many more..., So make sure you have subscribed to our page.

Enjoyed the story?
Support the Creator.

Subscribe for free to receive all their stories in your feed. You could also pledge your support or give them a one-off tip, letting them know you appreciate their work.

Subscribe For Free

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments (1)

  • shanmuga priya29 days ago

    Thank you for sharing.

OMKARWritten by OMKAR

Find us on social media

Miscellaneous links

  • Explore
  • Contact
  • Privacy Policy
  • Terms of Use
  • Support

© 2024 Creatd, Inc. All Rights Reserved.