Java variables can they reference storage alocated in stack or heap

1- In Java can a variable of class type reference storage allocated on the call stack?
2- In Java can a variable of class type reference storage allocated on the call heap?

1- In Java can a variable of class type reference storage allocated on the call stack?
2- In Java can a variable of class type reference storage allocated on the call heap?

Similar Messages

  • Concat java variable to a MySql select statement and exeucte

    Hi,
    I am trying to append a variable to a MySql select statement.
    Overview: I need to retrieve data from a MySql database with a java variable as a reference and select the data in the database based on that variable.
    CODE THAT I CURRENTLY HAVE:
    // Declare variables
    Connection conn = null;
    Statement st = null;
    Resultset rs2 = null;
    String st2 = null;
    String keyid = null;
    // Connect to database
    try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
          st = conn.createStatement();
          // Select data in Database with hanging equal sign
          st2 = ("SELECT * FROM table WHERE keyid= ");
          // Append keyid to hanging equal sign of select statement
          rs2 = st.executeQuery(st2 + keyid);
    }This is not working when I try to display the data.

    What is not working about it? Is there an error message? Stack Trace?
    Where do you get the value of keyId from?
    I would suggest that you use a prepared statement rather than building up a sql string like this. It prevents sql injection attacks
    // Declare variables
    Connection conn = null;
    PreparedStatement stmt = null;
    Resultset rs2 = null;
    String sql= null;
    String keyid = null;
    // Connect to database
    try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
          // Select data in Database with place holder for parameter
          sql = "SELECT * FROM table WHERE keyid= ?";
           // prepare the statement
          stmt = conn.prepareStatement(sql);
          // set the value of key id to use with the query
          stmt.setString(1, keyId);
          // run the query
          rs2 = st.executeQuery();
    catch (Exception e){
      System.out.println("An error occurred " + e.getMessage());
      e.printStackTrace();
    finally{
      if (rs2 != null) try { rs2.close(); } catch(SQLException ex){}
      if (stmt != null) try { stmt.close(); } catch(SQLException ex){}
      if (conn != null) try { con.close(); } catch(SQLException ex){}
    }

  • How can I reference a winforms control using a variable in Powershell?

    I have a powershell winform that has a lot of text boxes, but for the sake of this post, lets say I have 5. I want to loop through the 5 text boxes to see if their text property is empty. If the textbox contains something, I want to add the text value to
    an array. Here's an example of what I'm trying to do.
    textbox1.text = "Red"
    textbox2.text = ""
    textbox3.text = "Blue"
    textbox4.text = ""
    textbox5.text = ""
    $MyArray = @()
    for ($i = 1; $i -le 5; $i++) {
    If ($textbox[$i].text -ne "") {
    $MyArray += $textbox[$i].text
    I realize the textbox object is not an array so this code will not work. I guess the simple question is, How can I reference a set of static controls using a variable without having to do something like this
    [object[]]$textboxes = New-Object System.Windows.Forms.TextBox
    For ($i = 1; $i -lt 5; $i++) {
    $textboxes += New-Object windows.forms.textbox
    $textboxes[$i].DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
    $textboxes[$i].Name = $textboxes[$i]
    $BoxItems.Controls.Add($textboxes[$i])

    Hi D-Dub,
    here are two ways to retrieve the text value of $Textbox1:
    $Textbox1.Text
    (Get-Variable "Textbox1").Value.Text
    Now what could you do with the second way, inside a loop, I wonder ... ;)
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • How can I reference a variable in Regexp

    Hello Friends,
    I have this Regexp, to extract the county code: (971)
    select regexp_replace (regexp_replace('000971-05 7910 - 324324','\D'),'^0*(971)?0?') from dual;It is fine and does the need..
    But, thinking in the future, someone may need to eliminate the country code of (961), so it is better if I put the code in a variable, but
    How can I reference the county code using a variable in Regexp:
    declare
    a varchar2 (15);
    code number := 971;
    begin
    select regexp_replace(regexp_replace('000971 05 7910 - 324324','\D'),'^0*(code)?0?') into a from dual;
    dbms_output.put_line ( a);
    end;but, it does not work ??
    Best Regards,
    Fateh

    venx08 wrote:
    You need to bind the code variable value in the regular expression patternYes, that's the idea, but there is a caveat. You might need to escape every regexp special character that appears in code. If, for example code is 'A*B' you need to transform it into 'A\*B' unless you really want 'A*B' to be interpreted as uppercase A repeated zero or more times followed by uppercase B.
    SY.

  • How can we  use java variable in javascript code on JSP page?

    How can we use java variable in javascript code on JSP page?
    Pls help

    Think about it:
    JSP/Java is executed on the Server and produces HTML+JavaScript.
    Then that HTML+JavaScript is transfered to the client. The client now interpretes the HTML+JavaScript.
    Obviously there's no way to access a Java variable directly from JavaScript.
    What you can do, however, is write out some JavaScript that creates a JavaScript variable containing the value of your Java variable.

  • How can I assign javascript variables to jsp or java variables.?

    How can I assign javascript variables to jsp or java variables.?

    See I have generated some variables in the javascript which is on the jsp page. I want to assgin these variables to the jsp vaiables. Or how can I access javascript variables from jsp on the same jsp page.

  • Can one get the Java variables corresponding to the css properties

    Hi,
    I want to be able to get some css properties as Java variables so that I can animate their values.
    Through css there is no way to perform animations of properties, in a non discrete way.
    Cheers and thanks in advance,

    You may be interested in tracking progress on:
    http://javafx-jira.kenai.com/browse/RT-17293 "CSS Style Object Model in Java".
    In the meantime, maybe you make use of something like this which animates a value within a css style string.
    @Override public void start(final Stage stage) throws Exception {
      final Rectangle rectangle = new Rectangle(150, 100);
      DoubleProperty greenness = new SimpleDoubleProperty();
      greenness.addListener(new ChangeListener<Number>() {
        @Override public void changed(ObservableValue<? extends Number> number, Number oldValue, Number newValue) {
          rectangle.setStyle("-fx-fill: rgb(0, " + newValue + ", 0);");
      Timeline t = new Timeline(
         new KeyFrame(Duration.ZERO,       new KeyValue(greenness, 0)),
         new KeyFrame(Duration.seconds(5), new KeyValue(greenness, 255))
      t.setCycleCount(Animation.INDEFINITE);
      t.setAutoReverse(true);
      t.play();
      stage.setScene(new Scene(new Group(rectangle)));
      stage.show();
    }

  • How to get java variable in jstl???

    Hi,
    I am wondering the way to retrieve or set java variable in jstl.
    <%
    String str="123";
    %>
    <c:set var='str'> <<?????
    Edited by: gohgss on Oct 17, 2007 9:30 AM

    No, they exist in different 'places'. The JSTL variables are in one of four scopes ( page, request, session or application ) while the scriptlet variables are simply local to the _jspService() method of the translated JSP.
    It's not recommended to mix up scriptlets and EL/ custom tags.
    But if you do need to you can do this:
    <%
    String str="123";
    request.setAttribute("str", str);
    %>
    <c:set var='str'>  //now you can work with str, but it'll be happening via the requestScope----------------------------------------------------------------
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • How can I reference more than one jar file

    hi, In an applet, I use
    Archive = "foo.jar" to reference this jar file.
    But how can I reference more than one file?
    Thanks.

    Suggestion: spend a few minutes reading the tutorials.
    http://java.sun.com/docs/books/tutorial/applet/appletsonly/html.html
    You can specify multiple archive files by separating them with commas:
    <APPLET CODE="myapplet.class" ARCHIVE="file1, file2"     WIDTH=anInt HEIGHT=anInt>
    </APPLET>

  • Assigning javascript varibel value to java variable

    Hi all
    I want to find screen resolution in one jsp page.That can be done in javascript.
    (though 'screen.width and screen.height')
    But is there any way to assign that value to java variable.
    Any body has the idea?
    Help me.

    No, why ? becuase jsp is SERVER side
    There are workarounds, You can store your javascript values in hidden fields and submit your page with them to your JSP and then use them like that

  • Assigning javascript varible value to java variable

    Hi all
    I want to find screen resolution in one jsp page.That can be done in javascript.
    (though 'screen.width and screen.height')
    But is there any way to assign that value to java variable.
    Any body has the idea?
    Help me.

    No, why ? becuase jsp is SERVER side
    There are workarounds, You can store your javascript values in hidden fields and submit your page with them to your JSP and then use them like that

  • Assign j_user value to a java variable in umLogonPage.jsp

    Hi All
    I need to do some post processing immediately after login and require the user id for the same. So how do we acess the value in the user id field and assign it to a java variable in the umLogonPage.jsp..??
    Java specific forums claim that this is not possible directly and can be only done on submit function or through hidden fields in the form. Any ideas with regard to the form that is present in umLogonPage.jsp..??
    Thanks
    Deepak

    Hi,
    we use this for saving the login time of the user. There are few therads about creating a custom login module (for example: [Custom Login Module - how to go on |http://forums.sdn.sap.com/thread.jspa?threadID=357616]).
    We have created a login module which extends AbstractLoginModule, in login() method :
    public boolean login() throws LoginException  {
    Object option = g_sharedState.get("javax.security.auth.login.name");
    if (option != null && !option.equals(""))  {
      String l_userID = (String)option;
      IUserAccount l_account = UMFactory.getUserAccountFactory().getUserAccountByLogonId(l_userID);
      IUserAccount mutableAccount = accountFactory.getMutableUserAccount(account.getUniqueID());     
      l_mutAccount.setLastSuccessfulLogonDate(new Date());
      l_mutAccount.commit();
    about login modules and login stacks start here: [http://help.sap.com/saphelp_nw04/helpdata/en/8c/f03541c6afd92be10000000a1550b0/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/en/8c/f03541c6afd92be10000000a1550b0/frameset.htm]
    Hope this helps,
    Romano

  • Can the flash storage hard drives in the brand new 15inch Macbook Pro Retina Display laptops (10.22.13) be upgraded/replaced in the future?

    Can the flash storage hard drives in the brand new Macbook Pro Retina Display laptops that were just released a few days ago (10.22.13) be upgraded/replaced in the future?  I will need more than the basic 256GB for sample libraries using music software, among other things, but currently larger flash drives from Apple are too expensive.  I ask because I'm in the process of buying one of the new 15inch Macbook Pro Retina Display laptops right now (or at least right after I get an answer to this question). 
    I saw in the Mac store when I started looking at the build options for ordering the Macbook Pro that under Memory it said the memory was built into the computer and therefore could not ever be replaced or upgraded in the future.  So I was wondering if something similiar might be the case with the flash storage drives even though the same wasn't written under the hard drive options?  If these flash drives can be replaced in the future then I would just purchase the starting 256GB drive and suffer through using connected external hard drives, as unwieldy as that would be, until there were potential replacement flash drives with larger storage capacties available on the market or through Apple for more reasonable prices.  But if the hard drives in these laptops can't be replaced/upgraded I would go for the 500GB drive option (even though paying an additional $300, before taxes, for just 244GBs more storage space is absolutely outrageous no matter how great flash drives are with their read/write speeds, no moving parts to break, and lighter weight/thinner builds allowing for an overall thinner laptop).  I would even go for the larger 1TB option, which is really what I need, except that costs an additional $700 which is more than enough to buy me a new 50inch, HD, flatscreen TV from a reputable brand if I were so inclined!  (And yes, I understand the youth of the technology, current limits to flash drive capacities, and the reason for the high prices.  I know I'm not getting bilked...)
    So yeah, does anybody have an answer to this question?  Can the flash hard drives in the new Macbook Pro Retina Display laptops, just released, be upgraded/replaced in the future?  Any answers are greatly appreciated and will save me some much needed cash on my purchase of one of these laptops!  And I should also ask, if so, can they be replaced by the laptop owner with the normal toolset through the normal, easily done methods of hard drive replacement in laptops that has been common, or would I have to bring the laptop to a Apple technician?
    Thanks everybody!

    The modules are proprietary. They are installed in a slot secured with a tiny screw.
    macsales.com has been working on providing aftermarket modules for the older models that were on the SATA Bus.
    These newer ones are likley directly on the PCIe Bus. That will take some time to develop.

  • Using a java variable in jsp-Reports?

    Hello everyone,
    is it possible to use a java variable in the xml-definition of a report? Something like
    <%@ taglib uri="/WEB-INF/lib/reports_tld.jar" prefix="rw" %>
    <% String someSqlStatement="select * from emp"; %>
    <rw:report id="myReport">
    <rw:objects id="myObjects">
    <report DTDVersion="9000010" name="myReport">
    <data>
    <dataSource name="Q_1">
    <select>
    <![CDATA[
    <%= someSQLStatement %>
    ]]>
    </select>
    It won't work that way (as the string is not evaluated and inserted into the definition, but how could it be done? Would be great to modify the report programatically that way? Any ideas?
    TIA,
    Marcel Jantz

    To pass values to Reports, you should use the "parameters" attribute in the <rw:report> tag. In the above case you would have:
    <% String myParameters="p_someSqlStatement=select%20*%20from%20emp"; %>
    <rw:report id="myReport" parameters="<%= myParameters %>">
    <rw:objects id="myObjects">
    <report DTDVersion="9000010" name="myReport">
    <data>
    <dataSource name="Q_1">
    <select>
    <![CDATA[ &p_someSqlStatement ]]>
    </select>
    The body of the <rw:objects> tag isn't evaluated since the Reports Builder needs to be able to open and load the <rw:objects> tag. As the Reports builder doesn't run the .jsp on open, it only parses it, the <rw:objects> tag can't have values that need to be evaluated.

  • Why only final variables can be accessed in an inner class ?

    Variables declared in a method need to declared as final if they are to be accessed in an inner class which resides in that method. My question is...
    1. Why should i declare them as final ? What's the reason?
    2. If i declare them as final, could they be modified in inner class ? since final variables should not modify their value.

    (Got an error posting this, so I hope we don't end up with two...)
    But what if i want to change the final local variable within that method instead of within anonymous class.You can't. You can't change the value of a final variable.
    Should i use same thing like having another local variable as part of method and initializing it with the final local variable?You could do. But as in the first example I posted you are changing the value of the nonfinal variable not the final one. Because final variables can't be changed.
    If so, don't you think it is redundant to have so many local variables for so many final local variables just to change them within that method?If you are worried that a variable might be redundant, don't create it. If you must create it to meet some need then it's not redundant.
    Or is there any alternate way?Any alternate way to do what?

Maybe you are looking for

  • I can't burn my iDVD project to a DVD

    After creating my project the burn button does not respond. I had a newer version of iDVD (7.0.3) so I installed on my iMac. After installing all the updates I opened the iDVD program. I then got this message on the screen. "Your Macintosh does not h

  • Power Adapters

    hi, I just bought a new ibook g4 I've been on the computer that is listed for 2 years, and it was 3 years old when I got it, it recently died... However my problem lies wih the power adapter on my new iBook. After plugging the computer in I have foun

  • Gamma issue... beating a dead horse

    so so confused, about this gamma shift from After Effects to Final Cut. I rendered the same clip out 4 different times and each time it has different gamma. Here are my render settings: 1. v210 Codec 2. Quicktime Animation 3. Apple FCP Uncompressed 8

  • [svn:fx-trunk] 10092: Make applications accessible by default.

    Revision: 10092 Author:   [email protected] Date:     2009-09-09 09:28:04 -0700 (Wed, 09 Sep 2009) Log Message: Make applications accessible by default. The default of the accessible compiler option has changed from false to true. QE notes: None. Doc

  • Gcc could not work

    I config alchemy step by step 1.  ./config 2.  source alchemy-setup 3. alc-on and then I run "which gcc" , and it is alchemy gcc .. but when I run gcc --version to show the gcc version , it doesn't show any thing, So I think that alchemy gcc could no