8.6: Pass by Value vs. Pass by Reference - Processing Tutorial

Поделиться
HTML-код
  • Опубликовано: 2 дек 2024

Комментарии • 173

  • @AnjaniKumar
    @AnjaniKumar 8 лет назад +82

    Java is always pass by value, as explained here : ruclips.net/video/BHtfb3lfc-g/видео.html

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +37

      Yeah, I got this wrong, someday I'll try to remake this video to fix!

    • @miroko8477
      @miroko8477 6 лет назад +3

      #TheCodingTrain Yeah but when I watch this in 2018 and it feels lime you're dead

    • @APaleDot
      @APaleDot 5 лет назад +27

      This is misleading. The process described in the video you linked is the same as that described by Daniel.
      Furthermore, saying that Java is always pass by value is semantic hairsplitting.
      A variable holds a reference to an object. Copying that reference when passing it into a function is what passing by reference _means._ Calling it "pass by value" just because the reference is a value, and that value is copied is misleading and confusing because it conflates copying a primitive value with copying a reference value, which end up having _very_ different consequences for how the program runs.

    • @mehrosenasir3966
      @mehrosenasir3966 5 лет назад +6

      APaleDot , think it like this. when you have a String variable assign to some literal and if you update/changes the same variable then the variable will point to a new address because String objects are immutable and the previous literal will still be in the heap with no reference variable to it; later that will be removed by garbage collector.
      As we all know pass-by-value means we pass a copy of the data and the original data can’t be affected in the called fuction and pass-by-reference- means we pass the actual address to that data which can be affected in the called method.
      Now when we say java is totally pass by value what does it mean? The correct sentence would be “java pass reference by value”. To keep it simple whenever you hear the term pass-by-value, remember a copy of the data is created and passed.
      int a=5; //address 100
      Integer b= 5; // address 15
      if i pass ‘a’ to a function a copy will be created of the content and passed and if I passed ‘b’ a copy of reference will be passed (Remember, pass-by-value means passing a copy) to the function. Here is the trick if you change the content for ‘b’ inside the function, the original will ‘b’ will be unaffected. If java was really pass-by-reference then you can update the content of ‘b’ inside the function. And not to forget what I mentioned earlier regarding string objects that they are immutable and changing the variable content essentially means changing the reference of that variable. In Java all wrapper classes are immutable and that is why you will not b able to change the content of ‘b’(changes the reference).
      Any data Pass-by-value to a function will remain unaffected no matter what you do with it inside the function. So java is not pass-by-reference for objects and pass-by-value for
      primitives. It’s only pass-by-value .

    • @Farsmezan
      @Farsmezan 5 лет назад +6

      @@TheCodingTrain .. you shouldn't clarify things to people, until it's clear for you. Confusing people could make them lose interest in what you teach.

  • @zenryucds747
    @zenryucds747 6 лет назад +31

    3 minutes into the video and I understand more about this than my professors ever thought me. Amazing!

  • @RoundCorner93
    @RoundCorner93 8 лет назад +6

    I had to quickly review pass-by-value/pass-by-reference and this was the most concise/clear explanation I've run into so far. Thank you!

  • @mariosasic4251
    @mariosasic4251 5 лет назад +6

    Man, you explained something , that im struggling to get for weeks, just in 7 mins, and i got it completely.
    Thank you very much u have a talent to teach!

  • @tarkmenguc8031
    @tarkmenguc8031 3 года назад

    Thank you 3 years and you did not fix it yet. You are making it frustrating to people who want to learn more.! Such a thoughtful person.

  • @astghmelqumyan8303
    @astghmelqumyan8303 6 лет назад +13

    what a shame you dont have topics in java
    you r a great teacher, and explain everything so good... very very good...
    keep making new videos

  • @resai17
    @resai17 2 года назад +2

    Best video to clearly differentiate between PbV & PbR. Great work!

  • @piyushpatil2668
    @piyushpatil2668 3 года назад

    I was having so much trouble understanding this concept, dude just did that in 4:46 minutes, what a great teacher

  • @apeiy
    @apeiy 5 лет назад +14

    I know you got lots of hate about Java stuff BUT you helped me understand the passing by reference stuff that I needed for C++ so thank you! :)

  • @benesranur
    @benesranur 5 лет назад +1

    finally, this made sense, not the part where you were overlapping circles but the first part was perfect, I finally understand this concept. Thank you!

  • @saltanatkokjalova9097
    @saltanatkokjalova9097 2 года назад

    Finally, understood the difference between passing by value and passing by reference. Great content.

  • @applesmith4012
    @applesmith4012 2 года назад +1

    This is indeed one of the most clear and helpful tutorials that explain the difference between pass by value and pass by reference. Well done!

  • @demizhang8917
    @demizhang8917 5 лет назад +1

    Thanks for brilliant explanation! But there is something I can't understand.
    6:30 if fill(col); is under ellipse(x,y,r*2,r*2); the particle that changes color will be p1 rather than p2.
    I can't figure out why..

  • @xiangli3388
    @xiangli3388 7 лет назад +1

    Very nice tutorial, thank you. The tutorial hits the core of object-oriented programming. It would even better if there is a outline/summary at the beginning/end.

  • @TheEnglishQuail
    @TheEnglishQuail 7 лет назад +40

    UGH. It feels like nobody online is able to explain this concept in a way I can understand it :(

    • @jayantjolly
      @jayantjolly 7 лет назад

      Check out the videos of mycodeschool..I think that channel could!!

    • @ownagejuice1394
      @ownagejuice1394 6 лет назад +5

      if we're talking about using 'pass by value' VS 'pass by reference' in a method, here's a TIP you can understand. "pass by reference uses ampersand -> '&' " . If you see that symbol like " public String changeColor(String &favColor ) ", immediately that's 'pass by reference' . Everything else is pass by value. How about that? : )

    • @niche9015
      @niche9015 5 лет назад +8

      @@ownagejuice1394 except that this video is about Java, not C++.

  • @STDrepository
    @STDrepository 5 лет назад +1

    C# (Because it is a far superior language) is pass by value always by default. You can pass by reference by using the "ref" keyword in the parameter declaration and also when calling the function.
    change(ref x);
    static void change(ref int x){}

  • @jbei9981
    @jbei9981 8 лет назад

    Thank you so much. This is the first explanation I've found that actually helped rather than confusing me more

  • @flashyvirtouso7423
    @flashyvirtouso7423 4 года назад

    This is a tricky concept when you are learning programming languages like c ,etc,3 pages of gibberish text from the book solve ,hope you tube was there back in the 90's learning programming could be fun...thanks master!!!!

  • @angrybunny1993
    @angrybunny1993 6 лет назад

    The Best video i have found about pass by value and pass by reference.Thank u so much, Best teacher ever

  • @Dyslexic_Neuron
    @Dyslexic_Neuron 4 года назад +1

    WTF why did everyone knew java as both pass by reference and pass by value earlier and later in life realized that its always pass by value !! :D

  • @monicamonica6975
    @monicamonica6975 5 лет назад +1

    You've given very easy and understandable program in board

  • @creative.coderie
    @creative.coderie 8 лет назад +44

    What a great teacher :)

  • @dtaspinar
    @dtaspinar 7 лет назад

    Thanks a lot. We have the exact topic on "comparative programming languages" class at UoPeople this week and the video clarified the distinction between passing by reference and value.

    • @Bunny99s
      @Bunny99s 7 лет назад

      No, it does not. It explains the difference between a value type and a reference type, not the difference between passing by value and passing by reference. Java doesn't support passing by reference at all. Some people have posted links to other videos which explain it correctly.
      See this SO question:
      stackoverflow.com/questions/1068760/can-i-pass-parameters-by-reference-in-java

  • @aura-audio
    @aura-audio 5 лет назад +2

    Thank you for this video. I didn't know what Pass by Reference meant before watching it to be honest. Apple's programming language, Swift, uses this a lot when dealing with UnsafeMutableRawPointers which makes sense. It makes me wonder if referencing and using the & operator actually causes less crashes than using other passing methods.

  • @simm5622
    @simm5622 2 года назад

    Your a great teacher ever. Thank you so much for your efforts. 🏆🏆🏆🏆🏆

  • @aryan_karim
    @aryan_karim 5 лет назад

    most entertaining tech guy by far

  • @NobleAbsinthe
    @NobleAbsinthe Год назад

    Pass by value (using primitives) you make a copy, and that is what gets messed with, without affecting the original.
    Pass by ref(using objects) you are messing with the object itself because it isn't being copied.
    You could use a copy constructor to make a "clone" of an object and mess with that one while preserving the original.

  • @samstoyroom
    @samstoyroom 5 лет назад

    Best explanation in RUclips

  • @abora4766
    @abora4766 7 лет назад +9

    Sir,I respect you.

  • @tokidokiknitter1293
    @tokidokiknitter1293 8 лет назад

    Hi Dan, I am new to Processing, and your tutorials are excellent! Thank you so much for posting these!!

    • @TheCodingTrain
      @TheCodingTrain  8 лет назад

      +Tokidoki Knitter glad to hear, thank you!

  • @RS-so7ke
    @RS-so7ke 7 лет назад +13

    Java doesnt support pass by reference

  • @kevinbenavides92
    @kevinbenavides92 7 лет назад +2

    Thank you for clarifying this topic.

  • @familyzarazaga9906
    @familyzarazaga9906 8 лет назад +3

    When you created 'particle other' is this ('other) a new instance of the Class particle? But it is only declared inside the boolean function? How does processing recognise the 'other.x' as an example of type 'particle' and how does it link it with P2?

    • @creative.coderie
      @creative.coderie 8 лет назад +1

      "other" is just an argument of type Particle. Meaning you can only pass a Particle object in the overlaps method. It's like saying 'int x'. However, this time it's of type Particle instead of 'int'. Therefore, when you pass P2 in the overlaps method, processing checks whether P2 is a Particle object and finds that P2 matches the required argument type you specified (Particle) and recognizes it as the "Particle other". This is a wordy reply but I hope it helps.

    • @lucasvisionvjbitar
      @lucasvisionvjbitar 7 лет назад +1

      edit: I think it has something to do with the " ' other' " question.
      tried to add a particle but... (read more!)
      Heyy, Big Up from Brasil!!
      thanks for everything!!!
      I tried to add one more particle and the overlap function doesn't apply fully to the first particle called(p2) . I mean, when it overlaps one of the particles, the mouseParticle (p2) goes red, and the other goes green, but when the p2 overlaps the other circle(p3), it doesn't go red, only the overlapped goes green but (p2) keeps black.
      i figured it out that the order of the functions does matter, and the "problem" occurs on the first function declared.
      example:
      p2.overlaps(p1);
      p2 overlaps(p3);
      in this case, when p2 overlaps p1, p2 is still black and p1 goes green, and p2 goes red normally when overlaps p3.... and if I change the order
      p2.overlaps(p3);
      p2.overlaps(p1);
      then p2 only goes red when overlaps p1...
      i just don't understand why....
      mycode:
      Particle p1;
      Particle p2;
      Particle p3;
      void setup() {
      size(600,400);
      p1 = new Particle(100, 100, 50);
      p2 = new Particle ();
      p3 = new Particle(200, 200, 30);

      }
      void draw(){
      background(0);
      p2.overlaps(p3);
      p2.overlaps(p1);

      p2.x = mouseX;
      p2.y = mouseY;
      p1.display();
      p2.display();
      p3.display();
      }
      ///
      class Particle {
      float x, y;
      float r;
      color col;
      Particle() {
      x = random(width);
      y = random(height);
      r = random(20, 50);
      col = color(0, 100);
      }
      Particle(float tempX, float tempY, float tempR) {
      x = tempX;
      y = tempY;
      r = tempR;
      }
      void overlaps(Particle other) {
      float d = dist(x, y, other.x, other.y);
      if (d < r + other.r) {
      col = color(255, 0, 0, 100);
      other.col = color(0, 255, 0, 100);
      } else {
      col = color(0, 100);
      other.col = color (0, 100);
      }
      }
      void display() {
      stroke(255);
      fill(col);
      ellipse(x, y, r*2, r*2);
      }
      }

    • @Philanthrophxyz
      @Philanthrophxyz 7 лет назад +1

      I think this should fix the problem. It's a very small fix. The draw function is calling overlaps twice, so the second undoes the first's change to p2.col due to calling by reference (this is true no matter the order they are called).
      It's a simple fix, in the main program add the p2.col change to black each time, and in the class just remove the two.col = color(0) from the else statement, as that will update each time for the moving circle to be black when it overlaps one or the other circles...and you don't want that. Hope this helps.
      Here's the main program:
      void setup(){
      size(600, 400);
      p1 = new Particle(100, 100, 50);
      p2 = new Particle(500, 200, 100);
      p3 = new Particle(500, 100, 50);
      }
      void draw(){
      background(0);
      //reverts p2 back to black if not overlapping
      p2.col = color(0);
      //p2 reference passed into two, so when you change values of two
      //you also change values of p2 (by reference)
      p1.overlaps(p2);
      p3.overlaps(p2);
      //allows circle 2 to move with mouse
      p2.x = mouseX;
      p2.y = mouseY;
      //displays circles
      p2.display();
      p1.display();
      p3.display();
      }
      Here's the class setup:
      class Particle {
      float x, y, r;
      color col;
      Particle(float tempX, float tempY, float tempR) {
      x = tempX; //xposition
      y = tempY; //yposition
      r = tempR; //radius
      col = color(0); //color
      }
      //checks to see if circles overlap
      void overlaps(Particle two){
      float d = dist(x, y, two.x, two.y);
      if ( d < r + two.r){
      col = color(255, 0, 0, 100);
      two.col = color(0, 0, 255);
      }
      else{
      col = color(0);
      }
      }
      //draws particle
      void display() {
      stroke(255);
      fill(col);
      ellipse(x, y, r*2, r*2);
      }
      }

  • @anujmishra4013
    @anujmishra4013 8 лет назад +1

    you are truely amazing teacher you help me much thank you sir

  • @surajpoudel6646
    @surajpoudel6646 5 лет назад +1

    Such a beautiful explanation. You are awesome. 😘

  • @leifan9740
    @leifan9740 5 лет назад

    What an intuitive explanation! Many thanks!

  • @sentenced7259
    @sentenced7259 8 лет назад +1

    Thanks for the explanation. Do you have any more JAVA tutorials? I looked through you other videos but I can only find JS tutorials :(

  • @jagdeepsinghuppal8310
    @jagdeepsinghuppal8310 5 лет назад +1

    Too good ..!!! Very helpful video for java. 👌

  • @monikachuttani6645
    @monikachuttani6645 5 лет назад

    This is helpful indeed
    I never thought about that before

  • @rimshanadeem6759
    @rimshanadeem6759 8 лет назад

    amazing ....my concepts are now clear

  • @shanedetsch
    @shanedetsch Год назад

    aP = new Particle ( x, y ); would be a good addition to this review showing the pass by value nature of Java

  • @colorfulcodes
    @colorfulcodes 4 года назад

    You are an amazing teacher!

  • @torus151
    @torus151 3 года назад

    His smiling nature is enough to understand things

  • @rabinbk5014
    @rabinbk5014 6 лет назад +2

    You are cool sir. So is your explanation.

  • @fubaralakbar6800
    @fubaralakbar6800 6 лет назад +1

    I've been trying to understand this for years...now I think I've got it.
    You input a value (50 in this vid) into a function.
    You want to do some operations on that value to obtain a result.
    ...but the result of the operation (100) is stored in a separate variable call val.
    ...and since anything in a function is local, only the input values (50) and the return value can be seen by the rest of the program. You want the return value, not the original input value. So you to pass the result back to the main program.
    Why couldn't you could just say "return val;"?

  • @evanahannah2895
    @evanahannah2895 2 года назад +2

    Thank you so much, bearded Harry Potter 😃❤

  • @bradweir5579
    @bradweir5579 2 года назад

    I feel like understanding value and reference types are fundamental to a programmer's understanding of async and multithreaded code. I find that programmers are often told not to use pass by reference without being explained it's to safely avoid bad habits in the future when passing by reference could lead to race conditions and non-threadsafe code.

  •  7 лет назад

    How a can do that when overlap the particles change color but when no overlap conserv the original color, i.e. if I use one constructor than have color as a input argument, how can return to this color when no overlap the particles?

  • @harshalwaghmare440
    @harshalwaghmare440 3 года назад

    Heyy youuuu i just wanna thanks to you 🥺 my Mind is going to brust bcz of this concept but not after this video🌻

  • @annalisetrite7281
    @annalisetrite7281 4 года назад

    Fantastic explanation, thank you!

  • @pedromateus9575
    @pedromateus9575 6 лет назад

    how could you do the right side example the right way modyfing the argument of val?thanks

  • @Julian-mc7cm
    @Julian-mc7cm 7 лет назад

    How would I do this if they are two different classes instead of one?
    Also, the circle class is increasing in size and I want the square class to overlap only when the circle is bigger than a certain size?
    Thanks

  • @arturkarlov3000
    @arturkarlov3000 9 лет назад +1

    So, do I understand correctly that, if I actually wanted to do the stuff the change function does, I need to change the return type from void to something like int or float then? there has to be a way to make change (x) return 100 and assign it to x again, otherwise, why would we do it?

    • @TheCodingTrain
      @TheCodingTrain  9 лет назад +1

      +Artur Karlov Yes, this is indeed correct!

    • @arturkarlov3000
      @arturkarlov3000 9 лет назад

      awesome, thanks to you I feel like I am finally getting programming!

    • @awsomeguy563
      @awsomeguy563 8 лет назад

      What is the way to change the value of x then?

    • @creative.coderie
      @creative.coderie 8 лет назад

      +awsomeguy563 without using a function. so like this: x = x * 2; but if you wanted to print the value of x after it's been altered by the change function just put println(val); inside the function after val = val * 2;

  • @juanmanuelmillansanchez8165
    @juanmanuelmillansanchez8165 5 лет назад

    This video has been very usefull for me thanks u man !

  • @tarajano1980
    @tarajano1980 7 лет назад

    so cool your explanations ! great job.

  • @arrowmid
    @arrowmid 8 лет назад

    Hi Daniel, sorry if this is a silly question, but I don't understand if change() {} is a function which is native to Processing, or a function created solely for this video for demonstration purposes. I haven't found change() in the Processing Reference. Thanks for the wonderful series, I've learned a lot from them!

  • @annalisetrite7281
    @annalisetrite7281 4 года назад

    When I play around with this concept it doesn't seem to apply to String or BigInteger...could someone explain why?

  • @DerKever
    @DerKever 7 лет назад

    I have another question: If Java (and processing) only pass by value (as explained by other people here), why does the thing Daniel does at the end, the changing of the color-values of the particles work? If it is only ever referencing to the original value?
    Thanks!

    • @APaleDot
      @APaleDot 5 лет назад

      People who say that Java is only pass-by-value are splitting hairs and playing semantic games. Java has primitive types and reference types. Whenever you create an instance of an object, it gets stored as a reference type. Passing this reference to a function requires Java to copy that reference. This is what pass-by-reference means. People just like to be "right" about everything, so they say that because the reference is copied it's actually a pass-by-value, but the "value" being passed just happens to be a reference. It's just confusing nonsense.

  • @georgianadan9380
    @georgianadan9380 5 лет назад

    How is this correct? I mean I've tested with String, Integer and an object I've created and still have not have not the same results, it is always pass by value with what I've tested. The argument object does not change, once the called method is finished. I have not yet seen any pass by reference in Java.

  • @travisc2746
    @travisc2746 6 лет назад

    Hi, sir, I have a problem that i create 3 particles(particleC is moving when mouseX/Y is changing, others are created with random variables), so I write the code that just like you did in your video. However, my particle only change color when it overlays particleA but not change its color when it overlays particleB. How to fix this?

    • @TheChanclasVerdes
      @TheChanclasVerdes 6 лет назад

      try pC.overlaps(pA) && pC.overlaps(pB) since it's pC that's moving.

  • @queenkaine3619
    @queenkaine3619 4 года назад

    Can someone help me with thus please
    A method that takes an array of double. Return whether or not every element in the array appears in ascending order, begining with the SECOND element AND if the first element is equal to the sum of all elements beginning with the second element. You must use 1 loop at the most for this and recall the difficulty of checking equality with doubles that may contain math error.

  • @Bunny99s
    @Bunny99s 7 лет назад +14

    OMG, i can't believe people teach this simple concept the wrong way all the time in all programming languages...
    First of all JAVA *always* passes *variables* by "copy" or "value". Note that i said ALWAYS. There is not such a thing as passing a *variable by reference* . People seem to confuse what "variable" means. A variable is a piece of memory that holds information. For primitive types / value types the variable memory directly contains the *value* . However for reference type variables (like classes) our variable only contains a reference to another memory address. The main difference between *passing* by value and *passing* by reference is that the content of the *variable* can't be changed when it's passed by value as its value / content is copied into a local parameter variable of the method when you call it.
    On the other hand when passing a *variable* by reference you can actually modify the *content of the variable* inside the method. Of course, as i said, *this does not exist in JAVA*. However this is possible in C#, C++, C, ...
    In C# when you define a method like this
    void SomeMethod(ref int someNumber)
    {
    someNumber++;
    }
    "someNumber" is *not* a normal local variable inside the method and when calling the method you do *not* copy the content of the variable, but instead you *pass a reference* to the *variable* itself. Methods like this have to be called like this:
    int x = 5;
    SomeMethod(ref x);
    print(x);
    This will print "6". We give our method a reference to the x variable location in memory so inside SomeMethod "x" and "someNumber" refer to the same memory location. Therefore changes to someNumber will affect the content of x. C and C++ allow to directly pass a pointer to a variable. However C# ref parameters are "safe" as you can't store ref parameters for "later use".
    But again JAVA does *not support passing a variable by reference* . See this SO question:
    stackoverflow.com/questions/1068760/can-i-pass-parameters-by-reference-in-java
    Passing a reference type variable by value does the same as with primitive type variables. It copies the *content* of the variable into the local parameter variable inside the method. Of course the content of a reference type variable is the *reference* . However you still pass that reference by value as you copy the reference from the source variable to the local parameter. So the content of the variable can't be changed. You can of course change the object that is referenced by the reference value.

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад +6

      Thank you for this. I have since learned several times over how I botched the explanation in this video. I'll hopefully find the time to correct someday.

    • @Vercinaigh
      @Vercinaigh 6 лет назад

      This explanation was lost on my...I'm not a textual learner normally so i got a little lost on this vs your explanation in the video.

    • @APaleDot
      @APaleDot 5 лет назад

      I'm seeing this a lot in the comment section of this video, and it's causing a lot of confusion, so let me just say: Passing a reference by value _is_ passing by reference. That's how _all_ programming languages do it, and anyone who tells you otherwise is playing semantic games and making up unneeded concepts. Saying that copying the value of a reference type is "pass by value" is confusing. When you copy the reference to an object and pass it into a function, that _is_ passing it by reference. You are passing the reference to the object into the function.

  • @owningyourfinances
    @owningyourfinances 7 лет назад

    Thank you sir! Great examples!

  • @liveyounganastasia
    @liveyounganastasia 2 года назад

    Oh my god. you explain so well

  • @ARNafi-ev2xr
    @ARNafi-ev2xr 7 лет назад

    Great explanation

  • @aaronaaronaaron5922
    @aaronaaronaaron5922 5 лет назад +1

    I really like your chanel. Thanks a lot and cheers 🍻

  • @kennyl7542
    @kennyl7542 9 лет назад

    Hi Dan, thank you so much for these in-depth and newbie friendly videos on OOP.
    My question1 is, beside multiple constructors for class, I wonder is there a way to build multiple constructors for methods: without parameter and with parameters.
    I tried to make two methods with difference on whether having parameter or not, and it works. is it an appropriate way to do it?
    My question2 is, can we split a class tab into multiple tabs, as more and more methods make it difficult to organize in just one tab?
    maybe I should just split this one class into two related two classes to organize the methods. But the drawbacks would be any fields shared by both classes have to be taken out to become global variables, which will make first tab look messy. well, in this case, I guess, I should keep one class as one class no matter how many methods inside it? or maybe object interactions can help?
    thanks a lot

    • @TheCodingTrain
      @TheCodingTrain  9 лет назад

      +Kenny L 1) Indeed, this is called method "overloading". You can write a function with the same name, but different parameters and Java will know which one to call based on the arguments. 2) I wouldn't recommend splitting a class over multiple tabs as the start and end brackets could get out of place too easily. You could have a class store instances of other objects - this is probably the best solution for you.

    • @kennyl7542
      @kennyl7542 9 лет назад

      Thanks Dan

  • @oorschot5626
    @oorschot5626 3 года назад

    Can't seem to find anywhere what "change()" does.. Can someone help?

  • @PaulBaird
    @PaulBaird 6 лет назад

    I got it but I think you could make it better by using a much simpler method. Print one attribute value of the object. Pass the object to a method, and just do one thing to one attribute of that object and then print it again. Return from the method and print that attribute once more to show that the change is permanent..

  • @mohsankayani
    @mohsankayani 8 лет назад

    you confused me ! duahh !! but hats off liked your concept and java thingi !! :] thanks man !

  • @CyberAbyss007
    @CyberAbyss007 7 лет назад

    Great video! Thanks

  • @JustGotHeated
    @JustGotHeated 8 лет назад +6

    Lmao I don't get the point of Pass by Value still, cause it just returns the same number. What's the point?

  • @turkkis3955
    @turkkis3955 6 лет назад

    perfect explanation

  • @kaz9070
    @kaz9070 8 лет назад

    Thanks a lot for these videos, really helps me ;)

  • @user-be1wl6sb7q
    @user-be1wl6sb7q 3 года назад

    Can we use &p instead of ap?

  • @johanpicocrie7798
    @johanpicocrie7798 3 года назад

    Hallo is There a site were i van download these sketches?

  • @mnava19
    @mnava19 7 лет назад

    thank you very much , nicely explained

  • @juancarlosrestreposaldarri2386
    @juancarlosrestreposaldarri2386 7 лет назад

    I like very much your videos, thanks you. I have a doubt with this code. Why the Particle p3 do not behave the same with other Particles, p1 and p2; what is wrong here?
    Particle p1;
    Particle p2;
    Particle p3;
    void setup() {
    size(600,400);
    p1 = new Particle(100,220,50);
    p2 = new Particle(450,180,70);
    p3 = new Particle();
    }
    void draw() {
    background(0);

    p3.overlaps(p1);
    p3.overlaps(p2);
    p1.display();
    p2.display();
    p3.display();
    p3.x = mouseX;
    p3.y = mouseY;
    }
    class Particle {
    color col;
    float x;
    float y;
    float r;

    Particle() {
    x = random(width);
    y = random(height);
    r = random(30, 100);
    col = color(200);
    }
    Particle(float tempX, float tempY, float tempR) {
    x = tempX;
    y = tempY;
    r = tempR;
    col = color(200);
    }
    void display() {
    stroke(250);
    strokeWeight(2);
    fill(col);
    ellipse(x, y, r*2, r*2);
    }

    void overlaps(Particle other) {
    float d = dist(x, y, other.x, other.y);
    if (d < r + other.r) {
    col = color( 255, 0, 0, 200);
    other.col = color(0, 255, 0, 200);
    } else {
    col = color(0, 200);
    other.col = color(0, 200);
    }
    }
    }

    • @juancarlosrestreposaldarri2386
      @juancarlosrestreposaldarri2386 7 лет назад

      Thanks you for answering, i am so excited for that and that you take time to help others. I will to ask at the forum, thanks very much.

  • @saiashwinkumarc4221
    @saiashwinkumarc4221 4 года назад

    there's no pointers concept in java?

  • @李少轩-j4u
    @李少轩-j4u 7 лет назад

    hey sir i wanna ask is pass by value equal to pass by copy that you stated ?

  • @helloworld5794
    @helloworld5794 3 года назад

    Thank you nong!!

  • @md.safikhasan8517
    @md.safikhasan8517 6 лет назад

    thats a great understanding ... thanksyou a lot . :)

  • @shanisarathchndra5284
    @shanisarathchndra5284 6 лет назад +2

    java pass by value, always!

  • @RN_de_la_krm_team
    @RN_de_la_krm_team 3 года назад

    Thank you so much

  • @qtSoph
    @qtSoph 2 года назад

    thank you so freaking much

  • @dr.bizarreshow
    @dr.bizarreshow 4 года назад +3

    This guy looks like the professor from Money Heist

  • @phil5053
    @phil5053 4 года назад

    Thank you

  • @SSoundtruck
    @SSoundtruck 6 лет назад

    awesome. thank you and see you later alligator

  • @therealantonym8039
    @therealantonym8039 6 лет назад

    Umm...I know it's been 3 years since this video but, could we continue this in depth Java tutorial please? Or are there other videos on the channel I am not seeing? You are a great teacher and I'm currently learning from codecademy and this is a great supplement to that.

  • @Cornellie
    @Cornellie 3 года назад

    This video should be updated.

  • @MegaBdboy
    @MegaBdboy 7 лет назад +2

    It's the same in C++ ?

    • @tylertyler82
      @tylertyler82 7 лет назад

      Question or statement? Worded as statement but ends in question mark.. I'd like to know the answer to this as well?

    • @MegaBdboy
      @MegaBdboy 7 лет назад

      wQuestion.Because i know C++ has beside references pointers as well.

    • @kalarlapastos4824
      @kalarlapastos4824 7 лет назад

      yes the idea is the same

    • @aniekanumoren6088
      @aniekanumoren6088 7 лет назад

      is it possible to control whether i want to send a primitive data type by reference like in C++

  • @ShinobiEngineer
    @ShinobiEngineer 5 лет назад

    THANK YOU ! ! ! 🤓👍

  • @stefolino
    @stefolino 7 лет назад

    hi, what is this programming langage ?

  • @sharma93anks
    @sharma93anks 3 года назад

    omg!! amazing it was..

  • @domidarko1166
    @domidarko1166 Год назад

    This concept is very confusing to explain, especially to trainee devs even now being a senior dev for a fairly long time.
    Basically, there is no such thing in Java as pass-by-reference. As already pointed out, the primitive explanation is correct. Primitives reside on the stack. A copy of the value is passed to the method param and cannot be changed.
    Objects are stored in the heap. When the object reference is passed to the method param a copy is made on the stack which points to the same location to the original object on the heap. Therefore you can change the attributes of the object but the original version (memory reference) is not actually being changed, if that makes sense. Both references are just pointing to the data (values), its these values that are actually getting passed using pointers.

  • @rebeccahaokip5859
    @rebeccahaokip5859 4 года назад

    Lol make sense... after watching it again ... after 1 year

  • @mnsh6313
    @mnsh6313 7 лет назад +1

    gerrard pique!

  • @armanx2
    @armanx2 4 года назад

    aP will point to P and not to underlying value so far i know

  • @ianmakeedits
    @ianmakeedits 4 года назад

    you look like you planning to rob a bank. bank of spain, perhaps? kiddin, thank u for this

  • @godisnjiodmor
    @godisnjiodmor 3 года назад

    int x=10;
    int y;
    y=x;
    print x;
    ----------------
    x=10
    pass by ref.