October 2017
Beginner
318 pages
7h 26m
English
Java's decision to use objects of the String class as either string literals or genuine objects interchangeably is really powerful. It gives us way more options to manipulate text than we would otherwise have, but it does come with some trade-offs. While dealing with a String object, it's very important that we understand whether we're dealing with its string value or with the object itself. This is because we can get radically different behaviors. The preceding program we saw is designed to illustrate one of these instances.
It's a pretty simple program. Let's step through it and attempt to anticipate its output. We start off by declaring and instantiating two String objects: s1 and s2. We use the
Read now
Unlock full access