Q:

difference among ==,equals() and instanceof()

String s=new String("Computer");
if(s=="Computer")
    System.out.print("equals A");
if(s.equals("Computer"))
    System.out.print("Equal B");

Output is Equal B
Now why  == doesnot produce equals A
what is instanceof?

A:

== is referential equals, as in, 'is this exact object the exact same object as they other object?'.
When you made s you made a new object, so it won't be the same object as the string you're comparing it too (depending on the JVM you're using "foo" == "foo" will be true because it will use the same object internally).
When you called .equals() it (the String s)ran it's own logic to determine that it's the same object. In the case of String, it will compare it character by character.
instanceof is something else entirely, and will tell you if an object is an instance of a certain type of object, e.g. "foo" instanceof String is true.

A:

The equals() method will return true, if two Strings have the same value. The == operator will only be true, if both Strings point to the same underlying Object. Hence two Strings representing the same content are guaranteed to be equal, when tested by the equals(Object) method; whereas when tested with the == operator, it will only be true with they refer to the same Object. So, we should always use equals() for String comparison.
The instanceof keyword can be used to test if an object is of a specified type. For example,
if(foo instanceof Bar) { // must not pass
}

For more insight, see here.

