Welcome to a collection of Java Programs and Examples! In this article, you’ll find a variety of programming questions categorized as basic programs, control statements, arrays, strings, oops, and much more that are frequently asked in interviews and exams.
Each Java program will give you a different approach to solving a particular problem in Java. If you are new to Java programming, we highly recommend you to go through our article on Java tutorial, where we’ve covered all the basics and advanced topics of Java programming with practical examples and programs.
Java Topics:
Java Basic Programs
- Java Program to Read The Number From Standard Input
- Java Program to Get Input from the User
- Java Program to Multiply Two Floating-Point Numbers
- Java Program to Swap Two Numbers
- Java Program to Add Two Binary Strings
- Java Program to Add Two Complex numbers
- Java Program to Check Even or Odd Integers
- Java Program to Find Largest Among 3 Numbers
- Java Program to Find LCM of 2 numbers
- Java Program to Find GCD or HCF of 2 numbers
- Java Program to Display All Prime Numbers from 1 to N
- Java Program to Check Leap Year
- Java Program to Check Armstrong Number between Two Integers
- Java Program to Check whether the input number is a Neon Number
- Java Program to Check whether input character is vowel or consonant
- Java Program to Find Factorial of a number
- Java Program to Find Even Sum of Fibonacci Series Till number N
- Java Program to Calculate Simple Interest
- Java Program to Calculate Compound Interest
- Java Program to Find the Perimeter of a Rectangle
Java Pattern Programs
- Java Program to Print Right Triangle Star Pattern
- Java Program to Print Left Triangle Star Pattern
- Java Program to Print Pyramid Star Pattern
- Java Program to Print Reverse Pyramid Star Pattern
- Java Program to Print Upper Star Triangle Pattern
- Java Program to Print Mirror Upper Star Triangle Pattern
- Java Program to Print Downward Triangle Star Pattern
- Java Program to Print Mirror Lower Star Triangle Pattern
- Java Program to Print Star Pascal’s Triangle
- Java Program to Print Diamond Star Pattern
- Java Program to Print Square Star Pattern
- Java Program to Print Pyramid Star Pattern
- Java Program to Print Spiral Pattern of Numbers
Java Conversion Programs
- Java Program For Binary to Octal Conversion
- Java Program For Octal to Decimal Conversion
- Java Program For Decimal to Octal Conversion
- Java Program For Hexadecimal to Decimal Conversion
- Java Program For Decimal to Hexadecimal Conversion
- Java Program For Decimal to Binary Conversion
- Java Program For Binary to Decimal Conversion
- Java Program For Boolean to String Conversion
- Java Program For String to Double Conversion
- Java Program For Double to String Conversion
- Java Program For String to Long Conversion
- Java Program For Long to String Conversion
- Java Program For Int to Char Conversion
- Java Program For Char to Int Conversion
Java Classes and Object Programs
- Java Program to Create a Class and Object
- Java Program to Create Abstract Class
- Java Program to Create Singleton Class
- Java Program to Create an Interface
- Java Program to Show Encapsulation in Class
- Java Program to Show Inheritance in Class
- Java Program to Show Abstraction in Class
- Java Program to Show Data Hiding in Class
- Java Program to Show Polymorphism in Class
- Java Program to Show Overloading of Methods in Class
- Java Program to Show Overriding of Methods in Classes
- Java Program to Show Use of Super Keyword in Class
- Java Program to Show Use of This Keyword in Class
- Java Program to Show Usage of Static keyword in Class
- Java Program to Show Usage of Access Modifier
Java Methods Programs
- Java Program to Show Usage of Main() method
- Java Program to Show Use of Static and Non-static Methods
- Java Program to Show Usage of forEach() Method
- Java Program to Show Usage of toString() Method
- Java Program to Show Usage of codePointAt() Method
- Java Program to Show Usage of compare() Method
- Java Program to Show Usage of equals() Method
- Java Program to Show Usage of hasNext() and next() Method
- Thread Lifecycle Methods
Java Searching Programs
- Java Program For Linear Search
- Java Program For Binary Search
- Java Program to Recursively Linearly Search an Element in an Array
Java 1-D Array Programs
- Java Program to Search an Element in an Array
- Java Program to Find the Largest Element in an Array
- Java Program to Sort an Array
- Java Program to Sort the Elements of an Array in Descending Order
- Java Program to Sort the Elements of an Array in Ascending Order
- Java Program to Remove Duplicate Elements From an Array
- Java Program to Merge Two Arrays
- Java Program to Check if Two Arrays Are Equal or Not
- Java Program to Remove All Occurrences of an Element in an Array
- Java Program to Find Common Array Elements
- Java Program to Copy All the Elements of One Array to Another Array
- Java Program For Array Rotation
Java 2-D Arrays (Matrix) Programs
- Java Program to Print a 2D Array
- Java Program to Add Two Matrices
- Java Program to Sort the 2D Array Across Columns
- Java Program to Check Whether Two Matrices Are Equal or Not
- Java Program to Find the Transpose
- Java Program to Find the Determinant
- Java Program to Find the Normal and Trace
- Java Program to Print Boundary Elements of a Matrix
- Java Program to Rotate Matrix Elements
- Java Program to Compute the Sum of Diagonals of a Matrix
- Java Program to Interchange Elements of First and Last in a Matrix Across Rows
- Java Program to Interchange Elements of First and Last in a Matrix Across Columns
Java String Programs
- Java Program to Get a Character From the Given String
- Java Program to Replace a Character at a Specific Index
- Java Program to Reverse a String
- Java Program to Reverse a String Using Stacks
- Java Program to Sort a String
- Java Program to Swapping Pair of Characters
- Java Program to Check Whether the Given String is Pangram
- Java Program to Print first letter of each word using regex
- Java Program to Determine the Unicode Code Point at a given index
- Java Program to Remove leading zeros
- Java Program to Compare two strings
- Java Program to Compare two strings lexicographically
- Java Program to Print even length words
- Java Program to Insert a string into another string
- Java Program to Splitting into a number of sub-strings
Java List Programs
- Java Program to Initializing a List
- Java Program to Find a Sublist in a List
- Java Program to Get Minimum and Maximum From a List
- Java Program to Split a list into Two Halves
- Java Program to Remove a Sublist from a List
- Java Program to Remove Duplicates from an Array List
- Java Program to Remove Null from a List container
- Java Program to Sort Array list in an Ascending Order
- Java Program to Get First and Last Elements from an Array List
- Java Program to Convert a List of String to Comma Separated String
- Java Program to Add Element at First and Last Position of a Linked list
- Java Program to Find Common Elements in Two ArrayList
- Java Program to Remove Repeated Element From An ArrayList
Java Date and Time Programs
- Java Program to Format time in AM-PM format
- Java Program to Display Dates of Calendar Year in Different Format
- Java Program to Display current date and time
- Java Program to Display time in different country’s format
- Java Program to Convert the local Time to GMT
Java File Programs
- Java Program to Create a new file
- Java Program to Create a temporary file
- Java Program to Write into a file
- Java Program to Rename a file in java
- Java Program to Make a File Read-Only
- Java Program to Compare Paths of Two files
- Java Program to Copy one file into another file
- Java Program to Print all the Pattern that Matches Given Pattern From a File
- Java Program to Append a String in an Existing File
- Java Program to Read content from one file and writing it into another file
- Java Program to Read and printing all files from a zip file
Java Directory Programs
- Java Program to Traverse in a directory
- Java Program to Get the size of a directory
- Java Program to Delete a directory
- Java Program to Create directories recursively
- Java Program to Search for a file in a directory
- Java Program to Find the current working directory
- Java Program to Display all the directories in a directory
Java Exceptions and Errors Programs
- Java Program to Show Runtime exceptions
- Java Program to Show Types of errors
- Java Program to Handle the Exception Hierarchies
- Java Program to Handle the Exception Methods
- Java program to Handle the Checked exceptions
- Java Program to Handle the Unchecked Exceptions
- Java Program to Handle Divide By Zero and Multiple Exceptions
- Java Program to Show Unreachable Code Error
- Java Program to Show Thread interface and memory consistency errors
Java Collections Programs
- Java Program to Use Different Types of a Collection
- Java Program to Print a Collection
- Java Program to Compare Elements in a Collection
- Java Program to Get the Size of the Collection
- Java Program to Compare Elements in a Collection
- Java Program to Shuffle the Elements of a Collection
- Java Program to Reverse a Collection
- Java Program to Convert Collection into Array
- Java Program to Convert Array into Collection
- Java Program to Replace Elements in a List
- Java Program to Rotate Elements of a List
- Java Program to Iterate through Elements of HashMap
Java Multithreading Programs
- Java Program to Check the Thread Status
- Java Program to Suspend a Thread
- Java Program to Join Threads
- Java Program to Show Daemon Thread
Java More Java Programs
- Java Program to Print Fibonacci Series in Different Ways
- Java Program to Convert Linked list to an Array
- Java Program to Convert Vector to a List
- Java Program to Convert String to a List of Characters
- Java Program to Convert Iterator to a List
- Java Program to Convert List to a Map
- Java Program to Convert List to a Stream
- Java Program to Convert List to Set
- Java Program to Convert InputStream to String
- Java Program to Convert Set of String to Array of String
- Java Program to Convert String to Object
- Java Program to Convert string value to byte value
Also, check: