Facebook – https://www.facebook.com/TheNewBoston-464114846956315/ GitHub – https://github.com/buckyroberts Google+ …

source

38 Comments

  1. this keyword is used for calling data members not local variable…..u figured it out little wrong…..but u r doing a great job…

  2. Try running this.You will understand by yourself. Look how the value is changing.public class hachuwa {
    //The variableprivate String abc = "instance variable";
    public void main(string args[]){//Initializing your local variable
     String abc = " ";//Study what happens when you remove -this-.
     this.abc = "Parameter";
     System.out.print("Local ="abc);
    }
    void def(){
     System.out.print("Instance "+abc);

    }

  3. u are explaining exactly the opposite….. if we use this keyword , it will refer to instance variable….. and if we dont use this variable it will point to local variable ( arguments of functions)

  4. [ASK] this.hour should belong to the object's properties, right?

    “`
    private int hour, minute, second;

    public void setTime(int hour, int m, int s){
    this.hour = (hour>0 && hour <=24)? hour : 0;
    minute = (m>0 && m <=60)? m : 0;
    second = (s>0 && s <=60)? s : 0;
    }
    “`

  5. this.hour refers to the global variables. You are going to give some poor soul a headache trying to replicate your explanation into thier prgm.

    I'd like to point out that public variables can be accessed from a static context.

    I.e. from your apples class you can access the tuna variable:
    public int hour;
    using the (tuna Object).hour

    However, this is very bad practice. you always want to privatize all variables habitually if they need to be accessed from a static context you should implement setter and getter functions.

    This is because someone can set class specific variables outside of the constraints intended. They could for instances set the hour by calling
    (tuna object).hour = 0;
    and if for some reason you were dividing hours they could break your program by forcing a division by zero.

    The best way to cover your code is to not expose it, Privatize EVERYTHING.

    😛

  6. Yeah this is wrong…

    I always call my global varibles of my classes

    g_width, g_height, g_name so i know they are the global vars

    You could also write the first letter with a capital, which you never really so normal with camel case.

    You could write in full caps but that is usually used for constants (finals)

  7. ATTENTION!!! when we use 'this. ' . It will generally refers to data member of class. with using ' this.' if any change is made this will reflect to data member of class not local variable to method(function).

  8. but what if I am using same hour minute and second more than twice in a program.and "this" has other things too than this name management thing and I don't really understand that so please explain.

  9. Did his example work because he reassigned hours, minute, and second? If he just used this.hour, this.minute, this.second the out put would be 1, 2, 3?

  10. I don't get it, how is he wrong?
    What he's explaining also shows up in the program. Using .this made sure to use the variables in the setTime. That's what you see in the program as well right?? 🙂

  11. "this ones," You have got me ROLLING! it is late and i've been watching java videos for hours, and your humour is killing me, haha!

  12. Excuse me Bucky, wrong explanation as "this" refer to the variable of the current class, not the argument. 🙂

  13. Since bucky's explanation of the keyword "this" is wrong, I made a simple program to make things more clear because I was really confused at first:

    public class test{
    int a=5;

    void print(int a){
    System.out.println(a);
    System.out.println(this.a);
    }

    public static void main(String args[]){
    test object=new test();
    object.print(3);
    }
    }

    The output of this program would be:
    3
    5

    So inside the method print, a refers to the local variable and this.a refers to the instance variable.

  14. It uses setTine(int hour, int minute… by default. If you have some values that have the same name outside the method (private int hour; ) you need to use "this." to access them. If you want to use values that are even further out from the method you have to use "this.this." Fuck you Bucky! This is a troll tutorial xD

  15. When creating a new method, when do you use public String args.. and when do you use public void args…and why? For example: public String toMilitary(){} or public void toMilitary(){} If anyone could help me out with this that would be much appreciated.

  16. I think it is better to use setTime() instead of setTime(x,y,z), the input variable seems useless and easily misleading others

Leave A Reply

Please enter your comment!
Please enter your name here