💻Step 5: Java datatypes- 2nd hour +code

Get this in action on Youtube-

Data TypePrimitive/Non-primitiveDescription
bytePrimitiveA 8-bit signed integer. Range: -128 to 127.
shortPrimitiveA 16-bit signed integer. Range: -32,768 to 32,767.
intPrimitiveA 32-bit signed integer. Range: -2,147,483,648 to 2,147,483,647.
longPrimitiveA 64-bit signed integer. Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
floatPrimitiveA single-precision 32-bit floating point.
doublePrimitiveA double-precision 64-bit floating point.
booleanPrimitiveA true or false value.
charPrimitiveA single 16-bit Unicode character. Range: 0 to 65,535.
StringNon-primitiveA sequence of characters. Non-primitive data type.
ArrayNon-primitiveA group of variables of the same type. Non-primitive data type.
ClassNon-primitiveA template for creating objects. Non-primitive data type.
InterfaceNon-primitiveA blueprint for a class. Non-primitive data type.
EnumNon-primitiveA special data type that represents a fixed number of predefined constants. Non-primitive data type.

1-Data Types in Java

💡Primitive Data type(predefined)

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

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

💡-String
💡-Arrays
💡-Classes

-etc

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


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);
}
}
Run this Program ▶️

2-Program to print size(in bytes) of all non-primitive  datatypes (Using Wrapper classes of primitives datatypes)


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);
}
}
Run this program▶️

3-Program to print size(in bits) of all non-primitive  datatypes (Using Wrapper classes of primitives datatypes)


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);
}
}
Run this program▶️

4-Program to print Maximum  and Minimum value of all non-primitive  datatypes (Using Wrapper classes of primitives datatypes)

Note – Wrapper Classes – Class created with same name as primitive datatype and consists all properties of primitive datatype.


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);
}
}
Run this program▶️

Interview Questions —

  • What does primitive mean?
  • What is wrapper class?

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *