Data types in Java

Data types in Java

 Definition – “Data types in simple language we can says that the types of data we are using in the program”.

Data types are of two types –

1. PRIMITIVE DATA TYPES

2. NON-PRIMITIVE DATA TYPES

Primitive Data types

The list of the all primitive Data types is given below.

  1.  byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. char
  8. boolean

1. byte

  • The byte data type is used to store 8 bit singed integer value.
  • The range of byte data type is –128 to 127.
  • It holds the 1 byte of memory at run-time.

2.short

  • The byte data type is used to store 16 bit singed integer value.
  • The range of short data type is -32,768 to  32,767.
  • It holds the 2 byte of memory at run-time.

3.int

  • The byte data type is used to store  4 byte that is 32 bit singed integer value.
  • The range of int data type is -2,147,483,648 to
    2,147,483,647.
  • It holds the 4 byte of memory at run-time.

4.long

  • The byte data type is used to store 8 byte that is 64 bit singed integer value.
  • The range of long data type is 263 to
    263-1.
  • It holds the 8 byte of memory at run-time.

5.float

  • The byte data type is used to store 32 bit that is 4 byte singed integer value.
  • The range of float data type is 3.4e−038 to
    3.4e+038.
  • It holds the 1 byte of memory at run-time.

6.Double

  • The byte data type is used to store 8 byte that is 64 bit singed integer value.
  • The range of double data type is  1.7e−038 to
     1.7e+038.
  • It holds the 8 byte of memory at run-time.

7.char

  • char is stands for character. It is use to store 2 bytes that is 16 bits of data.
  • The range of char data type is ‘\u0000’ (or 0) to ‘\uffff'(or 65,535)
  • It holds the 2 bytes of memory at run-time.

8.boolean

Boolean is the data type which tells the compiler that the variable will hold only true or false, i.e 1 or 0.

Boolean values are the values which are returned by the conditional operators and these values are also used by the looping and branching statement.

Use this data type to store yes or no kind of information. It allocates the memory of 1 bit. The value can be true or false.

  • Size – 1 bit
  • Value – true or false

Non-primitive data types

Non-primitive data types

Non-primitive data types are also known as user-defined data-types. The variables created using such data type are also known as reference variables or objects.

The size of the nonprimitive data type varies and depends upon the structure of the class, interface, and number of the instance variable in it.

Arrays come under the non primitive data type. As the memory allocation is dependent on the programmer as well.

5/5

If you want to learn more about data type watch the following video

  •  Learn data types in HIndi.
  • Learn data type in English.
5/5
Hope you all like this content
Rate this post
Categories: Java

Saurabh

A digital marketer, programmer, and WordPress developer who is always looking for new technology stuff and news. Saurabh has 1+ years of experience in writing content and in web development.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.