Java is a widely-used programming language for developing mobile applications, desktop applications, web applications, games, and more. Java makes it easy for programmers to create, compile, and debug programs. This section contains a wide range of Java programming examples from basic programs to very complex and advanced Java programs.
These Java programming examples are categorized as basic, array, numbers, math functions, string, classes, inheritance, event handling, exception handling, collections, methods, java applets, searching, Sorting, etc. We have also listed programs on data structure topics like trees, heaps, linked lists, hash tables, stacks, and queues. Each sample program includes a program description, Java code, and program output. All examples have been compiled and tested on Windows and Linux systems.
- Simple Java Programs
- Java Programs on Numbers
- Java Programs on Date, Time & Year
- Special Java Programs
- Factorial & Fibonacci Programs in Java
- Conversion Programs in Java
- Pattern Programs in Java
- Java Programs on Data Types & Operators
- Java Programs on Math Functions
- Java Programs on Progression Series
- Java Programs on Area and Volume
- Java Programs on GCD, LCM & HCF
- Java Programs on Array
- Java Programs on Matrix
- Java Programs on Bitwise Operation
- Java Programs on Strings
- Java Programs on Classes
- Java Programs on Object & Method
- Java Programs on Inheritance
- Java Programs on Exception Handling
- Java Programs on Event Handling
- Java Programs on Collections
- Java Applet Programs
Data Structures and Algorithms:
In addition to the above categories, the Java programming examples also include programs on data structures and algorithms. These programs cover a wide range of topics, such as trees, heaps, linked lists, hash tables, stacks, and queues.
- Data Structures in Java
- Java Algorithms
- Java Programming Examples on Searching
- Java Programming Examples on Sorting
- Java Programming Examples on Tree
Simple Java Programs
- Java Program to Check Whether a Given Number is Even or Odd
- Java Program to Find the Sum of Even and Odd Numbers
- Java Program to Check Whether a Number is Positive or Negative
- Java Program to Find the Largest Number Among Three Numbers
- Java Program to Swap Two Numbers
- Java Program to Find the Number of Integers Divisible by 5
- Java Program to Check if Two Numbers are Equal
- Java Program to Find Sum of Digits of a Number
- Java Program to Find Sum of Digits of a Number using Recursion
- Java Program to Extract Digits from a Given Number
- Java Program to Increment by 1 to all the Digits of a Given Integer
- Java Program to Perform Arithmetic Operations
- Java Program to Print Binary Equivalent of an Integer using Recursion
- Java Program to Print Multiplication Table
- Java Program to Read a Grade and Display the Equivalent Description
- Java Program to Check Whether a Character is a Vowel, Consonant or Digit
- Java Program to Check Whether a Given Alphabets are Uppercase or Lowercase or Digits
- Java Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average
Java Programming Examples on Numbers
- Java Program to Find Prime Numbers in a Given Range
- Java Program to Check Prime Number
- Java Program to Check whether a Number is Prime or Not using Recursion
- Java Program to Check Whether a Given Number is Perfect Number
- Java Program to Check Armstrong Number
- Java Program to Print Armstrong Number between 1 to 1000
- Java Program to Reverse a Number
- Java Program to Reverse a Number and Check if it is a Palindrome
- Java Program to Reverse a Number and Find its Sum using do-while Loop
- Java Program to Reverse a Number using Recursion
- Java Program to Reverse a Number without using Recursion
- Java Program to Print First N Natural Numbers using Recursion
- Java Program to Find Sum of Natural Numbers using Recursion
- Java Program to Find Sum of Natural Numbers using While Loop
- Java Program to Print 1 to 10 Numbers using For Loop
- Java Program to Print the First n Square Numbers
- Java Program to Find the Sum of n Square Numbers
- Java Program to Find the Sum of n Cube Numbers
Special Java Programs
- Java Program without using the Main() Function
- Java Program to Print Statement without Semicolon
- Java Program to Print Semicolon without using Semicolon
- Java Program to Display the ATM Transaction
- Java Program to Get IP Address
- Java Program to Illustrate how User Authentication is Done
- Java Program to Shutdown Computer in Linux
Conversion Programs in Java
- Java Program to Convert Binary to Decimal
- Java Program to Convert Binary to Hexadecimal
- Java Program to Convert Binary to Octal
- Java Program to Convert Binary to Gray Code using Recursion
- Java Program to Convert Binary to Gray Code without Recursion
- Java Program to Convert Octal to Binary
- Java Program to Convert Octal to Decimal
- Java Program to Convert Decimal to Binary, Octal and Hexadecimal
- Java Program to Convert Decimal to Binary using Recursion
- Java Program to Convert Hexadecimal to Binary
- Java Program to Convert Hexadecimal to Decimal
- Java Program to Convert Fahrenheit to Celsius
Java Programs on Data Types & Operators
- Java Program to Convert Integer Values into Binary
- Java Program to Convert Integer Values into Byte, Character, Float
- Java Program to Convert Long Values into Byte
- Java Binary Literals
- Java Program to use Underscores in Numeric Literal
- Java Program to Perform Arithmetic Operations
- Java Program to Perform Relational Operations
- Java Program to Illustrate Use of Various Boolean Operators
- Java Program to Find Largest of Three Numbers using Ternary Operator
- Java Program to Illustrate Use of Pre and Post Increment and Decrement Operators
Java Programming Examples on Math Functions
- Java Program to Add Two Complex Numbers
- Java Program to Find Power of a Number
- Java Program to Implement the pow() Function
- Java Program to Find Product of Two Numbers using Recursion
- Java Program to Implement the sin() Function
- Java Program to Implement the cos() Function
- Java Program to Find the Roots of a Quadratic Equation
- Java Program to Calculate Simple Interest
Java Programming Examples on Progression Series
- Java Program to Find Sum of Series 1^2 + 2^2 + …. + n^2.
- Java Program to Find Sum of the Series 1/1! + 2/2! + 3/3! + ……1/N!
- Java Program to Find Sum of the Series 1/1!+1/2!+1/3!+…1/N!
- Java Program to Find Sum of the Series 1/1+1/4+1/9+…1/N^2
- Java Program to Add the nth Square Series
- Java Program to Generate Harmonic Series
Java Programming Examples on Area and Volume
- Java Program to Find the Area of a Circle
- Java Program to Find the Area of a Triangle
- Java Program to Find the Area of Parallelogram
- Java Program to Find the Area of Rhombus
- Java Program to Find the Area of Trapezium
- Java Program to Find Volume and Surface Area of Cone
- Java Program to Find Volume and Surface Area of Cuboids
- Java Program to Find Volume and Surface Area of Sphere
- Java Program to Find the Perimeter of a Circle, Rectangle and Triangle
- Java Program to Find the Area and Perimeter of Rectangle using Class
Java Programming Examples on Array
- Java Program to Find the Number of Elements in an Array
- Java Program to Find Largest Element in an Array
- Java Program to Find Second Largest and Smallest Elements in an Array
- Java Program to Find Local Maxima in an Array
- Java Program to Remove Duplicate Elements from Array
- Java Program to Merge Two Arrays
- Java Program to Find Sum and Average of All Elements in an Array
- Java Program to Search Key Elements in an Array
- Java Program to Count the Number of Occurrence of an Element in an Array
- Java Program to Find Union and Intersection of Two Arrays
Java Programming Examples on Matrix
- Java Program to Multiply Two Matrices
- Java Program to Display Lower Triangular Matrix
- Java Program to Display Upper Triangular Matrix
- Java Program to Find the Sum and Product of Elements in a Row/Column
- Java Program to Find Transpose of a Matrix
- Java Program to Find the Determinant of a Matrix
- Java Program to Find Inverse of a Matrix
- Java Program to Check if a Matrix is a Sparse Matrix
Java Programs on Bitwise Operation
- Java Program to Perform Bitwise Operations
- Java Program to Perform Addition Operation using Bitwise Operators
- Java Program to Multiply Number by 4 using Bitwise Operators
- Java Program to Check if Bit Position is Set to One or not
- Java Program to Convert Decimal to Binary and Count the Number of 1s
- Java Program to Swap Two Numbers using Bitwise XOR Operation
- Java Program to Count Set Bits using Bitwise Operations
Java Programs on Strings
- Java Program to Concatenate Two Strings
- Java Program to Remove All Adjacent Duplicates from String
- Java Program to Reverse Each Word in a String
- Java Program to Find the Largest and Smallest Word in a String
- Java Program to Find the First non-repeated Character in a String
- Java Program to Count the Number of Unique Words
- Java Program to Check if a Given String is Palindrome
Java Programming Examples on Classes
- Java Program to Illustrate Use of Constructor
- Java Program to Illustrates Use of Chaining Constructor
- Java Program to Illustrate Use of Final Keyword
- Java Program to Illustrate the Use of HashCode() Method
- Java Program to Create a Method without Parameters and with Return Type
- Java Program to Check Whether Which One is Executed First, Static Block or the Static Method
Java Programs on Object & Method
- Java Program to Count Number of Objects Created for Class
- Java Program to Implement the Passing and Returning Objects
- Java Program to Show the Nesting of Methods
- Java Program to Calculate Sum of Two Byte Values using Type Casting
- Java Program to Find Area of Square, Rectangle and Circle using Method Overloading
Java Programs on Exception & String Handling
- Java Program to Handle the Exception Using Try and Multiple Catch Block
- Java Program to Handle the User Defined Exception using Throw Keyword
- Java Program to Illustrate Use of getChar() and split() Method
- Java Program to Illustrate Use of Split() String Method
- Java Program to Create and Use String Class Methods
Java Programs on Event Handling
- Java Program to Close the Frame using WindowAdapter Class
- Java Program to Draw a Line using GUI
- Java Program to Draw a Smiling Face using Graphics Class Methods
- Java Program to Display Several Dots on the Screen Continuously
- Java Program to Create a Color Dialog Box to Change the Background Color of Frame
- Java Program to Display a Message in a New Frame
- Java Program to Display Text in the Frame by using DrawString and Inheriting JPanel Class
- Java Program to Create Text Area and Password Field
- Java Program to Get and Set State and Get Label of a Check Box
- Java Program to Create a Menu and Menu Bar
Java Programs on Collections
- Java Program to Implement ArrayBlockingQueue API
- Java Program to Implement ArrayList API
- Java Program to Implement ConcurrentHashMap API
- Java Program to Implement ConcurrentLinkedQueue API
- Java Program to Implement EnumMap API
- Java Program to Implement HashTable API
- Java Program to Implement LinkedBlockingQueue API
- Java Program to Implement LinkedList API
- Java Program to Implement PriorityBlockingQueue API
- Java Program to Implement WeakHashMap API
Java Programs on Applet
- Java Program to Create a Basic Applet
- Java Program to Display a Pie Chart using Frame
- Java Program to Create a Transparent Cursor
- Java Program to Show the use of Methods of Vector Class
- Java Program to Show the use of Various Methods of URL Class
- Java Program to Check Whether Antialiasing is Enabled or Not
Java Programming Examples on Sorting
Conclusion:
This article provides a comprehensive collection of Java programming examples. The examples are categorized and well-organized, making it easy to find the examples you need. The examples are also well-written and easy to understand.