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

Javaaaaa@A

Uploaded by

hindhuindhu8
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Javaaaaa@A

Uploaded by

hindhuindhu8
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Datatypes

Presented by

Indhumathi. J
Data Types in
Java:
Definition:
* Data types in Java define the type of data that can
be stored in variables. They specify the size and
type of values that can be held in variables,
helping to allocate the correct amount of memory.
* Purpose:
* To specify the kind of data a variable can
hold (e.g., integer, decimal, text, etc.).
To optimize memory usage and ensure type
safety (e.g., preventing operations between
incompatible data types).
Simple term’s:
*A data type tells the compiler what type of
value a variable will store and how much
memory it needs.
* For example, using int tells Java the
variable will hold whole numbers, while
String tells it to hold text.
Types of Data types:

Types of Data Types in Java:


1. Primitive Data Types:Predefined by the
language.Store simple values directly in
memory.Examples: int, float, char, boolean.
2. Reference Data Types:Store references
(addresses) to objects.Used for more
complex data structures.Examples: String,
Arrays, Classes
Primitive Data
types:
1.ByteDefinition:
8-bit integer. Stores small integer values.
Range: -128 to 127
Example:byte age = 25;
2. ShortDefinition:
16-bit integer. Stores slightly larger integer
values.
Range: -32,768 to 32,767
Example:short distance = 15000;
Primitive Data
Types(contd.)
3. intDefinition: 32-bit integer.
Default data type for integers.
Range: -2^31 to 2^31-1
Example:int population = 1000000;
4. longDefinition: 64-bit integer.
Used for large integer values
Range: -2^63 to 2^63-1
Example:long worldPopulation
=7800000000L;
Primitive Data Types
(contd.)
5. float
Definition: 32-bit floating point. Stores decimal values.
Example:
float temperature = 36.6f;
6. double
Definition: 64-bit floating point. More precise for
decimal values.
Example:
double pi = 3.14159;
Primitive Data Types
(contd.)
7. char
Definition: 16-bit Unicode character. Stores a
single character.
Example:
char grade = ‘A’;
8. boolean
Definition: Stores only two values: true or false.
Example:
boolean isJavaFun = true;
Reference Data
Types
1.StringDefinition:
Stores sequences of characters (text).
Example:String message = "Hello,
Java!";
2. ArrayDefinition:
Stores multiple values of the same data
type in a single variable.
Example:int[] numbers = {1, 2, 3};
Reference Data Types
3. ClassDefinition: (contd.)
A blueprint for creating objects.
Classes hold methods variables.
Example:class Car { String model =
"Sedan";}Car myCar = new Car();
4. InterfaceDefinition:
Specifies what methods a class must
implement but not how.
Example:interface Vehicle { void start();}
Summar
y
*Primitive Data Types: byte, short, int, long,
float, double, char, boolean
*Reference Data Types: String, Arrays,
Classes, Interfaces

You might also like