data type, type casting,constants. data types in java

11
Data type , Type Casting ,Consta nts

Upload: angel-hensley

Post on 02-Jan-2016

264 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Data type , Type Casting ,Constants

Page 2: Data type, Type Casting,Constants. DATA TYPES IN JAVA

DATA TYPES IN JAVA

Page 3: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Data types in javaEvery variable declared in a Java program is having the data type. Data type specifies the size and type of values that a variable can have. Java has a rich set of data types.

Page 4: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Integer Data Type

Page 5: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Real Data Type

Page 6: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Character & Boolean Data Type

• Character :In order to store single character constant in a variable, character data type is used.- minimum value is ‘\u000’=0- maximum value is ‘\uffff’=65535

• Boolean :Boolean data type is used to store two different values. But,values stored inside the boolean type will only be true and false.

Page 7: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Type Casting

Page 8: Data type, Type Casting,Constants. DATA TYPES IN JAVA

What is type casting?

Changing a value from one data type to another data type is known as data type conversion i.e. assigning a value of one type of a variable of another type is known as type casting.

Types of type casting:1. Widening Type Casting (Implicit)2. Narrowing Type Casting ( Explicit)

Page 9: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Widening Type Casting (Implicit)

• If a value of lower size data type converted to a value of higher size data type without loss of information is Implicit casting.

Page 10: Data type, Type Casting,Constants. DATA TYPES IN JAVA

Narrowing Type Casting ( Explicit)

• If a value of higher size data type converted to a value of lower size data type without loss of information is Implicit casting.

Page 11: Data type, Type Casting,Constants. DATA TYPES IN JAVA

MSBTE Question Bank:

Q1 .Write all primitive data type available in java with their storage sizes in bytes.(w-9, s-12)

Q2 . List different data types in java.(s-10)Q3. Give all the primitive data types available in

java with their strorage size in bytes. (s-13) Q4. Explain ‘type casting ‘ with example.(s-11)Q5

. What do you mean by type casting ?when is it needed?(w-12)