Basic Java Programs

Hi there , today i am going to show how to write basic programs in java?

Creating a source file:

Type the program in a notepad and save the file with the name that should match exactly the class name and with .java extension. Eg: HelloWorld.java

Compiling the source file:

Open command prompt and go to the directory where HelloWorld.java is located and type the command

The program will be compiled by javac compiler and HelloWorld.class file is created and ready to be executed.

Run the program:

Then type the command

This command will execute the class file and displays the output ‘Hello World’ .

Example Programs:
1.HelloWorld Program.

2.Fibonacci series:
What is Fibonacci series?
The first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. –
Write a java program to print fibonacci series?
Input: 10

3.Prime Number
What is prime number?
Prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers can’t be divided by other numbers than itself or 1. For example 2, 3, 5, 7, 11, 13, 17…. are the prime numbers.

4.Find Largest number Program

5.Palindrome number
What is Palindrome number ?
A palindrome number is a number that is same after reverse. For example 545, 151, 34543, 343, 171, 48984 are the palindrome numbers.

6.Factorial number
What is Factorial number?
Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!. For example:

Updated: September 29, 2016 — 2:48 pm

Leave a Reply

Your email address will not be published.

prabaweb.in Codelab- programming blog © 2017