/Java-Interview-Programs

Core Java Projects with complete source code

Primary LanguageJava

Interview Programs (In Java)

Basic Programs

  1. Check the given number is EVEN or ODD. [Solution]
  2. Write a Java Program to find the Factorial of given number. [Solution]
  3. Find the Factorial of a number using Recursion. [Solution]
  4. Swap two numbers without using third variable approach 1. [Solution]
  5. Swap two numbers without using third variable approach 2. [Solution]
  6. Swap two numbers without using third variable approach 3. [Solution]
  7. How to check the given number is Positive or Negative in Java? [Solution]
  8. Write a Java Program to find whether given number is Leap year or NOT? [Solution]
  9. Write a Java Program to Print 1 To 10 Without Using Loop. [Solution]
  10. Write a Java Program to print the digits of a Given Number. [Solution]
  11. Write a Java Program to print all the Factors of the Given number. [Solution]
  12. Write a Java Program to find sum of the digits of a given number. [Solution]
  13. Write a Java Program to find the smallest of 3 numbers (a,b,c) without using < or > symbol? [Solution]
  14. How to add two numbers without using the arithmetic operators in Java? [Solution]
  15. Write a java program to Reverse a given number. [Solution]

Numbers

  1. Write a Java Program to find GCD of two given numbers. [Solution]
  2. Write a java program to LCM of TWO given number. [Solution]
  3. Write a java program to LCM of TWO given number using Prime Factors method. [Solution]
  4. Check whether the Given Number is a Palindrome or NOT. [Solution]
  5. Write a Java Program to print all the Prime Factors of the Given Number. [Solution]
  6. Write a Java Program to check whether the Given Number is Prime Number or NOT. [Solution]
  7. Write a Java Program to print Prime Numbers from 1 to N. [Solution]
  8. Write a Java Program to check whether the given number is Armstrong Number or NOT. [Solution]
  9. Write a Java Program to print Armstrong Numbers between 1 to 1000. [Solution]
  10. Write a Java Program to check whether the given number is Perfect Number or NOT. [Solution]
  11. Write a Java Program to print Perfect Numbers between 1 to 1000. [Solution]
  12. Write a Java Program to check whether the given numbers are Amicable Numbers or NOT. [Solution]
  13. Write a Java Program to check whether the given number is Ramanujam's Number or NOT. [Solution]
  14. Write a Java Program check whether the given number is Automorphic Number or NOT. [Solution]
  15. Write a Java Program to print Automorphic Number between 1 to 1000. [Solution]
  16. Write a Java Program check whether the given number is Smith Number or NOT. [Solution]
  17. Write a Java Program to print Smith Number between 2 to 1000. [Solution]
  18. Write a Java Program to check whether given number is Kaprekar Number or NOT. [Solution]
  19. Write a Java Program to print Kaprekar Numbers between 1 to 1000. [Solution]
  20. Find the Largest Divisor. [Solution]
  21. Find the All Divisors of a Given number N. [Solution]
  22. How to check if two rectangles overlap with each other?

Array Based Programs

  1. Calculate the average of given array. [Solution]
  2. Find the second largest number in the given array. [Solution]
  3. Find the second minimum number in the given array. [Solution]
  4. Find the missing Number in the given array of 1 to N. [Solution]
  5. Write a Java Program to find the Intersection of two arrays. [Solution]
  6. Write a Java Program to find the Intersection of Two Sorted arrays. [Solution]
  7. Write a Java Program to find the Union of Two Arrays (UnSorted Array). [Solution]
  8. Write a Java Program to find the Union of Two Arrays (Sorted Arrays). [Solution]
  9. Write a Java Program to find the Union of Tow Arrays using HashSet. [Solution]
  10. Write a Java Program to Move all Zero to End of the Array. [Solution]
  11. Write a Java Program to Move all Zeros to Start of the Array. [Solution]
  12. Write a Java Program to Reverse the given array without using additional Array. [Solution]
  13. Write a program to find the Most Frequent Element in an given array. [Solution]
  14. Write a program to find the Most Frequent Element using Sorting. [Solution]
  15. Write a program to find the Most Frequent Element using HashTable. [Solution]
  16. Write a java program to Rotate the Given Array d times. [Solution]
  17. Find the pair of elements(X+Y) in the array whose sum is equal to given number Z. [Solution]

