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?

Similar Messages

  • Question about string constant in Hex display format

    how to get a plus of 2 string constant which is display in Hex display like attahced, for example I have string "28" and "5D" in Labview which has been in Hex format, the plus of this 2 string should be "85" in Hex. pls help on this, thanks
    Attachments:
    1.jpg ‏21 KB

    This'll work, too.  I'm afraid of casting types...
    Jm
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
    Attachments:
    hex.png ‏2 KB
    hex.vi ‏7 KB

  • 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

  • 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

  • Question about using constant variables in Forms

    As I am still very new to Forms, please forgive my ignorance if the answer to my question is very simple. I am trying to figure out how to use constant variables within my Forms application. For example, if I want to setup return code constants for the application (mind me, these are examples):
    RC_SUCCESS CONSTANT PLS_INTEGER := 1;
    RC_FAILURE CONSTANT PLS_INTEGER := 0;
    RC_YEAR_DATA_NOT_FOUND := 50;
    Then in a module I created, if I wanted to check the return code against one of the constants I would do:
    DECLARE
    rc PLS_INTEGER;
    BEGIN
    GET_YEAR_DATA('2000', rc);
    IF rc = RC_YEAR_DATA_NOT_FOUND THEN
    -- Do some error handling
    END IF;
    END;
    I know that you can declare constants within individual procedures or packages but I can't see to find information on how to do this globally for the application. I've read about using global variables within Forms but the CHAR data type only and the fact the value can be changed doesn't really fit for this purpose. Am I missing something? Is there a config file or something for the webserver that can be used to set these up??
    Any help would be appreciated.
    Thanks

    To declare constants create a Package-Specification in a pll and deifne all your constants there, something like:
    PACKAGE PK_CONSTANTS IS
      RC_SUCCESS CONSTANT PLS_INTEGER := 1;
      RC_FAILURE CONSTANT PLS_INTEGER := 0;
      RC_YEAR_DATA_NOT_FOUND := 50;
    END;Then attach that pll to all your forms-modules, and use it like
    IF rc = PK_CONSTANTS.RC_YEAR_DATA_NOT_FOUND THEN
    END IF;A word about exceptions or errors: In my eyes its clearer (and in case of exceptions even better) to raise an exception than to hide it behind return-codes.

  • A question about string.trim()

    I got a fragment of code as follows:
    String s = "abcd ";
    boolean a = (s.trim()=="abcd");
    boolean b = (s =="abcd ");
    Why a is false, b is true?

    The reason why the below code has true assigned to be is quite easy to explain:
    String s = "abcd";
    String y = "abcd";
    boolean b = (s == y);
    ...The String class has a "Pool" of strings. When you use String literals; the compiler automatically checks if it is in the String pool already and if it exists; a reference to that String is returned; if not a new entry in the pool is added and then you get a reference to that. This is only true for Stirng literals and String created using the intern() method.
    If you compile this code you will see that the strings are not equal:
    public static void main(String args[])
      String s = "abcd";
      String y = args[0];
      boolean b = (s == y);
      System.out.println(b);
    }This is because the "abcd" is in the String pool when your program starts; but because the value "abcd" passed in (is not created in the pool automaticlaly). Therefor they are two different String objects.
    This code block shows that you can add Strings to the pool. The intern() method checks to see if the String is in the pool already and if it is it will return you a reference to it; if not it will create one and then return it.
    public static void main(String args[])
      String s = "abcd ";
      String y = args[0].intern();
      boolean b = (s == y);
      System.out.println(b);
    }- Chris

  • Question about string manipulation

    Hello, I am practicing with Java and trying to learn it, and have a quick question. I am trying to get the count on a string of numbers for after a decimal point. the numbers are generated as the result of a math, so I can't use index, since the location of the decimal changes based on the number imputed. I want to figure this out on my own, but have hit a wall here, i've spent the past few hours trying every string command I can think of, and haven't figured it out yet, anyone mind pointing me in the right direction for which string to use? Thanks in advance for any help you can provide!

    Is this what you want?
    public class Fallen{
      public static void main(String[] args){
        String number = "123.45678";
        String frac = number.substring(number.indexOf('.') + 1);
        System.out.println(frac + " length=" + frac.length());
        frac = number.replaceFirst("^.+\\.", "");
        System.out.println(frac + " length=" + frac.length());
    }

  • Easy question about String

    Hi!
    I have a string in a variable. how can I check if the String is composed just by numbers?
    thank you very much!

    Use the following method from Integer API
    parseInt
    public static int parseInt(String s)
                        throws NumberFormatExceptionParses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002d') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.If it throws NumberFormatException its alphanumeric else its numeric. You would however have to remove any spaces or commas etc. since they are not mumeric either

  • A question about String.hashCode()

    Why the implementation of hashCode() for String class using 31 as a base?

    Why the implementation of hashCode() for String class
    using 31 as a base?I think it's a magic number. It has been found to produce a reasonably even distribution over the int range.

  • Question about String initialization~~~

    String a = "sss";
    String b = "sss";
    the result of a==b is true .
    String a = new String("sss");
    String b = new String("sss");
    however , the result of a==b is false .
    why? the operator "==" compares WHAT of two object ??
    thanks , ;[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    == compare the reference of the object
    String s1 = new String("sss") creates a new String object at location xxxxxx, while
    String s2 = new String("sss") creates a new String object at location yyyyy.
    therefor xxxxxxx != yyyyyyyy
    by location..the memory address
    String s3 = "sss"; // java create a new String object "sss" at location zzzzzzzz and assign the reference to s3
    String s4 = "sss"; // java assign the reference (location zzzzzzzz) to s4
    so s3 == s4....
    noticed only one String object is created...s3 and s4 holds the reference to the 1st String created..though it is not clearly shown in th ecode...it actually look something like this
    String temp = new String("sss");
    String s3 = temp;
    String s4 = temp;

  • Question about string array?

    Hello,
    When passing Stting arrays to a function, is there anyto test if the array is emply?
    void testFucntion(String[] test){
    }

    Or test the array is null.
    if (test == null || test.length == 0)

  • Another question about string!

    Hi,
    I want to return a function as true if all the characters in that string are hexDigit. false otherwise.
    & also another class should return as true if all the charaters are Digit. false otherwise i was using
    public boolean isDigit(String str)
    for (int i=0; I<str.length(); i++)
    if (str.charAt(i).isDigit)
    return true
    return false
    what's wrong with this code? what shall I use instead of this? can anyone Help please?

    The way you've written it, you'll be returning true as soon as the first digit in the string is found:
    // on first loop will check first char in string.
    if(str.charAt(i)isDigit)
    // first char in string is a digit so method returns true
    return true;
    [\code]
    You could change it so that you will return false when non-numerical character is found. If none is found you will fall out the loop and return true.if(!str.charAt(i).isDigit)
    return false;
    return true;
    [\code]
    Don't know if there's a method for checking hexDigit. If not use something like:
    if (str.charAt(x).isDigit || str.charAt(x) >='A' && str.charAt(x) <='F');
    [\code]

  • A question about string

    hello,
    String s1 = "123";
    String s2 = "123";The following codes, create two String objects or one object?
    Any ideas?
    Thanks.

    The compiler creates one string, and both variables get pointed at it.
    http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101083

  • Question about String

    hi all,
    I am new to java
    I have one problem..
    that is I have one string like : 85WS98(or also: 67S, 1G3)
    from this String I want to only the
    85W98 = 85;
    67S = 67
    1G3 = 1
    I am using below code but its not working for : 85W98 and 1G3
    StringBuffer sb = new StringBuffer();
    for(int i = 0; i < str.length(); i++){
    char comp = str.charAt(i);
    if(Character.isDigit(comp)){
    sb.append(comp);
    String result = sb.toString();
    So if anyone knows please send the solution
    thanks

    So you want all the numeric chars before the first non-numeric char?
    Change this part of the code:
    if (Character.isDigit(comp)) {
      sb.append(comp);
    } else break; // break after first non-numeric char

  • Question about string in xdoxslt

    Hi,
    When using xdoxslt i want to set a variable to store many fields which means the variable is a concat of the fields and it seems that the '||' is not allowed in xdoxslt.
    I find a function append_to() and uses it as below
    <?xdoxslt:set_variable($_XDOCTX,'PeopleCnt',xdoxslt:append_to($_XDOCTX,xdoxslt:get_variable($_XDOCTX,'PeopleCnt'),'sdfs'))?>
    and the output of PeopleCnt is still the original value.
    Is there anything wrong i have taken for this function or is there anyting else i can do?
    Thanks!

    This'll work, too.  I'm afraid of casting types...
    Jm
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
    Attachments:
    hex.png ‏2 KB
    hex.vi ‏7 KB

Maybe you are looking for