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.


Data types in java


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.

There are two types of Datatype.
  1. Primitive Data types.
  2. Non Primitive Data types.

  1. 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.

In java 8 primitive data types are available.


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

 2(16 bit)


-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:
               Boolean check = true;

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:
                 byte x = 200, byte y = -20

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: 
               short x = 425164, short y = -76686

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: 
            char text =‘a’

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: 
            int x = 826378, int y = -64782

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: 
             float x = 254.3f

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: 
           long x = 174636l, int y = -536452l

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: 
           double x = 321.4


Program for primitive data type
public class data {
public static void main(String[] args) {
boolean b = false;
byte by = 0;
short s = 0;
char c = 0 ;
int i = 0;
float f = 0;
long l = 0;
double d = 0;
by++;
s++;
                i++;
f++;
l++;
d++;
System.out.println("boolean value :"+b+"\n byte value :"+by+"\n short value :"+s+"\n char value :"+c+
"\n int value :"+i+"\n float value :"+f+"\n long value :"+l+"\n double value :"+d);

}

}

output :-

Data types


for more detail follow my Instagram id - https://www.instagram.com/asitmaharana10/

Thank you.