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 (Retired) Delivering the MVP Validation

Ray Wai
Ray Wai
2,355 Points

Why is there a difference between false & !true ?

Hi,

On the exercise where we are asked to validate the member variable naming, when I put

char secondLetter = fieldName.charAt(1);
if (Character.isUpperCase(secondLetter) = false) {
 throw new IllegalArgumentException("Second letter must be uppercased")
}

It has a compiler error saying

./TeacherAssistant.java:12: error: unexpected type
    if (Character.isUpperCase(second) = false) {
                             ^
  required: variable
  found:    value
1 error

But if I put

char secondLetter = fieldName.charAt(1);
if (Character.isUpperCase(secondLetter) != true) {
 throw new IllegalArgumentException("Second letter must be uppercased")
}

Everything works just fine and challenge is completed, but I do not see any difference between the two. What is going on?

Ray

Konrad Pilch
Konrad Pilch
2,435 Points

Do you kno what !false means and what true means?

Ray Wai
Ray Wai
2,355 Points

They mean the same thing

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

The error you are getting is not actually in reference to the fact that you put false instead of != true, in fact I am pretty sure that there is not difference.

The error you are receiving is the fact that you are assigning the variable to the value false in the conditional instead of testing for whether the value is false or not.

In the conditional you should be doing this:

if(value == false) {
//...do something
}

//or

if(value != true) {
//... do something
}

Hopefully this answers your question.

Ray Wai
Ray Wai
2,355 Points

Dane,

Yes, this indeed answers my question, thank you!