Lifetime and behavior of the String Constant Pool

If you 'inline' a String constant in Java, I'm aware in the VM spec that it says this String is put in the constant pool.
What is the lifetime of the constant pool and what is it tied to? Is there one constant pool per Class, per Class instance, or per VM?
If an instance is GC'd, do it's constants previously moved to the constant pool get destroyed, or do they live on until I create another instance of that Class?
Thanks, Kevin

Is the constant pool created at compile time and written into the Class file?Yes.
Each class has it's own constant pool which contains constant values and references to other classes and fields.
It is created a compile time.
A class (definition) is loaded by a classloader at runtime.
In theory you could have the same class loaded twice by different classloaders and each would have a copy of the class definition.
As far as I know, a class definition can only be removed from memory by nulling/garbage collecting the classloader that loaded it.
regards,
Owen

Similar Messages

  • Whats a String constant pool?

    I was reading an article about weak references and came across a peice of code
       Map<String,String> map = new WeakHashMap<String, String>();
          map.put(new String("Scott"), "McNealey");They also said
    if you don't call new String(), the reference for the map key will be to the system's string constant pool. This never goes away, so the weak reference will never be released. To get around this, new String("Scott") creates a reference to the reference in the string constant pool. The string contents are never duplicated. They stay in the constant pool. This simply creates a separate pointer to the string constant in the pool.
    I never heard of String constant pool could any one enlighten me. I didnt get the point of what above paragraph says also.
    Jubs

    No it won't: it will only be removed when the garbage collector rears
    its ugly head. Until then the reference will be present in the map.Okay it was unprecise. The item MAY be removed immediately after it
    has been inserted because the key object is only referenced from the
    Map itself.Yes, that is true, but mind though: any object that still has a strong
    reference to it will not be removed from that map. I use such weak maps
    for localization reasons a lot. When a localization changes (while the
    application is running), a whole lot of visual components must have
    their text part changed. They are all stored in such a weak reference map.
    Of course quite some visual components can be garbage collected
    at some time (think of labels etc. in JDialogs after the dialog has been
    disposed).
    These maps are ideal for those purposes.
    kind regards,
    Jos

  • What is the little square box in the string constant input?

    Hello LabVIEW World -
      I am attempting to understand a LabVIEW code that I did not write.  At one point, there is a string (Equal?) comparison that is comparing a string from a VISA Read to a string constant input.  The string constant has a little square box inside of it.
      Does anyone know what this little square box is?  (See attached screenshot)
      Thanks.
    DS
    Attachments:
    LittleSquare.JPG ‏69 KB

    When I place string constants like this I will display then either as hex or in the codes mode. Either of these will make the code more readable. Using the default ASCII string display is useless other than letting you know it is an unprintable character.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • I need a function that will go through and encrypt all the strings

    I want to use one way enryption and need a function that will
    go through and encrypt all the strings in my password column in sql
    server 2003.
    I also need a function that compares a test password string
    is equal to the hash value in the database. Can anyone give me some
    advice in this?

    Apparently it's not as simple as I thought. My first instinct
    was
    update yourtable set password = '#hash(password)#'
    but that will crash
    This is inefficient, but you only have to do it once.
    query1
    select id, password thepassword
    from yourtable
    cfloop query="query1"
    update yourtable
    set password = '#hash(thepassword)#'
    where id = #id#

  • Question about String constant pool

    Is there is any function available to find how many Sring literal in String Constant pool

    Well, there's stuff like BCEL.
    But it may not do what you want.
    Why do you want to find out what's in the constant pool?

  • Check if a single Text Item in a cell is bold and then grab the string that is bold

    I have written a script that runs through a table and parses out the information I need to create another table with some added information.
    The last piece that I can't seem to figure out is how to check if some text in a cell is bold and then grab said text to put in the new table.
    I will give a small table demo of what I am try to retrieve.
    Table A.
    Column 1
    Description
    123456
    This is a description (This is a note)
    789123
    This is a description (This is note A) (This is note B) (This is more stuff that isn't needed.
    Table B.
    Column 1
    Column 2
    Note
    1
    123456
    (This is a note)
    2
    789123
    (This is note A) (This is note B)
    I can pull all of the other information across that I am trying to get without any issue.
    I can't seem to figure out how to check the formatting of a TextItem to see if it is bold. I have been able to figure out how to check if a cell has bold text in it. using if ((tItems[counterVar].idata & Constants.FTF_WEIGHT) > 0). This ends up not working well because of a few issues. I was wondering if there is any way to check the formatting of a single character?
    I tried something similar to the following:
    prop_Change = tbl_Description_Cell.GetText(Constants.FTI_CharPropsChange);
    txt_String = tbl_Description_Cell.GetText(Constants.FTI_String);
    if (prop_Change.len > 0)
            if((prop_Change[0].idata & Constants.FTF_WEIGHT) > 0)
                    pOffset = prop_Change[0].offset;
                    for (var tbl_tItems = 0; tbl_tItems < txt_String.len; tbl_tItems++)
                            tOffset = txt_String[tbl_tItems].offset
                            if(tOffset == pOffset)
                                    alert(txt_String[tbl_tItems].sdata);
    Thanks,
    Steven

    Depends on your forms-version. If you are using a web-based version, you could have a look at the Java-bean-editor FRITE, it supports such features.

  • Revolve 810 and behavior of the arrow keys with Ctrl + Alt

    The behavior the left and right arrow key, in combination with Ctrl and Alt, is to modify the screen orientation. (Which can be help because the Revolve is easily confused.) However, I want to disable this behavior because I use those key combinations for other uses.
    How can I disable this behavior?

    I understand you want to disable the rotate shortcut keys.  
    It looks like it is using Intel, so I will provide the steps my Windows 7 system uses to disable these functions.  They should be similar to Windows 8 as well.  
    Right-click the desktop and select screen resolution.
    Select advanced settings.
    Select Intel Graphics Media Accelerator Driver for Mobile (wording may be different).  
    Click the Graphics Properties button.
    Select Options and Support of the graphics control panel.
    Disable Hot Key functionality and click apply then ok.  
    This should disable the hotkeys to rotate the screen.  
    Since the Revolve 810 is using an Intel graphics card similar to mine, the steps should be the same or similar.
    Let me know what happens.  
    ↙-----------How do I give Kudos?| How do I mark a post as Solved? ----------------↓

  • How to pass a XML message as a string and to change the string back to XML

    Hi there,
    in our current application, we have to access a webservice with a message whose XML Schema Definition was provided by the service's provider. But when accessing the webservice's WSDL, it says that the service expects the message part as a string type.
    How can I accomplish to send this structured message (as defined by the .XSD) to the webservice as a string?
    Thanks in advance,

    Michal,
    thanks very much for your help!
    I've managed to correctly serialize a xml into a string with the tips in your blog. However, I've not managed to perform the string -> xml (unserialize) step (I'm using Udo's sugestion).
    The problem is that XI generates a namespace prefix in runtime (it can be ns0, ns1, ns2..., depending on the context), and so I need to reference this namespace into the unserializing XSLT. With XMLSpy, I've managed to correctly transform it using the XPath "//*:my_tag" to the string tag, but this approach didn't work in XI.
    If I try to use just "//my_tag" the transformation concludes successfully, but XI says that the generated XML is not well-formed (probably because it doesn't fits the Schema of the target message, but I'm just guessing here). If I try to use "//:*my_tag", it doesn't even performs the transformation, and gives a "Problem When Testing" error, which says "Transformer configuration exception occurred when loading XSLT ...".
    Any ideas on how to reference namespace prefixes in XSLTs in XI?
    The codes of my XSLT's are below:
    XML to string:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <my_tag>
    <xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>
    <xsl:copy-of select="/"/>
    <xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>
    <xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
    </my_tag>
    </xsl:template>
    </xsl:stylesheet>
    String to XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my_prefix="http://my_namespace">
    <xsl:template match="/">
    <xsl:for-each select="//*:my_tag">
    <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    Thanks again!

  • Apostrophes And Parenthesis in the string

    Hi Everyone.
    How do you guys handle apostrophes and parenthesis in java?
    I have a solution where the client wants to put apostrophes and parenthesis in the database as part of their strings. ie O'reily (also known as dude)
    Now these apostrophes and parenthesis come from the database into the java program -- will it break my javascript strings manipulation? If so how can i treat it before it breaks the string
    I know for a fact it breaks my javascript.
    For example, I have a javascript method that is populated with variables that come from the database.
    onchange="return DoThisFunction("<%=rs.getString("whatever")%>","<%=rs.getString("whoever")%>");"
    thanks to parenthesis and apostrophes I get javascript alert errors can someone please enlightenme as to how i can fix this problem
    Sincerely and Gratefully Yours,
    Stephen A. Sutherland

    You sound pretty confused dude. This is a Java forum, not a JavaScript forum.
    The apostrophes and parenthesis will not interfere with your Java variables, since the Java code is compiled and not based on simple string-substitution. The situation for parens is identical.

  • How to call plsql procedure or function and getting back the string?

    Hi Everyone,
    i am using Jdev 11.1.1.5.0.
    i have a requirement to call plsql procedure or function from my backing bean java file and get back the returned value from the procedure or function.
    what piece of simple code i need to write in my backing bean?
    please suggest.
    Thanks.

    As always you write the method to call he pl/sql in the application module, expose this method to the client (so you see it in the datacontroll) then create a operation binding to the method and call this operation from the bean. The result you get by operation.getResult();
    You should never call pl/sql from the bean directly!
    The doc shows how to call the procedure from an application module: http://docs.oracle.com/cd/E21764_01/web.1111/b31974/bcadvgen.htm#sm0297
    Timo

  • Separating character and number within the string

    I want to separate the character and the number within one string.
    For example,
    12345ABCD (the numbers and character may differ in lengths)
    I want to separate into two different string of 12435 and ABCD.
    Your help would be greatly appreciated.
    Thanks!

    here is an example:
    sample_separator.sql
    declare
      i        number := 0;
      j        number := 0;
      x        number := 0;
      vBasis   Varchar2(40) := '12345ABCD';
      vString1 Varchar2(40);
      vString2 Varchar2(40);
    begin
      for x in 1 .. length(vBasis) loop
        for i in 0 .. 9 loop
          if substr(vBasis,x,1) = to_char(i) then     
            vString1 := vString1 || substr(vBasis,x,1);
          end if;
        end loop;
        for j in 65 .. 90 loop
          if substr(vBasis,x,1) = chr(j) then
            vString2 := vString2 || substr(vBasis,x,1);
          end if;
        end loop;   
      end loop;
      dbms_output.put_line('vString1: '||vString1);
      dbms_output.put_line('vString2: '||vString2);
    end;
    /when run:
    SQL> @r:\sample_separator.sql;
    vString1: 12345
    vString2: ABCD
    PL/SQL procedure successfully completed.
    SQL> hope this helps.

  • PDF links (7.11.2.2) and behavior on the web

    Hello all,
    I'm trying to generate a PDF file (from scratch, using a C++ library - but that's not relevant to my question) that uses links to specify the location of linked files relative to the root of a drive - NOT relative to the PDF file itself (i.e.  I don't want to use ../../).
    As best I can tell from the PDF specification (PDF32000_2008.pdf, section 7.11.2.2 and 7.11.2.3) - creating such links should be as simple as using a double forward slash to specify 'no drive'.
    e.g.   To link to the file in c:\images\test.jpg from a PDF file you know is also on the c: drive - the links written form is: //images/test.jpg (as per table 43)
    This works fine when I access it from my desktop - when both the PDF and JPG are on my c: drive - however if I copy the PDF to my test web server, and put the test.jpg file in a folder called images on the root of my web server - the link fails when executed in the PDF opened on the server (in the Reader loaded inside the browser).
    I can see what's happening - and want to know if there is something I can do (or should be doing) to fix it.
    What happens is that the 'no drive' path is actually removing too much from the path.
    Instead of trying to open http://127.0.0.1/images/test.jpg, the actual link that appears in the browser address bar is http://images/test.jpg.
    Any help would be much appreciated,
    Thanks
    Adam
    (I've attached a example.pdf file that contains a link to \images\test.jpg - which works on the desktop, but not in the browser)

    Hi Leonard,
    First off, thanks a lot for escalating this to the engineering team.  I didn't expect that from a free open forum.  - I'm impressed.
    Of course, the engineer is right - I didn't mention it because I was secretly hoping that there would be a solution that worked for both - given the portable nature of a PDF.  (I'm still befuddled as to why a root relative file path is processed the way that it is in the context of a web browser - I expected it to be relative to the root of the site)
    I guess, assuming it's possible to detect whether the PDF was opened in a standalone reader vs a browser using Acrobat JavaScript - I could generate link hotspots for both scenarios at publish time - defaulting one set to hidden (or back) - and then switch them when the PDF is loaded using script again. I'm not sure whether any of that will trip a security warning in the default configuration - but don't think so as we already use JavaScript to do multi-link menus.
    If nothing else, at least I know it isn't going to work the way it is (so won't keep trying to jiggle things) - and have some ideas on workarounds.
    Thanks for all your help,
    Adam

  • When String instances in Constant Pool will be GC'ed?

    Hi all,
    I'm involved in an application development; where we are storing numerous string objects into multiple HashMaps. Since the string objects created/placed in HashMap may have duplicate values; we're calling String::intern() method to make use of String Constant Pool feature in Java. But, my concern is - When the Constant String instance will be removed from Pool? Is it follow the same behaviour that if no references are presentm it is eligible for GC; i.e., removal of an instance from all HashMaps?
    Please help.
    Thanks & regards,
    R Kaja Mohideen

    EJP wrote:
    How do you figure?Doesn't say so in the Javadoc. It talks about another pool ...You're taking "A pool of strings, initially empty, is maintained privately by the class String." as meaning it's not "the constant pool"? I wouldn't interpret it that way. And based on the JVM spec, I don't see anything saying the intern()ed Strings go to a different pool than "the constant pool". And if it is a separate pool, then what does go into "the constant pool"?
    http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#22972
    "A runtime constant pool is a per-class or per-interface runtime representation of the constant_pool table in a class file (§4.4). It contains several kinds of constants, ranging from numeric literals known at compile time to method and field references that must be resolved at run time. "
    "Each runtime constant pool is allocated from the Java virtual machine's method area (§3.5.4)."
    http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#6656
    "The Java virtual machine has a method area that is shared among all Java virtual machine threads. [...] It stores per-class structures such as the runtime constant pool, field and method data, and the code for methods and constructors [...]"
    http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html#73272
    "The Java virtual machine maintains a per-type constant pool (§3.5.5),"
    "A string literal (§2.3) is derived from a CONSTANT_String_info structure (§4.4.3) in the binary representation of a class or interface. The CONSTANT_String_info structure gives the sequence of Unicode characters constituting the string literal.
    The Java programming language requires that identical string literals (that is, literals that contain the same sequence of characters) must refer to the same instance of class String. In addition, if the method String.intern is called on any string, the result is a reference to the same class instance that would be returned if that string appeared as a literal. Thus,
    ("a" + "b" + "c").intern() == "abc"
    must have the value true.
    To derive a string literal, the Java virtual machine examines the sequence of characters given by the CONSTANT_String_info structure.
    If the method String.intern has previously been called on an instance of class String containing a sequence of Unicode characters identical to that given by the CONSTANT_String_info structure, then the result of string literal derivation is a reference to that same instance of class String.
    Otherwise, a new instance of class String is created containing the sequence of Unicode characters given by the CONSTANT_String_info structure; that class instance is the result of string literal derivation. Finally, the intern method of the new String instance is invoked."
    Edited by: jverd on Jan 23, 2012 8:09 AM

  • What checks the String pool

    Hi there.
    With regard to the string pool,
    my book states that whenever the compiler
    encounters a string literal that it will check the pool to see if
    there is a matching string...
    This doesn't seem right to me.
    I would have imagined that the JVM would perform this operation at runtime.
    Maybe I'm wrong, but I googled it and I came across some sites that indicate that
    the JVM checks the string pool.
    Im just wondering which is it, the JVM or the compiler.
    Thanks & regards.

    jverd wrote:
    Both.
    String s1 = "abc";
    String s2 = "abc";Compiler sees the first line, looks for "abc" in the class' constant pool, doesn't find it, adds it, places reference to its position for the assignment to s1.
    Compiler sees the second line, looks for "abc", finds it, places reference to its position for the assignment to s2.
    At runtime, when class is loaded, VM loads class' String constant pool. When time comes to execute the above lines, the bytecode tells it which constant pool entry to reference.Great answer (No, I'm not sarcastic)

  • Richt Click Mouse with user32.dll and String Constant for Escape Key

    Hi, could some one provide the input parameters to use with Mouse_Event function in user32.dll to Right Click the Mouse?   Also, what is the string constant to send if one want to type the Escape Key (Esc)?  
    I have searched this forrum but only find the parameters for Left Mouse Click.  Thanks for any help.

    Hi,
    The mouse_event function has been superseded by the sendinput command.  To learn more about the function calls with user32.dll, have a look at the msdn.com website.  The user32.dll website is shown here.  The syntax for the mouse_event function is shown below:
    Syntax
    VOID mouse_event(      
        DWORD dwFlags,
        DWORD dx,
        DWORD dy,
        DWORD dwData,
        ULONG_PTR dwExtraInfo
    );I hope this helps,
    Regards,
    Nadim
    Applications Engineering
    National Instruments

