English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java flow control

Java array

Java object-oriented (I)

Java object-oriented (II)

Java object-oriented (III)

Java Exception Handling

Java List

Java Queue (queue)

Java Map collection

Java Set collection

Java input/output (I/O)

Java Reader/Writer

Java other topics

Java Examples大全

The best way to learn Java programming is through example practice. This page contains examples of Java basic concepts. It is recommended that you refer to the references in these examples and try to use them yourself. All the programs on this page have been tested and should run on all platforms.


  1. Java programs to print an integer (input by the user)

  2. Java programs to add two integers

  3. Java programs to multiply two floating-point numbers

  4. Java programs to find the ASCII value of a character

  5. Java programs to calculate quotient and remainder

  6. Java programs to swap two numbers

  7. Java programs to check if a number is even or odd

  8. Java programs to check if a letter is a vowel or consonant

  9. Java programs to find the largest number among three

  10. Java programs to find all roots of a quadratic equation

  11. Java programs to check for leap years

  12. Java programs to check if a number is positive or negative

  13. Java programs to check if a character is a letter

  14. Java programs to calculate the sum of natural numbers

  15. Java programs to find the factorial of a number

  16. Java programs to generate a multiplication table

  17. Java programs to display the Fibonacci sequence

  18. Java programs to find the greatest common divisor of two numbers

  19. Java programs to find the least common multiple of two numbers

  20. Java programs to display characters from A to Z using a loop

  21. Java programs to calculate the number of digits in an integer

  22. Java programs to reverse a number

  23. Java programs to calculate the power of a number

  24. Java programs to check if a number is a palindrome

  25. Java programs to check if a number is prime

  26. Java programs to display prime numbers between two intervals

  27. Java programs to check Armstrong numbers

  28. Java programs to display Armstrong numbers between two intervals

  29. Java programs to display prime numbers between two intervals using a function

  30. Java programs to display Armstrong numbers between two intervals using a function

  31. Java programs to display the factors of a number

  32. Java programs to create a simple calculator using switch ... case

  33. Java programs to check if a number can be expressed as the sum of two prime numbers

  34. Java programs to find the sum of natural numbers using recursion

  35. Java programs to find the factorial of a number using recursion

  36. Java programs to find the greatest common divisor using recursion

  37. Java programs to implement binary to decimal conversion

  38. Java programs to implement octal to decimal conversion

  39. Java programs to implement binary to octal conversion

  40. Java programs to reverse a sentence using recursion

  41. Java programs to calculate powers using recursion

  42. Java programs to calculate the average using an array

  43. Java programs to find the maximum element in an array

  44. Java programs to calculate the standard deviation

  45. Java programs use multidimensional arrays to add two matrices

  46. Java programs use multidimensional arrays to multiply a matrix

  47. Java programs multiply two matrices by passing a matrix to a function

  48. Java program finds the transpose of a matrix

  49. Java program finds the number of occurrences of a character in a string

  50. Java program calculates the number of vowels and consonants in a sentence

  51. Java program sorts elements in dictionary order

  52. Java program adds two complex numbers by passing a class to a function

  53. Java program calculates the time difference between two time periods

  54. Java code creates pyramids and patterns

  55. Java program removes all spaces from a string

  56. Java program prints an array

  57. Java program converts a string to a date

  58. Java program rounds a number to n decimal places

  59. Java program merges two arrays

  60. Java program implements the conversion between a character and a string

  61. Java program checks if an array contains a given value

  62. Java program checks if a string is null or empty

  63. Java program gets the current date/Time

  64. Java program converts milliseconds to minutes and seconds

  65. Java program implements the addition of two dates

  66. Java Program to Merge Two Lists

  67. Java program converts an ArrayList to and from an array

  68. Java program gets the current working directory

  69. Java program converts a HashMap to a list

  70. Java program converts an array to and from a Set (HashSet)

  71. Java program converts a byte array to hexadecimal

  72. Java program creates a string based on file content

  73. Java program appends text to an existing file

  74. Java program converts a stack trace to a string

  75. Java program converts a file to and from a byte array

  76. Java program converts an InputStream to a string

  77. Java program converts an OutputStream to a string

  78. Java program finds an enum by string value

  79. Java program compares strings

  80. Java program sorts a map by value

  81. Java program sorts an ArrayList of custom objects by property

  82. Java program checks if a string is a number

  83. Java program creates a directory

  84. Java program renames a file

  85. Java program lists files in a directory

  86. Java program copies a file

  87. Java program converts a char type variable to int

  88. Java program converts an int type variable to char

  89. Java program converts a long type variable to int

  90. Java program converts an int type variable to long

  91. Java program converts a boolean variable to a string

  92. Java program converts a string type variable to a boolean value

  93. Java program converts a string type variable to int

  94. Java program converts an int type variable to String

  95. Java program converts an int type variable to double

  96. Java program converts a double precision type variable to int

  97. Java program converts a string variable to a double precision

  98. Java programs convert double-precision type variables to strings

  99. Java programs convert primitive types to objects and vice versa

  100. Java programs implement bubble sort algorithm

  101. Java programs implement quick sort algorithm

  102. Java programs implement merge sort algorithm

  103. Java programs implement binary search algorithm

  104. Java programs call one constructor from another

  105. Java programs implement private constructors

  106. Java programs pass lambda expressions as method parameters

  107. Java programs pass methods as parameters to other methods

  108. Java programs calculate the execution time of methods

  109. Java programs convert strings to InputStreams

  110. Java programs convert InputStreams to byte arrays

  111. Java programs load files as InputStreams

  112. Java programs create files and write to them

  113. Java programs read the content of a file line by line

  114. Java programs delete files

  115. Java programs delete empty and non-empty directories

  116. Java programs get the file extension

  117. Java programs get the filename from an absolute path

  118. Java programs get relative paths from two absolute paths

  119. Java programs count the number of lines in a file

  120. Java programs determine the class of an object

  121. Java programs create enumeration classes

  122. Java programs print the objects of a class

  123. Java programs create custom exceptions

  124. Java programs create an immutable class

  125. Java programs check if two strings are anagrams

  126. Java programs calculate all permutations and combinations of strings

  127. Java programs create random strings

  128. Java programs clear StringBuffer

  129. Java programs capitalize the first letter of each word in a string

  130. Java programs iterate over each character in a string.

  131. Java programs differentiate between the == operator and equals() method for strings

  132. Java programs implement switch statements on strings

  133. Java programs calculate simple and compound interest

  134. Java programs implement multiple inheritance

  135. Java programs get the name and version of the operating system

  136. Java programs check if two of the three boolean variables are true

  137. Java programs traverse enumerations

  138. Java programs check birthdays and print happy birthday messages

  139. Java programs implement LinkedList

  140. Java programs implement stack data structure

  141. Java programs implement queue data structure

  142. Java programs get the middle element of LinkedList in one pass

  143. Java programs convert LinkedList to and from arrays

  144. Java programs convert ArrayList to and from arrays

  145. Java programs convert ArrayList to and from strings

  146. Java programs traverse ArrayList

  147. Java programs traverse HashMap

  148. Java Program to Traverse Set Collection

  149. Java Program to Merge Two Lists

  150. Java Program to Update the Value in HashMap Using Key

  151. Java Program to Remove Duplicate Elements from ArrayList

  152. Java Program to Get a Key from HashMap Using Value

  153. Java Program to Detect a Loop in LinkedList

  154. Java Program to Calculate the Union of Two Sets

  155. Java Program to Calculate the Intersection of Two Sets

  156. Java Program to Calculate the Difference Between Two Sets

  157. Java Program to Check if a Set is a Subset of Another Set

  158. Java Program to Sort Map by Key

  159. Java Program to Pass ArrayList as a Function Parameter

  160. Java Program to Traverse ArrayList Using Lambda Expressions

  161. Java Program to Implement Binary Tree Data Structure

  162. Java Program to Perform a Pre-order Tree Traversal

  163. Java Program to Perform a Post-order Tree Traversal

  164. Java Program to Perform an In-order Tree Traversal

  165. Java Program to Calculate the Number of Leaf Nodes in a Tree

  166. Java Program to Check if a String Contains a Substring

  167. Java Program to Access Private Members of a Class

  168. Java Program to Check if a String is a Valid Reorganization of Two Strings

  169. Java Program to Implement Graph Data Structure