Member variable verses method parameter to pass information

Hi all,
Is the a performance penalty in using method parameter, such as a String, to pass information into multiple methods( method1(String X), method2(String X), etc ) in a class verses using a class member variable to pass the information to the methods?
Thanks.

Never, ever, ever make a decision as to what should be parameter and what should be field based on this kind issue. If the value is reasoably part of the state of the object it should stored (or referenced by) a field. Otherwise it should not and so your left with it being a parameter or an atribute of some other object.
There is little if any performance cost in passing a parameter (on the order of 10's to 100's of nanoseconds on modern computers and JVM's. Optimizing in this area will only noticeably impact performance of such calls if it needs to get performed 100's of thousands or millions of times per second. That generally excludes everything any of us is likely to write.
Chuck

Similar Messages

  • Passing information to a method

    Im going through the java tutorial about passing information to a method
    and i am presented with this code.
    class RGBColor {
        public int red, green, blue;
    class Pen {
        int redValue, greenValue, blueValue;
        void getRGBColor(RGBColor aColor) {// is aColor a reference for RGBColor ?
            aColor.red = redValue; //is aColor then used to access the variables of RGBColor ?
            aColor.green = greenValue;// Are these values being initialised here
            aColor.blue = blueValue;
    RGBColor penColor = new RGBColor();// we are creating an instance of RGBColor called penColor
    pen.getRGBColor(penColor);// this is the bit i dont understand where the heck did pen.getRGBColor come from, i cant see anywhere where pen has been declared ..... or instantiated
    System.out.println("red = " + penColor.red +
                       ", green = " + penColor.green +
                       ", blue = " + penColor.blue);The follwoing is what it says in the java tutorial about the code
    The modifications made to the RGBColor object within the getRGBColor method affect the object created in the calling sequence because the names penColor (in the calling sequence) and aColor (in the getRGBColor method) refer to the same object.
    any guidance would be great

    Directly above the code that you don't understand is
    o A definition for a class Pen.
    o something called "pen" is probably declared somewhere like this:
    Pen pen;
    or
    Pen pen = new Pen(....);
    or
    Pen pen = something.getPen();
    So pen is an instance of Pen, and you can invoke the methods defined in class Pen, thus
    pen.getRGBColor(....);

  • Problem passing Session variable as URL parameter?

    Hi,
    I am trying to create a multiple page entry form using
    coldfusion session. But I am having some problem when passing the
    session variable to url parameter. For test purpose I have created
    the following code:
    <cfif Not IsDefined("SESSION.AE")>
    <!--- If structure undefined, create/initialize it
    --->
    <cfset SESSION.AE = StructNew()>
    <!--- Represent current form srep; start at one --->
    <cfset SESSION.AE.StepNum = 1>
    </cfif>
    <cfif IsDefined("Form.GoBack")>
    <cfset SESSION.AE.StepNum = #url.StepNum# - 1>
    <cfelseif IsDefined("Form.Next")>
    <cfset SESSION.AE.StepNum = #url.StepNum# + 1>
    </cfif>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    </head>
    <body>
    <form method="post"
    action="/AE/try.cfm?StepNum=#SESSION.AE.StepNum#">
    <input type="submit" name="GoBack" value="Back">
    <input type="submit" name="Next" value="Next">
    </form>
    </body>
    </html>
    When run it I get the following error:
    The value "" cannot be converted to a number
    The error occurred in C:\CFusionMX\wwwroot\AE\try.cfm: line
    11
    9 : <cfset SESSION.AE.StepNum = #url.StepNum# - 1>
    10 : <cfelseif IsDefined("Form.Next")>
    11 : <cfset SESSION.AE.StepNum = #url.StepNum# + 1>
    12 : <!---<cfset SESSION.AE.StepNum = #url.StepNum# +
    1>--->
    13 : </cfif>
    I couldn't figure out where is the problem. Any help is
    really appreciated.
    Thanks in advance.

    You are mixing up your gets and posts aren't you?
    You have your form method set to post which creates form
    variables not
    url variables. So when you try to use the url variable to set
    your
    session it does not exist.
    Change your SESSION.AE.StepNum = #url.StepNum# to
    Session.AE.StepNum =
    form.StepNum, note there is no need for the #'s.
    OR
    change your form method="post" to form method="get"
    Nagelia wrote:
    > Hi,
    >
    > I am trying to create a multiple page entry form using
    coldfusion session. But
    > I am having some problem when passing the session
    counter to url parameter. For
    > test purpose I have created the following code:
    >
    > <cfif Not IsDefined("SESSION.AE")>
    > <!--- If structure undefined, create/initialize it
    --->
    > <cfset SESSION.AE = StructNew()>
    > <!--- Represent current form srep; start at one
    --->
    > <cfset SESSION.AE.StepNum = 1>
    > </cfif>
    > <cfif IsDefined("Form.GoBack")>
    > <cfset SESSION.AE.StepNum = #url.StepNum# - 1>
    > <cfelseif IsDefined("Form.Next")>
    > <cfset SESSION.AE.StepNum = #url.StepNum# + 1>
    > </cfif>
    >
    > <html>
    > <head>
    > <title>Untitled Document</title>
    > <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    > </head>
    > <body>
    > <form method="post"
    action="/AE/try.cfm?StepNum=#SESSION.AE.StepNum#">
    > <input type="submit" name="GoBack" value="Back">
    > <input type="submit" name="Next" value="Next">
    > </form>
    > </body>
    > </html>
    >
    > When run it I get the following error:
    >
    > The value "" cannot be converted to a number
    >
    >
    > The error occurred in C:\CFusionMX\wwwroot\AE\try.cfm:
    line 11
    >
    > 9 : <cfset SESSION.AE.StepNum = #url.StepNum# - 1>
    > 10 : <cfelseif IsDefined("Form.Next")>
    > 11 : <cfset SESSION.AE.StepNum = #url.StepNum# +
    1>
    > 12 : <!---<cfset SESSION.AE.StepNum =
    #url.StepNum# + 1>--->
    > 13 : </cfif>
    >
    > I couldn't figure out where is the problem. Any help is
    really appreciated.
    >
    > Thanks in advance.
    >
    >
    >
    >

  • Class/member variables usage in servlets and/or helper classes

    I just started on a new dev team and I saw in some of their code where the HttpSession is stored as a class/member variable of a servlet helper class, and I was not sure if this was ok to do or not? Will there be problems when multiple users are accessing the same code?
    To give some more detail, we are using WebLogic and using their Controller (.jpf) files as our servlet/action. Several helper files were created for the Controller file. In the Controller, the helper file (MyHelper.java) is instantiated, and then has a method invoked on it. One of the parameters to the method of the helper class is the HttpServletRequest object. In the method of the helper file, the very first line gets the session from the request object and assigns it to a class variable. Is this ok? If so, would it be better to pass in the instance of the HttpServletRequest object as a parameter to the constructor, which would set the class variable, or does it even matter? The class variable holding the session is used in several other methods, which are all invoked from the method that was invoked from the Controller.
    In the Controller file:
    MyHelper help = new MyHelper();
    help.doIt(request);MyHelper.java
    public class MyHelper {
        private HttpSession session;
        public void doIt(HttpServletRequest request) {
            session = request.getSession();
            String temp = test();
        private String test() {
            String s = session.getAttribute("test");
            return s; 
    }In the past when I have coded servlets, I just passed the request and/or session around to the other methods or classes that may have needed it. However, maybe I did not need to do that. I want to know if what is being done above will have any issues with the data getting "crossed" between users or anything of that sort.
    If anyone has any thoughts/comments/ideas about this I would greatly appreciate it.

    No thoughts from anyone?

  • How to figure out class of method parameter given a VariableElement?

    Background:
    I have a class that extends AbstractElementVisitor6<String, VisitorContext>
    In visitExecutable() I do something like this...
    try {
        // processingMethod is a member variable of the visitor
        processingMethod = true; 
        MyAnnotation foo = e.getAnnotation(MyAnnotation.class);
        if (foo != null) {
            List<? extends VariableElement> parameters = e.getParameters();
            for (Element enclosee : parameters) {
                enclosee.accept(this, context);
            // do other stuff
            return null;
        return null;
    } finally {
        processingMethod = false;
    }I then end up in visitVariable(VariableElement ve, P). Which is good.
    However, I have been running in circles for at least a day now in the javadoc, trying to figure out how to get from a VariableElement to knowing what the class of the parameter is. I have figured out a way (correct or not) of knowing if it's a primitive type...
    ve.asType() instanceof PrimitiveType But I'm stuck on figuring out what the class of the thing is. The closest thing I can see is if I can somehow turn the VariableElement into a TypeElement, I can use getQualifiedName(), but I'm haven't found that, and I'm not sure if that's the right answer either.
    Here's the pseudocode of visitVariable...
    public String visitVariable(VariableElement e, VisitorContext context) {
        if(processingMethod) {
            // if it's a primitive type - OK
            //  do the right thing
            // else
            //   figure out what the class of e is   HELP!
            //   do the right thing  
            return null;
    }In summary...
    How do I get the class of a method parameter from a VariableElement?
    Thanks

    When would this not be possible? Intersections types. See [JLS 3rd 4.9|http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.9] Specifically
    "It is not possible to write an intersection type directly as part of a program; no syntax supports this."
    Also, I'm curious about the string representation in the first place. I assume there's not direct handout of class objects because we're in the compiler and can't assume that a type is a valid "thing" yet? e.g. it may not have been compiled yetCorrect.
    I was just thinking about how to represent the information, when it occurred to me that I probably ought to just reuse type mirrors and/or elements. Would you recommend this strategy? This is an interesting area of writing annotation processors. In order to apply any (what we call) extra-lingustic constraints and generate error messages when someone breaks the rules, you normally need the elements and types in order to make assertions about types being correct etc. I normally do this in the data collection phase, and don't collect any data for uses that are erroneous. I haven't tried doing the error checking after the collection phase.
    When you are generating the source code, (after all the data is collected) all you need is CharSequences (normally Strings). In fact extracting those from elements and types at the point that is writing the source file can make the code more complex than it needs to be, so I prefer to just have everything in Strings at this point. It makes the code that is generating code a little easier to understand. I often build an inner class to hold all the strings (in fields or in collections as appropriate) which I have collected from each annotated element, so there is some structure there.
    Are there any examples or other advice out there for doing this that you can point to?There are a few examples. Check out the [hickory project on java.net|https://hickory.dev.java.net/] You might find some useful tools there to assist writing your processor (such as prisms ) and [writing you unit tests|https://hickory.dev.java.net/nonav/apidocs/index.html?net/java/dev/hickory/testing/Compilation.html] . Hickory's unit tests include several examples of annotation processors, [this one|https://hickory.dev.java.net/source/browse/hickory/trunk/code/test/net/java/dev/hickory/incremental/ServiceProviderProcessor.java?rev=22&view=markup] illustrates the points I am making, and there are also some in code samples in the javadoc, for example [the same thing again |https://hickory.dev.java.net/nonav/apidocs/index.html?net/java/dev/hickory/incremental/StateSaver.html].
    Bruce

  • How can I pass information from one portlet to another?

    First, some background...
    I am using Portal 5.0.2 and developing portlets using JSP/Java on a remote server.
    I need to pass information from a portlet on pageA to another portlet on pageB, but I can't do it using the traditional methods, such as query string, session, cookies, etc. due to either portal framework limitations or because of functional constraints (basically, a user will not necessarily be logged in to the portal, but he can view anything available to the GUEST user). Here are the different ways I've considered using to save state and their limitations:
    Query string: can't use this because portlets on remote servers don't have access to it
    Cookies: if user disables cookies, code will not function properly
    Session variables: limited to one user's connection with one portlet (i.e., can't access a session variable set in portletA from portletB)
    Application variables: because the user may not be logged in, I have no way of uniquely naming variables, which is a necessity in order to maintain state for EACH user
    User Settings: again, the user may not be logged in, so I can't use these
    PCC: can't access client-side variables because server-side JSP executes first
    Are my assumptions above correct? Has anyone had any success using one of these methods given the same constraints, or does anyone have an alternative solution? I'd certainly appreciate any help anyone could provide.
    Thanks,
    Jose

    One possibility would be to use a Login PEI to set a unique UserInfo Name/Value for the user. I think in 5.0 each guest session is unique, so would have unique UserInfo. Then you could pass this value to your portlet (by specifying it in the web service) and use it as a key into a Application-scoped hashmap where you store your info. In other words, your Application variables option, but you have a way of uniquely naming your variables via PEI-set UserInfo.

  • Pass information between dom0 & domU thanks to web service API

    I have to build automation API in Java programming language for application deployment on virtualized infrastructures. Is there any way to pass information to application running inside the deployed virtual machine and to notify the host about some application's states? Everything using only the Webservice API...
    The principal examples I can give:
    For VMware (Virtual Infrastructure compliant products) & Virtualbox infrastructures, WS API give use the capability to set variables to retrieve them thanks to the guest tools ( vmware-guestd & VBoxControl )...
    For XenServer and Hyper-V, the only way we found to get that done is to directly write the variables in a part of the virtual machine configuration. Then, from the virtual machine, we need to connect to the XenServer/Hyper-V, identify the virtual machine which is currently running our application, and use it to retrieve the application configuration... The problem with the later is that we have to "hard write" the authentication information in the virtual machine, and to find a way to determine in which virtual machine the application is running ( this is done so far using NIC Mac address ).
    Because of the "light" documentation, i don't know if such a thing is possible for OVM manager...

    My mistake...
    on [http://download.oracle.com/docs/cd/E11081_01/doc/web.21/e14979/toc.htm|http://download.oracle.com/docs/cd/E11081_01/doc/web.21/e14979/toc.htm] , the method
    void      createPropertiesFileOnVirtualMachine(java.util.Properties props, VirtualMachine vm, java.lang.String propFileName)seems to do what I need...
    Now, because my test environment only allow PV Guests, I'd like to know if that also work for HW Guests?

  • How to assign my custom VBA variable to a parameter

    I want to be able to assign the value from my custom variable to a parameter from a script;
    but I cannot figure out if it is possible;
    I want to be able to manipulate a string using my VBA code, save this string to a variable, and pass it back to a one of the parameters on a page in a scripts, and continue playing the script with this new value instead, without using Data Bank;
    Thank you for help.

    Here is an example that sets a parameter named "UserName."
    Private Sub RSWVBAPage_beforePlay()
    Dim col As New Collection
    col.Add "MyName"
    RSWApp.SetParameterValues "UserName", col
    End Sub
    As you can see, this code is in the before play event. You must put this in before play in the page where the parameter exists. You can also use wild cards when identifying the parameter to be set.
    For example, if you needed to look for UserName_784328732 (with a changing number value)
    You could do the following RSWApp.SetParameterValues "UserName*", col
    I hope this is helpful

  • Variable Substitution Method

    Hi,
    When Im going through the variable substitution method with respect to the target directory:
    with the help of the blog
    An interesting usage of Variable Substitution in XI
    I dint understand what is the SID here. SID of different systems like DEV system, PRD system and etc. What exactly is an SID?
    If we take SID as a variable in the variable substitution method, then the value to VAR will be getting from the header i.e, Receiver_Service.
    From where does the Receiver_Service gets the SID? whenever the system is changed from DEV to PRD or to someother.
    Kindly let me know if i can get any such other blogs on this scenario.
    Thanks in Advance,
    Divya

    Hi ,
    As said above Message header contains the following informations
    sender_party
    sender_service
    receiver_party
    receiver_service
    interface_name
    interface_namespace
    message_id
    message_id_hex
    SID stands for System ID and is a three character unique name for a SAP system. It will be different for different systems like for Dev system it may be XXX and for quality system say YYY and similarly for production system say ZZZ. Message header values are accessed dynamically.
    Thanks!

  • GetVariable() doesn't work in FireFox for object member variables

    I'm trying to access Flash member variables from Javascript
    using GetVariable. The following line of code works for IE but not
    for Firefox:
    var variable = swf.GetVariable("someObject.someProperty");
    In IE, the GetVariable() function returns the correct value
    for the property. However in Firefox, the GetVariable() function
    returns "null" when trying to access the property. If I just try to
    access the object in Firefox (i.e. swf.GetVariable("someObject"), I
    get a string back (instead of the object that I am expecting). If I
    try to access a variable (such as a string) and not an object using
    GetVariable(), this works in both Firefox and IE.
    Any ideas what I am doing wrong? I suspect that my syntax for
    accessing object member variables in Firefox is incorrect but I
    have not been able to find any documentation on the correct syntax.
    Any assistance would be greatly appreciated.
    Thanks.

    Thanks, but this isn't an issue.
    The window.document.flashMovie will return the correct flash
    object/embed flash movie.
    The issue is that the GetVariable method wont return the
    object variable. When you try to get an simple variable that is in
    the _root timeline, it will return the value. Example:
    movie.GetVariable(_url) will return the url of the flash
    movie without any problem.
    But when you create an ActionScript class with
    userName property and then you will create the instance of
    it in the _root, you should be able to get it's value. Example:
    Flash:
    var obj = new SomeClass();
    obj.userName = "peter";
    JavaScript:
    movie.GetVariable("/obj:userName");
    or
    movie.GetVariable("obj.userName");
    This will return
    Peter for IE and null for Forefox/Opera.
    The same when you use the document.embeds[..].

  • How is the Method Parameter Identified in this Code Snippet ?

    package methods;
    public class Me10 {
         public static void main(String[] args) {
              short y=6;
              long z=7;
              go(y);
              go(z);
         public static void go(Short s)
              System.out.println("SHORT");
         public static void go(Long l)
              System.out.println("LONG");
         public static void go(int i)
              System.out.println("INT");
    O/P :
    INT
    LONGEven when y is declared as short why does the INT method get called ?
    What can we do so that when i pass y , short method will be called ?
    Thabks in Advance.

    as far as I understand, method parameters are identified per JLS section 15.12.2 'Determine Method Signature':
    "...This step uses the name of the method and the types of the argument expressions to locate methods that are both _accessible_ and applicable, that is, declarations that can be correctly invoked on the given arguments. There may be more than one such method, in which case the _most specific_ one is chosen. The descriptor (signature plus return type) of the most specific method is one used at run time to perform the method dispatch...
    ...The informal intuition is that one method is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error..." [...click here to continue reading if you're interested|http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.2|JLS 15.12.2 'Determine Method Signature']
    As for calling 'Short' method for 'y' value, I'd probably use something like go(new Short(y))

  • Passing information between class

    Greetings Fellow Developers,
    I have what I believe to be a simple question but my brain is only thinking in procedural at the moment so I'm in a bit of a fix.
    I'm working on a midlet and creating an message book application
    I must pass informatin class mesaj to JSMS
    public class mesaj extends DisplayTextBox{
          private static String mes="";   
        public mesaj() {
            super("mesaj&#305;n&#305;z",TextField.ANY);
       public  void setMesaj(){
            mes=getString();
        public static String getMesaj(){
            setMesaj();//there is problem with use static method
            return mes;
    public class JSMS extends MIDlet implements CommandListener{
       public void commandAction(Command c, Displayable d) {
             if(c==add){
                AddRecord(mesaj.getMesaj);
    }I have a problem using getMesaj method...
    can I passed information without non-static method
    thanx
    muratti32

    Hi,
    I think that your set and get methods are a bit wrong. Maybe they should be like this
    public void setMesaj(String m)
      mes = m;
    public static String getMesaj()
      return mes;
    }if you don't want to make static methods, you'll have to make an instance of the class, which methods you want to call.
    public class JSMS extends MIDlet implements CommandListener{
    private mesaj m = new mesaj();
       public void commandAction(Command c, Displayable d) {
             if(c==add){
                AddRecord(m.getMesaj);
    }kari-matti

  • Field-Symbols as Method Parameter

    Hi all,
    is there a way to create a field symbol within a method and export this field-symbol directly as a method parameter?
    The problem is that we can't pass a field symbol as method parameter unless it's assigned, but we would like to assign the field symbol within a method and give the result back to the calling program.
    We have managed to create a field symbol within the method and give back the result as a reference (we used the type ANY).
    We would like to pass the result field-symbol directly as a Method parameter.
    Any ideas?
    Best regards Dominik

    Hi all,
    thanks for you help. I managed to do the method calls with reference parameters but I'd like to do it with fieldsymbols instead.
    Your suggentions for field-symbold worked, but I could use them only with primitive datatypes.
    In my requirements the table must be created within the method, so the caller doesn't know the tablestructure.
    If a dummy table is assigned to the field-symbol before the call, the error "Two internal tables are neither compatible nor convertible" is produced.
    Is there a solution?
    Thanks in advance
    Dominik
    class ZZX0_CL_TEST definition
      public
      final
      create public .
    public section.
      class-methods FIELD_SYMBOLS_TAB_TEST
        changing
          !FS type ANY .
    METHOD FIELD_SYMBOLS_TAB_TEST .
      DATA: it_t000 TYPE TABLE OF t000.
      FIELD-SYMBOLS <field_symbol> TYPE ANY TABLE.
      ASSIGN it_t000 TO <field_symbol>.
      fs = <field_symbol>.
      EXIT.
    ENDMETHOD.
    REPORT zzx0_mini.
    DATA: it_mara  TYPE TABLE OF mara.
    START-OF-SELECTION.
    * Tabellen test
      FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.
      ASSIGN it_mara TO <fs>.
    *  ASSIGN it_t000 TO <fs>.
      CALL METHOD zzx0_cl_test=>field_symbols_tab_test
        CHANGING
          fs = <fs>.
      EXIT.

  • How to activate and passivate member variables?

    Hi
    ViewObjects have methods like
    public void passivateState(ViewRowImpl currentRow, Document doc, Element parent)andpublic void activateState(ViewRowImpl currentRow, Element elem)However, I can't find any example how to use them. Can anyone show me a code example how to use this methods? Can anyone point me to some documentation on this?
    Thank
    Frank Brandstetter

    Sorry, I should have mentioned, that I want to use this methods to passivate some member variables stored in my View. BC4J JavaDoc says, that I must override this methods to do this. But how?
    Thanks

  • Generate accessors does not pick up all member variables

    jdev 9052
    i have a class containing the following member variables:
    private String PrincipalName = null;
    private String DisplayName = null;
    private String Surname = null;
    private String FullName = null;
    private String Identifier = null;
    private String Givenname = null;
    private String Email = null;
    private String RemoteAddress = null;
    private String LoggedIn = null;
    i right click in the editor and select generate accessors. The dialog pops up, but only has DisplayName, GivenName, LoggedIn and RemoteAddress. once i generate the accessors for these, it then says 'There are no methods to generate'
    am i missing something here? why doesn't it recognise ALL my member variables??

    If you have either Outlook 2007 or 2010 and are running Vista SP2 or higher, you can enter the events in Outlook.  But the have to be entered on the iCloud calendar in Outlook, not a calendar from another external service such as Goigle (Gmail).

Maybe you are looking for

  • Retrurns/replacements

    What line type should I use for a)Return with no credit, and b) for the corresponding replacement item(ship-only workflow)? Can I put these 2 lines in the same SO?

  • Adding shutterfly upload software changed the defaul mail program in iPhoto

    I recently added the shutterfly upload software for iPhoto and in the process, it changed my default email program in iPhoto from Mail to some new microsoft program. I went into preferences to change back, but now Mail is greyed out and not an option

  • Regarding exit from the module pool screen

    h experts, i have developed a module pool report in which in the selection screen i have four fields which are mandatory ,when i execute the program without entering in the selection screen it do not allow to come out of the module pool screen ...wha

  • Turn off Parallel Query for instance

    I have a new 10g RAC instance, on Windows 2003 64, which was just converted from 8i. It is currently a 1 node cluster. The database was built with parallelism turned on and now we are experiencing severe performance degradation. Quest spotlight keeps

  • Matrix Footer

    Hi to All, I had created a  user screen with matrix..The matrix contains the calculation part..All the values of the particular column should be added and it should be displayed in the footer area of the matrix..(For Ex) MainMenu --> Reports --> Quer