knowledgediarybd.com

Your Virtual Knowledge Campus

Data Types and Variables

j2Data Types and Variables  are two important component in java programming. Variable that can assign some value & the data types which defines the type of the data like: integer,float,double.

Dear learner here, i will discuss various data types and variable of java programming that must be helpful  for your better experience.

Rules for variable name:

1.Variable names can’t start

with a number. You can have numbers elsewhere in the variable name, just not at the start. So “First_Number” is right bt “1st_Number” is wrong.
2. Variable names can’t be the same as java keywords.

3.You can’t have spaces in the variable name. So “First_Number”  is right but “First Number” is wrong.

4. Variable names are case sensitive. So kabir & Kabir are different variable names.

Data Type In java:

In java , data type is used to declare various types of data such as integer number, float number, character etc.There  are many data types in java. 

The basic data  types are :

1. int (Integer Like: 1,2,420…)

2. char( Character Like: a,b,X,Y…)

3. float (Floating point number Like: 3.1416)

4. double (Floating point number with high range Like:2.712356478952124)

Various Data types & their ranges:

Data Type
Size(bit)
Range(Inclusive)
byte
8
-128 to127
short
16
-32,768 to 32,767
int
32
-2,147,483,648 to 2,147,483,647
long
64
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float
32
3.4e−038 to 3.4e+038
double
64
1.7e−308 to 1.7e+038
boolean
1
Only “true/false”
char
16
0 to 65,535  (Unicode numbers)

Example of variable declaration:

package firstproject;

public class FirstProject

{

public static void main(String[] args)

        {

int first_number;

first_number = 21;

System.out.println(“First number = ” + first_number);

   }

}

For other data type declaration you’ve to change the int from the above code to your desired data types like long first_number;. You can have all the operations of variable like C/C++ in java.

Related Post or you may like:

knowledgediarybd.com © 2017
shares