Java Practice Programs

Java is a popular programming language that is used to develop a wide variety of applications. One of the best ways to learn Java is to practice writing programs. Many resources are available online and in libraries to help you find Java practice programs.

When practising Java programs, it is important to focus on understanding the concepts behind the code. Don't just copy and paste code from a website or book. Try to understand why the code is written the way it is. It will help you become a better Java programmer.

Java Basic Programs

  1. Fibonacci series in Java
  2. Factorial Program in Java
  3. Palindrome Program in Java
  4. How to reverse String in Java
  5. How to Reverse a Number in Java
  6. How do you find duplicate characters in a string
  7. How to Print ASCII Value in Java
  8. How to Create Object in Java
  9. How to Compare Two Objects in Java
  10. Program to swap two numbers
  11. Java Program to Find Sum of Natural Numbers
  12. Java Program to Display Odd Numbers From 1 to 100
  13. Sum of Numbers in Java
  14. Java Program to Find Largest of Three Numbers
  15. Java Program to Check if a Given Number is Perfect Square
  16. Java Program to Check if a Number is Positive or Negative

Java Number Programs

  1. Special Number in Java
  2. Perfect Number Program in Java
  3. Prime Number Program in Java
  4. Armstrong Number in Java
  5. Lucky Number in Java
  6. Spy Number in Java
  7. Evil Number Java
  8. Duck Number Java
  9. ISBN Number Java
  10. Krishnamurthy Number Java
  11. Xylem and Phloem Number in Java
  12. Kynea Numbers in Java
  13. House Numbers in Java
  14. Tribonacci Number Java
  15. Odious Number in Java
  16. Strontio Number in Java
  17. Tech Number in Java
  18. Fascinating Number in Java
  19. Sunny Number in Java
  20. Automorphic Number Program in Java
  21. Mystery Number in Java
  22. Lead Number in Java
  23. Bouncy Number in Java
  24. Economical Number in Java
  25. Neon Number in Java
  26. Unique Number in Java Program
  27. Power of a Number in Java
  28. Magic Number in Java
  29. Catalan Number in Java
  30. Self-Descriptive Numbers in Java
  31. Hogben Numbers in Java
  32. Centered Square Numbers in Java
  33. Nude Numbers in Java
  34. Sphenic Number in Java
  35. Program to determine whether a given number is a happy number
  36. Amicable Pair Number in Java
  37. Achilles Number in Java
  38. Frugal Number in Java
  39. Cullen Number in Java
  40. Smith Number in Java
  41. Tetranacci Number in Java
  42. Undulating Number in Java
  43. Moran Numbers in Java
  44. Cardinal Number in Java
  45. Pyramidal Number in Java
  46. Buzz Number Java
  47. Bell Number in Java
  48. Pancake Number in Java
  49. Sublime Number in Java
  50. Ramanujan Number or Taxicab Number in Java
  51. Untouchable Number in Java
  52. Pernicious Number in Java
  53. Narcissistic Number in Java
  54. Keith Number in Java
  55. Goldbach Number in Java
  56. Mersenne Number in Java
  57. Adam Number in Java

Data structures

Java Array Programs

  1. Java Program to sort the elements of an array in ascending order
  2. Program to print the elements of an array
  3. Program to print the elements of an array in reverse order
  4. Program to print the largest element in an array
  5. Program to print the duplicate elements of an array.
  6. Character Array in Java
  7. How to Take Array Input in Java
  8. Program to print the smallest element in an array
  9. Program to print the elements of an array
  10. Java Program to right rotate the elements of an array
  11. Java Program to print the sum of all the items of the array
  12. Java Program to print Odd and Even Numbers from an Array
  13. Java Program to remove duplicate element in an Array
  14. Program to copy all elements of one array into another array
  15. Jagged Array in Java
  16. Minimum Difference Subarrays in Java
  17. Beautiful Array in Java
  18. Dynamic Array in Java
  19. Iterate JSON Array Java
  20. String Array in Java
  21. Java ArrayList
  22. How to Create Array of Objects in Java
  23. Static Array in Java
  24. Java Program to find Largest Number in an Array
  25. Java Program to find Second Largest Number in an Array
  26. Java Program to sort the elements of an array in descending order
  27. Java Program to find Smallest Number in an Array
  28. Java Program to find Third Largest Number in an Array
  29. Program to print the duplicate elements of an array
  30. Passing Array to Function In Java
  31. Program to left rotate the elements of an array
  32. Add elements to Array in Java
  33. Program to print the sum of all the elements of an array
  34. Java Program to find Second Smallest Number in an Array
  35. Program to find the frequency of each element in the array
  36. Program to print the elements of an array present on even position
  37. Java Program to print the number of elements present in an array
  38. Array Rotation in Java
  39. Array Slicing in Java
  40. How to Create a Mirror Image of A 2D Array in Java
  41. Program to print the elements of an array present on odd position
  42. Peak Index of Mountain Array Problem in Java
  43. Plus One to Array Problem in Java
  44. Zigzag Array in Java
  45. Java Array Clone
  46. Find unique elements in array Java
  47. Java Program to Count the Occurrences of Each Character
  48. Program to copy all the elements of one array into another array
  49. Equilibrium Index of an Array in Java

