0% found this document useful (0 votes)
19 views20 pages

Java Data Types Explained

Uploaded by

thaparohan2019
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)
19 views20 pages

Java Data Types Explained

Uploaded by

thaparohan2019
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

Data Types

In java
Data Types in Java
Primitive Data types are stored in stack memory.
Source: Crunchify
Primitive Data Types

boolean
size : 1 bit
Values: `true` or `false`
Default Value: false

Used to store any characters.


Primitive Data Types

char
size : 2 byte (16 bits)
Range: ‘\u0000’ (0) to ‘\uffff’
(65,545)
Default Value: “\u0000”

Used to store any characters.


Primitive Data Types

byte
size : 1 byte (8 bits)
Range: -128 to 127
Default Value: 0

Used to save space in large arrays where the


memory savings are most needed.
Primitive Data Types

short

size : 2 byte (16 bits)


Range: -32,768 to 32,767
Default Value: 0

Similar usase to ‘byte’ but can hold larger


value
Primitive Data Types

int
size : 4 byte (32 bits)
Range: -2^31 to 2^31-1
Default Value: 0
Default data type to store integer value
Primitive Data Types

long
size : 8 byte (64 bits)
Range: -2^63 to 2^63-1
Default Value: 0L
Used when a wider range than `int` is needed.
“L” is added at the end of the number to
indicate a long literal.
Primitive Data Types

float
size : 4 byte (32 bits)
Range: Approx. ±3.40282347E+38F
(6-7 significant decimal digits)

Default Value: 0.0f

Used to save memory in large arrays of


floating-point numbers. Add an "f" or "F" at
the end of the number to indicate a float
literal
Primitive Data Types

double
size : 8 byte (64 bits)
Range: Approx.
±1.79769313486231570E+308
(15 significant decimal digits)

Default Value: 0.0d

Default data type for decimal values.


Add a ‘d’ or “D” at the end to indicate double
lieral.
Non-Primitive Data types are stored in heap memory.

Source: Crunchify
Non-Primitive Data Types

Array
Holds elements of the same type.
Used to store multiple values in single
variable.
Non-Primitive Data Types

Classes
A class is a blueprint for creating objects
(instances).
A class can contain fields, methods,
constructors, and nested classes.
Fields aka variables/attributes represent
the state or data of a class.
Methods define the behaviour of class.
Constructor is a special method used to
initialize object.
Access modifiers (public, private,
protected, default) control the visibility
and accessibility of class members.
Non-Primitive Data Types
Classes
Non-Primitive Data Types

String
String in java are objects that represents a
sequence of characters.
The `String` class is used to create and
manipulate strings.
Strings are immutable, meaning once
created, their values cannot be changed.
String literals are stored in a special
memory area known as the string pool.
The String class provides many methods
for string manipulation, such as length(),
charAt(), substring(), equals(), indexOf(),
toUpperCase(), toLowerCase(), trim(),
replace(), and more.
Non-Primitive Data Types

String
Non-Primitive Data Types

Interfaces
An interface is a reference type in Java,
similar to class.
It can only contain constants, method
signatures, default and static methods and
nested types.
All methods in an interface are implicitly
public and abstract, unless they are
default or static methods.
A class can implement multiple interfaces,
which helps achieve multiple inheritance
in Java.
Non-Primitive Data Types
Interfaces
Thank You
Like and share if you find it helpful

You might also like