Java Tutorial

Java : Part 1

Hello CHF,
Just wanted to write a tutorial, Welcome to the world of Java.
So first of all,Java is an Object Oriented Programming Language and its one of the latest and greatest coding language out there ,So if you are a intersted,you have

come to the right place , Good luck in studying this language.

The Basics
Types of Java Programs

So basically there are 3 types of Java programs.

1st one is Assignment Method
2nd one is Bluej Method [WORKS ONLY IF YOU HAVE BLUEJ]
3rd one is Buffer Method.

Assignment Method
In assignment method,the value of variables are already initialized in the source code.So the program executes for the same value of the variable every time its

executed.If you need to change the variable,you have to edit the value of the variable by opening the Source code.


Bluej Method
In bluej method,the variables are initialized,but the values are not entered.During the execution of the program,a dialog box appears asking you for the values of the

variables.Like this :

[Image: bj-call-dlg-2.png]

Buffer Method
This is the latest and the best method out there.In this method,we enter the value of the variables after executing the program.So its easier for the user to give any

value for the variable.

So now we have covered all the types of Programs.
Now lets learn each of them in detail
First,Assignment method.It's the most basic method out there and is simple to do.
Before beginning lets see a program snippet :


Code:
class chf
{
public static void main(String args[])
{
int a,b,sum;
a=10;
b=5;
sum=a+b;
System.out.println("The sum of the numbers is :"+sum);
}
}
So lets start with the structure.The first line of the program is class declaration.The class is declared.It can be any name except some keywords and it must not have

spaces in between them .It cannot start with a number too .

The next line is having a { which is the class opening

The next line ,we declare the main function.Every program has this line.So learn it thoroughly.

Now we open the main function using another {

Now the variables are declared using the lines int a,b,c;
The variables are initialized as Integer type.You can use,double,float,long for various numbers and char and string for Entering characted and words.

In the next line the problem is executed .The sum of the variables is found using sum=a+b.

Every line must end with a ";" which is a line terminator.

Now we need to print the output on the screen.So we use the System.out.println command.

Anything inside the brackets ,within the "" is printed as such.I also added the sum at the end .

The class and the main function is closed by using two } in successive lines.

So this is a very basic program..Learn it thoroughly and work through it.
You can use * for multiplying , / for dividing etc.