Primitive Data Types as Parameters

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.
go to previous page   go to home page   go to next page

Answer:

A primitive data type is one of the eight fundamental methods used to represent data that is built into Java.

Primitive Data Types as Parameters

The eight primitive data types are:

byteshortintlong floatdoublecharboolean

The word primitive means "a fundamental piece that is used to create other, larger parts." So far we have been using parameters with primitive data types. Here is a tiny program that reviews this:

class SimpleClass
{
  public void print( int x )
  {
    System.out.println("Value of the parameter: " + x );
  }
}

class SimpleTester
{
  public static void main ( String[] args )
  {
    int var = 7;
    SimpleClass simple = new SimpleClass();

    System.out.println("First  value of the local var: " + var );    
    simple.print( var );
    System.out.println("Second value of the local var: " + var );    
  }
}

QUESTION 3:

What is the output of the program?

First  value of the local var: 
Value of the parameter: 
Second value of the local var: