beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
    • Learn jQuery
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Java Programs – Java Programming Examples with Output

By Chaitanya Singh | Filed Under: Java Examples

To understand a programming language you must practice the programs, this way you can learn the language faster. This page includes java programs on various java topics such as control statements, loops, classes & objects, functions, arrays etc. All the programs are tested and provided with the output. If you new to java and want to learn java before trying out these program, then read my Core Java Tutorials.

Java Programs

Java Basic Programs
Java Program to Add two Numbers
Java Program to Check Even or Odd Number
Java Program to add two binary numbers
Java Program to add two complex numbers
Java Program to Multiply two Numbers
Java Program to check Leap Year
Java Program to check whether input character is vowel or consonant
Java Program to calculate compound interest
Java Program to calculate simple interest
Java Program to find quotient and remainder
Java Program to calculate power of a number
Java Strings Programs
Java Program to Convert char to String and String to Char
Java Program to find duplicate characters in a String
Java Program to check Palindrome String using Stack, Queue, For and While loop
Java Program to sort strings in alphabetical order
Java Program to reverse words in a String
Java Program to perform bubble sort on Strings
Java program to find occurrence of a character in a String
Java program to count vowels and consonants in a String
Java Arrays Programs
Java Program to Calculate average of numbers using Array
Java Program to Add the elements of an Array
Java Program to reverse an array
Java Program to sort an array in ascending order
Java Program to convert char Array to String
Java Program to Add Two Matrix Using Multi-dimensional Arrays
Java Recursion Programs
Java Program to Reverse a number using for, while loop and recursion
Java Program to check Palindrome string using Recursion
Java Program to Reverse a String using Recursion
Java Program to find Factorial of a number using Recursion
Java Programs on Numbers
Java Program to display first 100 prime numbers
Java Program to display prime numbers between 1 and 100 or 1 and n
Java program to break integer into digits
Java Program to check Prime Number
Java Program to check if a given number is perfect square
Java Program to find square root of a number without sqrt method
Java Program to print Armstrong numbers between a given range
Java Program to Find Sum of Natural Numbers
Java Program to check if a number is Positive or Negative
Java Program to generate Random Number
Java Program to check Armstrong number
Java Program to find GCD of two numbers
Java Program to find Largest of three numbers
Java Program to swap two numbers using bitwise operator
Java Program to find smallest of three numbers using ternary operator
Java Program to find largest of three numbers using ternary operator
Java Program to display alternate prime numbers
Java Program to display even numbers from 1 to n or 1 to 100
Java Program to display odd numbers from 1 to n or 1 to 100
Java Program to Find average of 3 numbers
Java Program to Find HCF and LCM of Two Numbers
Peterson Number in Java
Sunny Number in Java
Tech Number in Java
Java Input/Output Programs
Java Program to read number from Standard Input
Java Program to Get IP Address
Java Program to get Input From User
Java Programs on Geometrical Calculations
Java Program to Calculate Area of Rectangle
Java Program to Calculate Area of Square
Java Program to Calculate the area of Triangle
Java Program to Calculate Area and Circumference of Circle
Java Sorting/Searching Programs
Java Program for bubble Sort Ascending or Descending Order
Java Program for Linear Search
Java Program for Binary Search
Java Program for Selection Sorting
Java Conversion Programs
Java Octal to Decimal conversion
Java Program to Convert Decimal to Octal
Java hexadecimal to decimal conversion
Java Program to convert decimal to hexadecimal
Java binary to octal conversion
Java String to boolean
Java program to convert boolean to String
Java int to char conversion
Java char to int conversion
Java char to string conversion
Java long to int conversion
Java int to long conversion
Java Program to Convert Decimal to Binary
Java Program to convert binary to Decimal
Java Program to find ASCII value of a character
Java program for String to int conversion
Java program to convert int to String
Java program for string to double conversion
Java program to convert double to String
Java program to convert String to long
Java program to convert long to String
Other Java Programs
Java Program to print Floyd’s triangle
Java program to print Pascal triangle
Java Program to display Fibonacci series using loops
Java Program to find Factorial using loops
Java Program to make a calculator using switch case
Java Program to Calculate grades of Student
Java Program to perform Arithmetic Operation using Method Overloading
Java Program to find Area of Geometric figures using method overloading