String Based Programs

  1. Write a java program to check Given String is Palindrome or NOT. [Solution]
  2. How to Swap two Strings without using third (temporary) variable? [Solution]
  3. Write a java program to Reverse a String without using in-build function. [Solution]
  4. Write a java program to Count the Number of Words in a given String. [Solution]
  5. Write a java program to Count the Number of Vowels in the given string. [Solution]
  6. Check Given String is Rotation of Another String. [Solution]
  7. Write a Java Program to check two strings are Anagram to each other or NOT. [Solution]
  8. Write a Java program to find the Most Repeated Character in the Given String. [Solution]
  9. How do you count the Number of Words in a given String using Split method? [Solution]
  10. Write a Java Program to Print All Combinations of a given String. [Solution]
  11. Write a Java Program to Print All Permutations of a given String. [Solution]
  12. Write a Java Program to find All Subsets of a Given String using Bitwise approach. [Solution]
  13. Write a Java Program to find All Subsets of a Given String using Recursion approach. [Solution]

Converters

  1. Convert Decimal Number to Binary Number. [Solution]
  2. Convert Binary Number to Decimal Number. [Solution]
  3. Convert Decimal Number to Octal Number. [Solution]
  4. Convert Octal Number to Decimal Number. [Solution]
  5. Convert Decimal to Hexadecimal. [Solution]
  6. Convert Hexadecimal to Decimal. [Solution]
  7. Convert Octal to Binary Number. [Solution]
  8. Convert Binary Number to Octal. [Solution]

Sorting

  1. Bubble Sort [Solution]
  2. Quick Sort [Solution]
  3. Selection Sort [Solution]
  4. Insertion Sort [Solution]
  5. Merge Sort [Solution]

Searching

  1. Linear Search [Solution]
  2. Binary Search [Solution]

Matrix

  1. Write a Java Program to Add two Matrices. [Solution]
  2. Write a Java Program to Subtract Two Matrices. [Solution]
  3. Write a Java Program to Transpose a Matrix. [Solution]
  4. Write a Java Program to Multiply Two Matrices. [Solution]
  5. Write a Java Program to print the Matrix Spiral form. [Solution]
  6. Write a Java Program to check whether a Given Matrix is an Identity Matrix. [Solution]
  7. Check whether the Given Matrix is Sparse Matrix or NOT [Solution]
  8. Display the Lower Triangular Matrix [Solution]
  9. Display the Upper Triangular Matrix [Solution]
  10. Find sum of each row and each column of the Matrix. [Solution]

Print the Series

  1. Write the Java Program to print the following series EVEN number Series [Solution]
2 4 6 8 10 12 14 16 .....
  1. Write the Java Program to print the following series ODD number Series [Solution]
1 3 5 7 9 11 13 ....
  1. Write the Java Program to print the following series Pattern Series [Solution]
3, 33, 333, 3333, 33333, 333333 ....
  1. Write the Java Program to print the following series [Solution]
10 1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 10
  1. Write the Java Program to print the following series QuadraticSequence [Solution]
1 2 4 7 11 16 22 29 .....
  1. Write the Java Program to print the following series [Solution]
2 9 28 65 126 217 344
  1. Write the Java Program to print the following series Geometric Progression [Solution]
1 2 4 8 16 32 64 128 256 512 1024 ......
  1. Write the Java Program to print the following series Arithmetic Progression [Solution]
0 5 10 15 20 25 30 35 ....
  1. Write the Java Program to print the following series Fibonacci Series [Solution]
1 1 2 3 5 8 13 21 34 55 89 .....
  1. Write the Java Program to print the following series Prime Number Series [Solution]
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 .....
  1. Write the Java Program to print the following series Triangular Number Series [Solution]