Java Singly linked list Programs

  1. Java Program to create and display a singly linked list
  2. Java program to create a singly linked list of n nodes and count the number of nodes
  3. Java Program to search an element in a singly linked list
  4. Java program to insert a new node at the end of the singly linked list
  5. Java program to insert a new node at the beginning of the singly linked list
  6. Java program to create a singly linked list of n nodes and display it in reverse order
  7. Java Program to insert a new node at the middle of the singly linked list
  8. Program to sort the elements of the singly linked list
  9. Java program to delete a node from the beginning of the singly linked list
  10. Java program to remove duplicate elements from a singly linked list
  11. Java program to delete a node from the end of the singly linked list
  12. Java program to determine whether a singly linked list is the palindrome
  13. Program to swap the last element of the singly linked list from the first one
  14. Program to find the maximum and minimum value node from a singly linked list
  15. Program to swap nodes in a singly linked list without swapping data
  16. Insertion in singly linked list at beginning
  17. Java program to delete a node from the middle of the singly linked list
  18. Program to delete a new node from the beginning of the singly linked list
  19. Program to search an element in a singly linked list
  20. Searching in singly linked list
  21. Deletion in singly linked list at beginning

Java Doubly Linked List Programs

  1. Program to create and display a doubly linked list.
  2. Java program to create a doubly linked list of n nodes and display it in reverse order
  3. Java program to insert a new node at the end of the Doubly Linked List
  4. Java program to insert a new node at the middle of the Doubly Linked List
  5. Java program to sort the elements of the doubly linked list
  6. Java program to delete a new node from the beginning of the doubly linked list
  7. Java program to remove duplicate elements from a Doubly Linked List
  8. Java program to search an element in a doubly linked list
  9. Java program to rotate doubly linked list by N nodes
  10. Java program to convert a given binary tree to doubly linked list
  11. Program to insert a new node at the beginning of the doubly linked list.
  12. Java program to delete a new node from the middle of the doubly linked list

Java Circular Linked List Programs

  1. Program to create and display a circular linked list
  2. Java program to sort the elements of the Circular Linked List
  3. Java program to search an element in a Circular Linked List
  4. Java program to create a Circular Linked List of N nodes and count the number of nodes
  5. Java program to insert a new node at the end of the Circular Linked List
  6. Java program to insert a new node at the middle of the Circular Linked List
  7. Java program to insert a new node at the beginning of the Circular Linked List
  8. Java program to delete a node from the beginning of the Circular Linked List
  9. Java program to delete a node from the end of the Circular Linked List
  10. Java program to delete a node from the middle of the Circular Linked List

Java Tree Programs

  1. Java program to construct a Binary Search Tree and perform deletion and In-order traversal
  2. Java program to implement Binary Tree using the Linked List
  3. Java program to search a node in a Binary Tree
  4. Java program to find the maximum depth or height of a tree
  5. Java program to determine whether two trees are identical
  6. Java program to find the sum of all the nodes of a binary tree
  7. Java program to find the largest element in a Binary Tree
  8. Program to search a node in a Binary Tree
  9. Java program to create a doubly linked list from a ternary tree
  10. Java program to find the smallest element in a tree
  11. Segment Tree in Java
  12. Level Order Traversal of a Binary Tree in Java
  13. Morris Traversal for Inorder in Java
  14. Tree traversal (Inorder, Preorder an Postorder)
  15. Preorder Traversal
  16. Inorder Traversal
  17. Postorder Traversal
  18. Binary Tree Traversal in Data Structure
  19. Level Order Traversal of a Binary Tree in Java
  20. Zigzag Traversal of a Binary Tree in Java
  21. Vertical Order Traversal of a Binary Tree in Java
  22. Morris Traversal for Inorder in Java
  23. Morris Traversal for Preorder in Java
  24. Level Order Traversal in Spiral form
  25. Red Black Tree Java
  26. Level order Traversal in a Binary Tree
  27. Boundary Traversal of Binary tree

