int, float, double, char, boolean, byte, short, long

int, float, double, char, boolean, byte, short, long

In Java programming language, you get many fundamental options in default primitive data type, which helps Java developers to represent basic data type values ​​like numeric, character, true and false values, floating numbering, and double and long double in the Java program. In which primitive data type is the default built-in data type declaration method in Java programming. Java programmers use multiple data types in Java programs as data building blocks for data manipulation or containers for data type storage.

int, float, double, char, boolean, byte, short, long

So, let’s know better about different types of data type declaration methods in Java programming.

int Data Type in Java.

In Java programming, int data type is used to store a complete integer value. Where the default integer data type size storage value is 4 bytes (32 bits). And its default storage value is 0, and the range of integer data type is -2,147,483,648 to 2,147,483,647.

Int Data Type Example in Java.

int number = 9;

int temp = -30;

float data Type in Java.

In Java programming, float data type is used to store floating numbers in which integer number is followed by decimal number. Which represents single-precision floating point number in Java program. Where the default float data type storage size is 4 bytes (32 bits). Where the default float stores 0.0f value in Java. And its storage range is ±3.40282347E+38F.

Float Data Type Example in Java.

float salary = 1000.87f;

float height = 7.2f;

Remember, for float data type literal in Java program, we declare f or F after that, which indicates that the current number is a float value.

Double Data Type in Java.

Double data type represents a complete double-precision floating point data type values ​​in Java program. In which the default double data type storage size is 8 bytes (64 bits). And its default storage value is 0.0d. And its data storage range is ±1.7976931348623157E+308.

Double Data Type Example in Java.

double pi_value = 3.14977873232;

double range = 423398.1232;

char Data Type in Java.

Character data type is used to store and represent characters in Java programming. Which stores and represents a single character in the current Java program. Where the default character data type size is 2 bytes (16 bits) storage value. The default character data type holds the default value \u0000 (zero character). And its range is 0 to 65,535 (Unicode character) characters.

Char Data Type Example in Java.

char text = ‘P’;

char character = ‘m’;

char special = ‘$’;

Boolean Data Type in Java.

Boolean data type is used in Java programs to represent boolean values, where boolean data type represents the data value in true or false order. The default storage size of boolean data type can be 1 bit or more, such as 1 byte. And the default boolean value is false, and its storage range is in true or false order. You use Boolean data type to represent binary value or true value like yes/no, true/false value.

Boolean Data Type Example in Java.

Boolean isValue = True;

Boolean isMature = False;

Byte Data Type in Java.

Byte data type is used to store a single byte in Java program. It represents a small integer byte storage in Java program storage. Where the default size of byte data type is 1 byte (8 bits). And its default storage value is 0. And its default range is -128 to 127.

Byte Data Type Example in Java.

byte minNumber = -87;

byte maxNumber = 99;

Small Data Type in Java.

Small data type is used in Java program to store and process a small integer value. Where the default size of small data type is 2 bytes (16 bits). Where the default small data type storage value is 0, and its default range is -32,768 to 32,767.

Small Data Type Example in Java.

short temp = -20;

short distance = 190;

Long Data Type in Java.

In Java programs, long data type is used to store large-size data type. Where long data type represents a large integer data type value storage. And its default storage size is 8 bytes (64 bits). And the default storage value is 0L. And its storage range is -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Long Data Type Example in Java.

long infinite_number = 9834000000L;

long distanceToplanet = 348900000L;

Data type Summary Table.

int, float, double, char, boolean, byte, short, long Conclusion in Java Programming.

In Java Programming, you need to understand multiple data types for your programming projects and select and use them in your program based on the requirements. Using the right data type for a Java program improves memory efficiency and program performance in your program.

  • For small integer values ​​in Java programs, use byte or short data type.
  • For storing regular integer values ​​in Java programs, use int data type.
  • For storing large integer data values ​​in Java programs, use long data type.
  • For storing low precision floating-point numbers in Java programs, use float data type.
  • For storing high precision program data, use double data type.
  • For storing single character data type in Java programs, use char data type.
  • To store true/false values ​​in a Java program, use the boolean data type.