Mir se erdhët në xCoDeZz

United states of Albania

Krijo nje Llogari ose kyqu per te Vazhduar ne Forum

 A Noobs Guide To Java : Part #1 Login_10

Kyçu - Login

Emri Juaj:


Qëndro i identifikuar:

Nuk jeni ende anetar? Regjistrohu!

 A Noobs Guide To Java : Part #1 Welcom11

You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 A Noobs Guide To Java : Part #1 Empty A Noobs Guide To Java : Part #1 on Tue May 20, 2014 9:22 pm




Hello Zone-H,
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 noob,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 :
 A Noobs Guide To Java : Part #1 Bj-call-dlg-2

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 Smile

First,Assignment method.It's the most basic method out there and is simple to do.
Before beginning lets see a program snippet :


class chf
public static void main(String args[])
int a,b,sum;
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.

Buffer Method

In this method,the value of the variables are input while the program is executed.
So before learning this,you need to know a few things.
First we need to allow input and output statements.So we will use a line
"import java.io.*;" at the beginning of every program.
You also need to activate buffer by using a pair of lines


Input Stream Reader read =new Input Stream Reader (System.in);
Buffered Reader in=new buffered Reader (read);

Every program that needs buffer must have these lines to execute properly.
Now since the value is entered during execution,you wanna display something like "Enter the value of a and b"
So inorder to enter,first you need to initialize variables so that values can be entered into it.
Then for bringing a cursor so that values can be entered,You need to study another line :


a=integer.parseInt(in.readLine()); if its an integer
a=double.parseDouble(in.readLine()); if its double
a=in.read(); if its char
a=in.readLine()); if its String

So here is a quick program to find the sum of 2 numbers using buffer:


import java.io.*;
class sum
public static void main(String args[])
Input Stream Reader read =new Input Stream Reader (System.in);
Buffered Reader in=new buffered Reader (read);
int a,b,sum;
System.out.println("Enter two numbers");
System.out.println("The sum of numbers is : "+sum);

So in this program,the system will ask us to enter two numbers and proceed to do the rest.Bit more slick and awesome Smile

Mathematical Functions
Now we are going deep into program..We will be learning to use some functions.
Some of them are to find square root,rounding,etc
So if you need to find the square root of a number,say x, the syntax is :


For rounding it is :


These are just some commonly used commands.You can use math.max , math.min , math.pow (To raise to a power ) etc.


Next we are gonna learn loops
So first is the For Loop
A for loop consists of three parts.
Here is the syntax :



So the three parts are The initial value (i=4)
The test Condition (i=5)
The increment or decrement given by ++ or --
So first ,the system checks the initial value of i.In this case,its 1.Now the condition for the loop is checked which is whether i<5.
So if the condition is true,the statements inside the loop is executed.It can be anything ....
And after the loop execute 1 time,the value of i is increased by 1 since i++ is given which will increase i's value by 1.
The loop executes till the condition becomes false.In this case 4 times.
So for loop can be used to execute some commands a fixed number of times without needing to repeatedly type it 4 times Very Happy

So this will be the end of my small tutorial...Kinda big though.Will make another part for teaching more advanced stuffs...

Thanks for reading

Please don't copy this to other sites

Written by Zone-H

Please appreciate my efforts by commeting,giving reps,and sharing this post...

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum