Variables? References? Confused.

I've looked through documents on the internet, but I still do not get the idea.
When you parse a variable through a method, is that variable exactly same as the one parsed from?
For example,
EX1)
we have a method like this following:
public void methodEx(String a) {
a = "good";
now I have lines of codes here below:
String c = "bad"
methodEx(c);
output(c);
will this output "bad" or "good"?
EX2)
now I have lines of codes here below:
String c = "bad", a = "good";
c = a;
a = "bad";
output(c);
will this output "bad" or "good"?
The reason I'm asking is I'm confused how this 'parameter' actually works.
I thought when you parse a variable into a method, a new variable is created, but I tried to parse a JButton object and noticed that I could still change its states such as setEnabled(boolean state);
I'm very confused on how initializing a variable in a normal behavior and through parameter differs.
How does these things work?

Hackelt wrote:
I've looked through documents on the internet, but I still do not get the idea.
When you parse a variable through a method, is that variable exactly same as the one parsed from?Huh?
(Oh, you mean pass a variable to a method.)
will this output "bad" or "good"?Run it and see.
The reason I'm asking is I'm confused how this 'parameter' actually works.
I thought when you parse a variable into a method, a new variable is created, but I tried to parse a JButton object and noticed that I could still change its states such as setEnabled(boolean state);A copy of the reference is passed. Both references point to the same object. If you change the value of one reference--i.e., set it to null, or to point to a different object--the other reference is not affected. If you change the state of the one object that both references point to, then both references will see that change.

