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 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 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 |
manisha says
i need some case studies on java programming
Alee says
A very beautiful and well suited website —–> beginnersbook.com ;-)
crystal says
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”);
}
}
Quirkygeek says
A function doesn’t contain a main method
pratham programmer says
your s should not be small in the statement “system. out. print…” . It should be capital S
Arpita Mandal says
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!!
Shravya says
} bracket error
Last } bracket are required
Shweta says
You can’t pass any argument in main method
Vamshi Krishna says
actually we can, they’re called as “command line arguments”
Ram panwar says
Yes we can pass argument in main function using command line argument..as a string
Deepak Kumar says
You can pass arguments in main method but only as String…..
priya says
public static void main(String []args) will come instead of public Static void main(int age)
Isuru Harischandra says
“int age” should be “String[] args” / “String args[]” / “String[] arg” / “String arg[]”
Mohit Tyagi says
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.
geojeet tom says
haven’t put the third closed curly brackets
sudhan says
Give System.out.print
And close curly braces at end
Bhanu pratap singh yadav says
main function arguments are (String[] args)
Travis says
best java tutorial examples ever
Sindhu says
This page is awesome For beginners…it is very helpful…give me example programs which will be useful for real time projects
Sheldon says
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?
Anil says
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:
deepika says
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.
Nikhil Satpute says
# 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
elham says
How to convert char to numeric value
Arash says
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)
Chaitanya Singh says
You can refer this article: Java char to int conversion.
Priyanka says
Chaitanya , your posts are awesome 😊
Muqtasid khan says
Write a program to accept the length of and breath of a rectangle using scanner class and display its area and perimeter
anisha garg says
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.
gausmohammad says
please add more programs like matrix all operation and no. of time vowels occurrence in a string
Spandan says
54321
4321
321
21
1 Write the structure of the program using for loop
DWAIPAYAN DUTTA says
X!/10+(X+2)!/15+(X+4)!/20+………n plz solve this.
GESII LEIBOR says
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.
Siva kumar Nebarti says
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
Chaitanya Singh says
I will upload these programs soon.
Sachintha says
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.
Mohit Saini says
Very Well explained examples….. exact answers that are asked in interviews
Sujith says
Program for password it must contain one upper case and lower case and number and size of password 8-15
Anto says
What “System.out.println(“”)” means?
Please reply
Rakesh Gurung says
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