0% found this document useful (0 votes)
65 views

Data Types in Java: Dr. Kumud Tripathi

A data type specifies the type of data a variable can hold. Java has two types of data types: primitive and non-primitive. The primitive types include boolean, char, byte, short, int, long, float, and double, which have default sizes and values. Non-primitive types include classes, interfaces, and arrays. Each primitive type is suited for holding specific types of data, such as byte for saving memory in large arrays and long for larger integer values than int.

Uploaded by

SIDHANT BHAGAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Data Types in Java: Dr. Kumud Tripathi

A data type specifies the type of data a variable can hold. Java has two types of data types: primitive and non-primitive. The primitive types include boolean, char, byte, short, int, long, float, and double, which have default sizes and values. Non-primitive types include classes, interfaces, and arrays. Each primitive type is suited for holding specific types of data, such as byte for saving memory in large arrays and long for larger integer values than int.

Uploaded by

SIDHANT BHAGAT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Data Types in Java

Dr. Kumud Tripathi


Data Type

● A data type is used to indicate the type of data value stored in a variable
● There are two types of data types in Java:
1. Primitive data types: The primitive data types include boolean, char, byte, short, int,
long, float and double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces, and
Arrays.
Data Type Default Value Default size

boolean false 1 bit

char '\u0000' 2 byte

byte 0 1 byte

short 0 2 byte

int 0 4 byte

long 0L 8 byte

float 0.0f 4 byte

double 0.0d 8 byte


Byte Data Type

● The smallest integer type is byte.


● This is a signed 8-bit type that has a range from –128 to 127.
● The byte data type is used to save memory in large arrays where the memory savings is most
required.
● Example: byte a = 10, byte b = -20
Short Data Type

● short is a signed 16-bit type.


● It has a range from –32,768 to 32,767.
● The short data type can also be used to save memory just like byte data type.
● Example: short s = 10000, short r = -5000
Int Data Type

● The most commonly used integer type is int.


● It is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647.
● The int data type is generally used as a default data type for integral values unless if there is no
problem about memory.
● Example: int a = 100000, int b = -200000
Long Data Type

● long is a signed 64-bit type and is useful for those occasions where an int type is not large
enough to hold the desired value.
● It is a signed 64-bit type that has a range from –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807.
● Example: long a = 100000L, long b = -200000L
Float Data Type

● The type float specifies a single-precision value that uses 32 bits of storage.
● Single precision is faster on some processors and takes half as much space as double precision,
but will become imprecise when the values are either very large or very small.
● It has a range from 1.4e−045 to 3.4e+038.
● Example: float f1 = 234.5f
Double Data Type

● The type double specifies a double-precision value that uses 64 bits of storage.
● Double precision is actually faster than single precision on some modern processors that have
been optimized for high-speed mathematical calculations.
● It has a range from 4.9e–324 to 1.8e+308.
● Example: double d1 = 12.3
Char Data Type

● The char data type is a single 16-bit Unicode character.


● It has a range from 0 to 65535.
● Example: char letterA = 'A'
Boolean Data Type

● Java has a simple type, called boolean, for logical values.


● It can have only one of two possible values, true or false.
● The Boolean data type specifies one bit of information.
● Example: Boolean one = false

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy