O'Reilly logo

Java™ How To Program (Early Objects), Tenth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.6 Memory Concepts

Variable names such as number1, number2 and sum actually correspond to locations in the computer’s memory. Every variable has a name, a type, a size (in bytes) and a value.

In the addition program of Fig. 2.7, when the following statement (line 18) executes:

number1 = input.nextInt(); // read first number from user

the number typed by the user is placed into a memory location corresponding to the name number1. Suppose that the user enters 45. The computer places that integer value into location number1 (Fig. 2.8), replacing the previous value (if any) in that location. The previous value is lost, so this process is said to be destructive.

Fig. 2.8 | Memory location showing the name and value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required