Java is pass/call by value or pass/call by reference [MOST IMP. JAVA INTERVIEW QUESTION]| ode Decode

Java is pass/call by value or pass/call by reference [MOST IMP. JAVA INTERVIEW QUESTION]| ode Decode

Code Decode

4 года назад

129,242 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Shubham Tagalpallewar
Shubham Tagalpallewar - 29.08.2020 09:51

Thank you ma'am, I have been asked this question in interview and I was unable to answer properly, now I am confident on this topic.

Ответить
Alfiya Khan
Alfiya Khan - 30.08.2023 15:35

Ma'am I am having a doubt, starting 4 mins of the video where you said "to access a private method you have to make it static", I didn't get that point. Please explain.

Ответить
venkatesan elumalai
venkatesan elumalai - 28.08.2023 07:53

Good Video

Ответить
venkatesan elumalai
venkatesan elumalai - 28.08.2023 07:49

Nice Video

Ответить
Prudhvi Nadh
Prudhvi Nadh - 24.05.2023 06:59

Nice explanation

Ответить
Abhi Vela
Abhi Vela - 22.05.2023 05:01

The topics you cover here are so unique !!! I have seen many tutorials for Java..... But the type of topics you cover here and the explanation is top notch!!! ❤ Thank you for your efforts 🎉❤

Ответить
Roobanraj Krishnan
Roobanraj Krishnan - 09.04.2023 08:28

Thanks for this crystal Clear Explanantion .

Ответить
Azizbek Rasulmetov
Azizbek Rasulmetov - 06.03.2023 19:10

Did u said that u a passing object by value at the end ? When u actually passing the reference!

Ответить
Ab
Ab - 01.02.2023 20:28

Excellent

Ответить
Sravya Yeramareddy
Sravya Yeramareddy - 13.01.2023 00:49

Pass By Reference: Changing the value of the real address in the memory.
Pass By Value: Copying the value to another location and so the real value is not changed.(java)

Ответить
Shirish Bhadekar
Shirish Bhadekar - 06.01.2023 22:54

you rock

Ответить
Sai kumar Goud
Sai kumar Goud - 07.11.2022 17:09

Thank you mam I had understand very clearly but one doubt raised in mind that why java is particularly called pass by value here we are doing both pass by value and pass by reference can you please explain mam?

Ответить
Parag Bhangale
Parag Bhangale - 04.11.2022 19:14

how to write junit ?


myovject oldermethod()
{
other call//
hashmap map = new hashmap():

NewObj obj = service.myservice(map);
//logic

value = map.get(0); // here i am getting null pointer in junit test

return myobject;
}


class myservice{

NewObj myservice(hashmap map)
{
//logic

map.put(key,value):
return Newobj;
}


}
after that i am getting null if i mock the myservice ...how to write junit for oldermethod()

Ответить
AKSHAY DESHMUKH
AKSHAY DESHMUKH - 22.09.2022 14:42

call by rfrnce vs pass by rfrence same or
dfrnt

Ответить
anu rani
anu rani - 15.09.2022 19:10

Thankyou mam.. for explaning this in a wonderful way

Ответить
poorna chander rao nadipelly
poorna chander rao nadipelly - 11.07.2022 19:45

Mam im getting really confused with this concept? Please help me to understand

Ответить
Abhishek
Abhishek - 10.06.2022 12:47

Hum value bhi pass kr rhe hai aur object reference bhi pass kr pa rahe hai to java sirf passed by value kyu 🤔?

Ответить
lazy lizard
lazy lizard - 13.05.2022 12:28

JAVA IS ALWAYS PASS BY VALUE ALWAYS

Ответить
Barath Iraiyarul
Barath Iraiyarul - 28.04.2022 19:37

Thanks 👍

Ответить
Tapan Parida
Tapan Parida - 25.04.2022 01:12

God bless you mam for your good work…your work really helps people….keep up!!!

Ответить
sanketh s
sanketh s - 24.04.2022 11:13

nice explanation however had a doubt, since java is pass by reference for object as per your example for Animal Object.
i tried the same example with Integer since its an Object, the same was not happening.

Please check the below example.
public static void main(String[] args) {
Integer i = 10;
change(i);
System.out.println("main"+i);//op is 10

}

public static void change(Integer i) {
i =11;
System.out.println("method"+i);//op is 11
}

Ответить
commenter
commenter - 23.02.2022 07:14

Best explanation ❤️

Ответить
Hari Prasad
Hari Prasad - 01.02.2022 04:54

Super 🌟

Ответить
Ayyappa G
Ayyappa G - 05.01.2022 13:29

Need small clarification, when primitive variable 'a' passed as an argument to a method you said java copies the value of 'a' to a new memory location and that location address passed to that method as argument so value wouldn't update in parent class ? Same theory isn't applicable to objects ? Java doesn't copy the object to different memory location and sends that memory location address to method as an argument ?

Ответить
Rohit♠️
Rohit♠️ - 31.10.2021 18:55

Today this question asked by interviwer...I got trapped... there is mutable/immutable thing also matter to this pass by value or reference. Please clear this also.

Ответить
sanjay chandel
sanjay chandel - 25.10.2021 06:34

Best explanation !

