//Datatype:-
- //Datatype are used to represent type of data or information which are going to use in our java program.
- //in java it is mandatory to declare datatype before declaration of variable.
- //in java datatypes are classified into two types.
- //1.Primitive Datatype
- //2.Non Primitive Datatype
//Primitive Datatype:
- //It is language Defined datatypes
- //Memory size of primitive datatypes are fixed
- //all the primitive datatypes are keyword.
- //Keyword start with Lower cases.
- //there are 8 types of primitive datatypes.
=======================================================================
//Program I:-
package datatypes;
public class PrimitiveDatatypes
{
public static void main(String[] args)
{
//use
for (Numeric + Non Decimal)
byte a=123;
short b=12345;
int c=1234567890;
long d=1234567890;
//use
for (Numeric + Decimal)
float e=1.123456789f;
double f=1.123456789123456789;
//use
for character
char g='R';
//use
for conditional
boolean h=false;
System.out.println("byte = "+a);
System.out.println("short = "+b);
System.out.println("int = "+c);
System.out.println("long = "+d);
System.out.println("float = "+e);
System.out.println("double = "+f);
System.out.println("char = "+g);
System.out.println("boolean = "+h);
}
}
//Output:-
byte =
123
short =
12345
int =
1234567890
long =
1234567890
float =
1.1234568
double =
1.1234567891234568
char = R
boolean = false
=======================================================================//Non Primitive Datatype:
- //It is User Defined datatypes
- //Memory size of primitive datatypes are Not fixed
- //all the primitive datatypes are Identifire.
- //Identifire start with Upper cases.
- //there are 2 types of primitive datatypes.
- //e.g. String, Class.
//String:-
- //It is non Primitive Datatype.
- //If you want to store combination of multiple characters, digit, fraction numbrs, special characters then that type of information we have to store in String Datatype with Double inverted commas.
- //String name="Sambhaji";
=======================================================================
//Program II:-
package datatypes;
public class NonPrimitiveDatatype
{
{
String name="Sambhaji";
System.out.println("My Name is "+name);
}
}
//Output:-
My Name is Sambhaji
=======================================================================
0 Comments