In Java, there are two different types: primitives and object references.
Primitives include integers, floats etc and == works as you expected. With object references, when you use ==, it tests whether the references are equal, not whether the objects which those references point to are equal.
String is not a primitive, it is an object; therefore == will test the reference equality. You need to test equals() method to test for equality in terms of object's values.
As you can see, Java is not a pure object oriented language in this sense, you have variables that are not objects. For example, since integers are primitives, they don't have methods, so you can't do things like 3.add(4)
. Sometimes though, you need to make an object out of integers, that is when the wrapper classes like Integer come in. The conversion is automatic in some cases, and this is called autoboxing. For example, when you put an int to an ArrayList, autoboxing converts the int to an object since ArrayList accepts only objects; this conversion had to be manually done before Java 5.