go to previous page   go to home page   hear noise   go to next page


Yes. Otherwise it would not be clear what its bits represent.

Declaration of a Variable

Here is a program that uses the variable payAmount.

class Example
  public static void main ( String[] args )
    long payAmount = 123;    //a declaration of a variable

    System.out.println("The variable contains: " + payAmount );

The line   long payAmount = 123;   is a declaration of a variable. A declaration of a variable is where a program says that it needs a variable. For our small programs, declaration statements will be placed between the two braces of the  main   method.

The declaration gives a name and a data type for the variable. It may also ask that a particular value be placed in the variable. In a high level language (such as Java) the programmer does not need to worry about how the computer hardware actually does what was asked. If you ask for a variable of type long, you get it. If you ask for the value 123 to be placed in the variable, that is what happens. Details like bytes, bit patterns, and memory addresses are up to the Java compiler.

In the example program, the declaration requests an eight-byte section of memory named payAmount which uses the primitive data type long for representing values. When the program starts running, the variable will initially have the value 123 stored in it.

A variable cannot be used in a program unless it has been declared. A variable can be declared only once.


What do you think the program prints on the monitor? (You should be able to figure this out.)