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.
@CodeDecode4 жыл бұрын
M glad that you are. :) May you reach all the heights in your career
@nndsmsjsjs2501 Жыл бұрын
@@CodeDecode mam pass By Value Means Call by value Right?
@Neerajkushwaha-uz8wo10 ай бұрын
Us😄
@sravyayerrams Жыл бұрын
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)
@CodeDecode Жыл бұрын
👍👍
@amitjoshi9406 ай бұрын
Java 8 : pass by value or pass by reference
@dheebanm32073 жыл бұрын
Real time example is very easy to understand, thank you...
@CodeDecode3 жыл бұрын
Thanks Dheepu 👍
@vigneshramesh76914 жыл бұрын
With the Last example all the doubts are cleared that Java is pass by value. "Just passing a reference as value. " 8:12 - 8:16
@CodeDecode4 жыл бұрын
👍👍m glad you understood this so clearly 👍 appreciable
@roobanraj28 Жыл бұрын
Thanks for this crystal Clear Explanantion .
@CodeDecode Жыл бұрын
👍🙂
@renejacques82883 жыл бұрын
Clear explanation. I hope that'll help not to forget it again.
@CodeDecode3 жыл бұрын
Thanks 👍. Yes hopefully 😊
@TheMilinmodi8 ай бұрын
Thank you so much mam. Much clear till you convinced that java is pass by value but when you explained with java object then it becomes confusing. Please explain in detail for when we are changing the value using object. Also, Congratulations to you for new subscriber as well. Gone thru channel and found it very helpful.
@CodeDecode8 ай бұрын
Sure we will create a more clarity video on this. Thanks 👍
@avinashkumargond32917 ай бұрын
Last wala example related to refreneces, was really osm
@abhivela Жыл бұрын
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 🎉❤
@CodeDecode Жыл бұрын
Thanks Abhi 😊👍
@anurani70842 жыл бұрын
Thankyou mam.. for explaning this in a wonderful way
@secretsociety25103 жыл бұрын
This is very helpful video. Thanks a lot for explaining this👍
@CodeDecode3 жыл бұрын
Thanks Amogh for the nice words....
@dhananajaykrishna82594 жыл бұрын
Simple and clear explanation. Aweesome!!
@CodeDecode4 жыл бұрын
Thanks 👍
@WAQASAHMAD-cw1ds3 жыл бұрын
Thank you so much Ma'm to clearing my Concept... & Congratulations for a new subscriber 😉
@CodeDecode3 жыл бұрын
Thanks Waqas 👍👍
@Asadullah-bg5ny3 жыл бұрын
what a brilliant way of explaining , finally got the answer.
@CodeDecode3 жыл бұрын
Thanks 🙃
@gsathyanarayana73663 жыл бұрын
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 ?
@abduldaniq50043 жыл бұрын
Exactly I got that same doubt
@nrusinghacharya3 жыл бұрын
The problem you're facing here is statements like In Java, Objects are passed by reference, and primitives are passed by value. This is half incorrect. Everyone can easily agree that primitives are passed by value; there's no such thing in Java as a pointer/reference to a primitive. However, Objects are not passed by reference. A correct statement would be Object references are passed by value.
@shiva38953 жыл бұрын
@code_decode small question. If java is pass by value & values is passed after copying it. That means object reference value should also be copied first and than passed. If Yes, a memory address is being copied and that is my missconcecpt. Can you please explain. Thanks!
@singhji414910 ай бұрын
Great explanation 👌🙏
@CodeDecode10 ай бұрын
Thanks
@siddheshtoraskar95374 жыл бұрын
Great explanation with nice example 👍🏻
@CodeDecode4 жыл бұрын
Thanks 👍
@nagar4u3 жыл бұрын
Good content. Keep growing. Keep it up.
@CodeDecode3 жыл бұрын
Thanks 👍
@SaratKumar-qk7lu4 жыл бұрын
Good to see this channel.
@CodeDecode4 жыл бұрын
M glad you liked it
@nivassimhadri22293 жыл бұрын
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?
@CodeDecode3 жыл бұрын
Thanks a ton Nivas 🙂👍
@prudhvinadh5786 Жыл бұрын
Nice explanation
@CodeDecode Жыл бұрын
Thanks 😊👍
@sanketh7683 жыл бұрын
Thanks mam, please continue to make videos like these to help people. Maybe after java sometother topic like database
@CodeDecode3 жыл бұрын
Yes, definitely
@gargijoshi51863 жыл бұрын
Best explanation by far
@CodeDecode3 жыл бұрын
Thanks Gargi
@satyamshah91644 жыл бұрын
Very clear explanation mam!
@CodeDecode4 жыл бұрын
Thanks :)
@navneettripathi21104 жыл бұрын
Commenting for the 3rd time....for comparable comparator detailed video...
@CodeDecode4 жыл бұрын
. Sorry for keeping your topic on hold. I needed to cover basics first for that video. Now since we have covered most of the basics we can take that topic now.
@CodeDecode4 жыл бұрын
@navneet All you need to know about comparable and comparator Please like and subscribe. kzbin.info/aero/PLyHJZXNdCXscG1g50RaLZdXgBhC-C7dCy
@jeeteshkumar114 ай бұрын
Great explanation
@CodeDecode4 ай бұрын
Thanks 👍
@sabbaticalcountdown3 жыл бұрын
You did an excellent job explaining, thank you so much!! =)
@CodeDecode3 жыл бұрын
You are Welcome ....
@abhishekarya81083 жыл бұрын
Nice explanation!
@CodeDecode3 жыл бұрын
Thanks abhishek
@tapanparida31762 жыл бұрын
God bless you mam for your good work…your work really helps people….keep up!!!
@CodeDecode2 жыл бұрын
Thanks a lot Tapan 🙂👍
@sanketh7682 жыл бұрын
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 }
@thivagarmurugan29552 жыл бұрын
u creating primitive datatypes in main function and u just passing copy of i in change method so any changes made in change only affected in change alone not in main method the both different
@niteshbhati6496 Жыл бұрын
It is because all primitive wrapper classes (Integer, Byte, Long, Float, Double, Character, Boolean, and Short) are immutable in Java
@Dharmik_Vibes3 күн бұрын
primitive wrapper classes in Java (such as Integer, Double, Character, Boolean, Long, Short, Byte, and Float) are immutable. Explanation: An immutable object is an object whose state cannot be modified after it is created. In the case of primitive wrapper classes in Java, once an instance of a wrapper class is created, its value cannot be changed.
@kasiyedumati94233 жыл бұрын
Awesome explanation
@CodeDecode3 жыл бұрын
Thanks 👍👍
@saikumargoud32572 жыл бұрын
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?
@vigneshgvs Жыл бұрын
chatgpt gave below sample on justification: In Java, you always pass the value of the reference to an object when you pass it to a method. This means you are passing a copy of the reference, not the actual object. Java itself does not provide a way to pass the actual object by reference as some other languages might. Even when you pass an object as a method parameter, you're still passing a copy of the reference to that object. (kindda pass by value). However, the confusion often arises because operations on the object itself (like modifying its fields) are visible outside the method, giving the appearance that the object is being passed by reference. class Person { String name; Person(String name) { this.name = name; } } public class Main { public static void modifyReference(Person person) { person = new Person("John"); // This reassigns the reference locally, not affecting the original reference. } public static void modifyObjectFields(Person person) { person.name = "Jane"; // This modifies the actual object, affecting the original object. } public static void main(String[] args) { Person person = new Person("Alice"); modifyReference(person); System.out.println(person.name); // Output: Alice modifyObjectFields(person); System.out.println(person.name); // Output: Jane } }
@akah2 Жыл бұрын
Excellent
@CodeDecode Жыл бұрын
thanks
@pankajchandel10003 жыл бұрын
Best explanation !
@CodeDecode3 жыл бұрын
Thanks sanjay
@alfiyakhan4580 Жыл бұрын
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.
@veerannajakkula3 жыл бұрын
Good explanation. Thank You. You can also pass any list to a method and update the list in called method to provide more in-depth analysis.
@CodeDecode3 жыл бұрын
Sure 👍
@drashtinaik57513 жыл бұрын
It is perfect explanation. But still, can you please add new video on this with detail explanation and example.
@CodeDecode3 жыл бұрын
Sure Drashti, what do u want us to cover in that?
@drashtinaik57513 жыл бұрын
@@CodeDecode In detail with heap and stack memory allocation that will give much clarity .
@drashtinaik57513 жыл бұрын
@@CodeDecode And thank you for fastest reply.
@CodeDecode3 жыл бұрын
Sure. You need Java memory management. Right?
@CodeDecode3 жыл бұрын
No worries 😊😊
@commenter94512 жыл бұрын
Best explanation ❤️
@CodeDecode2 жыл бұрын
Thanks
@abhishekganguly1653 жыл бұрын
Hi mam, In 1:18- 1:21 aapne kaha ki "we are changing the value at the real address in the memory" this is pass by referance. and that is what is happening in your last example. when you passes a value the it is changing its value. If you are passing a referance, then the address of the object is getting copied, and it is changing the value inside that object. So can you Please expain me in details for call by referance with a heap and stack memory representation. if possible.
@abhishekganguly1653 жыл бұрын
I got it first in google search that: Pass-by-reference means to pass the reference of an argument in the calling function to the corresponding formal parameter of the called function. The called function can modify the value of the argument by using its reference passed in. The following example shows how arguments are passed by reference. So why cant we say java supports both. ?
@sriharikaranam33303 жыл бұрын
Java mainly dealing with 2 types.. 1. Primitive 2. Object In first case java is passing primitive value as argument of method. So any changes happened in method then new primitive will be created(which is short lived variable). It wont affect original primitive. In second case, lets say reference is 101011. Then java is passing that reference as argument of method. If any changes happened, reference value not get affected. Java will modify the object which is pointing to that reference. The reference value will be maintained as same. So Java is pass by value... In first case if original value changed, or in second case if the reference got changed, then it will be pass by reference..
@abhishekganguly1653 жыл бұрын
@@sriharikaranam3330 what you told I got. but point is what is pass by reference then? we will pass the referance and address will be change? or pass by reference is we pass the referance and the value inside the referance got change?
@sdef7194 жыл бұрын
Best explanation. Love it.
@CodeDecode4 жыл бұрын
Thanks 👍
@venkatesanelumalai-q5c Жыл бұрын
Nice Video
@CodeDecode Жыл бұрын
Thanks
@yoshitamahajan3534 жыл бұрын
In pass by value u mean the value doesn't change and in pass by reference value changed so ideally value changes when reference passed so it should be pass by reference?? Do let me know as I m still confused about this so
@CodeDecode4 жыл бұрын
Ok so let's understand it in this way. Reference is nothing but memory address. Now when ever you change any thing at memory address, the change is reflected every where. Now in case of Java, This memory address is sent as values in arguments to methods. So it's pass by value, but since memory address or reference is passed as values hence changes are reflected every where
@CodeDecode4 жыл бұрын
Now do you get the point?
@yoshitamahajan3534 жыл бұрын
@@CodeDecode and same in case of pass by value we create copy of the variable and pass the copy.. so again we pass value.. 1. In call by value , we create copy of the value and pass to the method 2. In call by reference,we pass the value of memory address to which the object is passed So in both cases value is passed hence java is call by value Am I r8? Please correct me if I m wrong..
@abhishekganguly1653 жыл бұрын
@@yoshitamahajan353 but both point 1 and 2 got satisfied right? so why this is only pass by value?? why it is not pass by refrerance?
@gokulaher24763 жыл бұрын
java is strictly pass-by-value method 'arguments' "value" initializes and assigns newly created method 'parameter'value
@CodeDecode3 жыл бұрын
That's what we have discussed here also right?
@gokulaher24763 жыл бұрын
Perfect... Your video on java 8 Predicate,function, supplier,consumer Bi.... Predicate, fu,ction,consumer and stream are very well explained..
@ayyappag70972 жыл бұрын
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 ?
@vaniraj84562 жыл бұрын
No here because we send the reference variable which holds the memory address of an object rather than holding the object
@AMANSINGH-yv4vv3 ай бұрын
Thanks so much ya!
@CodeDecode3 ай бұрын
🙂👍
@arpanbanejee51433 жыл бұрын
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, List 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(); }
@hariprasad26972 жыл бұрын
Super 🌟
@CodeDecode2 жыл бұрын
Thanks hari
@omprakash45583 жыл бұрын
So can we say, java is pass by reference for non-premitive data types?
@chaturvedisurbhi053 жыл бұрын
So we can say reference is passed as value so reference doesn't change but object value gets change in case of passing reference?
@deepkansara65479 ай бұрын
Consider this snippet: public static void main(String[] args) { Integer i = new Integer(3); modify(i); System.out.println(i); //Prints 3 } static void modify(Integer i) { i = i * 10; } In this case I have created the object of the Integer class and changed it's value. So as per this video, object can be changed as it is passed as a reference, I am getting the output as the same object it has been initialized with instead of modified version. In case of arrays, we can do modify the values of array. So I just want to know what kind of values are passed by value and what kind of values are passed by reference?? Anyone please help.
@arpit22839 ай бұрын
Bro, String and Wrapper classes like Integer , Double , BigDecimal are immutable classes. So , the value is not changed there.
@azizbekrasulmetov9293 Жыл бұрын
Did u said that u a passing object by value at the end ? When u actually passing the reference!
@barathiraiyarul44982 жыл бұрын
Thanks 👍
@CodeDecode2 жыл бұрын
👍
@aravindhravi23073 жыл бұрын
THIS IS GR8!!!
@CodeDecode3 жыл бұрын
Thanks 👍👍
@gokudominic33284 жыл бұрын
Why java is not both i.e. java is pass by value as well as pass by reference.??plzz ans
@CodeDecode4 жыл бұрын
Because Java is pass by value. That's why it's not both.
@gokudominic33284 жыл бұрын
No mam i mean java is always pass by value but by vedio java is seems to be both so how can you say tha pass by reference is equivalent to pass by value??
@gokudominic33284 жыл бұрын
My actual question is how pass by reference is equivalent to pass by value??
@CodeDecode4 жыл бұрын
Consider a scenerio : You are passing address or memory location itself.
@CodeDecode4 жыл бұрын
So while you are passing your variable as formal argument of the method, it is considered as pass by value. So yes you are correct when you say it's pass by value but actually in java, you pass memory reference itself as a value.
@poornachanderraonadipelly61282 жыл бұрын
Mam im getting really confused with this concept? Please help me to understand
@Rohit-yo4ik3 жыл бұрын
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.
@NareshKumar-dw9xp4 жыл бұрын
Yesterday I had an interview with Nokia , it was an on-campus placement interview.. You know what, they asked me why java is passed by value ? And they wouldn't satisfied with my answer. And hence I got rejected ☹️☹️.
@CodeDecode4 жыл бұрын
Was I able to clear your query? Did you watch this video before or you watched this now?
@NareshKumar-dw9xp4 жыл бұрын
@@CodeDecode That's the unfortunate mam. I watched it now. But noww I am clear amd confident. Probably next week I have an interview of TCS Digital SDE . I will never repeat this mistake ever. Thank you so much for this.
@CodeDecode4 жыл бұрын
Don't worry. As a fresher you will get ample of opportunities and each interview will teach you something new.
@CodeDecode4 жыл бұрын
Take it positively. Just make sure that you are clear with your basics. They will not go much high level. Prepare core Java thoroughly and I am sure you will crack something really worth cracking 👍
@CodeDecode4 жыл бұрын
All the best for the future companies. 👍
@asutoshsahoo37764 жыл бұрын
Got it that , the reference we pass in java function is as a reference to memory location as value, so though we pass a reference it is still Pass by Value, but then what is Pass by Reference exactly
@CodeDecode4 жыл бұрын
Your understanding is correct. Pass by reference is just a concept where you pass reference of variable or so called memory address of that variable itself as the formal argument. Doing so, if you change any thing locally in the method, the changes are no more local to that method, it's reflected every where Why so? Because you changed at the memory itself. Right? Now you got it ? If it would have been pass by value, different memory location is created for the formal argument and value will be copied. Hence if you change that value locally, the changes will be in newly created memory location and not in the original one
@deneshbabu51994 жыл бұрын
Then what exactly pass by reference?
@abhishekganguly1653 жыл бұрын
@@deneshbabu5199 same question bhai.
@abhishek_672 жыл бұрын
Hum value bhi pass kr rhe hai aur object reference bhi pass kr pa rahe hai to java sirf passed by value kyu 🤔?
@akshaydeshmukh14332 жыл бұрын
call by rfrnce vs pass by rfrence same or dfrnt
@swapnilhadge73833 жыл бұрын
You missed to mention difference between int and animal ...
@hasangalakdinu7 ай бұрын
thanks!!!
@CodeDecode6 ай бұрын
You're welcome!
@sharfan220104 жыл бұрын
Thankyou miss👍
@MultiMoonlight10 ай бұрын
Ma'am is your name Sana?
@temuryakhyoev59223 жыл бұрын
still a bit confusing about pass the object as a parameter
@paggybhangale2 жыл бұрын
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()
@sahilbhasin21124 жыл бұрын
gud job
@CodeDecode4 жыл бұрын
Thanks :)
@hhcdghjjgsdrt235 Жыл бұрын
you rock
@CodeDecode Жыл бұрын
:)
@SaiAbitathaDUCIC3 жыл бұрын
My exam begins in 2 hours 🙏
@CodeDecode3 жыл бұрын
All the best 👍💯
@nazimmohammad69843 жыл бұрын
Pl make it more clear.
@siddharthb22263 жыл бұрын
vera level
@CodeDecode3 жыл бұрын
Thanks
@hasnainansari62794 жыл бұрын
I m still confused ⁉️
@CodeDecode4 жыл бұрын
java is pass by value. But if you pass a reference variable as an argument and that changes then it is because you are passing memory reference as value. Hence it's never pass by reference. It's always pass by value.
@CodeDecode4 жыл бұрын
Still confused??
@littlethings22504 жыл бұрын
@@CodeDecode : passing memory reference as a value? But here we are not working on copy, instead the actual object itself isn't it? And in C, the concept of pointers and reference, there we pass reference as a reference or value?
@achyuth24244 жыл бұрын
Not understood please give more detail easy way of understanding
@CodeDecode4 жыл бұрын
Explaination : java is pass by value. But if you pass a reference variable as an argument and that changes then it is because you are passing memory reference as value. Hence it's never pass by reference. It's always pass by value. Still if it's not clear then please let me know I will put more examples for you.
@achyuth24244 жыл бұрын
@@CodeDecode more examples please
@guntakasomeshwar82623 жыл бұрын
I am unable to understand madam
@shivprasadgonare44742 ай бұрын
plz provide notes
@divyagracie2 жыл бұрын
02:51
@unknownuser-wr3zm3 жыл бұрын
tq
@CodeDecode3 жыл бұрын
👍
@cousinslove72094 жыл бұрын
Slow slow madam , not all members are quick learners as like you
@CodeDecode4 жыл бұрын
Will try to reduce pace from next videos 👍
@GameXanime634 жыл бұрын
U can do by urself if u don't know the playback option just click on the three dot and u can this playback option where u can reduce the speed of the vdo btw thank me later
@lazylizarts2 жыл бұрын
JAVA IS ALWAYS PASS BY VALUE ALWAYS
@CodeDecode2 жыл бұрын
Can you please explain how?
@lazylizarts2 жыл бұрын
@@CodeDecode its appropriate to say "Object reference is passed by value" for Non primitive type
@horuscoming4 жыл бұрын
You got to activate windows.
@CodeDecode4 жыл бұрын
Yeah will do that for sure...
@sudipghimire48233 жыл бұрын
This is too much of a hindi accent to take in..
@CodeDecode3 жыл бұрын
We are so sorry Sudip that our mother tongue is hindi. 👍