Java String Programs

  1. Java Program to find all the permutations of a string
  2. Java Program to separate the Individual Characters from a String
  3. Java Program to find Reverse of the string
  4. Java Program to count the total number of characters in a string
  5. Java Program to find all subsets of a string
  6. Java Program to determine whether one string is a rotation of another
  7. Write a Java program to count the number of words in a string
  8. Java Program to find maximum and minimum occurring character in a string
  9. Java Program to toggle each word in String
  10. Java Program to determine whether two strings are the anagram
  11. Program to print smallest and biggest possible palindrome word in a given string
  12. Java Program to swap two string variables without using third or temp variable
  13. Java Program to remove all the white spaces from a string
  14. Java Program to replace lower-case characters with upper-case and vice-versa
  15. Java Program to count the total number of vowels and consonants in a string
  16. Palindrome Partitioning Problem in Java
  17. Isomorphic String in Java
  18. Display Leaf nodes from Preorder of a BST in Java

Error and Exception Programs

  1. Java throw Exception
  2. Java Custom Exception
  3. Arithmetic Exception in Java
  4. Exception Class in Java
  5. InputMismatchException in Java
  6. Java Exception Propagation
  7. Java try-catch block
  8. customized exception in Java
  9. Java finally block
  10. How to avoid null pointer exception in Java
  11. ConcurrentModificationException in Java
  12. FileNotFoundException in Java
  13. Different Ways to Print Exception Message in Java
  14. How to resolve IllegalStateException in Java
  15. Exception Handling with Method Overriding in Java
  16. Java 7 Catch Multiple Exceptions
  17. NoClassDefFoundError in Java
  18. ClassCast Exception in Java
  19. Java Console Error
  20. Identifier Expected Error in Java
  21. Java Catch Multiple Exceptions
  22. lang.NoSuchMethodError
  23. Chained Exceptions in Java
  24. StringIndexOutOfBoundsException in Java
  25. NZEC in Java
  26. NoSuchElementException in Java
  27. Exception in Thread Main java.util.NoSuchElementException no line Found
  28. How to Create Test Cases for Exceptions in Java

Class and Interface Programs

  1. How to Create Singleton Class in Java
  2. Types of Classes in Java
  3. Marker Interface in Java
  4. ByteStream Classes in Java
  5. Dictionary Class in Java
  6. Abstract class in Java
  7. Wrapper classes in Java
  8. Java Inner Classes (Nested Classes)
  9. Java Math class
  10. Java StringBuffer Class
  11. Java Scanner
  12. Java static nested class
  13. Java FileInputStream Class
  14. Java FileReader Class
  15. Java Member Inner class
  16. Java Console Class
  17. How to create Immutable class
  18. Exception Class in Java
  19. Sealed Class in Java
  20. Why We Use Static Class in Java
  21. Singleton Class in Java
  22. Java Nested Interface
  23. Java Functional Interfaces
  24. Java Comparable interface
  25. Iterator in Java
  26. Java Runnable Interface
  27. Marker Interface in Java
  28. Servlet Interface
  29. Java 9 Private Interface Methods
  30. Java Predicate Interface
  31. Java Consumer Interface
  32. Lock Interface in Java
  33. TypeScript Interface
  34. if Condition in Lambda Expression Java
  35. How to Mock Lambda Expression in Java
  36. How to Return Value from Lambda Expression Java
  37. AWS Lambda in Java