Comments

  1. manisha says

    December 6, 2017 at 11:39 AM

    i need some case studies on java programming

    Reply
  2. Alee says

    January 11, 2018 at 12:37 PM

    A very beautiful and well suited website —–> beginnersbook.com ;-)

    Reply
  3. crystal says

    February 18, 2018 at 4:12 PM

    what is the error in this program

    class p3
    {
    public static void main(int age)
    {
    if(age>=18)
    {
    system.out.println(“eligible for election”);
    }
    else
    {
    system.out.println(“not eligible for election”);
    }
    }

    Reply
    • Quirkygeek says

      November 3, 2018 at 2:15 PM

      A function doesn’t contain a main method

      Reply
    • pratham programmer says

      November 11, 2018 at 2:22 PM

      your s should not be small in the statement “system. out. print…” . It should be capital S

      Reply
    • Arpita Mandal says

      November 21, 2018 at 9:35 AM

      Hey..there is a syntax error in your program!

      The “s” of “system” must be in caps…that is,
      It should be —
      System.out.println(“eligible…”);

      I hope it helps!!

      Reply
    • Shravya says

      December 9, 2018 at 6:01 AM

      } bracket error
      Last } bracket are required

      Reply
    • Shweta says

      December 20, 2018 at 3:54 AM

      You can’t pass any argument in main method

      Reply
      • Vamshi Krishna says

        July 28, 2019 at 5:42 AM

        actually we can, they’re called as “command line arguments”

        Reply
      • Ram panwar says

        September 10, 2019 at 3:33 PM

        Yes we can pass argument in main function using command line argument..as a string

        Reply
      • Deepak Kumar says

        May 11, 2020 at 1:59 AM

        You can pass arguments in main method but only as String…..

        Reply
    • priya says

      December 26, 2018 at 9:55 AM

      public static void main(String []args) will come instead of public Static void main(int age)

      Reply
    • Isuru Harischandra says

      December 18, 2019 at 9:19 AM

      “int age” should be “String[] args” / “String args[]” / “String[] arg” / “String arg[]”

      Reply
    • Mohit Tyagi says

      June 25, 2020 at 5:27 AM

      Four mistakes:

      1. main method should have String []args as arguments instead of age. Use public static void main(String args[])
      2. age should be declared as a variable before using. Use int age=10;
      3. System.out.println instead of system.out.println.
      4.Closing bracket fro class p3 missing. Use } at last.

      Reply
    • geojeet tom says

      September 30, 2021 at 12:13 PM

      haven’t put the third closed curly brackets

      Reply
    • sudhan says

      October 29, 2021 at 12:16 PM

      Give System.out.print
      And close curly braces at end

      Reply
    • Bhanu pratap singh yadav says

      January 31, 2022 at 10:28 AM

      main function arguments are (String[] args)

      Reply
  4. Travis says

    April 19, 2018 at 7:49 PM

    best java tutorial examples ever

    Reply
  5. Sindhu says

    May 5, 2018 at 7:37 AM

    This page is awesome For beginners…it is very helpful…give me example programs which will be useful for real time projects

    Reply
  6. Sheldon says

    May 8, 2018 at 1:04 AM

    How can I take an array for example five separate words and place them on separate lines evenly using astericks to make up the number on both ends in relation to the number entered by the user? Is a program to do this possible?

    Reply
  7. Anil says

    August 8, 2018 at 5:42 AM

    console application that receives any size of matrix and one parameter which is the Manhattan distance, this is K.

    The result should be Yes/No. Yes if there are any two similar items (integers) in the matrix that are in a distance of K from each other or less.

    Input: 1. Number of rows. 2. Matrix rows one line after the other in a new line between each matrix line. 3. K value. Output YES/NO Here is a sample for an input and output:

    Reply
  8. deepika says

    August 21, 2018 at 6:19 AM

    can you kindly provide program for the following
    java a program to create an array of 10 integers. Accept values from the user in that array. Input another number from the user and find out how many numbers are equal to the number passed, how many are greater and how many are less than the number passed.

    Reply
  9. Nikhil Satpute says

    August 31, 2018 at 3:07 PM

    # Suppose 450 is 3 digit number ….So 3 is its digit length. In that way calculate 5 digit random number ….do not run by using range ….get random number using length itself

    Reply
  10. elham says

    August 31, 2018 at 11:35 PM

    How to convert char to numeric value

    Reply
    • Arash says

      October 31, 2018 at 3:32 PM

      first U convert char to String with the method String s = String.valueof(char c), after this U convert String to numeric num like integer with Integer.parseint(String s)

      Reply
    • Chaitanya Singh says

      April 9, 2019 at 11:33 AM

      You can refer this article: Java char to int conversion.

      Reply
      • Priyanka says

        July 19, 2020 at 9:36 AM

        Chaitanya , your posts are awesome 😊

        Reply
  11. Muqtasid khan says

    September 2, 2018 at 2:03 PM

    Write a program to accept the length of and breath of a rectangle using scanner class and display its area and perimeter

    Reply
  12. anisha garg says

    December 5, 2018 at 3:42 PM

    can you please write a code on below question of complex number ??

    Print the sum, difference and product of two complex numbers by creating a class named ‘Complex’ with separate methods for each operation whose real and imaginary parts are entered by user.

    Reply
  13. gausmohammad says

    December 17, 2018 at 2:51 AM

    please add more programs like matrix all operation and no. of time vowels occurrence in a string

    Reply
  14. Spandan says

    December 17, 2018 at 1:23 PM

    54321
    4321
    321
    21
    1 Write the structure of the program using for loop

    Reply
  15. DWAIPAYAN DUTTA says

    January 30, 2019 at 3:18 PM

    X!/10+(X+2)!/15+(X+4)!/20+………n plz solve this.

    Reply
  16. GESII LEIBOR says

    February 6, 2019 at 2:24 PM

    Write java program to find if a name exists in a list of names.The program should display how many times the name occurs in the list.The program should have at least two instance methods.

    Reply
  17. Siva kumar Nebarti says

    September 20, 2019 at 3:42 PM

    Hi where can i get real time example programs such as
    1 find out the no of persons in a room
    2 Find the electricity bill for one month

    Reply
    • Chaitanya Singh says

      July 20, 2020 at 1:31 PM

      I will upload these programs soon.

      Reply
  18. Sachintha says

    September 20, 2019 at 5:17 PM

    I am new to java and I hope this beginnersbook.com would be very helpful to me. I am gonna start learning Java. Thank you very much.

    Reply
  19. Mohit Saini says

    September 30, 2019 at 12:20 AM

    Very Well explained examples….. exact answers that are asked in interviews

    Reply
  20. Sujith says

    December 18, 2019 at 5:34 PM

    Program for password it must contain one upper case and lower case and number and size of password 8-15

    Reply
  21. Anto says

    April 22, 2020 at 1:44 PM

    What “System.out.println(“”)” means?

    Please reply

    Reply
    • Rakesh Gurung says

      October 24, 2021 at 10:39 AM

      If we type
      System.out.println(“This is java”);
      This will display the output :This is java
      where as if you are taking about just the statement
      System.out.println(“”);
      Then it will print the blank or space in console

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Programs

  • C Programs
  • Java Programs

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap