Group 4 Type Conversion
Group 4 Type Conversion
TYPE CONVERSION
TYPE CONVERSION
TYPE CONVERSION
PRESENTED BY: GROUP 4
GUZMAN, CRISTIANERY KHIM B. CATAN, JAMES MICHAEL E. REDULA, JAYMOEN M. OCSIANO, LESLIE KATE C.
TYPE CONVERSION
Type Conversion is an essential aspect of
programming. It refers to the process of
converting one data type into another. This
can be done either implicitly or explicitly.
DATA TYPE
a set of values and a set of operations on those values.
string, for computing with sequence of characters, for input and output.
int, for computing with integers, for math calculations in programs
double, for computing with floating point numbers, typically for science
and math apps.
boolean, for computing with true and false, for decision making in
programs
CSC 104 - COMPUTER PROGRAMMING II Home About Content Others
TYPE CHECKING
The Java compiler is your friend: it checks for type errors in your code.
2 TYPES OF CONVERSION
Implicit Conversion (Widening Conversion)
Implicit conversion, also known as widening conversion, happens automatically when a smaller data type
is converted to a larger data type. This type of conversion is safe and does not result in data loss.
In this example, int is converted to long, and long is converted to double without any explicit cast.
Here, double is explicitly cast to long, and long is explicitly cast to int. The cast is necessary to inform the
compiler that you are aware of the potential data loss.
CSC 104 - COMPUTER PROGRAMMING II Home About Content Others
2 TYPES OF CONVERSION
CSC 104 - COMPUTER PROGRAMMING II Home About Content Others
You can see this by creating a program that uses such a function to generate a short sequence, and
observing that each time you run it it generates the same sequence. This option surprises the
unsuspecting, but is also quite a useful property in testing code. When a less predictable sequence is
required, one normally initialised the PRNG with a seed value that is itself unpredictable, often derived from
the current system time, since it is not normally predictable when a program will be started.
THANK YOU
THANK YOU
THANK YOU