java varargs parameters for method

in java ,programmer can declare a method with varargs parameter ,It means the method cannot parameter call 0 or more parameter . for example string.format . it possible with varargs feature.

2016-09-16-16_59_59-workspace-java-testbyrefvalue_src_testbyrefvalue_test-java-eclipse

Advertisements

Java and C# and java script call by value and call by Reference +Sample Code

 

        We have two simple method one method in java one method in c# ,both of this two method get one parameter and return parameter+1 after it,I change this sample for test a object input not primitive value.

.c#         

image00

Java :

image02

and java script:

image10

image03

also,you see our parameter not change after call function sum.

we change param type from integer to a class with a one property as integer .

C# :

image08

Java :

image05

    Javascript:

image04

image07

now we change the code and create new instance in sum method of input object:

C#:

image06

Java :

image09

now I change Call by value to reference :

C#:

image01

Java :

image11

so we have Error here , You simply can’t do that in Java.)

since Java doesn’t support pointers …

but in javascript :

  1. Javascript is always pass by value, but when a variable refers to an object (including arrays), the “value” is a reference to the object.
  2. Changing the value of a variable never changes the underlying primitive or object, it just points the variable to a new primitive or object.
  3. However, changing a property of an object referenced by a variable does change the underlying object.