Reputation: 21
I am in the confusion that when is the String object created? I mean at the time of identification process by a compiler where the compiler identifies each statement in a java class for binding OR at the time of execution by jvm, where the jvm executes each statement in the java class based on the binding.
Upvotes: 0
Views: 85
Reputation: 427
String s1 = "iByteCode";
How this works?
■ JVM checks the String constant pool first and if the string does not exist, it creates a new String object “iByteCode” and a reference is maintained in the pool. The variable ‘s1′ also refers the same object.
■ This statement creates one String object “iByteCode”.
Upvotes: 0
Reputation: 7267
No objects are instantiated at compile time. This is impossible, regardless of the type.
Compiling a java class converts it into byte code, this byte code is executed within the JVM and this is where your objects are created in the heap.
Upvotes: 1