Data types in Java  

Data Types in Java:-

The various sizes and values that a variable can store are referred to as data types.

There are two types of data in Java programming

A) Primitive data types: Integer, float, boolean, byte, short, long, char, and double are examples of primitive data types.

(B) Non-primitive data types: These include things like classes, interfaces, and arrays.

Java Primitive Data Types:-

The Java programming language supports the following primitive data types.

(1) Byte data type
(2) Boolean data type
(3) Int data type
(4) Short data type
(5) Char data type
(6) Double data type
(7) Float data type
(8) Long data type

Byte Data Type:

It is the first data type that requires the least amount of memory and may be utilized for numerous small ranges.

(A) One byte is allotted for the RAM.

(b) It may represent 256 in total (28).

(c) A byte can represent a positive number from 0 to 127 (because 0 is a positive number). per programming) and on the negative side, it can represent the number -1 to

128.

(d) The default value for byte is zero (0).

Example:- byte x1 = 20 ;

Boolean Data Type: –

One bit of information makes up the boolean data type.

For the Boolean data type, there are only two potential values.

that is both true and False.

a) It has not something a range of values of the variable.

(b) The values true or false are case-sensitive keywords.

Example:- boolean a = false; boolean b=true

Int Data Type:-

The int data type is a 32-bit signed type. The minimum value of the int data type is –
2,147,483,648 and the maximum value of the int data type is 2,147,483,647 precision
type.

(a) Its default value is 0.

(b) On the positive side 0 to 2,147,483,647 and on the negative side -1 to 2,147,483,647

(c) It can represent a total of 4,294,967,296

Example:- int a = 100000;

int b = -200000;

Short Data Type:-

The short data type is a 16-bit signed type. Its value-range lies between – 32,768 to 32,767. Minimum value of the short is -32,768 and the maximum value of the short is 32,767.

(a) Its default value is 0.

(b) It can represent a total of 65536(216) numbers.

Example:- short s = 10000;

Char Data Type:-

It has a single 16-bit Unicode character. Value-range of the char data type lies between -127 to 128. The char data type is used to store characters.

(a) It stores a single character such as a letter, number, and punctuation mark, or other symbols.

(b) Characters are single letters enclosed in single quotes.

Example:- char b = ‘A’; char a=’#’;

Double Data Type:-

the double data type is 64 bits signed type. Its value range is unlimited. The double data type is generally used for decimal (points) values just like float. The double data type does not use for precise values, such as currency.

(a) Its default value is 0.0d.

Example:- double d1 = 122.39;

Float Data Type:-

The float data type has a single-precision 32-bits type and its value range is unlimited.

(a) Its default value is 0.0F.

Example:- float f1 = 134.5f;

Long Data Type:-
It has a 64-bit two’s complement integer.
The minimum value long data type is – 9,223,372,036,854,775,808 and the maximum value of the long data type is 9,223,372,036,854,775,807.

(a) Its default value is 0.
Example:- long a = 100000L;

Non-Primitive Data Types:-
There are the following non-primitive data types available
in Java programming language.

(1) Array: – An array is the collection of homogeneous (or similar types) data types.

(a) An array is an object that holds a fixed number of values of homogeneous or similar data type.

(b) The length of an array is assigned when the array is created and after creation, its length is fixed.

Example:- int a[]=new int[6];

(2) Class: – A class is a “user-defined data type” from which objects are created of class. In general, class declarations can include components. And it consists of data and methods in the form of a unit.

(a) Modifiers: – A class can be public or default access.

(b) Class name: – The name of the class should begin with an initial capital letter.

(c) Body: – The class body is enclosed by braces {}.

Example: – public class car{ Public; char color; double model; Public void gear (); // behavior of a car}

(3) Interface: – An interface is basically a kind of class. So an interface is a collection of “methods” without actual definitions and “variables”.

Thus it is the responsibility of the class to define and implement the codes of these methods.

Example: – interface item { Static final int code=101; Satic final string name =”fan”; Void display (); }






Scroll to Top