1 3 6 10 15 21 28 36 45 55 .....
  1. Write the Java Program to print the following series
1 2 3 2 3 4 3 4 5 4 5 4 5 6 5 6 5 6 7 ....

Pattern Questions

  1. Write a Program to print Floyd's triangle? [Solution]
	1 
	2 3 
	4 5 6 
	7 8 9 10 
	11 12 13 14 15 
	16 17 18 19 20 21 
  1. Write a Program to print Pascal's triangle?
  2. Write a Java Program to print the following Pattern [Solution]
          1
          1 2
          1 2 3
          1 2 3 4
          1 2 3 4 5
          1 2 3 4 5 6
  1. Write a Java Program to print the following Pattern. [Solution]
          1
          2 2
          3 3 3
          4 4 4 4
          5 5 5 5 5
          6 6 6 6 6 6
  1. Write a Java Program to print the following Pattern. [Solution]
          6 5 4 3 2 1
          6 5 4 3 2 
          6 5 4 3 
          6 5 4
          6 5
          6
  1. Write a Java Program to print the following Pattern. [Solution]
          1 2 3 4 5 6
          1 2 3 4 5
          1 2 3 4
          1 2 3
          1 2
          1
  1. Write a Java Program to print the following Pattern. [Solution]
          1
          1 2 1
          1 2 3 2 1
          1 2 3 4 3 2 1
          1 2 3 4 5 4 3 2 1
          1 2 3 4 5 6 5 4 3 2 1 
  1. Write a Java Program to print the following Pattern. [Solution]
          1 2 3 4 5 6
          1 2 3 4 5
          1 2 3 4
          1 2 3
          1 2 
          1 
          1 2
          1 2 3 
          1 2 3 4 
          1 2 3 4 5
          1 2 3 4 5 6
  1. Write a Java Program to print the following Pattern. [Solution]
	1 2 3 4 5 6
	  2 3 4 5 6
	    3 4 5 6
	      4 5 6
	 	5 6
	 	  6
		5 6
	      4 5 6
	    3 4 5 6
	  2 3 4 5 6
	1 2 3 4 5 6
  1. Write a Java Program to print the following Pattern. [Solution]
	1
	2 1
	3 2 1
	4 3 2 1
	5 4 3 2 1 
	6 5 4 3 2 1
  1. Write a Java Program to print the following Pattern. [Solution]
	1
	1 0
	1 0 1
	1 0 1 0
	1 0 1 0 1
	1 0 1 0 1 0 
  1. Write a Java Program to print the following Pattern.
	1 1 1 1 1 1
	1 1 1 1 2 2
	1 1 1 3 3 3
	1 1 4 4 4 4
	1 5 5 5 5 5
	6 6 6 6 6 6
  1. Write a Java Program to print the following Pattern. [Solution]
9 9 9 9 9 9 9 9 9
  7 7 7 7 7 7 7
    5 5 5 5 5
      3 3 3
        1
  1. Write a Java Program to print the following Pattern. [Solution]
5 5 5 5 5 5 5 5 5
  4 4 4 4 4 4 4
    3 3 3 3 3
      2 2 2
        1
  1. Write a Java Program to print the following Pattern. [Solution]
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
  1. Write a Java Program to print the following Pattern. [Solution]
        A
      A B A
    A B C B A
  A B C D C B A
A B C D E D C B A
  1. Write a Java Program to print the following Pattern. [Solution]
        1
      1 2 1
    1 2 3 2 1
  1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
  1. Write a Java Program to print the following Pattern. [Solution]
        A 
      B A B
    C B A B C
  D C B A B C D
E D C B A B C D E
  1. Write a Java Program to print the following Pattern. [Solution]
        0 
      1 0 1
    2 1 0 1 2
  3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
  1. Write a Java Program to print the following Pattern. [Solution]
        A
      C B A
    E D C B A
  G F E D C B A
I H G F E D C B A
  1. Write a Java Program to print the following Pattern. [Solution]
        A
      A B C
    A B C D E
  A B C D E F G