Ответить
Abhishek Arya
Abhishek Arya - 24.10.2021 11:33

Nice explanation!

Ответить
Guntaka Someshwar
Guntaka Someshwar - 21.10.2021 10:33

I am unable to understand madam

Ответить
Nivas Simhadri
Nivas Simhadri - 21.10.2021 06:33

seen many videos from your channel, everything is on point explanation and also the slides are perfect to read even though there is no audio. where can we find all your presentation slides?

Ответить
Om prakash
Om prakash - 21.09.2021 17:39

So can we say, java is pass by reference for non-premitive data types?

Ответить
Siddharth b
Siddharth b - 10.09.2021 13:38

vera level

Ответить
Hey_babe
Hey_babe - 07.09.2021 06:56

The video views is equal to your subscriber count

Ответить
Gargi Joshi
Gargi Joshi - 22.08.2021 08:40

Best explanation by far

Ответить
Nazim Mohammad
Nazim Mohammad - 21.08.2021 18:04

Pl make it more clear.

Ответить
surbhi chaturvedi
surbhi chaturvedi - 03.08.2021 22:57

So we can say reference is passed as value so reference doesn't change but object value gets change in case of passing reference?

Ответить
Arpan Banejee
Arpan Banejee - 23.07.2021 09:47

Its still not clear to me-
Example 1-
If I just add tempList in my base case then I get [] [] [] [] as and, as it holds the reference and it gets modified in the recursive calls, so at each step when it hits the base case I need to capture the then state of the arraylist and store it in the res.


private static void backtrack(List<List<Integer>> list, List<Integer> tempList, int[] nums, int remain, int start) {
if (start >= nums.length && remain != 0) {
return;
} else if (remain == 0) {
list.add(new ArrayList<>(tempList));--> if I do not make a new list out of it , it gets modified. REFERENCE VAIRABLE THATS WHY!!
} else {
for (int i = start; i < nums.length; i++) {
if (nums[i] > remain) {
break;
}
if ((i > start && nums[i] == nums[i - 1])) {
continue; // skip duplicates
}
tempList.add(nums[i]);
backtrack(list, tempList, nums, remain - nums[i], i + 1);
tempList.remove(tempList.size() - 1);
}
}
}

But in this example, even if I set the prev pointer when my left recurison ends for the first time
,still its value is null when it backtracks-

private void convertBtToDll(Node temp, Node prev) {
if (temp == null) {
return;
}

convertBtToDll(temp.left, prev);

// marks the head -- leftmost node
if (prev == null) {
head = temp;
}

// make the links for the other nodes
else {
temp.left = prev;
prev.right = temp;
}
prev = temp; ----> even if I set it here it is null?????? why? isn't it a reference variable?
convertBtToDll(temp.right, prev);
}

public static void main(String[] args) {
ConvertBTtoDLL2 btToDll = new ConvertBTtoDLL2();
Node root = new Node(10);
root = new Node(10);
root.left = new Node(12);
root.right = new Node(15);
root.left.left = new Node(25);
root.left.right = new Node(30);
root.right.left = new Node(36);


System.out.println("After conversion to DLL");
Node temp = root;
Node prev = null;
btToDll.convertBtToDll(temp, prev);
btToDll.printDll();

}

Ответить
Dheeban M
Dheeban M - 21.07.2021 10:19

Real time example is very easy to understand, thank you...

Ответить
Sudip Ghimire
Sudip Ghimire - 09.06.2021 13:58

This is too much of a hindi accent to take in..

Ответить
g sathyanarayana
g sathyanarayana - 03.06.2021 22:03

Thank You for making this video. Need small clarification, when primitive variable 'a' passed as an argument to a method you said java copies the value of 'a' to a new memory location and that location address passed to that method as argument so value wouldn't update in parent class ? Same theory isn't applicable to objects ? Java doesn't copy the object to different memory location and sends that memory location address to method as an argument ?

Ответить
SecretSociety
SecretSociety - 25.05.2021 16:52

This is very helpful video. Thanks a lot for explaining this👍

Ответить
Gokul Aher
Gokul Aher - 25.05.2021 16:31

java is strictly pass-by-value method 'arguments' "value" initializes and assigns newly created method 'parameter'value

Ответить
Temur Yakhyoev
Temur Yakhyoev - 09.05.2021 03:56

still a bit confusing about pass the object as a parameter

Ответить
Drashti Naik
Drashti Naik - 07.05.2021 11:48

It is perfect explanation. But still, can you please add new video on this with detail explanation and example.

Ответить
kasi yedumati
kasi yedumati - 29.04.2021 05:30

Awesome explanation

Ответить
WAQAS AHMAD
WAQAS AHMAD - 27.04.2021 17:38

Thank you so much Ma'm to clearing my Concept... & Congratulations for a new subscriber 😉

Ответить
Swapnil Hadge
Swapnil Hadge - 24.03.2021 09:40

You missed to mention difference between int and animal ...

Ответить
Aravindh Ravi
Aravindh Ravi - 23.03.2021 21:03

THIS IS GR8!!!

Ответить
Sabbatical Countdown
Sabbatical Countdown - 14.03.2021 00:12

You did an excellent job explaining, thank you so much!! =)

Ответить