MY PROGRAMMING PARADISE
Variables:
Variables are used to store data in a computer’s memory. In other words, we can say, variables are just like a container that holds the value while the java program executed. There are three types of variables in java:
1- Local
2- Instance
3- Static
Rules for declaring identifier (Variable name)
1- All identifiers must begin with a letter, currency character, or underscore.
2- Blank spaces are not allowed.
3- An identifier name is case-sensitive.
4- A keyword cannot be used as an identifier.
Declaring variables:
byte age = 28;
short salary =32500;
float price = 25.50f;
char name = ‘v’;
boolean flag=true;
Data types:
There are two types of data types in java.
1- Primitive Data type
2- Non- primitive Data types
Primitive Data type:
There are mainly eight types of primitive data types:
Types | Size | Range | Default Value |
byte | 1 Byte | [-128, 127] | 0 |
short | 2 Byte | [-32,768 , 32,767] | 0 |
int | 4 Byte | [-231 , 231-1 ] | 0 |
long | 8 Byte | [-263 , 263-1] | 0 |
float | 4 Byte | [-] See Java Doc | 0.0f |
double | 8 Byte | [-]See Java Doc | 0.0d |
char | 2 Byte | [A, B, C…] | '\u0000' |
boolean | 1 Byte | [True, False] | False |
Non-Primitive Data type:
Non- Primitive data types refer to objects and hence they are called Reference Data types. Objects can be accessed through reference data types. Example of non-primitive data types includes String, Array, Classes, and Interface, etc.
Comments
Post a Comment