The best way to learn Java programming is by practicing examples. The page contains examples on basic concepts of Java. You are advised to take the references from these examples and try them on your own.

All the programs on this page are tested and should work on all platforms.

Want to learn Java by writing code yourself? Enroll in our Interactive Java Course for FREE.

  1. Java Program to Print an Integer (Entered by the User)
  2. Java Program to Add Two Integers
  3. Java Program to Multiply two Floating Point Numbers
  4. Java Program to Find ASCII Value of a character
  5. Java Program to Compute Quotient and Remainder
  6. Java Program to Swap Two Numbers
  7. Java Program to Check Whether a Number is Even or Odd
  8. Java Program to Check Whether an Alphabet is Vowel or Consonant
  9. Java Program to Find the Largest Among Three Numbers
  10. Java Program to Find all Roots of a Quadratic Equation
  11. Java Program to Check Leap Year
  12. Java Program to Check Whether a Number is Positive or Negative
  13. Java Program to Check Whether a Character is Alphabet or Not
  14. Java Program to Calculate the Sum of Natural Numbers
  15. Java Program to Find Factorial of a Number
  16. Java Program to Generate Multiplication Table
  17. Java Program to Display Fibonacci Series
  18. Java Program to Find GCD of two Numbers
  19. Java Program to Find LCM of two Numbers
  20. Java Program to Display Alphabets (A to Z) using loop
  21. Java Program to Count Number of Digits in an Integer
  22. Java Program to Reverse a Number
  23. Java Program to Calculate the Power of a Number
  24. Java Program to Check Palindrome
  25. Java Program to Check Whether a Number is Prime or Not
  26. Java Program to Display Prime Numbers Between Two Intervals
  27. Java Program to Check Armstrong Number
  28. Java Program to Display Armstrong Number Between Two Intervals
  29. Java Program to Display Prime Numbers Between Intervals Using Function
  30. Java Program to Display Armstrong Numbers Between Intervals Using Function
  31. Java Program to Display Factors of a Number
  32. Java Program to Make a Simple Calculator Using switch...case
  33. Java Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
  34. Java Program to Find the Sum of Natural Numbers using Recursion
  35. Java Program to Find Factorial of a Number Using Recursion
  36. Java Program to Find G.C.D Using Recursion
  37. Java Program to Convert Binary Number to Decimal and vice-versa
  38. Java Program to Convert Octal Number to Decimal and vice-versa
  39. Java Program to Convert Binary Number to Octal and vice-versa
  40. Java Program to Reverse a Sentence Using Recursion
  41. Java Program to calculate the power using recursion
  42. Java Program to Calculate Average Using Arrays
  43. Java Program to Find Largest Element of an Array
  44. Java Program to Calculate Standard Deviation
  45. Java Program to Add Two Matrix Using Multi-dimensional Arrays
  46. Java Program to Multiply Two Matrix Using Multi-dimensional Arrays
  47. Java Program to Multiply two Matrices by Passing Matrix to a Function
  48. Java Program to Find Transpose of a Matrix
  49. Java Program to Find the Frequency of Character in a String
  50. Java Program to Count the Number of Vowels and Consonants in a Sentence
  51. Java Program to Sort Elements in Lexicographical Order (Dictionary Order)
  52. Java Program to Add Two Complex Numbers by Passing Class to a Function
  53. Java Program to Calculate Difference Between Two Time Periods
  54. Java Code To Create Pyramid and Pattern
  55. Java Program to Remove All Whitespaces from a String
  56. Java Program to Print an Array
  57. Java Program to Convert String to Date
  58. Java Program to Round a Number to n Decimal Places
  59. Java Program to Concatenate Two Arrays
  60. Java Program to Convert Character to String and Vice-Versa
  61. Java Program to Check if An Array Contains a Given Value
  62. Java Program to Check if a String is Empty or Null
  63. Java Program to Get Current Date/TIme
  64. Java Program to Convert Milliseconds to Minutes and Seconds
  65. Java Program to Add Two Dates
  66. Java Program to Join Two Lists
  67. Java Program to Convert a List to Array and Vice Versa
  68. Java Program to Get Current Working Directory
  69. Java Program to Convert Map (HashMap) to List
  70. Java Program to Convert Array to Set (HashSet) and Vice-Versa
  71. Java Program to Convert Byte Array to Hexadecimal
  72. Java Program to Create String from Contents of a File
  73. Java Program to Append Text to an Existing File
  74. Java Program to Convert a Stack Trace to a String
  75. Java Program to Convert File to byte array and Vice-Versa
  76. Java Program to Convert InputStream to String
  77. Java Program to Convert OutputStream to String
  78. Java Program to Lookup enum by String value
  79. Java Program to Compare Strings
  80. Java Program to Sort a Map By Values
  81. Java Program to Sort ArrayList of Custom Objects By Property
  82. Java Program to Check if a String is Numeric
  83. Java Program to convert char type variables to int
  84. Java Program to convert int type variables to char
  85. Java Program to convert long type variables into int
  86. Java Program to convert int type variables to long
  87. Java Program to convert boolean variables into string
  88. Java Program to convert string type variables into boolean
  89. Java Program to convert string type variables into int
  90. Java Program to convert int type variables to String
  91. Java Program to convert int type variables to double
  92. Java Program to convert double type variables to int
  93. Java Program to convert string variables to double
  94. Java Program to convert double type variables to string
  95. Java Program to convert primitive types to objects and vice versa
  96. Java Program to Implement Bubble Sort algorithm
  97. Java Program to Implement Quick Sort Algorithm
  98. Java Program to Implement Merge Sort Algorithm
  99. Java Program to Implement Binary Search Algorithm
  100. Java Program to Call One Constructor from another
  101. Java Program to implement private constructors
  102. Java Program to pass lambda expression as a method argument
  103. Java Program to pass method call as arguments to another method
  104. Java Program to Calculate the Execution Time of Methods
  105. Java Program to Convert a String into the InputStream
  106. Java Program to Convert the InputStream into Byte Array
  107. Java Program to Load File as InputStream
  108. Java Program to Create File and Write to the File
  109. Java Program to Read the Content of a File Line by Line
  110. Java Program to Delete File in Java
  111. Java Program to Delete Empty and Non-empty Directory
  112. Java Program to Get the File Extension
  113. Java Program to Get the name of the file from the absolute path
  114. Java Program to Get the relative path from two absolute paths
  115. Java Program to Count number of lines present in the file
  116. Java Program to Determine the class of an object
  117. Java Program to Create an enum class
  118. Java Program to Print object of a class
  119. Java Program to Create custom exception
  120. Java Program to Create an Immutable Class
  121. Java Program to Check if two strings are anagram
  122. Java Program to Compute all the permutations of the string
  123. Java Program to Create random strings
  124. Java Program to Clear the StringBuffer
  125. Java Program to Capitalize the first character of each word in a String
  126. Java Program to Iterate through each characters of the string.
  127. Java Program to Differentiate String == operator and equals() method
  128. Java Program to Implement switch statement on strings
  129. Java Program to Calculate simple interest and compound interest
  130. Java Program to Implement multiple inheritance
  131. Java Program to Determine the name and version of the operating system
  132. Java Program to Check if two of three boolean variables are true
  133. Java Program to Iterate over enum
  134. Java Program to Check the birthday and print Happy Birthday message
  135. Java Program to Implement LinkedList
  136. Java Program to Implement stack data structure
  137. Java Program to Implement the queue data structure
  138. Java Program to Get the middle element of LinkedList in a single iteration
  139. Java Program to Convert the LinkedList into an Array and vice versa
  140. Java Program to Convert the ArrayList into a string and vice versa
  141. Java Program to Iterate over an ArrayList
  142. Java Program to Iterate over a HashMap
  143. Java Program to Iterate over a Set
  144. Java Program to Merge two lists
  145. Java Program to Update value of HashMap using key
  146. Java Program to Remove duplicate elements from ArrayList
  147. Java Program to Get key from HashMap using the value
  148. Java Program to Detect loop in a LinkedList
  149. Java Program to Calculate union of two sets
  150. Java Program to Calculate the intersection of two sets
  151. Java Program to Calculate the difference between two sets
  152. Java Program to Check if a set is the subset of another set
  153. Java Program to Sort map by keys
  154. Java Program to Pass ArrayList as the function argument
  155. Java Program to Iterate over ArrayList using Lambda Expression
  156. Java Program to Implement Binary Tree Data Structure
  157. Java Program to Perform the preorder tree traversal
  158. Java Program to Perform the postorder tree traversal
  159. Java Program to Perform the inorder tree traversal
  160. Java Program to Count number of leaf nodes in a tree
  161. Java Program to Check if a string contains a substring
  162. Java Program to Access private members of a class
  163. Java Program to Check if a string is a valid shuffle of two distinct strings
  164. Java Program to Implement the graph data structure
  165. Java Program to Remove elements from the LinkedList.
  166. Java Program to Add elements to a LinkedList
  167. Java Program to Access elements from a LinkedList.