A Primitive Variable

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.
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

Here is a tiny program that uses a primitive data type:


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

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

In this program, the variable value is the name for a 64 bit section of memory that is used to hold long integers. 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 will 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 .