Value type and Reference type in java? | SoloLearn: Learn to code for FREE!

0

Value type and Reference type in java?

Hi all, Just had a doubt ,is pass by value same as "Value type" and pass by reference same as "Reference type".Value type and reference type is a sub chapter in java in Sololearn. Thanks

5/22/2019 12:13:38 PM

swali1

7 Answers

New Answer

+2

Value type are all the types which with a lowercase letter (e.g. int, float, boolean, ...). When they are passed to a function their value is given to function and thus if they are in changed in the function, the change won't be visible outside the function. Reference types are all the other types. When passed to a function, the reference (or pointer) to the object is passed by value (Java is always passed by value) but since you use a reference to access the object, the modification will be visible outside the function

+3

swali1 Primitive datatypes like int, float, char, long double etc are Valuetype datatypes as they store the actual values in variable of respective datatype All other types are Reference type datatypes because the variable of respective type stores the address/reference of the data types e.g Strings, Arrays, Maps, List extra int i = 10; // i has actual value of 10 String str = "test" str has a reference to the address in memory where the string is actually stored.

+3

swali1 As Paul said in Java everything is pass by value. For primitive data types actual values are pased and for others the reference or address is passed by value. The terminology you have mentioned is misleading but widely use. Just remember everything is "call by value" or "pass by value"

+1

thanks -swim- and Paul

+1

ok ..got it -swim-

0

is "call by reference"="pass by reference"="reference types" and is "call by value"="pass by value"="value types"

0

btw can you refer to me a good article ,or thread or post or video ...on this concept of pass by value and pass by reference..it would be really helpful