How to add integers in java

This program will show to how to add intergers entered by user in command prompt..

For getting input number from user , java has builtin class Scanner in Util package

Package is set of related classes.

how to initiate Class for input

Scanner input = new Scanner(System.in)

After creating object of Scanner class , access  nextInt( ) method for getting input from user and assign that value to int variable.

int num1,num2,result ;
num1 = input.nextInt( ) ;
num2 = input.nextInt( );
result = num1 + num2;

after that output this result on console
here is code for adding numers

------------------------------------------------------------

import java.util.Scanner;
public class add_integers{

public static void main(String[] arg){

// scanner for input
Scanner input = new Scanner(System.in);
int num1;
int num2;
int result;

System.out.println("please enter number 1");
num1 = input.nextInt();
System.out.println("please enter number 2");
num2 = input.nextInt();

result = num1 + num2;

System.out.println("Addition is "+result);
       }

}

How to set enviroment variable for java in Windows XP/7

For  executing java program java program needs to be placed in bin folder .

But if you want to execute java program without placing it in bin folder of java you have to create the enviroment variable in windows..

For creating enviroment variables

Go to

My Computer  --> Properties ->Advanced -> Enviroment Variables --> System Variables

In system variables you will see value and variable

Here is variable which name is  Path

here append full path of java.

for append just place   ;  at end  and then paste java path

Ex : C:\Program Files\Java\jdk\bin

Ex :   java folder\bin

now close cmd   .. and  include your folder where java program is saved  and execute java prgram.



Say Hello to JAVA

Java is one of the most popular programming language . Java is 100% object oriented programming means in java every program must contain atleast one class.
Java contains very rich libraries which are called packages.

Today we will say Hello world to java.. So are you ready...

First go to oracle website and download the JDK.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

After downloading install JDK.

Now create a file name as Hello.java

here is hello word program code..


class Hello{
public static void main(String[ ] arg){
    System.out.println("Hello Java");

}

}


Now copy this file and paste in java bin folder.

now go to Run and  write cmd, then DOS will be open

in DOS set the path for bin file of java. Use the CD command for set the path
write command  cd\

cd :\ cd program files

cd:\ program files\cd java

cd:\ program files\java\cd bin

cd:\ program fies\java\bin

cd:\ program fies\java\bin/javac Hello.java  

cd:\ program fies\java\bin\java Hello





output

Hello Java