25 Java Code-Based Questions For Practice:

25 Java Code-Based Questions For Practice:

Practice with these 25 questions before your technical round :). Let me know how you cracked your Interviews.

Beginner (5):

  1. Write a Java program to print "Hello, World!" to the console.
  2. Write a Java program that takes two numbers as input from the user and prints their sum.
  3. Write a Java program to check if a given number is even or odd.
  4. Write a Java program to find the factorial of a number. (Hint: Use a loop to multiply a number by all the positive integers below it.)
  5. Write a Java program to check if a given character is an alphabet (a-z or A-Z).


Intermediate (10):

  1. Write a Java program to reverse a string.
  2. Write a Java program to find the largest element in an array.
  3. Write a Java program to check if a number is a prime number. (Hint: A prime number is only divisible by 1 and itself.)
  4. Write a Java program to print the Fibonacci sequence up to a certain number. (The Fibonacci sequence is where each number is the sum of the two preceding numbers.)
  5. Write a Java program to sort an array in ascending order. (There are multiple sorting algorithms - you can choose Bubble Sort, Selection Sort, or Insertion Sort for this example.)
  6. Write a Java program to create a simple calculator that can perform addition, subtraction, multiplication, and division.
  7. Write a Java program to convert a string to uppercase and lowercase.
  8. Write a Java program to check if a string is a palindrome. (A palindrome is a word or phrase that reads the same backward as forward.)
  9. Write a Java program to search for a specific element in an array.
  10. Write a Java program to create a simple Mad Libs game. (A Mad Libs is a fill-in-the-blank story where users provide different words to create a funny story.)


Advanced (10):

  1. Explain the concept of inheritance in Java and write a simple example.
  2. Explain the concept of polymorphism in Java and write a simple example with method overriding.
  3. Explain the difference between primitive data types and reference data types in Java.
  4. Write a Java program to create a class called "Student" with attributes like name, roll number, and marks. Create objects of this class and perform various operations on them.
  5. Explain the concept of exceptions in Java and write a program that handles a specific exception. (e.g., Division by zero exception)
  6. Write a Java program to create a thread that prints a message every second. (This is a basic introduction to multithreading.)
  7. Explain the concept of collections in Java and give examples of commonly used collections. (e.g., ArrayList, HashMap)
  8. Write a Java program to read data from a text file and display it on the console.
  9. Write a Java program to connect to a database (e.g., MySQL) and perform a simple CRUD operation (Create, Read, Update, Delete). (Note: This requires additional libraries)
  10. Explain the concept of Java Generics and how they can be used to write more generic code.

This list provides a mix of questions with varying difficulty levels. So you can touch every aspect of your JAVA interview...

Keep Learning !

Best!

DCodeU-Your Interview Partner


To view or add a comment, sign in

More articles by 𝐒𝐫𝐞𝐞𝐥𝐚𝐤𝐬𝐡𝐦𝐢 𝐀𝐣𝐚𝐲𝐚𝐤𝐮𝐦𝐚𝐫

Insights from the community

Others also viewed

Explore topics