November 13, 2000

Memory Addresses

Question: How do I get the addresses of primitive variables, reference variables, and objects in Java? Answer: Unlike systems programming languages like C, Java does not have pointers. Objects are all accessed via references, which can be thought of as safe pointers with no pointer arithmetic. Primitivetypes can only be

String Equality

Question: When you compare two objects through the”== operator,” Java checks for reference equality. For example, if you create two String objects with “new” keywords and initialize them with same value and compare them with if(s1==s2), it returns false because the references are not same. But if you initialize two