[Java] Bucky's 16th and 17th tutorials.

Rafay

var nerd; nerd = db_getUser("rafay");
Messages
2,106
Location
Pakistan
Hey guys, I understood almost nothing from Bucky's 16th and 17th tutorial on thenewboston. I watched it several times but couldn't get my mind set on what's he saying. If anyone of you could try to explain both of those (or at least 16th), it will really appreciated.

9t78g0U8VyQ[/media]] - 16th
tPFuVRbUTwA[/media]] - 17th
 
GPow69 said:
I'm writing out a post right now, hopefully it'll help, I'll be done in a bit :tongue:
Thank you so much. I had a feeling that you will be the one to help me out. :wink:
 
GP is the master of Java on TMS :biggrin:
I won't bother writing a reply because GP's will be 10 times better and more understandable :wink:
 
- He makes a private variable (Type string) called girlName; Public variables can be used by ANY class, but private variables can only be used by the class they're in (In this case, only things INSIDE tuna.java can use girlName)

- He then makes a method called setName - Its purpose is to give a value to the variable girlName - In the perameters, he defines a new variable called name - He does this in the perameters so it can be set simply by calling the "setName" method somewhere else, and filling the arguments in. In the method he makes it so girlName is the same as whatever words are held in the variable name.

- Makes a return method for the variable girlName - He puts string because this method is going to return (send the user) a string (The string that's being held in girlName) - 'return girlName' will just print out whatever's being held in girlName when this 'getName' method is called on.

- Creates a method for the final output, he calls it saying. It's only purpose is to output the 'final statement'. He uses a printf, which is just a formatted print. %s tells the print that the variable it's going to be recieving its data from will be a string. The he just puts the name of the string in there so it knows which one to retrieve the info from; getName. So basically it'll print out "Your first gf was" and then (aka print) will return girlName

- He goes back to the class called apples, and it's got a scanner to take input and an object to 'connect' apples.java to tuna.java

- Obviously he prints out a line that asks for your input - Creates a variable (He calls it temporary, but really it exists forever, but it won't be used except to take user's input) - sets it equal to whatever user types in.

- He uses his object for the other class (tuna) and 'asks' the object to call on the method inside tuna, which is called setName - In the arguments, he types in temp - Basically, whatever string comes into temp will get sent to setName (Remember that setName's purpose was to give a value to the variable girlName) (So temp gets your input, throws it over to 'name', and then name gives it to girlName)

- Then he uses the tuna object again, this time to get whatever the method 'saying' does (In this case it prints out that line of text, plus returns girlName (Does that because it calls getName, which returns girlName))


I hope that helps you, I tried to go into as much detail as possible on EVERYTHING, because I don't know what you did and didn't understand :tongue:
That's it for the 16th, I'll write one for the 17th now. Stand by :megusta:



- A constructor will allow you to assign a value to a variable as soon as your object is created.

- Basically, he creates a constructor - The method's name has to be the same as the class - The constructor's purpose is to pass a value (this value would be given FROM the tuna object in the apples class) into the string variable called girlName.

- The constructor is again, going to be recieving a string value, so in the perameters he sets it to a string and calls it 'name'. (Whenever the tuna object is used, it will take whatever the object's arguments are and substitute it into the string variable called 'name', which was just created in the statement "public tuna (String name)")

- The constructor is going to send whatever value arrives in 'name' to the variable girlName.

- He modifies the tuna object and adds "kelsey" to the arguments. The argument will arrive in 'name', and then be sent to girlName because that's what the constructor is there to do.

- Now whenever the tuna object is called, it will again run 'saying' which just prints out "your first gf was %s " and then returns girlName.

- He makes a second object of tuna to demonstrate that the objects are seperate from each other; whatever goes into the first one will not affect or be affected by the second one. Both have their own arguments, and when those arguments are sent to the class 'tuna', they're handled seperately (but in the exact same way)


And that's what I got for 17. Hope that helps too, ask more questions if you have any or I wasn't clear enough :biggrin:
 
He then makes a method called setName - Its purpose is to give a value to the variable girlName - In the perameters, he defines a new variable called name - He does this in the perameters so it can be set simply by calling the "setName" method somewhere else, and filling the arguments in. In the method he makes it so girlName is the same as whatever words are held in the variable name.
Could you go a little over on "setting variables in parameters". I couldn't grasp the logic because he didn't go in detail and I'm a such a noob, anyway. I know this is probably from a previous tutorial but I didn't get it either. If I'm having ANY confusion, I don't know, I just can't concentrate on next tutorials because I keep thinking about the old one.
 
Variables in perameters are basically there to accept whatever 'arguments' are given to it when the method is called upon. [That's what the little brackets () are there for at the end of a call, for example derp(arguments go in here :megusta:); ]
Whatever you put into (where it says "IN HERE") derp(IN HERE); will get sent to the method, and dealt with in the perameters. In those perameters are a variable, that variable takes the data, and waits to be used in that method (In my example, whatever comes into derp will be used in the derp method at some point)

So if you create a String variable in the perameters of that method [ public void derp (String HERP) ], and then you put in something for the arguments when you call on that method [ derp("Pie, lol"); ], it will store "Pie, lol" in the string variable HERP.
In the same way, if it was [ public void derp (int datinteger) ], you'd put in an integer when you call it [ derp(69); ] - That would make "datinteger" hold the value 69.

It's basically just the same as creating a regular variable, but it's used only when you call a method, and it's created in the perameters.


I feel like I'm bad at explaining, tell me if you don't get it and I'll try again xD

Btw my post is updated with 17.
 
Thanks a lot GP. I'll read all of this tomorrow (It's 6 in the morning and I haven't slept). I hopefully I understand all of this. Thanks a lot man, much appreciated! :)
 
Back
Top Bottom