Strongly typed language

Any type mismatches are errors should be corrected before compilation of the class.

Primitive Types or Simple Types

  • Integer: byte, short, long, int. all are signed, positive and negative values.

    byte- width is 8. used for a stream of data from network and which don't have specific type.

ex: byte b,c;

short- width is 16. it is the least used data type.

ex: short a,b;

int- width is 32. used in control loops and indexes.

ex: int a,b;

int a=1000;

long- width is 64. used for big data, whole numbers needed.

ex: long l,m;

long l=1235678890;

  • Floating-point numbers: float,double. these are the real numbers means in fractional numbers for example calculating area of circle etc.

    float- width is 32.it is a single precision value.

    ex: float f=3.14;

    double- width is 64. faster than single precision. used in sin(), sqrt(), cos() etc.

    ex: double d=3.1426.

  • Characters:char.width is 16-bit. no negative chars.

    //Example for character data type
        class Char_Example
        {
        public static void main(String args[])
        {
        char c=88;
    
        char a= 'Y';
        System.out.println("c value is::"+c);//X
        System.out.println("a value is::"+a);//Y
    
         c++; 
        System.out.println("after increment c value is::"+c);//Y
    
          a++;** \(Z\)**
         System.out.println("after increment a value is::"+a); //Z
      }
      }
    

Output::

c value is::X

a value is::Y

after increment c value is::Y

after increment a value is::Z

  • Boolean: boolean. width is 8-bit. used for logical values as true or false to control conditional statements like in if conditions.

results matching ""

    No results matching ""