A B C D E F G H I
  1. Write a Java Program to print the following Pattern. [Solution]
        1
      3 2 1
    5 4 3 2 1
  7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1
  1. Write a Java Program to print the following Pattern. [Solution]
        1
      1 2 3
    1 2 3 4 5
  1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9
  1. Write a Java Program to print the following Pattern. [Solution]
        A
      C C C
    E E E E E
  G G G G G G G
I I I I I I I I I
  1. Write a Java Program to print the following Pattern. [Solution]
        A
      B B B
    C C C C C
  D D D D D D D
E E E E E E E E E
  1. Write a Java Program to print the following Pattern. [Solution]
        1
      3 3 3
    5 5 5 5 5
  7 7 7 7 7 7 7
9 9 9 9 9 9 9 9 9
  1. Write a Java Program to print the following Pattern. [Solution]
        1
      2 2 2
    3 3 3 3 3
  4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
  1. Write a Java Program to print the following Pattern. [Solution]
        *
      * * *
    * * * * *
  * * * * * * *
* * * * * * * * *
  1. Write a Java Program to print the following Pattern. [Solution]
A B C D E
  A B C D
    A B C
      A B
        A
  1. Write a Java Program to print the following Pattern. [Solution]
E E E E E
  D D D D
    C C C
      B B
        A
  1. Write a Java Program to print the following Pattern. [Solution]
1 2 3 4 5
  1 2 3 4
    1 2 3
      1 2
        1
  1. Write a Java Program to print the following Pattern. [Solution]
5 5 5 5 5
  4 4 4 4
    3 3 3
      2 2
        1
  1. Write a Java Program to print the following Pattern. [Solution]
* * * * *
  * * * *
    * * *
      * *
        *
  1. Write a Java Program to print the following Pattern. [Solution]
        A
      A B
    A B C
  A B C D
A B C D E
  1. Write a Java Program to print the following Pattern. [Solution]
        A
      B B
    C C C
  D D D D
E E E E E
  1. Write a Java Program to print the following Pattern. [Solution]
        1
      1 2
    1 2 3
  1 2 3 4
1 2 3 4 5
  1. Write a Java Program to print the following Pattern. [Solution]
        1
      2 2
    3 3 3
  4 4 4 4
5 5 5 5 5
  1. Write a Java Program to print the following Pattern. [Solution]
        *
      * *
    * * *
  * * * *
* * * * *
  1. Write a Java Program to print the following Pattern. [Solution]
E D C B A
E D C B
E D C
E D
E
  1. Write a Java Program to print the following Pattern. [Solution]
E E E E E
D D D D
C C C
B B
A
  1. Write a Java Program to print the following Pattern. [Solution]
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
  1. Write a Java Program to print the following Pattern. [Solution]
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
  1. Write a Java Program to print the following Pattern. [Solution]
A B C D E
A B C D
A B C
A B
A
  1. Write a Java Program to print the following Pattern. [Solution]
A A A A A
B B B B
C C C
D D
E
  1. Write a Java Program to print the following Pattern. [Solution]
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
  1. Write a Java Program to print the following Pattern. [Solution]
* * * * *
* * * *
* * *
* *
*
  1. Write a Java Program to print the following Pattern. [Solution]
A
A B
A B C
A B C D
A B C D E
  1. Write a Java Program to print the following Pattern. [Solution]
*
* *
* * *
* * * *
* * * * *
  1. Write a Java Program to print the following Pattern. [Solution]
