Primitive data types in java
Data types :-
Data types are the most important basis for any programming language. It is a very important concept for all beginners. The type of data is important to represent the type, environment and operation of the stored value.
Java data types are the basic and first things you should know before moving on to other Java concepts. This is very helpful in all aspects of Java, be it creating a simple program or upgrading any application or software.
In this study, we will discuss all the important factors in learning data types in Java. Also, I bet after finishing this article, you will not face any difficulty in this topic.
Before we start with Java data types, let's first learn about data types in general.
what is data types in Java :-
In computer science, data type is a data element that tells the compiler or translator how the producer intends to use the data.
The type of data limits the value that speech can make, such as flexibility or function. It describes how the values of that type of data are stored in memory and what functions can be performed in the data.
Data types include storage categories such as whole numbers, floating prices, strings, characters, etc.
For example, if the variable is a data type "int", then it can only hold the numerical values.
Before migrating to Java Data types, you should know the language types.
There are two main types of languages:
The first is a statically typed language in which the data type for each variant must be defined at the time of integration. That is, we must declare the type of variable before using it.
Once we have announced the variability of a particular data type, then we will not be able to change its data type again. However, they can be converted to other species using transparent streaming in Java, other than boolean. Other typed languages are C, C ++, C #, Java, and Scala.
For example, if we write int num = 5;
It then means that the variable num is of a complete type and holds a number of numbers and its type will always be the same.
Another language is dynamically typed language. In this type of language, data types can change with respect to time and variables are checked during launch.
Other languages that are strongly typed are Ruby, Python, Erlang, Perl, VB and PHP.
Data types in java:-
Java is a statically typed language. The basis of any programming language is its data types and operators. Java comes with a rich collection of both data types and operator, making it suitable for any type of program.
- Primitive Data types.
- Non Primitive Data types.
- Primitive Data types:-
As the name suggests, programming language first describes the types of old data. The first types are the most basic data types available in Java. There are 8 types of old data in Java: byte, char, short, int, long, float, double and Boolean.
DATA TYPES |
BYTE |
RANGE |
DEFAULT
VALUE |
EXAMPLE |
BOOLEAN |
1(1 bit) |
Not specified |
False |
True |
BYTE |
1(8 bit) |
-128 to +127 Or -27 to 27– 1 |
0 |
123 |
SHORT |
|
-215 to +215– 1 |
0 |
1234 |
CHAR |
2(16 bit) |
0 to 216– 1 |
‘/u0000’ |
‘Asit’ |
INT |
4(32 bit) |
-231 to 231– 1 |
0 |
1234 |
FLOAT |
4(32 bit) |
-2-149 to (2-2-23) · 2127 |
0.0 |
12.23 |
LONG |
8(64 bit) |
-263 to 263– 1 |
0 |
12345 |
DOUBLE |
8(64 bit) |
-2-1074 to (2-2-52) .21023 |
0.0 |
123.345 |
BOOLEAN :-
- Boolean information sort speaks to one bit of data.
- Any Boolean variable can assume one of the two values: true or false.
- This information sort is utilized for basic banners that track genuine/false conditions.
- The default value for this data type is false.
- Example:
Byte :-
- Byte information sort is a 8-bit marked two’s supplement whole number.
- Maximum worth is 2^7 -1, which is equal to 127. This value is also included in the range of these values.
- Minimum worth is -2^7, which is equal to -128.
- Default value stored in a variable of this type is 0.
- byte information sort is utilized to spare space in vast exhibits, principally set up of numbers, since a byte is four times littler than an int.
- Example:
Short :-
- Short information sort is a 16-bit marked two’s supplement number.
- Maximum value is 2^15 -1, which is equal to 32,767. This number is also included in the range.
- Minimum value is -2^15, which is equal to -32,768.
- short information sort can likewise be utilized to spare memory as byte information sort. A short is 2 times littler than an int.
- The default value for this data type is 0.
- Example:
Char :-
- Char information sort is a solitary 16-bit Unicode character.
- Maximum value for a variable of this type is “\uffff” (or 65,535 comprehensive).
- Minimum value for a variable of this type is “\u0000” (or 0).
- Char information sort is utilized to store any character.
- Example:
Int :-
- int information sort is a 32-bit marked two’s supplement number.
- Maximum value for this data type is 2^31 -1, which is equal to 2,147,483,647. This number is also included in the range for this data type.
- Minimum value for this data type is -2^31, which is equal to - 2,147,483,648.
- int is for the most part utilized as the default information sort for its indispensable qualities unless there is a worry about memory.
- The default value for this data type is 0.
- Example:
Float :-
- float is a data type, which is know for its solitary exactness, 32-bit IEEE 754 gliding point.
- float is for the most part used to spare memory in vast exhibits of coasting point numbers.
- The default value for this data type is 0.0f.
- float information sort is never utilized for exact values, for example, money.
- Example:
Long :-
- Long information sort is a 64-bit marked two’s supplement whole number.
- Maximum value for this data type is 2^63 -1, which is equal to 9,223,372,036,854,775,807.
- Minimum value for this data type is -2^63, which is equal to -9,223,372,036,854,775,808.
- This sort is utilized when a more extensive memory range than int is required.
- The default value for those data type is 0l.
- Example:
Double :-
- Double information sort is a float with twofold exactness 64-bit IEEE 754 drifting point.
- This information sort is for the most part utilized as the default information sort for decimal qualities.
- double information sort ought to never be utilized for exact values, for example, money.
- The default value for this data type is 0.0d.
- Example:
output :-
for more detail follow my Instagram id - https://www.instagram.com/asitmaharana10/
Thank you.
2 Comments
ReplyDeleteAwesome blog. Thanks for sharing such a worthy information....
Data science course in Delhi
Data Science Course in Gurgaon
Wow, wonderful blog. Thanks for sharing this informative article with us.
ReplyDeleteI arppreciate your thoughts. Looking forward for reading more...
Website Design Dubai
Post a Comment