Numeric promotion in Java
Numeric promotion also known as Implicit casting or java automatic conversions where conversion of a smaller numeric type value to a larger numeric type automatically, so that integer and floating-point operations may take place. In numerical promotion , byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.
In the above case, int i is promoted to double so the calculation can be performed. In some ways, you can think of this is analogous to boxing , but boxing involves moving from a struct to an object that is from the stack to the heap. But, using the analogy does give an idea of the fact the integral value is being made into a floating point to perform the calculation.
Widening Primitive Conversion
19 specific conversions on primitive types are called the widening primitive conversions:
Narrowing Primitive Conversion
22 specific conversions on primitive types are called the narrowing primitive conversions:
- Java Interview Questions-Core Faq
- Important features of Java
- What is the difference between JDK and JRE?
- What gives Java its 'write once and run anywhere' nature?
- What is JVM and is it platform independent?
- What is Just-In-Time (JIT) compiler?
- What is the garbage collector in Java?
- What is NullPointerException in Java
- Difference between Stack and Heap memory in Java
- How to set the maximum memory usage for JVM?
- Why do we need Generic Types in Java?
- What does it mean to be static in Java?
- What are final variables in Java?
- How Do Annotations Work in Java?
- How do I use the ternary operator in Java?
- What is instanceof keyword in Java?
- How ClassLoader Works in Java?
- What are fail-safe and fail-fast Iterators in Java
- What are method references?
- "Cannot Find Symbol" compile error