Java does not support pass by reference. Java actually pass-by-value for all variables running within a single VM. pass-by-value means pass-by-variable-value and that means pass-by-copy-of the variable.
It makes no difference if you are passing primitive or reference variable, you always passing a copy of the bits in the variable.
For example: if u are passing the variable with the value 3, you are passing the copy of variable representing 3. If you are passing an object reference variable, you are passing the copy of the bits representing the reference to an object.
RE: Does Java support pass by reference. If yes/no- why?
Java does not support pass by reference. Java actually pass-by-value for all variables running within a single VM. pass-by-value means pass-by-variable-value and that means pass-by-copy-of the variable.
It makes no difference if you are passing primitive or reference variable you always passing a copy of the bits in the variable.
For example: if u are passing the variable with the value 3 you are passing the copy of variable representing 3. If you are passing an object reference variable you are passing the copy of the bits representing the reference to an object.
RE: Does Java support pass by reference. If yes/no- why?
Yes java do support pass by reference. when ever we pass an object to the method it is call by reference only. The changes made for the state of the object inside the method call which is in other object will be reflected in the original object passed in ...
RE: Does Java support pass by reference. If yes/no- why?
Java is purely pass-by-value only. The confusion is because when an object is passed the objects value which in this case is the memory allocation is passed. Since the object received in the method has the same memory reference this seems like it is passed by reference.
RE: Does Java support pass by reference. If yes/no- why?
Java is purely pass-by-value only. The confusion is because when an object is passed the objects value which in this case is the memory allocation is passed. Since the object received in the method has the same memory reference this seems like it is passed by reference...........
RE: Does Java support pass by reference. If yes/no- why?
hi there the java technology supports a kind of pass by reference but this process applies only to the objects not the primitive data types i.e if you are familiar with c++ then you must be knowing that whatever changes you make in the the reference that are reflected back in call by reference in the same way this happens in java but only in case of the objects.try a programme in which you instantiate a class and try to modify the primitive data type by calling it from the main method and kind of same process apply it to the case of objects you will find that only in the case of the objects the change occurs.for any further query please ask byeee
RE: Does Java support pass by reference. If yes/no- why?
Java always makes a copy of arguments & pass the copy.The called method has a local copy of data.If the the method changes the data it changes the copy So original value is not changed. When we pass a prmitive like int the method gets its own int value.a copy of original.
When we pass an Object the value that is copied & set along a referance or pointer to the object.the method gets its own copy of pointer it does not gets own copy of object. If method changes the copy of pointer to point to another object the original pointer is not effected.
If the method changes the sme of the attribute of the object it canges original object.
RE: Does Java support pass by reference. If yes/no- why?
In Java copies of references of Objects are passed. So everything is passed by value. Be it an object reference or a primitive data type. If you modify the object reference in a method it won't have any effect on the referenced that was passed.