Call by Value

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:

  • formal parameter — the identifier used in a method to stand for the value that will be passed into the method by a caller.
  • actual parameter — the actual value that is passed into the method by a caller.

Call by Value

The type of parameter passing that Java uses is called call by value. Some programming languages use other methods of parameter passing, although call by value is the most common.

This is how call by value works:

  1. When the caller invokes a method, the caller provides a list of values (the actual parameters) in the parameter list.
  2. When the invoked method starts running, these values are copied to the formal parameters.
  3. The invoked method uses the formal parameters to access these copied values.
  4. Any change that the method makes to the value held in a formal parameter changes only that copy.
  5. The invoked method cannot use a formal parameter to send a value back to the caller.

QUESTION 2:

(Review:) What is a primitive data type?