Skip to main content

Type Conversion

 

Operations in our applications will commonly involve multiple data types. Because of that, we must deal with type conversions. Now there are implicit type conversions, and those are type conversions that are performed automatically by the compiler. To see a simple example of that, we look at something like here we have an integer iVal that we've assigned the value 50. If I then say long lVal equals iVal, the compiler must convert that 32bit integer iVal into a 64bit integer as it's stored into lVal. And there are also explicit type conversions, and these are conversions that I explicitly perform in my code and I do that using a cast operator. We see here if I had that long lVal = 50 now, so I'm now assigning a 64bit integer the value of 50, if I want to assign that into this iVal, a 32bit integer, I have to explicitly cast it. I must tell part of that I want to go from that 64bit integer into a 32bit integer. And I do that by using the type I want to convert to, in this case, int, putting it inside of parentheses, and putting it next to the value I want to cast. So, this says, the int in parentheses says, take the lVal and cast it down to a 32bit integer. If we look now at these implicit type conversions, these are generally what we call widening conversions, and these can be done automatically because we're moving to a wider data type. So, if I have a 32bit integer and I want to move to a 64bit integer, that's wider, right? So, the values can be safely moved, so those can be done implicitly. And the compiler must make decisions about how to make these conversions. And the rules are straightforward. If I have expression with multiple integer sizes in it, maybe have a short and a long, whatever the largest integer size is what things will be converted to. So, if I do an operation with a short and the long, the short will be implicitly cast into a long. If I perform an operation with mixed floatingpoint sizes, so I have a float and a double, it'll always go to the double because double is the largest floatingpoint size. And then if I have an operation that uses integer types and floatingpoint types, the compiler will cast to whatever the largest floating point in the equation is. So, if I do an operation with a long and a float, the long will be cast to a float. If I do an operation with a long and a double, the long will then be cast to a double. Explicit type conversions are the ones that we explicitly perform in our code using this cast operation. When we do that, we're taking responsibility for whatever happens as a result of that type conversion. Because of that, we can perform both widening conversions and narrowing. So, widening going from a 32 bit to say a 64 bit, narrowing going from a 64 bit down to a 32 bit. We should just want to be aware that we know what could potentially happen. If we do an explicit cast from a floating point to an integer, while floating points can have fractional portions, integers can't. So, any fractional portion would be dropped when I cast that float down to an integer. You want to be careful when performing a narrowing conversion. If I have a 64bit integer, it can hold values that are too large to fit into a 32bit integer. So, if I cast that 64 bits to a 32 bit, the program will do it, but if the value was too large to fit into a 32 bit, you'll get some odd results from that. So, you want to make sure that when you're casting it, doing a narrowing cast, that you know that what you're doing is safe. And the last one is just that you want to be careful when converting from an integer to a floating point. Because if you have an integer with many significant digits, because of the way floating points are stored, you could lose some of those significant digits. The deep details of how these type conversions occur are beyond the scope of this course, but if you'd like to understand them in more detail, I've got that URL on the screen for you that actually points to the Java documentation that talks about those details. If you check that out, you'll particularly want to look at the sections on widening primitive conversion and narrowing primitive conversion.


Demo: Type Conversion


Comments

Popular posts from this blog

Brief Overview of RPA

Brief Overview of RPA:     §   In short, it’s a way for machines to replace human workers in regular activities done across the organization.     §   It works on both Front End & Back End applications/operations.     §   BOT provides Virtual automation agents , it acts like MIMIC HUMANS .     §   BOT ’s available in Clouds/Servers     §   BOT is nothing but a configurable software set up, works only on rule-based triggers     §   It automates Non-Value –added works     §   It is a Sub Domain of BPMS (Business Process Management Software)

RPA Life Cycle

RPA Life Cycle: It is similar to software development life cycle with some minor changes. Technically, we called it as ‘ Life Cycle of a Bot’   Analysis:           ·     RPA Cycle begins from ‘ Analysis ’ phase.           ·     In this, Business Team & RPA Strategist/Architect identifies business process to automate           ·     After finalizing feasibility on process, implement plan of work (which includes documentation, Resources count & Time  ...) Development:          ·       Dev. Team starts working on requirements wrt to Environment.          ·       We called this phase as ‘ Bot Development ’          ·       Based on Tool selection , Limited/No coding is required ...

Why RPA, Why not Other Tools

Like below there are several features compared to other tools RPA QTP/UFT SELENIUM Commercial Commercial Open Source Less Programming Moderate Programming More Programming License Cost is Less License Cost is More No license cost Free Version No/Minimal additional cost for extra bots Add-Ins Additional cost is very high Free/Paid Add-Ins are available ROI is more ROI is less compare to RPA ROI is more as Open Source Error rate almost to Zero Error rate is moderate Error rate is moderate Customer Satisfaction is high Customer Satisfaction is Moderate Customer Satisfaction is Moderate User Friendly User Friendly Complex 24*7 support 24*7 support No Support