Maybe you are looking for

  • My iPad says I am connected to wifi, but the internet won't work. I have tried turning wifi on/off and also resetting the network settings. Help!

    The past two days my iPad mini has not been working with the wifi at my house. There is also and iPhone 5 and an iPad air that are working perfectly fine. I don't know what to do

  • Realtime delay of 'live' stream

    Hello, I'm speccing a job for a client who wants to use live streams and have cutomers phoning in to direct the show as it happens in the studio. One consideration is how 'live' is live streaming in flash. Does anyone know roughly what the delay from

  • Close_form rolls back ?

    Hi, In my form I am opening a second form by using open_form then after I am done with the second form I close it from the first form by using close_form. Everything works fine up to here. The problem is calling the close_form rolls back the session

  • Check Browser Compatibilty  Problem with CS5.5

    Hi, I am having problems with the Check Browser Compatibilty function, it seems to pick up the issues in an HTML file but ignores errors in CSS files. I have run the check on CS4 and it work fine. Example of the File @charset "utf-8"; /* CSS Document

  • Validation URI: hostname could not be parsed

    Hi there, I freshly installed a new BPC 7.0 SP04 environment (Windows 2003, SQL Server 2008). Everything seems to work fine except in BPC for Excel where I constantly receive this "Validation URI: hostname could not be parsed". The data manager also