Argument Passing

I have probably a very simple question. I'm passing the arguments by call-by-reference and after the 1st using of the methods, a and b are changed (this is normal), but how can i make it without changing their initial values.
I think the soltution is something very basic for java, but i'm new to java and i need help :)
public static void main(String args[])
    Rational a = new Rational(10, 20);
    Rational b = new Rational(30, 10);
    Rational rez = new Rational(0, 1);
    rez = a.add(b);
    System.out.println(":\n"+rez.num+"\n-\n"+rez.den);
    rez = a.sub(b);
    System.out.println(" \n"+rez.num+"\n-\n"+rez.den);
    rez = a.mul(b);
    System.out.println(" \n"+rez.num+"\n-\n"+rez.den);
    rez = a.div(b);
    System.out.println(" \n"+rez.num+"\n-\n"+rez.den);
      }Maybe the right question is: how this code could work without a and b changing their values after calling the methods.
P.S. I hope you understand what I'm asking. Sorry for my bad English
Edited by: asemenea on Jul 28, 2008 10:38 AM

I'm not very good at English and I understood wrong what I read from Schildt:Rule #1: Don't use Schildt as a source of Java expertise.
All parameters to methods are passed "by value." In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter's value without affecting values in the code that invoked the method. For example:
class PassByValue {
    public static void main(String[] args) {
        double one = 1.0;
        System.out.println("before: one = " + one);
        halveIt(one);
        System.out.println("after: one = " + one);
    public static void halveIt(double arg) {
        arg /= 2.0;     // divide arg by two
        System.out.println("halved: arg = " + arg);
}The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:before: one = 1.0
halved: arg = 0.5
after: one = 1.0You should note that when the parameter is an object reference, the object reference -- not the object itself -- is what is passed "by value." Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show the distinction:
class PassRef {
    public static void main(String[] args) {
        Body sirius = new Body("Sirius", null);
        System.out.println("before: " + sirius);
        commonName(sirius);
        System.out.println("after:  " + sirius);
    public static void commonName(Body bodyRef) {
        bodyRef.name = "Dog Star";
        bodyRef = null;
}This program produces the following output: before: 0 (Sirius)
after:  0 (Dog Star)Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.
The following diagram shows the state of the variables just after main invokes commonName:
main()            |              |
    sirius------->| idNum: 0     |
                  | name --------+------>"Sirius"       
commonName()----->| orbits: null |
    bodyRef       |______________|At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the "after" line would say "null". However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.
Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
-- Arnold, K., Gosling J., Holmes D. (2006). The Java? Programming Language Fourth Edition. Boston: Addison-Wesley.
~

Similar Messages

  • Mod_plsql: /pls/apex/wwv_flow.accept HTTP-400 Too many arguments passed in.

    Hi All ,
    I want one solution i have a report which fectches the ppt that r stored in db,If i search more results it errors out so i have reduced the results and it was working fine.Now i see it is giving the same error(as below) althorugh it was working fine by reducing results in query.Can anybody please help me in this.
    the error is
    Bad Request
    Your browser sent a request that this server could not understand.
    mod_plsql: /pls/apex/wwv_flow.accept HTTP-400 Too many arguments passed in. Got 3250 parameters. Upper limit is 2000
    Oracle-Application-Server-10g/10.1.3.1.0 Oracle-HTTP-Server Server at insightapps.oraclecorp.com Port 80

    Section 1.10 of the Oracle HTTP Server mod_plsql User's Guide states the following
    The total number of name value pairs that can be passed to a PL/SQL procedure is 2000.
    mod_plsql limits the total number of parameters that can be passed to a single procedure to 2000.
    mod_plsql limits the size of a single parameter that can be passed to a procedure to 32000 bytes.
    It would be helpful to know how each of these apply in the APEX context
    Varad

  • HTTP-400 Too many arguments passed error

    I am getting the following error when using a multiselect list item to select/update data in the tabular form.
    Bad Request
    Your browser sent a request that this server could not understand.
    mod_plsql: /pls/otn/wwv_flow.accept HTTP-400 Too many arguments passed in. Got 2346 parameters. Upper limit is 2000
    Oracle-Application-Server-10g/10.1.2.3.0 Oracle-HTTP-Server Server at apex.oracle.com Port 80
    I have built this prototype application on the Oracle’s hosted apex.oracle.com site.
    The application page has three sections. Section 1 is an HTML region with the multiselect list. Section 2 is an HTML region with 20 text items. Section 3 has the tabular form with 25 columns that are used to update the data. The tabular form pagination values “Number of Row” and “Maximum Row Count” are set to 500.
    Up until now, the multiselect list in the Section 1 was just a simple select list and I never had any issues. I guess the number of arguments passed was low. Per our customer requirement, I had to change the simple select list to a multiselect list. Now, If I select multiple values in the select list, I get the above mentioned error. But, it does not seem to happen all the time. For example, the first time I select 3 values in the multiselect list, the page renders fine, and I am able to enter/save data in the tabular form. Then, I select two other values in the multiselect list, I would get the error.
    I am getting this error on the Oracle’s hosted apex.oracle.com site where my prototype application exists. And, according to the error oracle is using 10g/10.1.2.3.0. Is there any way to circumvent this issue so I can demo my application to the customer using the multiselect list?
    I found several threads on this forum regarding the same error and it seems that there was a bug in the older versions of Oracle Application server. Also, there were discussions about setting the PlsqlMaxParameters.
    Our dev/test/prod environment would be set up using the Oracle Application Server-10g/10.1.3. The question is would we need to add a line to set the PlsqlMaxParameters value in the plsql.conf file? In addition, what is the maximum value that it can be set to?
    Please forgive me for the longwinded description and the question - only way I could describe the situation.
    Thanks,
    DP

    Varad and Sc0tt,
    Thank you both for your responses.
    Varad – Yes, I can/will reduce the amount of data so it does not cause the tabular form to go over the 2000 field limit. If that is not possible, I will at least make the users aware of this issue. Since the same data is used for the other pages in the application, the users might want to keep all the data.
    Sc0tt – thanks for providing the information for your environment and settings. To plan for the future, we will have to set the value to something high also, around 8-10K range, and adjust later if we have to.
    Thank you both, I will mark both of your answers as helpful and the question as being answered.
    DP
    (Have either of you used the jquery datepicker solution? If yes, can you please take a look at my thread: Thread: Jquery Datepicker calendar problem with page scrolling
    Jquery Datepicker calendar problem with page scrolling

  • PAPI-WS Arguments passing

    hi all,
    I am confusing with PAPI-WS argument passing.
    ArgumentsBean argBean = new ArgumentsBean();
    ArgumentsBean.Arguments args = argBean.getArguments();
    ArgumentsBean.Arguments.Entry entry = new ArgumentsBean.Arguments.Entry();
    entry.setKey("");
    entry.setValue("");
    args.getEntry().add(entry);
    argBean.setArguments(args);
    Holder<ArgumentsBean> holder= new Holder<ArgumentsBean>();
    this is my code sample. Entry object can only add String variable.
    So, it means we can only pass String variable from PAPI-WS. isn't it?
    If i want to pass java Object, is it possible?
    With Regards,
    WP

    hi all,
    I am confusing with PAPI-WS argument passing.
    ArgumentsBean argBean = new ArgumentsBean();
    ArgumentsBean.Arguments args = argBean.getArguments();
    ArgumentsBean.Arguments.Entry entry = new ArgumentsBean.Arguments.Entry();
    entry.setKey("");
    entry.setValue("");
    args.getEntry().add(entry);
    argBean.setArguments(args);
    Holder<ArgumentsBean> holder= new Holder<ArgumentsBean>();
    this is my code sample. Entry object can only add String variable.
    So, it means we can only pass String variable from PAPI-WS. isn't it?
    If i want to pass java Object, is it possible?
    With Regards,
    WP

  • HTTP-400 Too many arguments passed

    Hello There,
    I installed the fresh 10g and applied patchset 2 on it. I get following error:
    HTTP-400 Too many arguments passed upper limit is 2000
    Please help

    Hello Qiang,
    Little more detail for your reference.
    README for 3355915
    MODPLSQL VERSION 9.0.2.6.0A ONE-OFF PATCH
    Date: January 6, 2004
    o What is in this patch?
    -> FIXES FOR:
    Bug#3355915 : BACKPORT BUG#3329645
    Bug#3116388 : TASK: MOD_PLSQL DOES NOT ALLOW PASSING MORE THAN 2000 PARAMETERS
    Bug#3024540 : NON-SUCCESS CODES WITH NO CONTENT SHOULD SERVE OHS ERRORDOCUMENT
    Bug#2023253 : NLS:FILE IS NOT PROPERTY UPLOADED IF IT'S FILENAME CONTAINS 0X5C
    Bug#3329645 : MODPLSQL IS UNABLE TO PASS PARAMETER LESS THAN 32K BYTES
    Bug#3264502 : DOC PATH REQUEST WITH PERPACKAGE AUTH CALL WRONG AUTH FUNCTION
    Bug#2802064 : ORA-01036 ILLEGAL VAR NAME/NUMBER USING VARIABLE NAMED P_ARRAY
    o What version can I apply this patch on?
    -> iAS 9.0.2.x.x

  • HTTP-400 Too many arguments passed - Upper Limit is 4000

    Hi,
    I have encountered this problem with Apex 3.0.1 on Oracle 10g and unfortunately I am not able to increase the PlsqlMaxParameters value of 4000 due to business rules. With regards to this and workarounds, I have the following queries:
    1) Can someone suggest possible workarounds for this problem - I am basically presenting the user with a checkbox response and sometimes this may involve over 400 records sometimes - alot I know but users would like to see everything on a single page - no pagination. This is calling the HTTP-400 error - any suggestions for workaround(s) or do I need to rewrite the page with pagination or something else?
    2) Would using APEX_COLLECTIONS assist in breaking down on the number of parameters sent to mod_plsql?
    3) Would increasing the PlsqlMaxParameters to say 10000 cause any performance issues?
    Any other help on this would be much appreciated.
    Thanks.
    Tony.

    Hi,
    It is indeed a valid work around
    http://iadvise.blogspot.com/2008/05/apex-http-400-too-many-arguments-passed.html
    It can have some performance effect.
    But test this for your situation.
    Kind regards,
    Iloon

  • WLST script argument passing

    Is it possible to pass arguments to a wlst script which can then be accesses via sys.argv[1:]? The execfile() command seems to only take the filepath. Do I have to use the properties file?
    Thanks,
    - Nathan

    Nathan,
    you can invoke the script directly as,
    java weblogic.WLST foo.py myarg1 myarg2
    and in your script you can get reference to the arguments passed in using the sys.argv.
    I do not think execfile supports passing in arguments, yes, you may want to try using the properties file.
    Thanks,
    -satya

  • Argument Passing In RMI

    In case of RMI, are arguments passed by Value or passed by reference?
    Please elaborate and explain as I am completely confused.

    Arguments to or return values from remote methods can be of almost any type, including local objects, remote objects, and primitive types. More precisely, any entity of any type can be passed to or from a remote method as long as the entity is an instance of a type that is a primitive data type, a remote object, or a serializable object, which means that it implements the interface java.io.Serializable.
    A few object types do not meet any of these criteria and thus cannot be passed to or returned from a remote method. Most of these objects, such as a file descriptor, encapsulate information that makes sense only within a single address space. Many of the core classes, including those in the packages java.lang and java.util, implement the Serializable interface.
    The rules governing how arguments and return values are passed are as follows.
    Remote objects are essentially passed by reference. A remote object reference is a stub, which is a client-side proxy that implements the complete set of remote interfaces that the remote object implements.
    Local objects are passed by copy, using object serialization. By default all fields are copied, except those that are marked static or transient. Default serialization behavior can be overridden on a class-by-class basis.
    Passing an object by reference (as is done with remote objects) means that any changes made to the state of the object by remote method calls are reflected in the original remote object. When passing a remote object, only those interfaces that are remote interfaces are available to the receiver; any methods defined in the implementation class or defined in nonremote interfaces implemented by the class are not available to that receiver.

  • Argument passing to a .exe?

    Hi,
    I have a .swf file through which i am passing arguments to .exe file which is basically a C++console application, how is it possible, should i tweak the sourcecode in th application file for it to accept the arguments passed?
    Pls suggest

    i'm not sure how you're passing those arguments but yes, the exe will need to parse those argumetns.

  • RPC Argument Passing

    Hi,
    I am trying to set up an RPC detector that runs an applet. The Applet currently just contains CLI commands, but I would like to use arguments passed from the SOAP request in the CLI commands. From the RPC syntax, the following should be accepted:
    <?xml version="1.0"?>
    <SOAP:Envelope xmlns:SOAP="http://www.cisco.com/eem.xsd">
    <SOAP:Body>
      <run_emscript>
        <script_name> name of script </script_name>
        <argc> argc value </argc>
        <arglist>
        <l> argv1 value </l>
        <l> argv2 value </l>
        <l> argvn value </l>
        </arglist>
      </run_Eemscript>
    </SOAP:Body>
    </SOAP:Envelope>
    My simple message is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP:Envelope xmlns:SOAP="http://www.cisco.com/eem.xsd">
      <SOAP:Body>
        <run_eemscript>
          <script_name>Event_RPC</script_name>
          <argc> argc test </argc>
          <arglist>
               <l> argv1 100</l>
           </arglist>
        </run_eemscript>
      </SOAP:Body>
    </SOAP:Envelope>
    However, whenever the <arglist> is included I receive an error code response. I would expect the arglist to be accepted and an action command something like the following to be accepted:
    action 1.0 cli command "switchport access vlan $_rpc_arg1"
    Has anyone had experience with this?
    Thanks,
    Jason

    I have tried the suggestion, but now receive the following response:
    <?xml version="1.0" encoding="UTF-8"?>
    http://www.cisco.com/eem.xsd">
          Event_RPC
          2
            <1>100
            <2>200
    ]]>]]>
    got data:
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>http://www.cisco.com/eem.xsd\">-15844577'Embedded Event Manager' detected the 'fatal' condition 'unknown event ID']]>]]>\r\n"

  • The 'argumentname' argument passed to the 'Methodename 'function is not of type 'Dto name'

    Hi, there!
    Sr for that question, because it should be pretty easy to answer, but i'm totally new to coldfusion
    and googled for about an hour now. I have a orm DTO.cfc:
    <cfcomponent entityname="testDTO" persistent="true" table="test"  schema="informix" output="false">
        <!---- properties ----> 
    </cfcomponent>
    and have a service Methode in test.cfc
        <!---- Add test---->
        <cffunction name="createTest" returntype="testDTO" access="remote">
            <cfargument name="item" type="testDTO" required="true" />
            <!---- Auto-generated method
              Insert a new record in test---->
            <cfset entitysave(item) />
            <!---- return created item ---->
            <cfreturn item/>
        </cffunction>
    i try to call via the the <cfInvoke>-Tag
    <cfset lieferant = entityNew('test')>
    <cfinvoke
        component="#request.componentbase#.test"
        method="createTest"
        item="#test#"
        returnvariable="test">
    but the error
    'The ITEM argument passed to the createLieferant function is not of type testDTO.'
    appears on function call. I just can't find a way to tell cf that lieferant is of type testDTO.
    When i type the methodes parameter to struct the methode call works well.
    Thanks for your help in advance!
    Florian

    I'm assuming your extract there isn't quite right:
    <cfset lieferant = entityNew('test')>
    <cfinvoke
        component="#request.componentbase#.test"
        method="createTest"
        item="#test#"
        returnvariable="test">
    You're doing item="#test#", surely this should be item="#lieferant#"?
    In which case, you've done  <cfset lieferant = entityNew('test')>, which is of type "test", not "testDTO"?
    If you're still having trouble, remove the item="" attribute from CFINVOKE and use CFINVOKEARGUMENTs instead.

  • JCS operation arguments, pass by reference or copy?

    Can I assume that objects passed from JPF into JCS, or between JCS arguments are passed by reference?
    [email protected] (replace MASK with '_')

    I'm asking this because the JCS may be in its own project independent of the web project, I wonder if it will still be pass by reference vs copy.
    If it is pass by copy, I'll need to return beans passed into JCS operations as follows:
    formBean = myControl.actionA(formBean);
    [email protected] (replace MASK with '_')

  • VBA Function with Range Argument passed to Excel Solver

    I set up a function to run solver with some specific cells but solver seems not to receive the inputs. I consider the arguments as ranges passed by ByVal and ByRef with no success. The solver has already been done directly in the spreadsheet so the problem
    has a solution.
    Function Garch(control As Boolean, ByRef MyArg As Range, ByRef LogL As Range) As String
    If control = True Then
        Worksheets("Garch").Activate
        SolverOkDialog setCell:=LogL, MaxMinVal:=1, byChange:=MyArg
        SolverAdd cellRef:=persistence, relation:=1, formulaText:=0.9999
        SolverSolve userFinish:=False
        Garch = "Done"
        Else
        Garch = "Not Done"
    End If
    End Function

    Andreas,
    I liked the concept but I need to loop through columns instead of rows, I tried unsuccessfully the code below, any suggestions?
    Sub MacroX()
      Dim i As Long
      Dim j As Long
        For i = 3 To 3
        j = i * 4 + 2
        SolverReset
        SolverOk SetCell:=Range(Cells(12, j)), MaxMinVal:=1, ByChange:=Range(Cells(3, j), Cells(7, j)), Engine:=1, EngineDesc:="GRG Nonlinear"
        SolverAdd cellRef:=Range(Cells(6, j)), relation:=1, formulaText:=0.9999
        SolverSolve userFinish:=True
      Next
    End Sub

  • TfvcTemplate.12.xaml / msbuild argument passing

    I am using Octopack to custom bundle some plugin assemblies.  I need to pass the build server target directory as an argument to Octopack so it knows which build server folder to bundle my plugins from.  
    Here are the TFS 2013 / MSBuild args that I have so far.  The ??? is what I am not sure of...
    /p:RunOctoPack="true" /p:OctoPackPublishPackageToFileShare="c:\NuGet\Foo" /p:OctoPackNuGetProperties="MyTargetDirectory=???"
    What do I put in for ??? to have MSBuild pass the target directory?
    thanks

    Hi Scott,  
    Thanks for your post.
    Please try the TFS 2013 Build environment variables in your MSBuild:
    https://msdn.microsoft.com/en-us/library/hh850448.aspx.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • CFC argument passing problem.

    What is wrong with this? I have a form that passes 3 elements
    to a cfc for
    insert. It is telling me that I am not passing the title.
    This is my CFC:
    <cffunction name="AddJob" access="public"
    returntype="void">
    <cfargument name="title" required="yes" type="string">
    <cfargument name="doc" required="yes" type="string">
    <cfargument name="cats" required="yes" type="numeric">
    <cffile action="upload"
    destination="E:/www/contactus/employment"
    nameconflict="overwrite" filefield="doc">
    <cfquery name="Addjob" datasource="***">
    INSERT INTO EmpJobs (title, doc, catid)
    VALUES ('#arguments.title#', '#cffile.serverfile#',
    #arguments.cats#)
    </cfquery>
    </cffunction>
    This is the Submit Code:
    <cfif IsDefined ('Add_Job')>
    <cfinvoke component="#Jobs#" method="AddJob">
    <cfinvokeargument name="title" value="#Form.title#">
    <cfinvokeargument name="doc" value="#Form.doc#">
    <cfinvokeargument name="cats" value="#Form.catid#">
    <cflocation url="index.cfm" addtoken="no">
    </cfif>
    This is the form.
    <form action="" method="post"
    enctype="multipart/form-data" name="add"
    id="add">
    <table width="100%" border="0">
    <tr>
    <td width="20%"><div align="right">Job
    Title:</div></td>
    <td width="80%"><input name="title" type="text"
    id="title"
    size="45" /></td>
    </tr>
    <tr>
    <td><div align="right">Description Document:
    </div></td>
    <td><input name="doc" type="file" id="doc"
    /></td>
    </tr>
    <tr>
    <td><div align="right">Employment Category:
    </div></td>
    <td><select name="catid" id="catid">
    <cfoutput query="GetCats">
    <option value="#empid#">#cat#</option>
    </cfoutput>
    </select> </td>
    </tr>
    <tr>
    <td> </td>
    <td><input name="Add_Job" type="submit"
    id="Add_Job" value="Add
    New Job Posting" /></td>
    </tr>
    </table>
    </form>
    What am I missing? Thanks!

    Everything in your code seems to be fine.
    Try general debugging using CFDUMPS. If does not work try
    passing the whole
    form object to the method : -
    Submit Code:
    > <cfif IsDefined ('Add_Job')>
    > <cfinvoke component="#Jobs#" method="AddJob">
    > <cfinvokeargument name="FormObj" value="#Form#">
    CFC:
    > <cffunction name="AddJob" access="public"
    returntype="void">
    > <cfargument name="FormObj" required="yes"
    type="struct">
    > <cfquery name="Addjob" datasource="***">
    > INSERT INTO EmpJobs (title, doc, catid)
    > VALUES ('#arguments.FormObj.title#',
    '#cffile.serverfile#',
    #arguments.FormObj.cats#)
    > </cfquery>
    > </cffunction>

  • Argument passing to Trigger

    Hi all,
    I want to know if there is a way in which i can pass arguments to a trigger.
    I have two procedures A1 and A2 bothe update a table in which a trigger is defined.i want to know which procedure has called the trig.
    Is there anyway i can achieve it?
    Thanks
    Glen.

    Thanks a lot for that information LC.
    But can i use this in trigger?
    My Trigger is fired every time when a Update happens on the Employee table ( for ex)
    There are two procedures which updates the Employee table they are,
    -> Proc1
    -> Proc2
    Now i am only interested to know when Proc2 does the update and TRigger is fired.
    I want to have a separate code to execute in the trigger when Proc2 does the update
    and separate code in trigger to execute when Proc1 does the update.
    Is there anyway in which i can do it?
    Also can a problem arise if two simulataneous users one invokes Proc1 and one invokes Proc2?
    If so how can i overcome this problem?
    Guys your help will be very valuable..
    Thanks
    Glen.

Maybe you are looking for