I am C++/C# developer and new to Java. Some reference found on internet suggests that we cannot have call by reference in Java. Is it completely true, or by any way I can return more than one value from function?
Secondly, default parameter is not seems to support in Java, I am also trying to find is there any way to use default arguments in Java.
Thanks.
Some reference found on internet suggests that we cannot have call by reference in Java. Is it completely true
Yes. Java is pass-by-value, always. The values which are passed are either references or primitive values. (Objects are never passed, or returned. The value of a variable is always a reference or a primitive value. It's really important to understand this.)
or by any way I can return more than one value from function?
You can create your own type composed of the various values. That's normally what I'd do. You could use an AtomicReference<V>
parameter or an array as a sort of ref
parameter... but I'd strongly encourage you not to. It would be very non-idiomatic.
Secondly, default parameter is not seems to support in Java, I am also trying to find is there any way to use default arguments in Java.
No, there isn't. The closest approach is to overload the method, making an implementation with fewer parameters call an implementation with more parameters, specifying a default value as the "missing" arguments.
See more on this question at Stackoverflow