0% found this document useful (0 votes)
12 views9 pages

SILCHAR_UNIVE_EXAM_TOP_MCQ

The document provides an overview of data types in Java, categorizing them into primitive and non-primitive types. It details the characteristics, sizes, ranges, and examples of various primitive types such as byte, short, int, long, float, double, char, and boolean, as well as non-primitive types like strings and arrays. Additionally, it explains variables, constants, type casting, and the Unicode system used for character encoding in Java.

Uploaded by

hritikasharma856
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)
12 views9 pages

SILCHAR_UNIVE_EXAM_TOP_MCQ

The document provides an overview of data types in Java, categorizing them into primitive and non-primitive types. It details the characteristics, sizes, ranges, and examples of various primitive types such as byte, short, int, long, float, double, char, and boolean, as well as non-primitive types like strings and arrays. Additionally, it explains variables, constants, type casting, and the Unicode system used for character encoding in Java.

Uploaded by

hritikasharma856
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/ 9

cIASSMAte

Date :

Pago

DATA TYPES
TYPES AND VARIABLES IN
JAVA
1. Prinzitive Data Types:
Primitive data types are the mast basic types a
data that are predened in Java.
Jhese types represent simple values Such as umbers
and characters.

List cf Primniive Data lypes


1 byte Size : 1 byte (8 bits)
Range : -128 to 127
" Default value : 0
" Example. : byte a: 100;
. shor: " size 4 byBes (32 bits)
. Range : -2,147, 483, 648 to R147483,647
" Default value : 0
" Example :short b32000;
3 size : 4 bytes (32 bits)
" Range: -2,147, 483,648 to 2,147,483, 647
" Default value : 0
Exanmple : imt c= 1000 ;
@
Curious-proprammer
clASSMAAe
Date
Page:

4. Long: siZe : 8 bytes (64 bits)


Range-9.23,372, 036,854, 775,808 to
9.223,372,036 854,775,807.
Default value : OL
Example: long d=1234567890L ;
5- loaf : size : 4 bytes (32 bits)
" Range : used for decimal values (single precision)
" Default value : 0.0
Example: Hloat e = 3.14f:
6: clouble : size : 8 bytes (64 bits)
Used tor : Decimal yalues (double precisiom)
"Detault value : 0-0d
Example couble f: 3.14159;
7. char: "size : 2 bytes 16 bits)
" Used for i single characters
Defaut value \uo000" (noll characer)
.Example char g 'A';
8: boolean: Size : bit
Used for : True/False yalues
Default value : false.
"Example: booleamhe true;
@curiOus - programtr
cIASSMAte

2 Non- Rr1mitive Dala Types


Nom- Primitive can types , also knoum as reference
types are used to store more CoTmplex structures.
These are objecBs created from classes.
2.1. Strigs:
String is
represernted
a sequerice ¢
o characters , and it
as an object in Java:
Strings are. immutable meaning that their
Contert cannot be changed once created.

Exanmple :

String message " Hello, Java!" ;

String operations Can include :


Comcateration : "Hello" + + "World"

Length : mess age -Length ()


Substring : Message..-substri (0, 5)
@curiOUs-proq ammcT
cIASSMAte
Date :
Page:

22. Arrays
" An Array is a collecton dof variables the
same
locations
type, stored in contiquous memors

Arrays have fixed size after they arecreated.

Example
int [] mumbers = S1,2,3, 4,53i
string [l names
na ="Alice " " Bob', "Charlie "3;

You can acess elements using an index Cstarting


from 0) :

System. out-printa (mumbers[O] ) W


output:l

@
cuTious - pgcammer
cIASSMAte
Date
Page

8. Variables and Constants:


3-1. Variables:
"AA Yariable is a ontainer for storing data.
H has a ame a type and a value.

Variables are declared by specifying the type


tollowed by the name.
Synlox:
Kdatatype> <yariable -nanme > = <value >j

Example
int age = 25j
String nam : "John"i

( curious
ziOus -- programmer
cIASSMAte
Date :
Page:

32. Conslants :
A CoYstant 1S variable whose value can not
be changed Omce. is asigned.
Comst ants are. declared using the tinal keybard.

Sumlax:
Final <datatype> <constant-name> = <value >;

Example:
tinal int MAX- VALUE =100 i

(@ uriouS--progammer
Fxamples requires
one. 14
Comvering to
Narrouim automaically.
(Manual) : happensIH
Comverting casting
refers
Type Cost4.iTypen1g. 4:
Example Widening ):another.
Example (Automatic lype
int
Casting
i=
10; : a
Casting
double a int In
larger smaller efers
asting
rplicit to Java and
ening @ to long to
Curious data dota ,
înt Converting Type
here
astirg - type type
progcammer oat are Comversion
to to to two one
(int Page: Date :
cIASSMAte
a double. a :
to larger data
smaller types
lomg
me
type
int)
cIASSMAte to t 2nofher.
the
type
(double int
to
:DatePage:
(str)i
Casting changing.
to
cnary"s parseInt
string
l
one
data
typ ways Explicit (@Curious
-progr
ammer
Narrowimg Conversiom
(Narrowing
(widening)
to two -Integer
"123"
refers
Conversion:
in
= di
314 Conversion
Conyersiomdome str
String
(int) variable
from
num
d be Exaaple
= 4.2.
Type Implicit
double
j Can int
int Te
Type
This "
cIASSMAte
Date
Page:

5 Unicode System :
Uricodeis. a character encoding standard that
1S used to represernt texd and symbols in
Java

.Each character is assigned a unique Uhinde


code point
The char data type in Java stores a single
Umicocde character.

Erample:
char 1etter ='A; I micocle for 'A' is 65

char symbol ='u0041'; IlUicode represe ntation

You might also like