19 Pass by Value vs. Pass by Reference

 

After reading lesson 19, you will be able to:

  • Understand how Java passes arguments to parameters in a method
  • Understand the impact of pass by value vs. pass by reference

In this lesson, you will learn that all arguments are copied into the parameter variables when a method is called. For this lesson, I want to have a consistent naming for the values described, so here is a diagram of the terms in this lesson:

Figure 19.1 Diagram identifying the key terms for a method call

In figure 19.1, I have identified the key terms that are used when calling a method.  Methods are designed to allow the calling program to pass in values as arguments.  In this lesson, I will review scenarios that pass primitive data types, Strings and other objects.  For each scenario, I will identify if it is a pass by value or pass by reference.

19.1   Passing Primitive Types

19.2   Passing Reference Types

19.3   Summary