DataTypes

Datatype is used to determine the kind of data that is. going to be stored in the variable. The data can be classified mainly as Primitive/Build In Datatypes, and User Defined Datatypes.

Primitive Datatypes are referring the following set of datatypes

INT – Integer

The int data type can have values from -231 to 231-1(32-bit signed two’s complement integer).The range might different as well on the version of Java. The latest the Java, the range will increase a little bit more address unsigned integer range. The implementation of using the int. – Integer datatype is as follow

class Main {
  public static void main(String[] args) {
    	
    int range = -4250000;
    System.out.println(range);  // print -4250000
  }
}

Figure 1.1 – Integer Variable Declaration And initialization

SHORT – Integer

The short data type in Java can have values from -32768 to 32767(16-bit signed two’s complement integer). the implementation of the short integer is as follow

class Main {
  public static void main(String[] args) {
    	
    short temperature;
    temperature = -200;
    System.out.println(temperature);  // prints -200
  }
}

Figure 1.2 – Short Integer Variable Declaration And initialization

LONG – Integer

The long data type can have values from -263 to 263-1 (64-bit signed two’s complement integer). The implementation of the Long integer will be as follow

class LongExample {
  public static void main(String[] args) {
    	
    long range = -42332200000L;
    System.out.println(range);    // prints -42332200000
  }
}

Figure 1.3 – Long Integer Variable Declaration And initialization

Scroll to Top