0% found this document useful (0 votes)
29 views5 pages

Data Types

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

Data Types

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

There are two types DataType:

1) primitive dataType.

2) Non Primitive dataType.

Primitive DataType:

byte
short
int
long

float
double
char
boolean

1) primitive dataType.

1) byte

Example :

package primitiveDataTypes;

public class ByteDemo {

public static void main(String[] args) {

// range -128 to 127

byte b = 90;
System.out.println(b);

byte b1 = -128;
System.out.println(b1);

byte b2 = 127;
System.out.println(b2);

// byte b3=128;

// byte b4=-129;

}
}

2)short .

Example :

package primitiveDataTypes;

public class ShortDataType {


public static void main(String[] args) {
// range = -32768 to 32767

short s = 3456;
System.out.println(s);

short s1 = -32768;
System.out.println(s1);

short s2 = 32767;
System.out.println(s2);

// short s3=-32769;
// short s5=32768;

}
}

3) int .

Example :

package primitiveDataTypes;

public class IntDemo {

public static void main(String[] args) {

// range = -2147483648 to 2147483647

int i = 5686769;
System.out.println(i);

int i1 = -2147483648;
System.out.println(i1);

int i2 = 2147483647;
System.out.println(i2);

// int i3 = 2147483649;

// int i4 = -2147483649;

}
}

4) long .

Example :

package primitiveDataTypes;

public class LongDemo {

public static void main(String[] args) {


// range = -9223372036854775808 to 9223372036854775807

long l = 457777878787987L;
System.out.println(l);

long l1 = -9223372036854775808L;
System.out.println(l1);

long l2 = 9223372036854775807L;
System.out.println(l2);

// long l3 = 9223372036854775808L;

// long l4 = -9223372036854775809L;
}

5)float .

package primitiveDataTypes;

public class FloatDemo {

public static void main(String[] args) {

float f = 123.89f;
System.out.println(f);

float f1=234.151577F;
System.out.println(f1);
}
}

6)double

package primitiveDataTypes;

public class DoubleDemo {

public static void main(String[] args) {

double d = 8978.937D;
System.out.println(d);
double d1=7567789748975898398d;
System.out.println(d1);
}
}

7)boolean

package primitiveDataTypes;

public class BooleanDemo {


public static void main(String[] args) {

boolean b = true;
System.out.println(b);

boolean b1 = false;
System.out.println(b1);

}
}

8) char

package primitiveDataTypes;

public class CharDemo {

public static void main(String[] args) {

char c='s';
System.out.println(c);

char c1='D';
System.out.println(c1);

}
}

9)String

package nonprimitiveDataTypes;

public class StringDemo {

public static void main(String[] args) {

String s="Santosh";
System.out.println(s);
}
}

default valus of dataTypes:

package defaultvaluesofDataType;

public class DefaultDemo {

static byte b;
static short s;
static int i;
static long l;
static float f;
static double d;
static char c;
static boolean b1;
static String s1;

public static void main(String[] args) {

System.out.println(b);
System.out.println(s);
System.out.println(i);
System.out.println(l);
System.out.println(f);
System.out.println(d);
System.out.println(c);
System.out.println(b1);
System.out.println(s1);
}
}

You might also like