Java Variables and Datatype

A variable provide us with named storage that our program can process.
Each variable in java has a speciifc type, which determines the size and layout of the variables memory. The range of values that can be stored within that memory and the set of operations that can be applied to the variable name.

You must declaration all variable before that can be used.
Data_type variable = value;

To declare more than one variable of the specified type, you canuse a comma-seprated list.

int a,b,c;
// declares three ins a,b,c

int a=10,b=20;
// examples of initilizations

double pi=3.14;
// declares and assings value for pi

char a = 'a';
// that char variable is inilizations with the value 'a';

Constants: during the execution of program, value mmay change, A constant represents permanant data that never changes.

Data types: in Java data tyepes divided into two types: primitive and non-primitive

Primitive data types contains: integers, floats, characters, boolean
non-primitive contains: classes, interfaces, array

Integer: This group includes bytes, short, int and long which are whole signed numbers.

Floating points: This group includes float and double, which represents number with fraction precision.

Character:  This group includes cjar, which represent character set like letters and numbers.

Boolean: This include boolean, which is special type of representation of true or false value.

Some data types with their ranges and size:

byte: -128 to 127 (1 byte)

int: -32,768 to 32,767(4 byte) 

float: 3.4e-038 to 1.7e+0.38(4 bytes)

double: 3.4e-038 to 1.7e+308(8 bytes)

char:  holds only a single character(2 bytes)

boolean: can take only value true or false (1 bytes).

Comments

Popular posts from this blog

JAVA Features

Java Fundamentals