Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Efficiency! Building the Model

When do I need to use a parameter?

This question had to come quite sooner, but I thought that with more practice I'll eventually figure it out. Still, I'm looking at the codes in the videos and still don't understand when is actually necessary to use parameters. For me, it feels like a parameter would fit everywhere and vice-versa (wouldn't fit). What questions should I give myself in order to understand if a method requires parameters in it or not?

1 Answer

Ronald Williams
.a{fill-rule:evenodd;}techdegree seal-36
Ronald Williams
Java Web Development Techdegree Graduate 25,021 Points

Here is a question you can ask yourself: Does this method require outside variables / information? Here are two scenarios to help:

1). A method that when called plays your music:

// notice there is no parameter in this method
public void play() {
    playingMusic = true;

2). A method that adds a song to your favorite playlist:

// notice this method takes a song i.e. the one you are adding to the playlist
public void addSong(Song song) {