>For example,
>String s = new String("java");
>As I know, s is a referece, but I do not clearly >know what is a object. Does object only exist in >runtime? who can explain for it or show me a >example for what they are difference? Thanks in >advance!
a) As you have said, "s" is a reference. So, its just a small piece of memory with an address in it. That address points to the real object in memory.
b) The real object (the object created by your 'new String("java")' statement) is an instance of the class java.lang.String. That object is a chunk of memory with "java" in it along with some other class instance members (non-static variables) that hold information about the String object. It also has references to the methods of the String object. See java.lang.String in the
Java 2 Platform, Standard Edition, v 1.3.1
API Specification
c) Oh, yes, the run time question. Well ... this may be tricky. Because quoted strings are pretty static in nature (the compiler already knows what you want in your string) it could be creating something at compile time. Certainly dynamically created strings are run-time. To answer this more you need someone with more insight into compilers and Java VMs.