Basic Java Coding Questions
1. Write a program to print "Hello, World!" in Java.
2. Write a program to swap two numbers without using a third variable.
3. Write a program to check if a number is even or odd.
4. Write a program to find the largest of three numbers.
5. Write a program to reverse a number.
6. Write a program to check if a number is prime.
7. Write a program to find the factorial of a number using recursion.
8. Write a program to print the Fibonacci series up to N terms.
9. Write a program to check if a number is palindrome.
10. Write a program to check if two numbers are anagrams.
11. Write a program to find the sum of digits of a number.
12. Write a program to print all prime numbers in a given range.
13. Write a program to count the number of vowels and consonants in a string.
14. Write a program to count the occurrences of a character in a string.
15. Write a program to reverse a string without using built-in functions.
OOPs Concept Coding Questions
16. Write a Java program to demonstrate a class and object.
17. Write a program to show the use of constructors in Java.
18. Write a program to demonstrate encapsulation with getter and setter methods.
19. Write a program to implement inheritance in Java.
20. Write a program to demonstrate method overloading.
21. Write a program to demonstrate method overriding.
22. Write a program to create an abstract class and implement it.
23. Write a program to create and use an interface.
24. Write a program to show the use of the “this” keyword.
25. Write a program to show the use of the super keyword.
26. Write a program to demonstrate constructor overloading.
27. Write a program to demonstrate multiple inheritance using interfaces.
28. Write a program to implement a Singleton class in Java.
29. Write a program to create an immutable class in Java.
30. Write a program to demonstrate the difference between static and non-static methods.
31. Write a program to demonstrate the difference between composition and inheritance.
32. Write a program to show the use of an inner class in Java.
33. Write a program to override the toString() method in Java.
34. Write a program to implement shallow and deep copy cloning in Java.
35. Write a program to overload the main() method in Java.
Would you like solutions for any of these? 🚀
1. Star (*) Patterns
1. Print a solid square pattern.
2. Print a hollow square pattern.
3. Print a right-angled triangle pattern.
4. Print an inverted right-angled triangle pattern.
5. Print a pyramid pattern.
6. Print an inverted pyramid pattern.
7. Print a diamond pattern.
8. Print a hollow diamond pattern.
9. Print a Pascal’s Triangle pattern.
10. Print a Floyd’s Triangle pattern.
2. Number Patterns
11. Print a half pyramid of numbers.
12. Print an inverted half pyramid of numbers.
13. Print a full pyramid of numbers.
14. Print a diamond pattern of numbers.
15. Print Floyd’s triangle.
16. Print Pascal’s triangle.
17. Print a number pyramid where each row contains row index repeated.
18. Print a number pyramid where numbers increase in each row.
19. Print a square number pattern with increasing numbers.
20. Print a zigzag number pattern.
3. Alphabet (Character) Patterns
21. Print a character right-angled triangle.
22. Print an inverted character triangle.
23. Print a character pyramid.
24. Print a diamond pattern with characters.
25. Print a hollow alphabet pyramid.
26. Print an alphabet square pattern.
27. Print an alphabet butterfly pattern.
28. Print a reverse alphabet pattern.
29. Print a V-pattern with alphabets.
30. Print a zigzag character pattern.
4. Miscellaneous Patterns
31. Print a butterfly pattern.
32. Print an hourglass pattern.
33. Print a spiral pattern.
34. Print a cross (X) pattern.
35. Print a wave pattern.
36. Print a checkerboard pattern.
37. Print a right Pascal’s triangle.
38. Print a left Pascal’s triangle.
39. Print a Christmas tree pattern.
40. Print a hollow pyramid with a border.
Would you like solutions for any of these? 🚀
You said:
Matrix based questions also
ChatGPT said:
Here are some important matrix-based coding questions frequently asked in Java interviews:
1. Basic Matrix Operations
1. Print a 2D matrix.
2. Find the sum of all elements in a matrix.
3. Find the sum of each row in a matrix.
4. Find the sum of each column in a matrix.
5. Find the largest and smallest element in a matrix.
6. Count the number of even and odd elements in a matrix.
2. Matrix Transformations
7. Transpose of a matrix.
8. Rotate a matrix by 90 degrees clockwise.
9. Rotate a matrix by 90 degrees counterclockwise.
10. Rotate a matrix by 180 degrees.
11. Reverse the rows of a matrix.
12. Reverse the columns of a matrix.
3. Special Matrix Patterns
13. Print a diagonal matrix (principal and secondary diagonals).
14. Print the boundary elements of a matrix.
15. Print a matrix in a spiral order.
16. Print a zigzag traversal of a matrix.
17. Print a matrix in wave form (column-wise or row-wise).
18. Print a lower triangular matrix.
19. Print an upper triangular matrix.
4. Matrix Computations
20. Add two matrices.
21. Subtract two matrices.
22. Multiply two matrices.
23. Find the determinant of a matrix.
24. Find the inverse of a matrix.
25. Check if a matrix is symmetric.
26. Check if a matrix is an identity matrix.
27. Check if a matrix is a sparse matrix (more zeroes than non-zero elements).
28. Check if a matrix is a magic square (sum of rows, columns, and diagonals are the same).
29. Find the saddle point of a matrix (smallest in its row, largest in its column).
5. Advanced Matrix Problems
30. Implement Floyd-Warshall
31. Algorithm for shortest paths in a matrix.
32. Implement the boundary fill algorithm for matrix filling.
33. Implement the flood fill algorithm (used in image processing).
34. Find the longest increasing path in a matrix.
35. Count the number of islands in a binary matrix (DFS/BFS approach).
36. Find the shortest path in a binary matrix (Dijkstra’s or BFS).
37. Find the largest rectangular sub-matrix with all 1s in a binary matrix.
38. Convert a matrix into a diagonal matrix.
39. Implement matrix exponentiation for fast Fibonacci calculations.
40. Rotate a matrix without using extra space.
41. Find the row with the maximum number of 1s in a binary matrix.