Sunday, October 25, 2009

How to declare a varibale in java

The different type of variables are use to store data in different format.and they get different memory size to store data.as a example the int data type is made up with 4 bytes.and others get different sizes.
before the use a variable in java, you should declare it,
e.g. :-

type name [=value1], name [=value2] ...;

this example showing you how to declare int type variable in java,

public class A
{
public static void main(String args[])
{
int marks;
float balance;
String name;
}
}

after declare the variable you can assign value for that,



public class A
{
public static void main(String args[])
{
int marks;
float balance;
String name;

marks=80;
balance=4555.75;
name="madura";


}
}

you can declare variable and assign a value as follow,


public class A
{
public static void main(String args[])
{
int marks=80;
float balance=4555.75;
String name="madura";
}
}

No comments: