From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Converting numeric values - Java Tutorial
From the course: Java 8 Essential Training
Converting numeric values
- You can make copies of and convert numbers to different types. In this example, in the ConvertingNumbers project, I have one line of executable code. It's declaring an integer value named intValue1 with a value of 56. If I declare a second integer value, with intValue2, and I say assign the value intValue1, I know have two copies of the value. When you're working with primitives, you're always making a copy of the value, you're not creating a reference to the original value. So now, if I want to output the value, with System.out.print.ln, I'll say The second value is, and then I'll append the new value. Then I'll run the code. And I get the second value is also 56. But let's say that I wanted to take that integer and turn it into a long integer. Here are the rules. When you're converting from a type that uses a smaller amount of memory, to a type that uses a larger amount of memory, that's called widening the type. When you're going from a larger to a smaller, that's called…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Working with primitive variables8m 4s
-
Declaring and initializing numeric primitives6m 14s
-
Representing currency values with BigDecimal5m 10s
-
Converting numeric values5m 37s
-
Using mathematical operators and the Math class6m 1s
-
Working with Boolean values and expressions4m 49s
-
Working with character values3m 23s
-
Using Java operators6m 11s
-
-
-
-
-
-
-
-
-
-