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! While you're at it, check out some resources Treehouse students have shared here.

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 Objects Creating the MVP Current Progress

Chris Rubio
Chris Rubio
1,643 Points

question ...ok on the video CURRENT PROGRESS min 4:48 --he said String progress = ""; could he have done = null instead

question ...ok on the video CURRENT PROGRESS min 4:48 --he said String progress = ""; could he have done = null instead of the quotations ?

1 Answer

Ben Reynolds
Ben Reynolds
35,170 Points

No, because later in the method he starts concatenating values to the progress string and needed a blank starting point. An empty string is still a string, that is an instance of the String class, even if it doesn't have any characters assigned to it yet.

Null on the other hand is not, and if you try to concatenate to it, it will first convert that null to the word "null". When I tested in JShell I got this:

String a = null;
a += "test";
// resulting value of a was "nulltest"