Data Types In Java

In this page, We will learn about Data Types In Java | What is data Types in Java? | Primitive Data Types In Java | What is Primitive Data Types In Java? | What is Boolean Data Type? | What is Byte Data Type? | What is Short Data Type? | What is Int Data Type? | What is Float Data Type? | What is Long Data Type? | What is Float Data? | What is Double Data Type? | What is Char Data Type? |


What is data Types in Java?

Data types indicate the specific sizes and values that can be stored in the flexible. There are two variety of data variety in Java programming:

  • Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.
  • Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.
Data Types In Java

What is Primitive Data Types In Java?

In Java language, untrained data variety are the building blocks of data consumption . These are the most vital data variety available in Java language. Java is a statically-typed programming language. It means, all flexible must be announced before its use. That is why we need to reveal flexible variety and name. There are 8 variety of untrained data variety :

  • boolean data type
  • byte data type
  • char data type
  • short data type
  • int data type
  • long data type
  • float data type
  • double data type
Data Types Default Value Default Size
boolean false 1 bit
char '\u0000' 2 byte
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte

What is Boolean Data Type?

The Boolean data variety is used to store only two probable values: true and false. This data variety is used for elementary flags that track true/false conditions.

The Boolean data variety indicate one bit of information, but its "size" can't be prominent precisely.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      boolean a = true;
      boolean b = false;  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

Output:


  true
  false


What is Byte Data Type?

The byte data variety is an example of untrained data type. It is an 8-bit signed two's accompaniment integer. Its amount- variety lies between -128 to 127 (comprehensive). Its minimum amount is -128 and maximum amount is 127. Its default amount is 0.

The byte data variety is used to recover memory in big arrays where the memory savings is most required. It recover capacity because a byte is 4 times smaller than an integral. It can also be preloved in place of "int" data variety.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      byte a = 2;
      byte b = -4;  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

Output:


  2
 -4


What is Short Data Type?

The short data variety is a 16-bit signed two's complement integer. Its amount-variety lies between -32,768 to 32,767 (comprehensive). Its minimum amount is -32,768 and maximum amount is 32,767. Its default amount is 0.

The short data variety can also be used to recover memory just like byte data variety . A abrupt data variety is 2 times smaller than an integer.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      short a = 2000;
      short b = -2000;  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

Output:


  2000
 -2000


What is Int Data Type?

The int data type is a 32-bit signed two's complement integer. Its amount types lies between - 2,147,483,648 (-231) to 2,147,483,647 (231-1) (inclusive). Its minimum amount is - 2,147,483,648 and maximum amount is 2,147,483,647. Its default amount is 0.

The int data types is generally preloved as a default data types for integral amount unless if there is no problem about memory.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      int a = 200000;
      int b = -300000;  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

Output:


  200000
 -300000


What is Long Data Type?

The long data types is a 64-bit two's complement integer. Its amount type lies between -9,223,372,036,854,775,808(-263) to 9,223,372,036,854,775,807(2^63-1)(comprehensive). Its minimum amount is - 9,223,372,036,854,775,808 and maximum amount is 9,223,372,036,854,775,807. Its default amount is 0. The long data variety is used when you need a range of values more than those distribute by int.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      long a = 200000L;
      long b = -300000L;  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

  

Output:


  200000L
 -300000L


What is Float Data?

The float data types is a single-precision 32-bit IEEE 754 floating point. Its amount range is unlimited. It is recommended to use a float (instead of double) if you need to recover memory in large arrays of floating point numbers. The float data types should never be preloved for precise values, such as currency. Its default amount is 0.0F.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      float a = -2.00;
      float b = 2.00;  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

  

Output:


  -2.00
   2.00


What is Double Data Type?

The double data types is a double-precision 64-bit IEEE 754 floating point. Its amount range is endless. The double data variety is generally preloved for decimal amount just like float. The double data type also should never be preloved for precise amount, such as currency. Its default amount is 0.0d.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      double a = -2.00;
      double b = 2.00;  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

  

Output:


  -2.00
   2.00


What is Char Data Type?

The char data type is a single 16-bit Unicode character. Its amount type lies between '\u0000' (or 0) to '\uffff' (or 65,535 inclusive).The char data is type preloved to store characters.

Example:

  import java.io.*;
  class Simple{  
    public static void main(String args[]){
      char a = 'D';
      char b = 'C';  
      System.out.println(a);  
      System.out.println(b);
    }  
  }

  

Output:


  D
  C


Best way of learing

Self learing is the best learing in the world. Discover yourself first then will get what you are And what you want to do .It will push you for self learing.

Why you need to learn coding?

Coding will play a vital role in one's life . It will help to open a new window of thinking . You can think better way than past . It helps to organise all the thing in better way .