Data Types in java – Primitive and Non-Primitive Data Types

0
23

Data types always reference what type of data that has to be stored by a variable. Every data have a different size and value.

Data types in java.

Data types always reference what type of data that has to be stored by a variable. Every data have a different size and value.

The memory contains two different data type:-

  1. Primitive
  2. Non-Primitive

Must Read:- Full Explained Aggregation, Composition, And Association In Java.

What is Primitive Data Type?

Any data type that is predefine or inbuilt in the system is called a primitive data type in java.

In java, primitive data types building blocks of data implementation. These are the basic data types, which are available in java.

primitive data type list.

  1. Boolean data type.
  2. Short data type.
  3. Int data type.
  4. Long data type.
  5. Byte data type.
  6. Char data type.
  7. Float data type.
  8. Double data type, etc.

Boolean data type in java. 

These are store only two types of values.

  1. true
  2. false

a boolean data type used to track true and false conditions. and these data types have one bit of information, but its size cant be defined precisely.

For example:- boolean ten= false.

Byte data type in java.

Byte data types are like primitive data types. It is an (8bit) signed two complements integers.

Its value range is between -128 to 127. that means its minimum value starts from -128, and its maximum value goes until 127. and bytes contain 0 default value.

Byte data types used to save memory in the array, where we must need to save because it is 4 times smaller compared to an integer.

For Example: byte a = 20, byte b = -40

Must Read:- JVM Architecture in Java| How JVM Works? | JVM in Java Full Explained

Char data type in java.  

Chare data types are store characters. Char data types stored values in the Unicode characters. and its value range is between ‘\u0000’ (or 0) to ‘\uffff or 65,535 inclusive.

For Example:- char A=’A’;

Short data type in java.

They also used to save memory similar to the byte data types. And short data type 2 times smaller compared to an integer.

Its value range is between -32,768 to 32,767. That means its minimum value starts from -32,768, and its maximum value goes to 32,767. And Short contains 0 default value.

Example: short A = 5000, short r = -2500

Int data type in java.

Int data types used as default integer values, and these data types do not affect memory storage.

the values range of Int data types is – 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1), That means the minimum value is – 2,147,483,648 and its maximum value is 2,147,483,647. And also contains 0 default value.

Example: int x = 200000, int y = -400000

Long data type in java.

Long data types are store the long-range integer values.

the values range of Int data types is from [-9,223,372,036,854,775,808](-2^63) to [9,223,372,036,854,775,807](2^63 -1). That means the minimum values is from 9,223,372,036,854,775,808(-2^63) and max values until 9,223,372,036,854,775,807(2^63 -1). And also contains 0 default value.

Example: long a = 200000L, long b = -400000L

Float data type in java.

Float data types don’t have any range to store values. They are stored at floating values like 1646.52f.

For Example- 545.4f

Double data type in java.

They are used from decimal values similar to float.

Double data types double-precision of 64-bit IEEE 754 floating points.

For Example- doubled =23.3.

Here is a complete range table for these data types.

Non Primitive data types in java?

Any data type that is not predefined or user-defined, or customized is called a non-primitive data type

Note:- when the object is data, then the class should be a data type.

List of Non-primitive data types.

  • Strings
  • Arrays
  • Classes
  • Interface, etc.

Strings data type in java:

String data types represent the sequence of characters in java and using java.lang.String class, we can create String Objects in java.

Arrays data type in java: 

Arrays are homogeneous data implementation of java objects, and it stores multiple values in the memory storage. We can access a specific element by its index.

Classes data type in java: 

Class is a context or blueprint or a java program template, which contains all the data like variablesmethodsobjects, and describes the object’s behavior and states

Interface data type in java: 

Similar to the class. The interface also has methods and variables, but in the interface, methods have only signatures. These methods do not contain the body. These types of methods we called abstract methods.

0 0 vote
Article Rating
Previous articleHow to Download and Install Java JDK 15 in Windows 10 ?
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments