·  JAVA – Syntax – Variables


- Info:

  - JAVA has 8 primitive types for storing variables of different type and length shown below in bold blue font.

  - Every other type of data in JAVA is Object.

  - There are no primitive types for storing strings.

    Instead they are stored in objects of classes String or StringBuffer.

  - Any decimal number written in code, like 123.56, is implicitly converted into double primitive type.

    This is why you have to excplicitly downcast them to smaller container like float.

  - Any integer number written in code, like 156, is implicitly converted into int primitive type.

    This is why you have to excplicitly downcast them to smaller containers like byte and short.


- Defining integer constants of different base:


  - Integer constants can be DIRECTLY defined only in decimal, octal or hexadecimal format but not in binary format:

    int value = 65  ;    //Decimal     value.

              = 0x41;    //Hexadecimal value.

              = 0101;    //Octal       value.


  - Binary constants, and all the other constants different from 10, 8 and 16 base can be defined like this:

    int value = Integer.parseInt("54");     //Decimal value since default base is 10.

        value = Integer.parseInt("11", 2);  //Use base two making it binary number: 1*2+1=3.

        value = Integer.parseInt("K0", 25); //Use base 25. F=15. FGHIJK=>K=20. 20*25=500.


- Primitive Types and String Containers:

  boolean        - true or false


  char           - 16-bit unicode character 


  byte           -  8-bit two's complement

  short          - 16-bit two's complement 

  int            - 32-bit two's complement 

  long           - 64-bit two's complement 


  float          - 32-bit IEEE 754

  double         - 64-bit IEEE 754


  String         - Class for storing constant strings.

  StringBuffer   - Class for storing dynamic strings.