Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

A. Introduction to Java Applications > A.6. Memory Concepts

A.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. A.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 number1 (Fig. A.8), replacing the previous value (if any) in that location. The previous value is lost.

Image

Fig. A.8. Memory location showing the name and value of variable number1.

When the statement (line 21)

number2 = input.nextInt(); // read second number from user


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial