facebook

Wednesday, 8 January 2020

Step 4:Datatypes : 2nd Day +code

1-Data Types in Java

Primitive Data type(predefined)

-int
-short
-long
-float
-double
-char
-byte
-boolean

maxresdefault

Non-Primitive Data type (Referenced/Developer/User defined)-

-String
-Arrays
-Classes
-etc

datatypesinjava
1-Program to show declaration,instantiation, initialization of all primitive datatypes & non primitive String and then print their values.
declaration-assigning of name
instantiation-assigning memory
initialization-assigning values
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package dataype1;
 
public class Dt {
 
public static void main(String[] args) {
 
double d=137.98d;
float f=23.2f;
long l=997511632l;
int i=45;
char v='a';
short s=23;
byte b= 67;
boolean b1=true;
 
String s6="ngfgdgd  utuytuytb 76575";
 
System.out.println(d);
System.out.println(f);
System.out.println(l);
System.out.println(i);
System.out.println(v);
System.out.println(s);
System.out.println(b1);
System.out.println(s6);
}
}

2-Program to print size(in bytes) of all non-primitive  datatypes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package dataype1;
 
public class Dt1 {
 
public static void main(String[] args) {
 
 System.out.println(Double.BYTES);
 System.out.println(Float.BYTES);
 System.out.println(Long.BYTES);
 System.out.println(Integer.BYTES);
 System.out.println(Character.BYTES);
 System.out.println(Short.BYTES);
 System.out.println(Byte.BYTES);
}
}
3-Program to print size(in bits) of all non-primitive  datatypes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package dataype1;
 
public class Dt2 {
 
public static void main(String[] args) {
 
 System.out.println(Double.SIZE);
 System.out.println(Float.SIZE);
 System.out.println(Long.SIZE);
 System.out.println(Integer.SIZE);
 System.out.println(Character.SIZE);
 System.out.println(Short.SIZE);
 System.out.println(Byte.SIZE);
}
}
4-Program to print Maximum  and Minimum value of all non-primitive  datatypes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package dataype1;
 
public class Dt3 {
 
public static void main(String[] args) {
 
System.out.println(Double.MAX_VALUE);
System.out.println(Float.MAX_VALUE);
System.out.println(Long.MAX_VALUE);
System.out.println(Integer.MAX_VALUE);
System.out.println(Character.MAX_VALUE+0);
System.out.println(Short.MAX_VALUE);
System.out.println(Byte.MAX_VALUE);
 
System.out.println(Double.MIN_VALUE); //
System.out.println(Float.MIN_VALUE);
System.out.println(Long.MIN_VALUE);
System.out.println(Integer.MIN_VALUE);
System.out.println(Character.MIN_VALUE+0);
System.out.println(Short.MIN_VALUE);
System.out.println(Byte.MIN_VALUE);
}
}