Similar Messages

  • Help with where variable references point

    public class Test {
         public static void main(String[] args) {
              Integer four = new Integer(4);
              Integer five = new Integer(5);
              Integer hey = four;
              System.out.println(hey);              //output here is 4
              hey = five;
              System.out.println(hey);              //output here is 5
              five = null;
              System.out.println(five);              //output here is null
              System.out.println(hey);              //output here is 5***why not null??
              hey = null;
              System.out.println(hey);              //output here is null
    }When the variable hey points to five which has been set to null, why does printing out "hey" not show null, but rather 5?! Thanks.

    Oh, that makes sense.
    My confusion was that I thought the reference of
    "hey" would point to the reference of "five",
    rather than to the actual object.Variables don't "point" to references, they contain references.
    So iiuc, there is no such variable that ever points
    to a reference? Meaning, a 'string' will
    always be tied directly to the balloon, and
    never to another 'string' as I described above?No, a variable can contain a reference to an object that has a member that contains another reference. The simplest form of this structure is a variable that holds a reference to an array of objects. Those objects could be arrays of objects, etc.
    Also, does that mean the following two options are
    absolutely identical?
    - pointing a variable to an object Bla
    - pointing a variable to the variable that points to
    the same object BlaThe 2nd is impossible. Variables can't "point" to variables. They can only hold references to objects.

  • BeX variable exit confusion

    In my BW system, someone has created a query. There is a variable in this query.
    The value for this variable is filled by an exit but the description of the variable is filled at run time by what it is unclear.
    The description for the current month is displayed as 'MAY 2008' and for june it will be 'JUNE 2008'. Wanted to know where this logic is built?
    Regards,
    Srinivas

    If you look at the text variable, the text variable would be created with a characteristic are reference. The value for the text variable comes from that characteristic - it's the value that the char holds.
    Click on the text variable selection screen. in the list of variables, choose ur variable and choose display - you can find the char that loads data into the variable. for a given query, the text variable will hold only one value and this value shows up in the report.
    Hope this answers you!
    ~ Arun Kk

  • Reference confusion....

    <sigh>......I thought I was being clever here, but apparently not. :)
    I had two methods that, apart from the List result variable and the String SQL were exactly the same, so I thought I'd write a general method (getResultList) that would do both in one, so to speak and just pass the result object references as parameters to the method. The method works, but the reference variables are still null when I try and use them.....specifically I get a NullPointerException.
    Here is the code.......my thinking must be faulty here, because the two Lists (listBasePatientDetails and listNormalPatientIDs) which hold the results are null when I try and use them after calling loadData().
    private OracleDataConnection theConnection;
    private List listNormalPatientIDs;
    private List listBasePatientDetails;
    private boolean loadData() {
            if (getNormalPatientIDs() == false || getBasePatientDetails() == false) {
                return false;
            } else {
                return true;
        private boolean getNormalPatientIDs() {
            String sqlString = "SELECT PATID_REFNO FROM PATIENT_IDS";
            if (!getResultList(sqlString, listNormalPatientIDs)) {
                ErrorList.addError(new ErrorItem(ErrorList.DATABASE_QUERY_FAILED, 0, "RPatientID::getNormalPatientIDs()", "Could not retrieve normal patient IDs. Database query failed"));
                return false;
            } else {
                return true;
        private boolean getBasePatientDetails() {
            String sqlString = "SELECT PATID_REFNO, PITYP_REFNO, PATNT_REFNO, IDENTIFIER FROM PATIENT_IDS";
            if (!getResultList(sqlString, listBasePatientDetails)) {
                ErrorList.addError(new ErrorItem(ErrorList.DATABASE_QUERY_FAILED, 0, "RPatientID::getBasePatientDetails()", "Could not retrieve base patient details. Database query failed"));
                return false;
            } else {
                return true;
        private boolean getResultList(String sSQL, List returnList) {
            List resultList;
            if (theConnection.hasConnection()) {
                resultList = (List)theConnection.executeSQL(sSQL);
                if (resultList == null) {
                    return false;
                } else {
                    returnList = resultList;
                    return true;
            } else {
                // Lost database connection.
                ErrorList.addError(new ErrorItem(ErrorList.DATABASE_CONNECTION_FAILED, 0, "RPatientID::getResultList", "Could not retrieve query data. Database connection lost."));
                return false;
        }So whats going wrong here? Is the result List reference used as a parameter going out of scope or something after returning from getResultList? I must have some gap in my thinking, because I thought references were pretty similar to pointers......ie. they just point to the objects rather than hold the objects themselves.
    Suggestions? Thanks all.

    public class ReturnTest {
      private static String s = "hio";
      public static boolean stuff(String str) {
        str = "YAHOOOOoooOOO";
        return false;
      public static void main(String[] args) {
        System.out.println(s);
        stuff(s);
        System.out.println(s);
    }Try compiling that. When you run it you will notice that s still prints out as "hio." This is basically what you are doing with your method.
    The parameter "str" (or returnList in your case) has a different address (pointer) than the original s. This is because Java makes copies of all the objects you pass to methods as paramters. To make your method work, you're either going to have to modify your two private lists directly or do something along the lines of this:
    public class ReturnTest {
      private static String s = "hio";
      public static boolean stuff(String str) {
        str = "YAHOOOOoooOOO";
        s = str;
        return false;
      public static void main(String[] args) {
        System.out.println(s);
        stuff(s);
        System.out.println(s);
    }Note how I put "s = str;" in the stuff() method. If you were to run this, you would see the output:
    hio
    YAHOOOOoooOOO
    Like I said, there's probably a better way to do this, but that's my solution to your predicament.

  • Generic / variable reference to json array field name

    hi -- I have a javascript function that I want to make variable-based, so it can be used throughout my application.
    It creates and parses a json object. I ultimately need to reference a field in that object. The field name is the name of database column
    that was queried in the called application process.
    For example, if the query executed was: select my_id from my_table where my_name = 'the_name', and the object that holds the parsed
    AJAX response is jsonobj, then I need to reference: jsonobj.row[0].my_id
    I don't want my_id to be hardcoded in the reference. Rather, I want to pass the string 'my_id' into the javascript function (let's call
    the variable dest_item_name) and then reference (something like): jsonobj.row[0].<dest_item_name>.
    (How) can I do this? Please tell me I can! :)
    Thanks,
    Carol

    Hmmm, well, I thought I described my goal in the first post... but I'll try again.
    hi -- I have a javascript function that I want to make variable-based, so it can be used throughout my application.
    The function does this:
    ajaxRequest = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=LOOKUP_VALUE',0);
    ajaxRequest.addParam('x01', source_item_value); -- equal to 'basin'; this is the value that will be used to lookup the value of dest_column_name
    ajaxRequest.addParam('x02', source_column_name); -- equal to 'my_name'; this is the name of the database table column that will be = 'basin'
    ajaxRequest.addParam('x03', dest_item_name); -- equal to P3_MY_ID; this is the name of the page item that will be set to the returned value
    ajaxRequest.addParam('x04', dest_column_name); -- equal to 'my_id'; this is the name of the table column that gets queried
    ajaxRequest.addParam('x05', lookup_table_name); -- my_data; this is the table to query
    ajaxResponse = ajaxRequest.get();
    if (ajaxResponse) {
    var jsonobj= ajaxResponse.parseJSON();
    $s(dest_item_name, jsonobj.row[0].my_id);
    The goal of this javascript and application procedure is to have a generic method for looking up values
    in the database. In the above example, I want to query my_data to get the value of my_id where my_name = 'basin'.
    The application procedure LOOKUP_VALUE uses the x variables to construct that SQL query. For the above values, the
    returned query is: select my_id from my_data where my_name = 'basin';
    Then I set my dest_item_name (P3_MY_ID) to the value in the parsed json object. But as you can see, if I'm querying a different
    table with different column names, the reference to jsonobj.row[0].my_id won't work, because the database column name
    will be different. I've gotten around this by aliasing the queried field to RETURN_VALUE, so I'm just doing:
    $s(dest_item_name, jsonobj.row[0].rerturn_value); -- which works great.
    But my goal was to somehow be able to reference the variable dest_item_name (which is the name of the queried database
    column) in my $s set statement.
    Possible? If so, I'm sure it could come in handy at some point.
    Thanks,
    Carol

  • Variable Reference of Instance Name

    While I have had no problems with bracket evaluation of
    constants and number variables, I don't know the coding convention
    for brack evaluation of a string.
    I get an undefined for oBtnName
    oBtnName = new Object;
    oBtnName = this["mcWing" + aWingColor[nIdx] + "Btn"];
    where aWingColor is an array of strings. So I tried setting
    aWingColor[nIdx] to variable thinking the inside array brackets
    were goofing this up:
    oBtnName = new Object;
    var sWingColor:String = aWingColor[nIdx];
    oBtnName = this["mcWing" + sWingColor + "Btn"];
    trace (sWingColor + " " + oBtnName._name );
    returns Pink undefined
    and interactive debug is showing oBtnName as undefined as
    well.
    So, then I tried this
    oBtnName = this["mcWing" + sWingColor._value + "Btn"];
    and then this
    oBtnName = this["mcWing" + "[sWingColor]" + "Btn"];
    and so on and so on. . . .

    Isn't
    this["mcWing" + aWingColor[nIdx] + "Btn"]=new Object()
    the same as
    var oBtnName:Object = new Object;
    oBtnName = this["mcWing" + aWingColor[nWingRollIdx] + "Btn"];
    I am doing this to shorten the reference name
    Here is the rest of the code
    mcWingPinkBtn.onRollOut = function () {
    clearInterval(nInterval);
    nWingRollIdx = 1;
    nInterval = setInterval(fFadeOutWing, 1);
    function fFadeOutWing():Void {
    var oBtnName:Object = new Object;
    oBtnName = this["mcWing" + aWingColor[nWingRollIdx] +
    "Btn"];
    oBtnName._alpha -= nAlphaIncrement;
    ----oBtnName is undefined here so the following if doesn't
    work -----
    if(oBtnName._alpha <= nAlphaStart) {
    oBtnName._alpha = nAlphaStart;
    clearInterval(nInterval);
    updateAfterEvent();

  • BW Master Data for Customer Exit Variable Reference

    Good day Experts,
    I have several queries that I would like to remove the hard coding of values on to prevent yearly maintenance. In these queries there are two conditions each condition is on different key figures that is amount by year.  The query is only to report on data that for the two amounts (separated by year) is greater than the specified values. I want to change the condition so the value is no longer hard coded so the query will role automatically as the time period changes. The year amount values that the condition will need to reference are not currently stored in our BW system. I would like to create master data that is maintained directly in the BW system for the amounts that a variable for the condition in the query can then access.
    I know it can be set up as master data and then referenced through a customer exit variable but when I set up the master data if I do the Amount as a key figure I cannot maintain the key figure value for the master data manually in BW, if I set the Amount up as a numeric characteristic then I canu2019t directly use a decimal. Am I missing something in the key figure setup then referencing the key figure as an attribute of the year value or do I need to do it as a characteristic and use a conversion routine or something for data manipulation?
    Can someone please give me some guidance to what the best way to do this is?
    The data necessary master data for storage in BW is the YEAR and a single dollar value:
    For Example:     
    Year          Amount
    2009           101.50
    2008          207.80
    2007          807.40

    I figured out that I can use an amount in the master data and maintain the amount manually as long as I use the amount with a currency instead of setting the currency in the key figure.

  • Changing shared variable reference modes for all nodes in applicatio​n. Shortcut?

    I have a large application which makes extensive use of both network-published and single-process shared variables.  I want to change the reference mode of every such node in the application from absolute to target-relative.  Is there any way to do this without having to open every subVI in the application and use the right-click menu on every node?
    Sean

    I don't know of any shortcut, but if you want to change the reference node of everything in the application you could probably script it.  I was thinking something similar to what I have below where you traverse the BD of a specific VI for all SharedVariableNodes and change the relative mode to Target Relative.
    Depending on how your project is organized you can add some additional functionality before the open VI reference to go through and open the reference of every VI in your project.
    Matt J
    Professional Googler and Kudo Addict
    National Instruments

  • Variable declaration confusion

    What is difference with the following declaration?
    String x;
    String x = new String();The first creates a variable of type String, while the second creates an instance of the String class. Does it mean that the first x do not inherit all the goodies from String as the second x does?

    veryConfused wrote:
    Both x variables are references to String, so both have the same String members available. For the first one, you won't be able to use any of those members until the compiler is certain you've done x = to assign it a value.So if I just do
    String x = "";would that be the same as x = new String(). Because I have done that before and the compiler seems fine with it. Does that mean the compiler takes,
    String x = "";
    //and treat it as a
    x = new String();
    The effect will be almost the same. Basically Strings are tricky in one way: The compiler supports String literals. Those are String objects that are directly represented in code: "foo" would be such a literal, as would "".
    Every String literal the compiler sees will be put into a constant pool and whenever it is found in a class it will be represented by that single instance from the constant pool, so strictly speaking it does not create a new String object when you use the first line.
    The tricky bit is that String and Class are the only Classes that support literals (i.e. whose objects can be directly represented in source code) and when you use the literals it behaves slightly different than if you used new to create a new object.

  • Empty Dropdown after adding variable reference to

    Hi ,
    I am facing a problem while trying to convert the currency from the report result.After right click and select Gloal currency translation ,it is giving me an empty dropdown menu.
    If I give a fixed date in the currency translation type in T- code RSCUR ,it works fine ,I get all the translation type I created in the dropdown menu.When I give a variable for time reference
    dropdown menu is empty.have anyone faced this earlier?
    we are on BI platform
    Thx
    sheeba

    Hi,
    First step is the check the data insde P table ( example /BIC/PXXX which will be there in the in master data and text tab)
    if you find the data for newely added attributes then it works fine.
    or else
    Delete the master data
    programs for individual IinfoObject  master data deletion:
    RSDMD_DEL_BACKGROUND or RSDMD_DEL_MASTER_DATA_TEXTS
    then delete the transformation and recreate the transformation followed by DTP once again
    activate all atributes individually once again
    load data to the infoobject and check it.
    you should be able to relove the problem
    santosh

  • Timer & Variable Reference

    Hi.
    I am trying to create a clock on my GUI application but am getting a
    NullPointerException error whenever the app runs. This is the code:
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new frmMain().setVisible(true);
    java.util.Timer t = new java.util.Timer();
    t.scheduleAtFixedRate(new java.util.TimerTask() {
    public void run() {
    jLabel1.setText("Test");
    }, 0, 500);
    This is just a test that was generated using NetBeans and the jLabel has been added through the NetBeans GUI. It is in the variables declaration as
    "private static javax.swing.JLabel jLabel1;"
    Any ideas what I'm doing wrong? I assume I'm referencing jLabel1
    incorrectly somehow...
    BTW, before someone asks I'm not using the Swing Timer as I want the timer to consistenly fire at 500 ms and not 500ms + previous overhead.

    Sorry I'm a bit new to Java -- what is NPE? Also, my apologies for not posting in the proper format; I'll remember that for the future as there doesn't seem to be a way to edit the post now.
    Regarding initializing the reference to the jLabel -- doesn't the variable declaration, "private static javax.swing.JLabel jLabel1;" do that?
    Thanks.

  • Use Exit Variable - Reference Data?!?

    I am deriving currency from cost center using user exit.  My function module runs fine on the test cases.  Now, I am using the variable in a template.  It's a simple template with cost center in the header data, GL account in the lead column and amount key figure in the data column.  I am using the variable under the data column along with the key figure.  When the user opens the template, he needs to enter a cost center.  As soon as the cost center is entered, there is an error thrown with the message "Values do not agree with the reference data - Message:UPC523".  I do not know how to resolve this error message.  Could someone please post their inputs?  As always, I will reward helpful contributions.  Thanks.

    Hi Sameer,
    The message means that the value of cost center does not match with the reference master data available in the system.
    When the user enters the cost center value, the application would validate the same with the available values for that particular Infoobject, if the user is not allowed to enter "user defined values". If these values do not match with the master data values it will give you this message.
    You may not get this messages if the user has the option to enter "user defined values".
    To resolve the error Check the master data for cost center, activate master data.
    Hope it helps.
    Anurag

  • Linq Queries : Translate Local variable references

    Hello !
    I'm using the information from this MSDN Blog :
    http://blogs.msdn.com/b/mattwar/archive/2007/08/01/linq-building-an-iqueryable-provider-part-iii.aspx
    everything works very well except the case when I have a DateTime variable inside the query that I have to translate .
    This is my case :
    On my database I have the table orders where dt column have Date Type and store only the date.
    Now if I have this query :
    DateTime dt1 = Convert.ToDateTime("01/01/2012");
    var query = db.Orders.Where(c => c.dt == dt1);
    If I try to translate , the returned expression is :
    SELECT * FROM (SELECT * FROM Orders) AS T WHERE (dt = '01/01/2012 12:00:00 AM')
    As you can see the translated query contains the time at the end , and my query everytime return no records.
    What can I do that in translated query the value to be only the date without the time.?
    I try many variants , I format the variable only to date format , but it's the same thing.
    Thank you !

    the simpliest solution would be to use the Date-Portion of your DateTime-Object
    another Solution would be the ToString method like
    c.dt.ToString("MM.dd.YYYY") == dt1.ToString("MM.dd.YYYY")
    it may not be exactly like this... but you'll find the right toString method yourself. There is even a toString-Method wich you can pass a CultureInfo-object, but i found the best way for coparing Dates is to provide a const format-string that is used to
    compare DateTime-Types.
    To put in some extra suggar, you could try to override the DateTime-Equal-Operator-Implementation.

  • Variable references to objects

    OK, I've got a 15x3 grid of dynamic text fields in an object called "textbox" that I want to reference through a for loop, so I don't have to have 45 lines of code for assigning stuff to those fields.
    I have each dynamic field named by their placement in the grid, so, c0a, c0b, c0c, c1a, c1b, c1c, etc.
    I can also name them c00, c01, c02, if necessary.
    I tried:
    for (i=0; i<15; i++) {
       textbox.c[i]a.text = "Cell " + i + " A";
       textbox.c[i]b.text = "Cell " + i + " B";
       textbox.c[i]c.text = "Cell " + i + " C";
    but that gives me a syntax error.
    I also tried naming them c00, c01, c02, c10, c11, c12, etc., so I could do a double nested loop:
    for (i=0; i<15; i++) {
         for (n=0; n<3; n++) {
              textbox.c[i][n].text = "Cell " + i + n;
    but that gives me a syntax error too.
    So, is there a way to access all of these with a for loop, or am I going to have to do it the long way?
    (I'm using AS2)

    You are close but not quite as far as using the bracket notations with strings to target objects.  You need to build the entire string inside the brackets...
    for (i=0; i<15; i++) {
       textbox["c"+i+"a"].text = "Cell " + i + " A";
       textbox["c"+i+"b"].text = "Cell " + i + " B";
       textbox["c"+i+"c"].text = "Cell " + i + " C";
    And you could use String(i) in place of just i in the brackets to be more correct, but in AS2 it is less picky that way.

  • Session variable reference in report title.

    Can someone suggest me a answer for my problem?
    I want to display the report title by with the logged in username. So, I've created a report and in the 'Edit View' of 'Title'view of that report, i just placed '@{NQ_SESSION.user}' in the Sub title section. But instead of displaying user name in the report subtitle, i have it displayed '@{NQ_SESSION.user}'. Can someone tell me where am doing wrong?

    I Apologize stijn. I should have done that!! Will do it from next time.
    The thread you referenced have 2 ways:
    1.@{biServer.variables}
    2.@{session.serverVariables}
    I have tried with both like @{biserver.user} and @{session.user} placing them inthe report title view. These 2 doesnt work and giving me the same old result- displaying the same code!! :(
    Am i doing any wrong here in referencing the variables??
    Daan,
    I followed the John's like and it was not helpful either!! :(
    Actually, John was referencing it through column and later hiding that column. Am not sure which column to select here. So, i took one column and applied the formula and hide that column. But, its throwing error saying that the valueof{session.user} doesnt exist!!
    Since am new to this technology, can you guys guide me?

  • "this" reference confusion

    Hi
    It is a basic doubt about the this.
    As I run the test program here I expect the out put to be :
    mainTESTMISC
    SUPERMISC
    TestMisc@19821f
    TESTMISC
    class SuperMisc {
         public String     SRC     = "SUPERMISC";
         public void log() {
              System.out.println(SRC);
              System.out.println(this);
              System.out.println(this.SRC);
    public class TestMisc extends SuperMisc {
         public String     SRC     = "TESTMISC";
         public static void main(String... args) {
              TestMisc t = new TestMisc();
              System.out.println("main" + t.SRC);
              t.log();
    but the output actually is
    mainTESTMISC
    SUPERMISC
    TestMisc@19821f
    SUPERMISC
    Not that there is something wrong happening here but only that I am not able to understand that why the this.SRC is still getting the value of SRC in the super class. while "this" is the TestMisc object and TestMisc has a variable SRC in it.
    Please help in making me understand the reason for this behavior.
    Sapan

    sapan wrote:
    Hi EJP,
    I do not want to get the output as I expect, But my question is about the reason why this is happening.
    I just want to understand what I am missing in the behavior of the "this".
    Sapan'this' always refer to the class variable (present class), and the reason the output is coming like you mentioned is because: you calling the super class method and in super class method the visible variable "SRC' value is SUPERMIC. And the super class method can never look /use the derived class variable.
    Edited by: 833545 on Jul 26, 2012 6:09 PM

Maybe you are looking for

  • Unhandled exception occurred during the execution of the workflow instance

    I had a workflow and library working with no issues, but had to move the library and export the workflow to another subsite (though on the same web site/collection).  I followed these how-tos: http://msdn.microsoft.com/en-us/library/office/jj819316%2

  • Re: How to connect Equium A200 to TV

    How do you connect to TV with Equium A200 series?

  • Managing/viewing Premiere Pro reviews

    I have a couple questions regarding managing and viewing reviews that are uploaded from Premiere Pro CS5: Is the only means of navigating through the "parts" of a particular review the up and down arrows and the "# of #" box in the upper left corner

  • Error 1004 on my MacBook Pro - HELP!

    Hello I keep getting Error 1004 whenever i try to upgrade to Mountian Lion or download any other apps. I have tried googling this subject too death and nothing! any help would be greatly appreciated. warm regards

  • Need Info about Information Templates(iProcurement)

    Hi OAf & iProcurement Guys, I implemented Information Templates(3 Templates) to suit our oraganization. Can we restrict these templates only for particular users ? If so let me know. Thanks in Advance Thanks & Regards Palakondaiah.U