In this article we give the information about Data types in Java there are two types in java such as Primitive data types and non primitive data type.

Data types in Java

There are two types of data types in Java, such as

  1. Primitive Data Types
  2. Non-Primitive Data Types

Primitive Data Types in Java:

Primitive Data Types means that all the data types that come under this data type do not need to import the class. This Primitive Data Types is also called Primary Data Type.

  • Boolean
  • Char
  • Int
  • short
  • Byte
  • long
  • Float
  • Double
  1. Boolean data type in java

If you want to check True or False condition in your programming then this Boolean Data Types is used. Boolean Data Types are declared through Boolean Keyword and the size of Boolean is never fixed, it depends on JVM, the default value of this Boolean is False.

  1. Character data type in java

Character is used to store a single alphabet or a numeric value. And we write this alphabet inside Single Quote, whose size is 2 bytes.

Example – ‘A’

  1. Int data type in java

In this you use only data of Integer types, which ranges from 0 to 9. The size of Int is 4 bytes, and mostly this Int data is used in programming.

Example – Int a=10;  The value of this Int is (- 2147483648 to 2147483648).

  1. Short data type in java

Whenever we store data inside an array, we use this short. In which the memory size is very less. And the size of this short is 2 bytes. In which the default value of this Short is 0. Example – Salary 25000;

  1. Byte data type in java

We also use Byte like Short Data Types, meaning wherever more memory needs to be used, we use this Byte, and this Byte is also used to save memory space. Just as Short is used inside the Array, similarly Byte is also used to store data inside the Array. And the value of Byte is (-128 to 127) in which the size of Byte is 1 Byte. Example – Age = 26;

  1. Long data type in java

It is used to store data of Integer type. This means that there is a range for using Integer Data Types, and wherever there is a need to store any data type outside this range, even then these Long Data Types are used. Whose value is ended with L-Letter. Size of long is 8 bytes. Example – 80000000L

  1. Float data type in java:-

Float Data Types are used to store Decimal Value. Meaning, Float is used in the value which contains Point. Because integer data types cannot store the value of Point, the size of Float is 4 bytes. The value in Float is terminated with F – Letter.

Like – temp = 34.4f ;

  1. Double data type in java

This Double also stores Point Value like Float. Which are not stored inside Value Float, meaning – whose length is larger. Suppose there are 4 or 5 digits after Point, then this Double is used instead of Float. Size of double is 8 bytes. And the ending letter of this double starts with D. as – 3.1412d

So this is Primitive Data Types. Now we try to know all these data types better through a program.

  1. Non-Primitive Data Types in Java:-

Non Primitive Data Types means – whatever data types are included in it, if you access or define those data types for variables, then first of all you have to import all those data types in your programming. And after that the object of all of them has to be defined. Meaning, an instance will have to be created in runtime if these data types are to be used.

4 types of data types can be seen under Primitive Data Types.

  • String
  • Classes
  • Interfaces
  • Array
  1. String :-

String means, if you use more than one alphabet, and that too inside double quote, then it is String. It means sequence of character, like if you use a word inside double quote, then it is String. , like – “Yashraj”;

  1. Classes :-

First of all you have to import the class, and then create the object. And then that object is stored inside a variable, and to store it in the variable, the type of class has to be mentioned. Then you can use this class. The object you have created inside the class contains methods and variables.

And there is no default value in this class, hence this class comes in Non Primitive Data Types.

  1. Interfaces:-

Interface is like a class, where methods are declared and kept, which are defined later. So these are Interfaces Classes.

  1. Array :-

If we have to store multiple values ​​of Integer, then we use Array. Array is a collection of similar data, meaning many values ​​are stored inside one data. For example, if we want to store the names of 50 students, then we will have to use an array of String types.

Data types in Java

Difference Between Primitive or Non Primitive Data Types in Java:-

Primitive Data Types :-

  1. Class does not have to be defined in Primitive Data Types.
  2. It includes Int, Boolean, Char, Short, Float, all these data types.
  3. Primitive Data Type can hold only one value.
  4. Very little memory is used inside it.
  5. The size of Primitive Data Type is already defined.
  6. The data types contained in it are used for the very first time.
  7. Data is stored in Primitive Data Types.

Non Primitive Data Types :-

  1. Class has to be defined within this.
  2. It includes all data types like String, Object, Class, Interface, and Array.
  3. It can hold more than one value.
  4. More memory is used in Non Primitive Data Type.
  5. In this, the size of the data is not defined in advance, it is user defined.
  6. Data Types are used very slowly in this.
  7. References are stored in Non Primitive Data Types.

Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Join Now: Data Warehousing and Data Mining 

Leave a Reply

Your email address will not be published. Required fields are marked *