Java Examples

The best way to learn any programming language is by practicing examples on your own.

This page contains examples on basic concepts of Java programming like: loops, functions, classes, etc.

All programs in this page are tested and verified.

Feel free to use the source code on your system.

Popular examples:

Java Program to Print an Integer (Entered by the User)
Java Program to Add Two Integers
Java Program to Multiply two Floating Point Numbers
Java Program to Find ASCII Value of a character
Java Program to Compute Quotient and Remainder
Java Program to Swap Two Numbers
Java Program to Check Whether a Number is Even or Odd
Java Program to Check Whether an Alphabet is Vowel or Consonant
Java Program to Find the Largest Among Three Numbers
Java Program to Find all Roots of a Quadratic Equation
Java Program to Check Leap Year
Java Program to Check Whether a Number is Positive or Negative
Java Program to Check Whether a Character is Alphabet or Not
Java Program to Calculate the Sum of Natural Numbers
Java Program to Find Factorial of a Number
Java Program to Generate Multiplication Table
Java Program to Display Fibonacci Series
Java Program to Find GCD of two Numbers
Java Program to Find LCM of two Numbers
Java Program to Display Characters from A to Z using loop
Java Program to Count Number of Digits in an Integer
Java Program to Reverse a Number
Java Program to Calculate the Power of a Number
Java Program to Check Whether a Number is Palindrome or Not
Java Program to Check Whether a Number is Prime or Not
Java Program to Display Prime Numbers Between Two Intervals
Java Program to Check Armstrong Number
Java Program to Display Armstrong Number Between Two Intervals
Java Program to Display Prime Numbers Between Intervals Using Function
Java Program to Display Armstrong Numbers Between Intervals Using Function
Java Program to Display Factors of a Number
Java Program to Make a Simple Calculator Using switch...case
Java Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
Java Program to Find the Sum of Natural Numbers using Recursion
Java Program to Find Factorial of a Number Using Recursion
Java Program to Find G.C.D Using Recursion
Java Program to Convert Binary Number to Decimal and vice-versa
Java Program to Convert Octal Number to Decimal and vice-versa
Java Program to Convert Binary Number to Octal and vice-versa
Java Program to Reverse a Sentence Using Recursion
Java Program to calculate the power using recursion
Java Program to Calculate Average Using Arrays
Java Program to Find Largest Element of an Array
Java Program to Calculate Standard Deviation
Java Program to Add Two Matrix Using Multi-dimensional Arrays
Java Program to Multiply to Matrix Using Multi-dimensional Arrays
Java Program to Multiply two Matrices by Passing Matrix to a Function
Java Program to Find Transpose of a Matrix
Java Program to Find the Frequency of Character in a String
Java Program to Count the Number of Vowels and Consonants in a Sentence
Java Program to Sort Elements in Lexicographical Order (Dictionary Order)
Java Program to Add Two Complex Numbers by Passing Class to a Function
Java Program to Calculate Difference Between Two Time Periods
Java Code To Create Pyramid and Pattern
Java Program to Remove All Whitespaces from a String
Java Program to Print an Array
Java Program to Convert String to Date
Java Program to Round a Number to n Decimal Places
Java Program to Concatenate Two Arrays
Java Program to Convert Character to String and Vice-Versa
Java Program to Check if An Array Contains a Given Value
Java Program to Check if a String is Empty or Null
Java Program to Get Current Date/TIme
Java Program to Convert Milliseconds to Minutes and Seconds
Java Program to Add Two Dates
Java Program to Join Two Lists
Java Program to Convert List (ArrayList) to Array and Vice-Versa
Java Program to Get Current Working Directory
Java Program to Convert Map (HashMap) to List
Java Program to Convert Array to Set (HashSet) and Vice-Versa
Java Program to Convert Byte Array to Hexadecimal
Java Program to Create String from Contents of a File
Java Program to Append Text to an Existing File
Java Program to Convert a Stack Trace to a String
Java Program to Convert File to byte array and Vice-Versa
Java Program to Convert InputStream to String
Java Program to Convert OutputStream to String
Java Program to Lookup enum by String value
Java Program to Compare Strings
Java Program to Sort a Map By Values
Java Program to Sort ArrayList of Custom Objects By Property
Java Program to Check if a String is Numeric