FAQ: Learn Java: Manipulating Variables - Equals and Not Equals

This community-built FAQ covers the “Equals and Not Equals” exercise from the lesson “Learn Java: Manipulating Variables”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

FAQs on the exercise Equals and Not Equals

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I was trying the first part of the lesson – to test for the same number of songs.
Here is what I wrote: boolean sameNumberOfSongs = (songsA == songsB);
It gave me an error.
The correct solution: boolean sameNumberOfSongs = songsA == songsB;
Is there a convention or syntax statement why my version wouldn’t work?

Not really. That was a good answer, though the parentheses seem rather overkill.

The problem with the evaluator in that kind of practices, is that it doesn’t just focus on the results of the program. It also focuses on whether you created the variables it asked for, with the right name, and gave them the value it asked for. Thing is, in a Java program, variables created that way don’t exist after compilation. They’re replaced with positions in memory, and that doesn’t have a name.

So the evaluator cannot just look at the effects of the code you typed: that wouldn’t enable to check whether you created the variables it asked for. The evaluator analyzes what you typed in your program, and checks that it is “close enough” to a typical way to respect the instructions.

In your case, the evaluator didn’t expect that someone could add parentheses, that are not needed but perfectly valid. Wasn’t expected, therefore doesn’t count as “close enough” to the expected solution.

boolean sameNumberOfSongs = (songsA == songsB);