go to previous page   go to home page   go to next page

Answer:

Data TypePrimitive Class
int    X    
String        X
long    X    
double    X    
Applet        X
boolean    X    
Scanner        X

The correct way to do this is to recognize the primitive data types. Everything else must be a class. Class names usually begin with a capital letter, but this is not required by syntax.


A Primitive Variable


class EgLong
{
  public static void main ( String[] args )
  {
    long value;

    value = 18234;
    System.out.println( value );
  }
}

The example program uses primitive data type long for the variable value. The statement

value = 18234;

puts a particular bit pattern in that 64 bit section of memory.

With primitive data types, a variable is a section of memory reserved for a value that uses that data type.

For example by saying long value, 64 bits of memory are reserved for an integer. By saying int sum, 32 bits of memory are reserved an integer.

Object reference variables do not work this way, however. The next several pages discuss this.


QUESTION 3:

(Thought Question:) Each primitive data type uses a fixed number of bits. For example, all variables of type double are 64 bits long. Do you think that all objects of the same type are the same size? Click here for a .