Data types in Java
- WHAT IS THE DATA TYPES
- TYPES OF DATA TYPES
According to data, variables can have a wide range of sizes and values. In Java there are mainly two different data types:
Basic data structures - The following are the most fundamental types of
data storage: boolean, character, byte, int, long, float, and double.
Non-primitive data types: Non-primitive data types include classes,
interfaces, and arrays.
Primitive data types
Java's data manipulation is based on primitive data types. These are the
most basic data types in Java.
There are 8 types of primitive data types in Java: -
- Boolean data type
- byte data type
- char data type
- short data type
- int data type
- long data type
- float data type
- double data type
Non-primitive
data types
There are a greater number of primitive data types like: -
· String
- Array
Boolean data type
In a
Boolean data type, there are only two possible values that may be represented:
true and false. This data type is perfect for basic flags with true or false
criteria.
Boolean
data types describe themselves as having a single piece of information; its
"size" is not indicated.
Example: -
Boolean one =false
Byte data
type
The byte is
among the most fundamental types of data. This is a signed integer since it has
eight bits and the two's complement. Its possible values range from -128 to
127. It has a minimum value of -128 and a maximum value of 127. It defaults to
0.
The Byte
data type is invaluable for large arrays in terms of memory conservation. This
helps save space since bytes are four times smaller than integers. Being used
as a "int" data type is an additional potential use.
Example: -
byte a =10, byte b = -20
Short data
type
Signed
integers with two scores are condensed to 16 bits. It can have a value between
-32,768 and 32,767. It can have any of the following values: the whole numbers
-32768 to 32767. By default, its value is zero.
You can
utilize the short data type in the same way as you would bytes to save memory.
A short data type is one that is twice as tiny as an integer.
Example: -
short s=10000, short r = -4000
Int data
type
A signed,
two-coordinate integer with 32 bits is represented by the data type
"int". Values between -2,147,483,648 (-2^31) and 2,147,483,647 (2^31
-1) are contained within the range. Its possible values range from
-2,147,483,648 to 2,147,483,647. It has a default value of 0.
The int
data type is usually used as the default data type for integral values unless
there are memory problems.
Example: -
int a =50, int b= -80
Long data
type
An integer
having 64 bits of two's complement is referred to as a long data type. Its
value is conceivable between -9,223,372,036,854,775,808 (-2^63) and
9,223,372,036,854,775,807 (2^63 -1) inclusive. The range of potential values is
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. By default, it is set
to 0. When it doesn't cover the range of numbers you require, you can use the
long data type.
Example: -
long a =400L, long b=-200L
Float data
type
For
floating-point computations, a 32-bit IEEE 754 floating-point number is
utilized as the data type. There is no range to its value. Use float rather
than double when working with large arrays of floats to save memory. Coins and
other exact numbers should never be kept in float variables. It has a default
setting of 0.0F.
Float
a=490.3, float b=598.4
Double data
type
The data
type is an IEEE 754 floating-point number with 64 bits of precision. Its value
is infinite in scope. Similar to float values, decimal numbers are frequently
stored as double data types. Not to add, never use the double data type to
record exact quantities, such as coins. It has a default value of 0.0d.
Example: -
d =34.6
Char data
type
The Char
data type represents one 16-bit Unicode character. Its value range is '\u0000'
(inclusive, or 0) to '\uffff' (inclusive, or 65,535). Programmers use the Char
data type to store text.
Example: -
char letter a =’a’
No comments:
Post a Comment