Explicit and Implicit DataTypes Conversion in Java
Programming Guru
Type conversion in Java with Examples Java provides various data types just likely any other dynamic languages such as boolean, char, int, unsigned int, signed int, float, double, long, etc in total providing 7 types where every datatype acquires different space while storing in memory. When you assign a value of one data type to another, the two types might not be compatible with each other. If the data types are compatible, then Java will perform the conversion automatically known as Automatic Type Conversion, and if not then they need to be cast or converted explicitly. For example, assigning an int value to a long variable.
#java #datatypesinjava #datatypesconversion
Type Casting in Java In Java, type casting is a method or process that converts a data type into another data type in both ways manually and automatically. The automatic conversion is done by the compiler and manual conversion performed by the programmer. In this section, we will discuss type casting and its types with proper examples.
Types of Type Casting There are two types of type casting:
Widening Type Casting Narrowing Type Casting Widening Type Casting Converting a lower data type into a higher one is called widening type casting. It is also known as implicit conversion or casting down. It is done automatically. It is safe because there is no chance to lose data. It takes place when:
Both data types must be compatible with each other.
The target type must be larger than the source type.
For example, the conversion between numeric data type to char or Boolean is not done automatically. Also, the char and Boolean data types are not compatible with each other. Let's see an example.
Follow my Facebook Page : https://www.facebook.com /105940115222549 Follow me on Instagram : https://www.instagram.com/p/CViUlw2sOMi Follow me on tumblr : http://programming-guru.tumblr.com Follow me on reddit : https://www.reddit.com/u/Programming_guru1?utm_medium=android_app&utm_source=share ... https://www.youtube.com/watch?v=AdMlAXFoRv4
11763201 Bytes