Data Types in Java | infoStud blogs

Data types indicate the various sizes and values that can be put away or stored in the variable. There are two types of Data types in Java: 

  • Primitive Data Type
  • Non Primitive Data Type

Primitive Data types: These data types contain boolean, char,  byte, short, int, long, float, and double.

Non Primitive Data Type: The non-crude information types incorporate Classes, Interfaces, and Arrays. 

Java Primitive Data Types 

In Java language, primitive data types are the building blocks or data manipulation. These are the most essential data types accessible in the Java language. 

Java is a statically typed programming language. That is to say, all variables should be proclaimed or declared before their utilization. That is the reason we need to declare the variable's type and name. 

Primitive data types in java
Data type in Java


Data Type table

Boolean Data Type 

The Boolean data type is utilized to store just two potential values: false and true. This data type is utilized for basic banners that track simple true/bogus conditions. 

The Boolean data type indicates the one bit of data, however, its "size" can't be characterized definitely. 

Example: Boolean one = false 

Byte Data Type 

The byte data type is an illustration or example of a primitive data type. It is an 8-digit marked two's complement number (Integers). Its value lies between - 128 to 127 (comprehensive). Its base value is - 128 and its greatest value is 127. Its default esteem is 0. 

The byte data type is utilized to save memory in huge or large arrays where memory savings is generally required. It saves space in light of the fact that a byte is multiple times less than a number. It can likewise be utilized instead of the "int" information type. 

Example: byte a = 16, byte b = - 10 

Short Data Type 

The short data type is a 16-bit signed two's complement Integer. Its value lies between - 32,768 to 32,767 (comprehensive). Its base or minimum value is - 32,768 and maximum or extreme value is 32,767. Its default value is 0. 

The short data type can likewise be utilized to save memory very much like a byte data type. A short data type is 2 times less or smaller than an Integer number. 

Example: short s = 2000, short r = - 4000 

Int Data Type 

The int data type is a 32-bit signed two's complement Integer number. Its values lies between - 2,147,483,648 (- 2^31) to 2,147,483,647 (2^31 - 1) (comprehensive). Its minimum value is - 2,147,483,648and greatest worth is 2,147,483,647. Its default esteem is 0. 

The int data type is by and large utilized as a default data type for necessary integral values except if there is no issue about memory. 

Example: int a = 60000, int b = - 800000 

Long Data Type 

The long data type is a 64-bit two's complement integer number. Its value lies between - 9,223,372,036,854,775,808(- 2^63) to 9,223,372,036,854,775,807(2^63 - 1)(inclusive). Its minimum value is - 9,223,372,036,854,775,808 and greatest value is 9,223,372,036,854,775,807. Its default value is 0. The long data type is utilized when you need a scope of values more than those gave by int. 

Example: long a = 1000L, long b = - 2000L 

Float Data Type 

The float data type is a solitary or single-precision 32-bit IEEE 754 floating-point. Its value range is limitless. It is prescribed to utilize a float (rather than double) in the event that you need to save memory in enormous or large arrays of floating-point numbers. The float data type ought to never be utilized for exact values, like money. Its default value is 0.0F. 

Example: float f1 = 232.6f 

Double Data Type 

The double data type is a  64-bit IEEE 754 floating-point (double-precision). Its value reach is limitless. The double data type is generally utilized for decimal values very much like float. The double data type likewise ought to never be utilized for exact values, like money. Its default value is 0.0d. 

Example: double d1 = 14.5

Char Data Type

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

Example: char letterA = 'B'



Post a Comment

0 Comments