SlideShare a Scribd company logo
4
Most read
7
Most read
9
Most read
Type casting in java
Type casting in java
 Type Casting.
 Assigning a value of one type to a variable of
another type is known as Type Casting.
 Example
 int x = 10; byte y = (byte)x;
 There are TWO types of type casting.
1. Widening Casting(Implicit).
2. Narrowing Casting(Explicit).
 In widening casting we converted the data or
value into broad data
 Example
public class Test
{
public static void main(String[] args)
{ int i = 100;
long l = i; //no explicit type casting required
float f = l; //no explicit type casting required
System.out.println("Int value "+i);
System.out.println("Long value "+l);
System.out.println("Float value "+f);
}
}
 Out put
Int value 100
Long value 100
Float value 100.0
 In Narrowing casting we converted the data
or value into Narrow data
 Example.
 public class Test
{
public static void main(String[] args)
{ double d = 100.04;
long l = (long)d; //explicit type casting required
int i = (int)l; //explicit type casting required
System.out.println("Double value "+d);
System.out.println("Long value "+l);
System.out.println("Int value "+i);
}
}
 Output
Double value 100.04
Long value 100
Int value 100
Thank you.

More Related Content

What's hot (20)

PDF
Arrays in Java
Naz Abdalla
 
PPTX
Java exception handling
BHUVIJAYAVELU
 
PPTX
Inner classes in java
PhD Research Scholar
 
PPTX
Constructor in java
Pavith Gunasekara
 
PPTX
Method overloading
Lovely Professional University
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Interface in java
PhD Research Scholar
 
PPS
Java Exception handling
kamal kotecha
 
PPTX
java interface and packages
VINOTH R
 
PPTX
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
PPTX
This keyword in java
Hitesh Kumar
 
PPTX
Java constructors
QUONTRASOLUTIONS
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PDF
Generics
Ravi_Kant_Sahu
 
PPT
Class and object in C++
rprajat007
 
PPTX
Oop c++class(final).ppt
Alok Kumar
 
PPT
Inheritance in java
Lovely Professional University
 
PPTX
Operators in java
AbhishekMondal42
 
PPT
Exception Handling in JAVA
SURIT DATTA
 
Arrays in Java
Naz Abdalla
 
Java exception handling
BHUVIJAYAVELU
 
Inner classes in java
PhD Research Scholar
 
Constructor in java
Pavith Gunasekara
 
Method overloading
Lovely Professional University
 
Classes, objects in JAVA
Abhilash Nair
 
Interface in java
PhD Research Scholar
 
Java Exception handling
kamal kotecha
 
java interface and packages
VINOTH R
 
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
This keyword in java
Hitesh Kumar
 
Java constructors
QUONTRASOLUTIONS
 
Data Types & Variables in JAVA
Ankita Totala
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Generics
Ravi_Kant_Sahu
 
Class and object in C++
rprajat007
 
Oop c++class(final).ppt
Alok Kumar
 
Inheritance in java
Lovely Professional University
 
Operators in java
AbhishekMondal42
 
Exception Handling in JAVA
SURIT DATTA
 

Similar to Type casting in java (20)

PPTX
Type Casting in java programming language.pptx
simranpreet12ka4
 
PPTX
Type casting
Ruchika Sinha
 
PPTX
Data types in java
HarshitaAshwani
 
PPTX
Type cast operator
ASHUTOSH TRIVEDI
 
PPTX
Type casting
simarsimmygrewal
 
PPTX
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
AhmedMehmood35
 
PPTX
Java Datatypes
Mayank Aggarwal
 
PPTX
Chapter 3.4
sotlsoc
 
PPTX
Chapter i(introduction to java)
Chhom Karath
 
PPT
9 cm604.8
myrajendra
 
PPT
3. Data types and Variables
Nilesh Dalvi
 
PPTX
01 Java Language And OOP PART I
Hari Christian
 
PPTX
Java Tutorial Lab 2
Berk Soysal
 
PPTX
java Basic Programming Needs
Raja Sekhar
 
PPTX
Ifi7184.DT lesson 2
Sónia
 
PPTX
Java Type Casting
AathikaJava
 
PPTX
Type casting in ooabap
biswajit2015
 
PPTX
Data types in java.pptx power point of java
rabiyanaseer1
 
PPT
2.DATA TYPES_MB_2022.ppt .
happycocoman
 
Type Casting in java programming language.pptx
simranpreet12ka4
 
Type casting
Ruchika Sinha
 
Data types in java
HarshitaAshwani
 
Type cast operator
ASHUTOSH TRIVEDI
 
Type casting
simarsimmygrewal
 
OOP - Lecture04 - Variables, DataTypes and TypeConversion.pptx
AhmedMehmood35
 
Java Datatypes
Mayank Aggarwal
 
Chapter 3.4
sotlsoc
 
Chapter i(introduction to java)
Chhom Karath
 
9 cm604.8
myrajendra
 
3. Data types and Variables
Nilesh Dalvi
 
01 Java Language And OOP PART I
Hari Christian
 
Java Tutorial Lab 2
Berk Soysal
 
java Basic Programming Needs
Raja Sekhar
 
Ifi7184.DT lesson 2
Sónia
 
Java Type Casting
AathikaJava
 
Type casting in ooabap
biswajit2015
 
Data types in java.pptx power point of java
rabiyanaseer1
 
2.DATA TYPES_MB_2022.ppt .
happycocoman
 
Ad

Recently uploaded (20)

PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
community health nursing question paper 2.pdf
Prince kumar
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Ad

Type casting in java

  • 4.  Assigning a value of one type to a variable of another type is known as Type Casting.  Example  int x = 10; byte y = (byte)x;
  • 5.  There are TWO types of type casting. 1. Widening Casting(Implicit). 2. Narrowing Casting(Explicit).
  • 6.  In widening casting we converted the data or value into broad data  Example
  • 7. public class Test { public static void main(String[] args) { int i = 100; long l = i; //no explicit type casting required float f = l; //no explicit type casting required System.out.println("Int value "+i); System.out.println("Long value "+l); System.out.println("Float value "+f); } }  Out put Int value 100 Long value 100 Float value 100.0
  • 8.  In Narrowing casting we converted the data or value into Narrow data  Example.
  • 9.  public class Test { public static void main(String[] args) { double d = 100.04; long l = (long)d; //explicit type casting required int i = (int)l; //explicit type casting required System.out.println("Double value "+d); System.out.println("Long value "+l); System.out.println("Int value "+i); } }  Output Double value 100.04 Long value 100 Int value 100