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

Data Types I

The document discusses data types in Java, categorizing them into primitive types (boolean, char, byte, short, int, long, float, double) and non-primitive types (Classes, Interfaces, Arrays). It explains the necessity of variable declaration in Java as a statically typed programming language and addresses the size of the char datatype in relation to the Unicode system. The document also touches on type casting and the implications of using different data types in memory.

Uploaded by

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

Data Types I

The document discusses data types in Java, categorizing them into primitive types (boolean, char, byte, short, int, long, float, double) and non-primitive types (Classes, Interfaces, Arrays). It explains the necessity of variable declaration in Java as a statically typed programming language and addresses the size of the char datatype in relation to the Unicode system. The document also touches on type casting and the implications of using different data types in memory.

Uploaded by

49gmy2ckt8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Data Types ...

Java .
Data Types in Java

Primitive data types: Non-primitive data types:

The primitive data types The non-primitive data


include boolean, char, byte, types include Classes,
short, int, long, float and Interfaces, and Arrays.
double.
Q. Why do we need to declare the variable before using it in java?

statically typed programming


Language
.

woul
as
int = 10 5 ; x
·

/ it
boolean b = 0
; X
8
Patatypes

Like
3 Gi
·
Int
Char
·

signed
long
·

·
Double

Byte point
·

Short
Slowing
·

float
Q. Char Datatype can store a single character so why is it of size
2 bytes and what is \U0000?

While using 16 bits for every character may seem like overkill for representing many
characters that only need 8 bits (or even fewer), Java's design emphasizes consistency,
portability, and robust internationalization support. This design decision ensures that Java
can handle text and characters from various languages and character sets without
requiring extensive conversions or adjustments.

It is because java uses Unicode system not ASCII code


system. The \u0000 is the lowest range of Unicode system.
charc
'Al ; ~withmetic

:


I

S 0 .

ph (c 1)+
I

, O
1166 on

C 2
.

-
intn=c ; 1165 Cert
"

craw b :
I hard m :

int a :
"A-is' ;
Chart= 65; v
AB 2B

byte- Shoot

uB
testin
↑ int
long > -
float s Double
- VB 8 B YB 8B
Char
4 ?
Tnese] [
Floating-point
In memory is
way
to
represent no ·

So that store the of


diff
no
.
,
can
long
↑ double d = 130 . 456 ;

int = lint)d : //130

byte b =

(byte) & ; 1/-126

= byte b = 100 ,

b = b+ 2 ; Il Error
- -

You might also like