Pass by Value vs Pass by Reference in Java explained in Detail with Memory Diagram

preview_player
Показать описание
Support Simple Snippets by Donations -
--------------------------------------------------------------------------------------------- In this java programming tutorial video, we will study and understand the working of java pass by value vs pass by reference. In java programming, primitive data is always passed by value where as the reference type data is always passed as reference.
In this video will study and understand the difference between the 2 types in details.

Simple Snippets Official Website -
Simple Snippets on Facebook -
Simple Snippets on Instagram -
Simple Snippets on Twitter -
Simple Snippets Google Plus Page -
Simple Snippets email ID -

Рекомендации по теме
Комментарии
Автор

Hey Guys, if you want more such tech educational videos on this channel then please support me by subscribing to this channel & also share it with your friends as it helps me create more content just for you ✌

SimpleSnippets
Автор

😊😊 Finally, you have cleared my doubts after my 4 year of engineering

anilbaiga
Автор

awesome, i always had doubt about this topic until i saw this video. Thanks for the lovely explanation.

tanumaysaha
Автор

You deserve way more subscribers, loving your c++ OOP playlist... Its just perfect.

nightflms
Автор

Your justttt osmmm bro like ur way of teaching its simply superb..

manognakandukuri
Автор

amazing subscribed you need more views man good job lads

Fnaf-vhcs
Автор

Excellent 👌 work bro
Always good explanation 👍

mayurkadam
Автор

so if only primitive datatypes ex: int, float are passed by value
then why Integer, Long are also pass by value

manojnandhan
Автор

please use black screen to teach.It has less strain on the eyes.As usual love your channel.

teetanrobotics
Автор

Hi Tanmay I had a little doubt from the logic you explained.

class Main {
// swap() doesn't swap i and j
public static void swap(Integer i, Integer j)
{
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args)
{
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println("i = " + i + ", j = " + j);
}
}

So, in the given example the values don't swap. i and j are referencing to the same memory locations and temp is a new variable that is changing the references. So it should get swapped but it isn't. Can you give a proper explanation to this.

swapneil
Автор

There is no Pass by reference concept in java as java do not supports pointers, even objects are passed by value in java

sciencephobia
Автор

I believe that there is a slight mistake here. Java is purely "PASS BY VALUE". There is NO such thing as "PASS BY REFERENCE" in Java. Please, check this video to get the clarity in the concept.


Also, I really love your content and visual explanation. It's only in this video that I felt that there is something wrong. I feel that all you need to add in the end is that if the a[] in displayArray() method is made to point to a new array, any changes made from there, will not affect your original array named as arr[] whose value will remain as [0, 0, 0]. This happens because the location of the array arr[] was copied to a[] and now the location of the new array is copied to a[]. This happens because java is pass by value and only the values stored in the variables are copied. I apologise if my explanation is weak, but please do check the attached video and I think you will get what I am trying to convey.

I appreciate all the efforts you put in! Thanks and Best of Luck ahead.

Wael

wael
Автор

Your justttt osmmm bro like ur way of teaching its simply superb..

manognakandukuri