A
B B
C C C
D D D D
E E E E E
  1. Write a Java Program to print the following Pattern. [Solution]
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
  1. Write a Java Program to print the following Pattern. [Solution]
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Brackets or Parentheses Problems

  1. Write a Java Program to find out whether the given string is Balanced Parentheses or NOT? [Solution]
	()() 	- VALID
	(()) 	- VALID
	())( 	- INVALID
	((	- INVALID
  1. Generate Balanced Parentheses of N pairs. [Solution]
	N = 2		N= 3
	()()		()()()
	(())		(())()
			()(())
			(()())
			((()))
  1. Generate All possible combinations of Parentheses.
	N = 2		N= 3
	()		()
	()()		()()
	(())		(())
			()()()
			(())()
			()(())
			(()())
			((()))
  1. Count the Number of possible combinations of Parentheses.
	N = 2		N= 3
	()		()
	()()		()()
	(())		(())
	Output = 3	()()()
			(())()
			()(())
			(()())
			((()))
			Output = 8

Java Interview Questions

  1. What do you know about JVM, JRE and JDK?
  2. Is JRE platform dependant or independent?
  3. Which is ultimate base class in java class hierarchy? List the name of methods of it?
  4. Which are the reference types in java?
  5. What is narrowing and widening?
  6. How will you print "Hello CDAC" statement on screen, without semicolon?
  7. Can you write java application without main function? If yes, how?
  8. What will happen, if we call main method in static block?
  9. In System.out.println, What is meaning of every word?
  10. How will you pass object to the function by reference?
  11. What is constructor chaining? How can we achieve it in C++?
  12. Which are the rules to overload method in sub class?
  13. What is the difference between finalize and dispose?
  14. What is shut down hook?
  15. What is the difference between final, finally and finalize?
  16. What is the difference between checked and unchecked exception?
  17. What is exception chaining?
  18. What is the difference between throw and throws?
  19. In which case, finally block doesn’t execute?
  20. What is upcasting?
  21. What is dynamic method dispatch?
  22. What do you know about final method?
  23. What is the difference between abstract class and interface?
  24. What is fragile base class problem and how can we overcome it?
  25. Why java does not support multiple implementation inheritance?
  26. What is marker interface? List the name of some marker interfaces?
  27. What is the significance of marker interface?
  28. What is the difference between Comparable and Comparator?
  29. What is the difference between Array and ArrayList?
  30. What is the difference between HashSet and HashMap?
  31. What is the difference between HashTable and HashMap?
  32. Which collection classes are synchronized?
  33. What is the difference between ArrayList and Vector?
  34. What is the difference between Enumeration and Iterator?
  35. What is the difference between Iterator and ListIterator?
  36. What is the difference between fail-fast and fail-safe iterator?
  37. How can you copy elements of one collection into another without iterator?
  38. What is the difference between String and StringBuffer?
  39. What is the difference between StringBuffer and StringBuilder?
  40. How can you check wheather string is palindrome or not?
  41. Can we write multiple public classes in single .java file? If no why?
  42. What is serialization and deserialization?
  43. If serializable class do not contain serializable fields, what will happen? If its problematic then how will overcome it?
  44. Which two techniques allow us to create new instance from existing one?
  45. Which members do not serialize?
  46. What is metadata? What is advantage of it?
  47. What is bytecode?
  48. What is reflection?
  49. Which features of java makes it platform dependant?
  50. What is applet?
  51. Can you explain life cycle of applet?
  52. Why AWT components are heavy weight component?
  53. What is thread?
  54. Which are the types of thread? What is the difference between them?
  55. Explain life cycle of thread?
  56. What is race condition? How can we overcome it?
  57. What is synchronization? How can we achieve it?
  58. How can we share object between the threads?
  59. Why wait, notify and notifyall methods belongs to Object class instead of Thread class?
  60. What do you know about volatile keyword in java?
  61. What is the difference between Thread. Sleep and Thread.yield?
  62. What is deadlock? How can we avoid it?
  63. Why thread based multitasking is faster than process based multitasking?
  64. When we should use Thread class and Runnable interface to create thread?
  65. What is wild card? Which are the types of it?
  66. What is the difference between TCP and UDP protocol?
  67. What is socket?
  68. When we should use socket and rmi?
  69. How will you write code for linkedlist in java?
  70. What is wrapper class? What is need of it?
  71. What are the various access specifiers for Java classes?
  72. What's the purpose of Static methods and static variables?
  73. What is data encapsulation and what's its significance?
  74. What is a singleton class? Give a practical example of its usage.
  75. What are Loops in Java? What are three types of loops?