From the course: Java 8 Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Passing arguments by reference or by value - Java Tutorial
From the course: Java 8 Essential Training
Passing arguments by reference or by value
- One of the questions you have to answer when you learn a new programming language is whether arguments passed into a method are being passed by copy, or by reference. Let's define these terms. When you pass arguments by copy, that means you're passing a variable into a function or a method, and within the method, a copy of the variable is received. It's not attached in any way to the original value before it was passed in. And when you pass into a method by reference, that means you're referring to the original object, the object that existed outside the method, and if you make any changes to the object within the method, it'll affect whatever was passed in originally. In Java, variables are always passed into methods by copy. But there are certain behaviors that can make you think you're passing by reference. I'm going to describe three scenarios, and explain how each of them proves the point that arguments are passed by copy. Let's take the simplest scenario, passing primitive…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Programming conditional logic3m 45s
-
(Locked)
Using the switch statement4m 51s
-
(Locked)
Creating looping code blocks5m 23s
-
(Locked)
Creating reusable code with methods4m 15s
-
(Locked)
Overloading methods with different signatures4m 51s
-
(Locked)
Passing arguments by reference or by value4m 47s
-
(Locked)
Challenge: Creating a more complex calculator application1m 53s
-
(Locked)
Solution: Creating a more complex calculator application3m 23s
-
(Locked)
-
-
-
-
-
-