How do you declare variables

Declaration of a variable

Here is a program that uses the variable.

class example {public static void main (String [] args) {long wage amount = 123; // declaration of a variable System.out.println ("The variable contains:" + wage amount); }}

The line is the declaration of a variable. The declaration a variable is the place where the program says that it needs a variable. For our small programs, the declaration statements will be placed between the two curly brackets of the method.

The declaration assigns a name and a data type for the variable. You could also require that a certain value be put in the variable. In a high-level programming language (such as Java), the programmer does not have to worry about how the computer hardware actually implements this requirement. When you request a variable of type, you get it. If you request that the value 123 be put in the variable, then that's what happens. Details such as bytes, bit patterns and memory addresses are up to the Java compiler.

In the sample program, the declaration requests an eight-byte section of memory with the name that uses the primitive data type to represent values. Initially, the value 123 will be stored in the variable.

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

QUESTION 3:

What do you think does the program display on the screen at runtime? (You should be able to figure that out.)