Java Matrix Programs

  1. Java Program to add two matrices
  2. Java Program to transpose matrix
  3. Java Program to multiply two matrices
  4. Java Program to display the lower triangular matrix
  5. Java Program to find the sum of each row and each column of a matrix
  6. Java Program to determine whether a given matrix is an identity matrix
  7. Java Program to display the upper triangular matrix
  8. Java Program to determine whether a given matrix is a sparse matrix
  9. Rotate Matrix by 90 Degrees in Java | Rotate Matrix in Java Clockwise and Anti-clockwise
  10. Normal and Trace of a Matrix in Java
  11. Java Program to Print Matrix in Z Form
  12. Set Matrix Zeros in Java
  13. Find Saddle Point of a Matrix in Java
  14. Print Matrix Diagonally in Java
  15. Rotate A Matrix By 180 Degree in Java
  16. Find Saddle Point of a Matrix in Java
  17. Program to print the elements of an array in reverse order
  18. Set Matrix Zeros in Java
  19. Java Program to subtract the two matrices

Java Pattern programs

  1. Alphabet Pattern in Java
  2. Ladder Pattern in Java
  3. Fish Pattern in Java
  4. Zig Zag Star and Number Pattern in Java
  5. Heart Pattern in Java
  6. Butterfly Pattern in Java
  7. Crown Pattern in Java
  8. Swastika Pattern in Java
  9. Christmas Tree Pattern in Java
  10. Java Program to Print Spiral Pattern
  11. Print Pencil Shape Pattern in Java

Java Conversion Programs

  1. Java Convert String to int
  2. Java Convert int to String
  3. Java Convert Binary to Decimal
  4. Java Convert int to char
  5. Java Convert Decimal to Binary
  6. Java Convert long to int
  7. Java long to String
  8. Convert Roman to Integer in Java
  9. Java Convert int to long
  10. Java Convert String to double
  11. Java Convert String to char
  12. Java Binary to Hexadecimal Conversion
  13. Java Convert Decimal to Octal
  14. Java String to Date
  15. Java Convert char to String
  16. Convert Integer to Roman Numerals in Java
  17. Convert IP to Binary in Java
  18. Program to convert Celsius into Fahrenheit
  19. Program to convert Fahrenheit into Celsius
  20. Java Convert int to double
  21. Java Convert Octal to Decimal
  22. Program to convert hours into minutes and seconds
  23. Program to Convert m to Feet and Inches
  24. Program to Convert Inches to cm
  25. Program to Convert cm to Feet and Inches
  26. Java Program Number to Word
  27. Java Convert Decimal to Hexadecimal
  28. Program to Convert Inches to meter
  29. Program to Convert Meter to Centimeter
  30. Java Convert boolean to String
  31. Program to Convert Feet to cm
  32. Program to Convert mm to cm
  33. Program to Convert millimeter to Feet
  34. Program to Convert Feet to m
  35. Java Convert char to int
  36. Java Convert double to int
  37. Program to Convert Feet to Inches
  38. Program to convert temperature degree from Celsius to Kelvin
  39. Java String to float
  40. How to convert byte array to String in Java
  41. Java Convert String to boolean
  42. Program to Convert Inches to Feet
  43. Java Hexadecimal to Binary Conversion
  44. Java Convert double to String
  45. How to convert String to String array in Java

Java Game Programs

  1. Tetris Game in Java
  2. Stone Game in Java
  3. Sudoku in Java
  4. FizzBuzz Program in Java
  5. Puzzle Game in Java
  6. Example of Pic Puzzle Game
  7. Tic Tac Toe Game in Java

File Handling programs

  1. How to Create a File in Java
  2. How to delete a file in Java
  3. How to Read CSV File in Java
  4. Java FileWriter Class
  5. Java File Extension
  6. Java FileReader Class
  7. How to Read Excel File in Java
  8. Java Program to find the number of the words in the given text file
  9. Java FileInputStream Class
  10. Copy Content/ Data From One File to Another in Java
  11. Java Get File Size
  12. Java Program to find the most repeated word in a text file
  13. Java - RandomAccessFile
  14. How to read file line by line in Java
  15. Read PDF File in Java
  16. How to Create Zip File in Java
  17. Java Program to find the most repeated word in a text file
  18. How to make an executable jar file in Java
  19. Java File Upload to a Folder
  20. Java Create Jar Files
  21. List All Files in a Directory in Java
  22. Zipping and Unzipping Files in Java
  23. Java SFTP | File Transfer Using SFTP in Java JSCH
  24. Example to retrieve file from Oracle database