Shashank,
For simplicity, lets make an assumption, in.readLine() returns a new String object that was supplied on the command line.
1. Now if you supplied "good" on the command line you'll get new String("good") as a result of calling in.readLine(). The result of the new String is that a new String is created i.e. it is not picked up from the String pool(check the java api)
2. The String literal "good" defined in check_food is a compile-time constant i.e. it exists in the pool - JLS 15.28
Based on the 2 facts above, both the String instances do not point to the same reference & since == is a
test for reference equality they do not evaluate to true with the exception being thrown in check_food.
To see the difference between String's created using the new operator & String literals try the following -
* check_food("good")
* check_food(new String("good"))
As a general rule, never test String's for equality using ==, always use the equals method supplied in the String class.
Ashish Hareet