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
- Primitive Data Types
- 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
- 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.
- 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’
- 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).
- 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;
-
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;
- 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
- 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 ;
- 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.
-
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
- 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”;
- 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.
- Interfaces:-
Interface is like a class, where methods are declared and kept, which are defined later. So these are Interfaces Classes.
- 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 :-
- Class does not have to be defined in Primitive Data Types.
- It includes Int, Boolean, Char, Short, Float, all these data types.
- Primitive Data Type can hold only one value.
- Very little memory is used inside it.
- The size of Primitive Data Type is already defined.
- The data types contained in it are used for the very first time.
- Data is stored in Primitive Data Types.
Non Primitive Data Types :-
- Class has to be defined within this.
- It includes all data types like String, Object, Class, Interface, and Array.
- It can hold more than one value.
- More memory is used in Non Primitive Data Type.
- In this, the size of the data is not defined in advance, it is user defined.
- Data Types are used very slowly in this.
- References are stored in Non Primitive Data Types.
Some More:
POP- Introduction to Programming Using ‘C’
OOP – Object Oriented Programming
DBMS – Database Management System
RDBMS – Relational Database Management System
Join Now: Data Warehousing and Data Mining