Thank you. I don't have my copy to hand now, but can look later.Crystal Zeng wrote:. . . Page 361
Devid Smith wrote:
I think you should put the idea that "an object can't be used directly" out of your head. The bottom line is that you need an object reference in order to use an object and there are other ways you can obtain an object reference besides assigning one to a reference variable.
Its such a good idea.I agree with you on 100%
What are the methods in question?Thanks in advance
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Yes it does.Tim Holloway wrote:. . . I don't remember if StringBuilder's appen() method supports method chaining. . . .
Campbell Ritchie wrote:
Yes it does.Tim Holloway wrote:. . . I don't remember if StringBuilder's appen() method supports method chaining. . . .
The toString() call is redundant.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Junilu Lacar wrote:
Crystal Zeng wrote:My confusion comes from the mind that I always think of new **() as an object and an object isn't allowed to be used directly.The book called <Head First Java>never says new operator will return a reference.From the descriptions below, I tend to think of the right side of = operator as an object.
This goes back to Bear's original point about programmers using shortcut notations to avoid saying "object reference" vs. "object" all the time. In many cases, in fact I'd say usually, "reference" and "object" are interchangeable. You just have to learn to discern when the distinction between the two matters in the context of the discussion and when it doesn't.
I think you should put the idea that "an object can't be used directly" out of your head. The bottom line is that you need an object reference in order to use an object and there are other ways you can obtain an object reference besides assigning one to a reference variable.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Stephan van Hulst wrote:If we're being pedantic, the new keyword is an operator that takes a class name and an argument list, and returns a reference to a new object.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Crystal Zeng wrote:
Only if you see the img named 444PNG(put your mouse around the img until the mouse is changed to "hand" icon and click it, it can be displayed), you may understand why I tend to think of the right side of = operator as an object rather than a reference according to the description based on the img.
What the book says:
But with polymorphism, the reference and the object can be different.
The looong version, without using shortcut terms:
The right hand side of the assignment statement, new Dog(), will create a new Dog object. Since you can only access objects through references, the new operator will actually return a reference to the new Dog object that it created. That reference is then assigned to the myDog variable, which has a declared type of Animal. If you're wondering how the type of the myDog variable can be different from the type of the reference returned by the new operator that is assigned to it, it's because of polymorphism. Since a Dog is a subclass of Animal, a reference to a Dog object can be assigned to a reference variable for an Animal object. This is because whatever you can do with an Animal, you should also be able to do with a Dog.
Crystal Zeng wrote:1. Can you provide strong evidence to say new operator returns a refernce?
The Offical Java Tutorial wrote:The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory.
Crystal Zeng wrote:2.It is so strange for a book read by beginners not to descripe clearly every time it refers to "reference "or"object" instead of abbreviating , I mean as accurate as math concept.
I take that as meaning you are saying other people are coding badly. [Maybe that isn't what you are trying to say.] I can understand that; you always have to take precautions against people using your code badly or providing bad code for you to use. But I think it is a bit overpessimistic to expect that people will supply you with badly‑written code. That is also, partially, what the /** documentation comments */ are there for: to explain any side‑effects.Gerard Charles wrote:. . . I will say that assuming code that you did not write follows a particular coding style / practice definitely isn't a good idea, and if you don't realize that, you haven't been coding long enough.
A field defaults to pointing to null, as do elements of arrays before they are filled.Crystal Zeng wrote:As for Step One, when declaring a reference variable before assigning it a reference to an object, does a reference pointing to nothing exist in this variable? . . .
Not 100% certain, but I am pretty sure it is an instance of one of the event classes for GUIs. I suggest you start with the Java™ Tutorials, and see whether that helps.S Fox wrote:wow! what is an "event object" ??? . . .
Well, that is the idea of an object languageS Fox wrote:. . . I never thought of events as being objects . . .
Don't know, but probably yes. Go through the methods of JComponent and see whether there is anything for firing events.So you could do something like Event e = new Event(null); . . .
Crystal Zeng wrote:As for Step One, when declaring a reference variable before assigning it a reference to an object, does a reference pointing to nothing exist in this variable?
The distinction for this picture is either there is a remote without linking an object in the cup,or just an empty cup.Which one is more accurate?
I think of a reference as a remote.
S Fox wrote:... here's a mind bender, where is the reference returned to if you don't assign it? To NULL? To the code block where that method was called from? Or is the interpreter smart enough to know never to even send it?
Junilu Lacar wrote:
Of course, when you assign an object reference to the variable, you definitely are putting a remote (the reference to the new object) that works with a specific TV (the new object) into the cup (the reference variable) labelled "originOne".
Junilu Lacar wrote:
Thank you so much. I got it now.