This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes what is the different Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the different " Watch "what is the different " New topic

what is the different

William Janet

Joined: Feb 10, 2011
Posts: 4
What is the difference between these two statements:

1) return foo.equals("abcde");

2) return "abcde".equals(foo);
Buddhika Mawella
Ranch Hand

Joined: Jan 06, 2011
Posts: 36

Think about a situation where variable foo has the value 'null'. when foo is null if you execute
that will create a NullPointerException.
but folowing code will never throw a NullPointerException

since "abcde".equals(null) always return Boolean 'false'.
hope you got it..

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 36598
Welcome to the Ranch

Please always tell us what the question is about.
subject: what is the different
Similar Threads
still new to testing, how do I test this method:
2 complex problems
2 complex problems
Reverse 5 digit number by multiplying 4
Best way to figure out overlapping of strings