There is a million ways to remember things better, if we are to judge the amount of books and tutorials on improving ones memory. However, they all rely on some "method" that equals more work. And you're quite likely not to bother for long then, right?
Inspired by Cyborg 101 by Angus Wong, and especially chapter 3 on "RAM Upgrade", I decided to try to gather my peculiar memorizations and explainations here. This will be very dependent on my sick and twisted mind, and also my interests and subjects. However, they can serve as examples for just how wierd and twisted ANY subject can be remembered. [PARENTAL GUIDANCE!]
In its current state, its mearly a gathering point for explainations and memorizations, many just snipped from e-mails, news-posting etc. Might improve over time thou.
package bizarre.de.sade;
interface Master {
public Slave getSlave();
public void setSlave(Slave s);
}
interface Slave {
public Master getMaster();
public void setMaster(Master m);
}
class BDSMPerson extends Person implements Master, Slave {
//...
private Master masterHoldingChainAroundMyNeck;
private Slave slaveIAmHoldingInAChain;
}
Mental image: (choose sex of subjects using your own preference)
1. person is strongly dominatingly dressed: Whip, Leather, Cape, Hat,
Coat... And a leash going to the second person.
2. person, less dominatingly dressed, more submissive undertones. Has
a dog collar around neck, no hat, but still dressed up. Holds a leash
going to the third person.
...etc ad nauseum, or the last BDSM party goer has joined the linked
list.
Last person: Naked, wearing only the leash around her neck. Last
element of the linked list.
[Nasty girl]---o[Bad girl]---o[Slave girl]
Now this is also a "doubly-linked" list, since we have a reference
both to the next element (the persons slave), and the previous element
(the persons master). If a person can't get ahold of the leash going
from her collar, (The one her master/mistress holds her by) perhaps
because her arms are restrained at the waist, then we can only
traverse the list one way, and then it would be a "singly-linked"
list. (This is accomplished by removing the variable
private Master masterHoldingChainAroundMyNeck
)
Any artists who want to give their impression of this? I won't dare put anyones real work here as "grafical illustration". (You never thought you'd surf for sex pictures as part of serious learning, did you? Eh? ;-)
Every object exists in the memory... somewhere...
When you call a method, like
Then, a VALUE is passed. That value is an INDEX of sorts, that allows the VM to find the object in memory. How exactly this is done, depends... on what? The VM!
doFoobar(Object myFoo);
Microsofts VM (at least used to) use pointers. That means the value probably was the value of the pointer. Others may use an index into a giant array of Objects... (sounds a wee bit better, atleast when you consider GC'ing....)
So when you have something like
then you don't "have" the value of the object, but a value that is a
HANDLE of sorts, a LEASH that goes to the correct dog. Then when you
call
Dog myPet = new Poodle();
you give a COPY of the LEASH to the Vet... he can't unplugg YOUR leash and plugg it to another dog... he can, however, castrate, kill, and shave the dog ... or whatever the sick bastard might think of... He can also unplug HIS leash (which was a copy of yours, remember) and plug it on another dog... but you still will have your dog in your leash... nomatter what...
myVet.castrate(myPet);
That is why the swap function won't work.
Calls by reference/pass by reference... its all academia... get it clear in your heads, and throw the dull words out the window... we're here to learn, not play rhetoric games, right?.... right?
Gawd, will people please try to get the right definition before they argue? reference parameters != reference if it was, what is the "parameters" word for? Seems redundant, eh?
Reference parameters would suggest that the method DOESN*T get a reference to the object, but a reference to the reference (no thats not a glitch, it should say reference twice) of the object (in java that is)
Java works like this: myObj -> [TheRealObject] <- methodsLocalObj They point to the same thing, but can't affect what the other points to.
Whereas the discussion is, do we need: methodsLocalObj -> myObj -> [TheRealObject] when we call a method? Theres another level of indirection, so they CAN affect what the other points to.
So that you stick your complete hand into the woodchipper when you feed it? Sounds like a recipe for a bloody mess, right? Reference parameters = hold log, stick hand in chipper, mechanics grab hand, then process log. Reference by value = hold log, stick log in chipper, mechanics grab ahold of log, and can't make you drop the log. Process log (and watch those fingers, will ya?)
Lets continue the dog analogy I used in the other thread:
Reference = a leash to a dog/person/thing
Object = a Dog (Poodle, GreatDane, GermanShepperd, take your pick)
Value of reference = "connects to that dog", or the location of the dog-collar if you will.
Dog myPet = new GreatDane(); // I'm holding the dog
ourVet.vaccinate(myPet); // the castration ex. is getting me queasy in the long run
I'm not giving my dog over. I'm not giving MY leash over. I'm giving him a COPY of my LEASH (VALUE of REFERENCE). He therefore can't affect the status of my leash, cause he never touches it. Everything that is passed by value is copied. So the reference is copied. But NOT the object.
And the discussion is: does Java need arguments passed by reference, as opposed to passed by value of reference? Should the vet, if your dog dies, be able to replug YOUR lash to another dog? N-O!!!!! His own leash? Whatever he pleases... he probably has to help someone else, right? [This is off the top of my head, and whatever nasty things I've said, I'll just generally apologize, cause this is driving me up the wall....]
>Would you please help me out with the "passed by reference" concept. >Can you explain this to me: > What is the difference between "passing a reference to an object by >value" and > "passing a reference to the object"? > >Here's my attempt at answering my own question: >(Let's assume that the object is an array of characters, called arrayCh > and that it is located in memory beginning at location ABC444) > >If I'm "passing a reference to an object by value", then I'm actually >passing >ABC444 as my parameter. Would that be correct?
Sounds quite correct, but the actual implementation depends on the VM... could be an index, but still, as a mental model, that is absolutely correct.
>If I'm "passing a reference to the object", then, well, I guess I really >don't have a clue. Help!
This is a bit more complex, and thinking C++ might help a bit. When you have a method like swap(int& a, int& b) then you actually HAVE hold of the int, so that int age=20, height=178; swap(age, height) would make age == 178, and height == 20
When you're passing BY reference as this, you're giving them controll on what you have on "your" side (the calling body).
Objects aren't on your side, nor the methods side... Its in "Object-space".
So passing BY reference would mean they have hold of your REFERENCE, and not the object. So a swap would work.
This is equivalent to a pointer... When you pass a pointer, they also get the adress space. If you pass it by reference, then they have ahold of your pointer, and can change its position. Big difference.
As an example, think about method calling, like putting logs in a wood-chipper.
pass-by-value-of-reference: you stick the log in the machine, it grabs it, and chews it up.
pass-by-reference: you stick your complete arm in the machine, it grabs the log, chews it up, and puts it back into your hand.
Since a "pass-by-reference" means that it could in fact just keep the lo g and give you some old sawdust instead. (Since you have no idea what is happening with your hand)
Actually, the phrase "pass-by-reference" gets confusing too, since its a nice short form for how Objects are passed in Java, but its not quite true.
Your number-model is the most correct as far as Java is concerned, and is the one to keep "upside the head". ====
Another way to look at it. If "int" is a primitive, think of the REFERENCE you have, as a primitive too. (The object isn't primitive, but the reference is... and any "Object" variable, is a reference...) int myInt = 9; // just the number 9 Object myObj = new Thing(); // myObj is a number, a "pseudo-pointer" to a Object on the heap. Lets call the number ABC444, as you did. When you call a method: smackItAbout(myInt, myObj); What gets passed, is the values. The number nine, and the ABC444 number, is copied into similar variables, namely aInt and aObj, if the method is: public void smackItAbout(integer aInt, Object aObj){ ... } Can you inside this method mutiliate the object? No problem? If the number nine was an array index, could you access that element and mutilate that too? (Sure, if you have the array, no problem) Those last statements show the same amount of indirection (as a model, not talking implementation) However, what is the "pass-by-reference" as opposed to "pass-by-value-of-reference" ? Lets think that a reference to the variables holding the numbers were passed, instead of a copy. Then myInt = 5; smackItAbout(myInt, myObj); could result in myInt NOT being 5 anymore! You stuck your complete "myInt"-hand into the method, and it could muck about with it! Same thing goes for the reference. The method can still mutilate and abuse your precious object (as it always could), but now it can also mutilate your reference (myObj) to point to something completely different. (And thusly a swap is possible) This means that the following might be possible. myObj = new String("Hi"); smackItAbout(myInt, myObj); System.out.println(myObj); could result in something different that "Hi" being printed? How is that? A String object can't be changed, so what DID change? The reference! Your reference (myObj)! This happened cause the method could make your myObj point to something else! (Thankfully, this isn't how Java operates as standard, and perhaps it shouldn't become an option neither! But thats a matter of opinion.)