Originally Posted by
spoon!
No. There is no such thing in Java. All objects are on the heap.
Excuse me? I believe you have a misunderstanding. There are,
absolutely, local variables in Java, and
String a = "Java String";
is definitely
a local variable assignment, thus placing it within the scope of the current method. Methods live on the stack, thus the method's local variables also live within the stack.See here for
more on variables.
When you do "new String(...)", it creates a new String object that is not the same as any other object, so it is guaranteed not to be == to another object.
Did you misread my post? I stated that the statement using
new creates an object. What do you believe
new is for? Simply put, creating
new objects.