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)

Similar Messages

  • To check the string for a particular character

    i want to check the string contains ',' (comma) or not. can anyone help me?

    i want to check the string contains ',' (comma) or
    not. can anyone help me?you can use 'indexOf' method at string object
    String s1 = "test,tet1";
    boolean bfind = s1.indexOf(',') > -1 or
    boolean bfind = s1.indexOf(",") > -1

  • Need reg_exp for checking the string contains only alphanumeric or not

    Dear All,
    I need to check the given string in if condtion contains only the alphanumeric or not pls help me..
    like
    if reg_exp then
    end if;
    thanks,
    Oracle

    Hi,
    REGEXP_LIKE ( str
                , '[^[:alnum:]]'
                )returns TRUE if the string str contains any character other than an alphanumeric.
    You can use this wherever conditions are allowed, such as a WHERE clause or a CASE expression. For example:
    SELECT     str
    .     CASE
             WHEN  REGEXP_LIKE ( str
                         , '[^[:alnum:]]'
             THEN  'Contains speace, punctuation or special symbol'
             ELSE  'Okay'
         END               AS is_alnum
    FROM     table_x
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    Edited by: Frank Kulash on Dec 30, 2011 4:37 AM

  • Jdbc: character encoding.. what is the string ?

    I have been looking for an hour now, and have had no luck..What is the syntax of building a
    jdbc url, where the charset is set to utf-8
    regards
    Ben

    Use the substring (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#substring(int)) and indexOf method:
    String name = "Brandon Bell";
    String suffix = name.substring(name.indexOf('o'));now the String suffix has the value "on Bell".

  • Checking the string

    How to check the presence of numerals in a String?

    also, you can use regular expressions... but I would suspect checking each char might be faster.

  • Why jvm maintains string pool only for string objects why not for other objects?

    why jvm maintains string pool only for string objects why not for other objects? why there is no pool for other objects? what is the specialty of string?

    rp0428 wrote:
    You might be aware of the fact that String is an immutable object, which means string object once created cannot be manipulated or modified. If we are going for such operation then we will be creating a new string out of that operation.
    It's a JVM design-time decision or rather better memory management. In programming it's quite a common case that we will define string with same values multiple times and having a pool to hold these data will be much efficient. Multiple references from program point/ refer to same object/ value.
    Please refer these links
    What is Java String Pool? | JournalDev
    Why String is Immutable in Java ? | Javalobby
    Sorry but you are spreading FALSE information. Also, that first article is WRONG - just as OP was wrong.
    This is NO SUCH THING as a 'string pool' in Java. There is a CONSTANT pool and that pool can include STRING CONSTANTS.
    It has NOTHING to do with immutability - it has to do with CONSTANTS.
    Just because a string is immutable does NOT mean it is a CONSTANT. And just because two strings have the exact same sequence of characters does NOT mean they use values from the constant pool.
    On the other hand class String offers the .intern() method to ensure that there is only one instance of class String for a certain sequence of characters, and the JVM calls it implicitly for literal strings and compile time string concatination results.
    Chapter 3. Lexical Structure
    In that sense the OPs question is valid, although the OP uses wrong wording.
    And the question is: what makes class Strings special so that it offers interning while other basic types don't.
    I don't know the answer.
    But in my opinion this is because of the hybrid nature of strings.
    In Java we have primitive types (int, float, double...) and Object types (Integer, Float, Double).
    The primitive types are consessons to C developers. Without primitive types you could not write simple equiations or comparisons (a = 2+3; if (a==5) ...). [autoboxing has not been there from the beginning...]
    The String class is different, almost something of both. You create String literals as you do with primitives (String a = "aString") and you can concatinate strings with the '+' operator. Nevertheless each string is an object.
    It should be common knowledge that strings should not be compared with '==' but because of the interning functionality this works surprisingly often.
    Since strings are so easy to create and each string is an object the lack ot the interning functionality would cause heavy memory consumption. Just look at your code how often you use the same string literal within your program.
    The memory problem is less important for other object types. Either because you create less equal objects of them or the benefit of pointing to the same object is less (eg. because the memory foot print of the individual objects is almost the same as the memory footpint of the references to it needed anyway).
    These are my personal thoughts.
    Hope this helps.
    bye
    TPD

  • How does the String class achieve this.

    How come we can do the following with the String class:
    // The class is initialized using the equals sign!
    String s = "Hello, World"";I am currently checking the string class but can not find what makes the above possible. could anyone help me?

    ok sorry for not being so clear :)
    When having a String class, we can initialize it by doing the following:
    String myString = "Hello World"; Whis as JosAH explained it is handeled by the compiler. However my common sense tells me that the String class is nothing but a normal class (not like int, long, etc). So if it a normal class, then in that class there is a way to understand what = "somthing" means, and update it's state accordingly.
    I would like to do the same think with my class. example:
    Person MyPerson = "John, Smith";The above is a stupid example, however it gathers my point. The String class sess what is inside the quates and updates it state (with the help of the compiler). Can the Person class do the same? how?

  • How to get these substrings based on the string entered

    Hi friends
    i want the substring entered in the string
    the string is something like this: 1234,3653,7684,3254,8777,987,234
    now i want
    the substrings between commas
    can some one help me with it pls
    in the first substring i need 1234
    in the second i need 3653...
    so on till the end..
    what ever the string be until the last one
    pls help

    Hi,
    You can do something like this:
    SELECT     txt
    ,     REGEXP_SUBSTR (txt, '[^,]+', 1, 1)     AS part_1
    ,     REGEXP_SUBSTR (txt, '[^,]+', 1, 2)     AS part_2
    ,     REGEXP_SUBSTR (txt, '[^,]+', 1, 3)     AS part_3
    FROM     table_x
    ;If there are fewer than n parts, then the technique above will not raise an error; it will just return NULL for part_n.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    Explain how you get those results from that data.
    What do you want if the input is like this"
    {code}
    'foo,,bar'
    {code}
    ? Do you want to consider this as 2 parts ('bar' is the 2nd) or a s 3 (the 2nd is NULL, and 'bar' is the 3rd)? Include examples in your sample data and results.
    Always say what version of Oracle you're using.

  • What does the sync mail checkbox do in iTunes?

    Can anyone help me understand what checking the "sync mail" feature does when synching my iPhone with iTunes?
    I'm not sure that it does anything since my mail.app and my iphone are both checking the pop 3 server.

    Probably most of these 300+ tracks are sourced from a single general location which cannot be accessed or found on your new computer configuration. Right-click on several of the exclamation mark-ed tracks, choose Get Info. The location will be revealed at the very bottom of the newly opened window after "Where:".
    You can try to fix iTunes exclamation for some or all of these tracks with a third-party app. Despite that it is still in beta it managed to find some of my missing songs in my library.

  • Match the string for a particular format

    i want to chek the string for a particular format..
    lets say for ex ,
    i have to check the string for 6A1N format where A - Alphabets and N - Numbers.
    that means my string exactly contains 6 alphabets from a to z and one number from 0 to 9
    like this i want to check for two more fromats..they are..
    2A7N1A or
    9N1A

    koneru9999 wrote:
    will the pattern is helpful in my case?
    and i don't have any idea doesn't mean finsh reading all the API right?You need to study http://www.regular-expressions.info/ and then http://java.sun.com/docs/books/tutorial/essential/regex/ .

  • Plugins to thicken the STRINGS

    Hi All,
    What plugins will you insert to the track to Fatten or Thicken the Strings (software instrument)? Besides, what will Plugin to sweetening the strings so?
    Appreciate!

    What people usually refer to as "thickening" strings isn't actually done with effects - it's done by layering multiple sounds, or playing additional octaves or harmonics. You might also want to add a dash of chorus and/or a short delay, but the more processing you do the more unnatural the sound will be (but maybe that's okay).
    "sweetening" suggests more that the strings aren't sitting properly in the mix and need some EQ - impossible to help much without knowing what role the strings are supposed to be playing and what else is going on, but if they are too boomy, try cutting the low mids. If they are competing with the vocal, cut the high mids and add a some air.

  • How to check the value of a string is numeric, alphanumeric or characters?

    Hi All,
    I have a task to validate an employee Id. Suppose the employee Id is E121212. Now as per the validation rule I need to check "the first letter of the employee Id is a character and rest are numbers." How can I do this? Please reply.
    Thanks & Regards
    Bibhuprasad Soumyaranjan

    >
    Hi Bibhuprasad,
    I have a task to validate an employee Id. Suppose the employee Id is
    E121212. Now as per the validation rule I need to check "the first letter
    of the employee Id is a character and rest are numbers." How can I do this? Please reply.Everyone else has proposed REGEXP_LIKE, and while it's very powerful, it is
    also very CPU intensive. You should always use Oracle's string functions
    instead of Regular Expressions if possible.
    I played around with
    WITH data
         AS (SELECT 'E11212' s FROM DUAL
             UNION ALL
             SELECT '121212' FROM DUAL
             UNION ALL
             SELECT 'EE121212' FROM DUAL
             UNION ALL
             SELECT 'É121212' FROM DUAL
             UNION ALL
             SELECT 'E1EEEEEEEE' FROM DUAL
             UNION ALL
             SELECT 'E134343444' FROM DUAL)
    SELECT s,
      CASE
        WHEN (SUBSTR(s, 1, 1) BETWEEN 'A' AND 'Z') -- AND (TO_NUMBER(SUBSTR(s, 2, LENGTH(s)), 999999) > 111111)
          THEN 'Correct Format'
        ELSE
          'Incorrect Format'
        END mySSN,
        SUBSTR(s, 2, LENGTH(s)) AS theNumber
    FROM data;I think that this can be worked so that it willl go what you require without using
    REGEXP_LIKE.
    HTH,
    Paul...
    Bibhuprasad Soumyaranjan

  • What is the use of at-exit in mudule pool

    hi
    what is the use of at-exit in mudule pool. what is the use when we keep the function type as 'E' for a function code

    AT EXIT-COMMAND lets you call a module before the system executes the automatic fields checks.
    Automatic field checks can be avoided through AT EXIT-COMMAND, which works exactly the same way as CANCEL works from standard tool bar.  In the R/3 screen, if your want to quit the processing of that particular screen without entering the mandatory fields then user can click the CANCEL button, same functionality can be incorporated in the user defined transaction by usine AT EXIT-COMMAND.  This module can be called before the system executes the automatic field checks.
    Code for AT EXIT-COMMAND in flow logic and in module pool program can be written as follows.
    In Flow Logic:
    PROCESS AFTER INPUT.
    MODULE EXIT AT EXIT-COMAND.
    In Module Pool Program:
    MODULE EXIT.
    case okcode.
    when 'EXIT'.
    leave to screen 0.
    ENDMODULE.
    To achieve this kind of functinality, the pushbutton or menu item should be assigned a function type 'E' (Exit).  It tells the system to process this particular module before carrying out any field checks.
    Rewards if useful.

  • 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

  • What is the main use of pooled talbe and where are they use?

    Hi gus:
             Can somebody tell me what is the main use of pooled table and where are they use,thanks!
            Regards
             Jerry
    Moderator message - Please search before asking - post locked
    Edited by: Rob Burbank on Sep 1, 2009 9:11 AM

    Hi,
    Table pools are special table types in the ABAP Dictionary. The data from several different tables can be stored together in a table pool or table cluster. Tables assigned to a table pool or table cluster are referred to as pooled tables or cluster tables.
    This table are similar to the CLUSTER table types but these work on "LINEAR SEARCH" while CLUSTER TABLE uses "BINARY SEARCH to retrieve the data from the various tables and thsi is mainly used in the logical databases "LDB's" used in HR or ABAP-HR.
    A table in the database in which all records from the pooled tables assigned to the table pool are stored corresponds to a table pool.
    The definition of a pool consists essentially of two key fields (Tabname and Varkey) and a long argument field (Vardata).
    Table Clusters Several logical data records from different cluster tables can be stored together in one physical 
    record in a table cluster.
    A cluster key consists of a series of freely definable key fields and a field (Pageno) for distinguishing continuation records. A cluster also contains a long field (Vardata) that contains the contents of the data fields of the cluster tables for this key. If the data does not fit into the long field, continuation records are created. Control information on the structure of the data string is still written at the beginning of the Vardata field.
    Regards,
    Samad.

Maybe you are looking for