Is Java String stored in Unicode??

I have a few questions regarding String in Unnicode:
1) Is really all internal representation of String is in Unicode?
2) If so, why do we need the Collator class? As refer to the javadoc "The Collator class performs locale-sensitive String comparison". If all String are stored in Unicode, why do we require this classs to do the comparison. should it be as simple as comparing with the ASCII value? Because every char should be assigned a unique 16 bit number, therefore it should be trival to do this.
3) Also, I do not understand why the String.charAt(), String.lenght() will return wrongly in Internationalization programing, as each of the char in String are 16 bits unicode.
I am new to the Internationalization and please correct me if any of my understand is wrong.

1) Is really all internal representation of String is
in Unicode?Yes.
2) If so, why do we need the Collator class? As refer
to the javadoc "The Collator class performs
locale-sensitive String comparison". If all String are
stored in Unicode, why do we require this classs to do
the comparison. should it be as simple as comparing
with the ASCII value? Because every char should be
assigned a unique 16 bit number, therefore it should
be trival to do this.The order of the characters in the Unicode is not always the same as the order of the characters in a particular language's alphabet. For example in Lithuanian the letter y comes near the beginning of the alphabet, close to i and j. And in French it's normal to put e and é together in alphabetical lists, whereas they are not adjacent in Unicode.
3) Also, I do not understand why the String.charAt(),
String.lenght() will return wrongly in
Internationalization programing, as each of the char
in String are 16 bits unicode. They do? Who says so?

Similar Messages

  • Are java byte[] stored on the heap?

    are java byte[] stored on the heap?
    If not, How can I clear a byte[]?
    For example in C, I could simply put the '\0' at
    the zeroth index.
    Please help.
    hm

    Yes, byte[] objects are stored on the heap. In Java, all objects are stored on the heap, all arrays are objects, and byte[] is an array.
    You seem to be equating byte[] with a C-style string. That kind of thinking will get you into all kinds of trouble in Java. Strings in Java are sequences of Unicode characters. Byte arrays can be converted to and from Strings using encodings such as UTF-8.

  • Transform string to a unicode

    Hello all,
    I want to know how can we transform a string to a 16-bit unicode, please?
    ( i want to transform a string to look like "\u062a\u0635\u0628\u062d "
    and then store it in a string variable to use it).
    can you give me the code?
    it's urgent

    your right that I asked how to turn a String into UNICODE
    and if you noticed my code you will find that I used the code that turn a string retrieved from database into unicode then store in a PDF file,but my problem here is when I tried to store these data in the PDF File, it stored as it is, I mean it stored the unicode string as it is (string) not convert it to the equivalent character as in the following example.
    I used this way (turn a String into UNICODE) because I found an example of how to put data written in a language other than english in a PDF file.
    this is the example:
    import java.awt.Color;
    import java.io.FileOutputStream;
    import com.lowagie.text.Chunk;
    import com.lowagie.text.Document;
    import com.lowagie.text.Element;
    import com.lowagie.text.Font;
    import com.lowagie.text.PageSize;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.pdf.BaseFont;
    import com.lowagie.text.pdf.ColumnText;
    import com.lowagie.text.pdf.PdfContentByte;
    import com.lowagie.text.pdf.PdfPCell;
    import com.lowagie.text.pdf.PdfPTable;
    import com.lowagie.text.pdf.PdfWriter;
    * Writing RTL text such as Arabic or Hebrew.
    public class RightToLeft {
    * Writing RTL text such as Arabic or Hebrew.
    * @param args no arguments needed
    public static void main(String[] args) {
    try {
         // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("righttoleft.pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();
    BaseFont bf = BaseFont.createFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, true);
    Font f2 = new Font(bf, 24, Font.NORMAL, Color.BLUE);
    float llx = 100;
    float lly = 100;
    float urx = 500;
    float ury = 800;
    ColumnText ct = new ColumnText(cb);
    ct.setSimpleColumn(llx, lly, urx, ury, 24, Element.ALIGN_LEFT);
    ct.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
    ct.setLeading(0, 1);
    ct.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(ar1, new Font(bf, 16)));
    ct.addText(new Chunk(ar2, new Font(bf, 16, Font.NORMAL, Color.red)));
    ct.go();
    ct.setAlignment(Element.ALIGN_JUSTIFIED);
    ct.addText(new Chunk(ar3, new Font(bf, 12)));
    ct.go();
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(ar4, new Font(bf, 14)));
    ct.go();
    ct.setSpaceCharRatio(PdfWriter.SPACE_CHAR_RATIO_DEFAULT);
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk("\n\n\n", new Font(bf, 16)));
    ct.addText(new Chunk(he1, new Font(bf, 16)));
    ct.addText(new Chunk(he2, new Font(bf, 16, Font.NORMAL, Color.red)));
    ct.go();
    ct.setAlignment(Element.ALIGN_JUSTIFIED);
    ct.addText(new Chunk(he3, new Font(bf, 12)));
    ct.go();
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.addText(new Chunk(he4, new Font(bf, 14)));
    ct.go();
    document.newPage();
    String atext = "\u062a\u0635\u0628\u062d ";
    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_NO_BIDI);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
    for (int k = 0; k < 5; ++k) {
    PdfPCell cell = new PdfPCell(new Phrase(10, atext + k, f2));
    if (k == 2) {
    cell.setColspan(2);
    ++k;
    table.addCell(cell);
    document.add(table);
    // step 5
    document.close();
    catch (Exception e) {
    e.printStackTrace();
    /** arabic text */
    public static String ar1 = "\u0623\u0648\u0631\u0648\u0628\u0627, \u0628\u0631\u0645\u062c\u064a\u0627\u062a \u0627\u0644\u062d\u0627\u0633\u0648\u0628 + \u0627\u0646\u062a\u0631\u0646\u064a\u062a :\n\n";
    /** arabic text */
    public static String ar2 = "\u062a\u0635\u0628\u062d \u0639\u0627\u0644\u0645\u064a\u0627 \u0645\u0639 \u064a\u0648\u0646\u064a\u0643\u0648\u062f\n\n";
    /** arabic text */
    public static String ar3 = "\u062a\u0633\u062c\u0651\u0644 \u0627\u0644\u0622\u0646 \u0644\u062d\u0636\u0648\u0631 \u0627\u0644\u0645\u0624\u062a\u0645\u0631 \u0627\u0644\u062f\u0648\u0644\u064a " +
    "\u0627\u0644\u0639\u0627\u0634\u0631 \u0644\u064a\u0648\u0646\u064a\u0643\u0648\u062f, \u0627\u0644\u0630\u064a \u0633\u064a\u0639\u0642\u062f \u0641\u064a 10-12 \u0622\u0630\u0627\u0631 1997 " +
    "\u0628\u0645\u062f\u064a\u0646\u0629 \u0645\u0627\u064a\u0646\u062a\u0633, \u0623\u0644\u0645\u0627\u0646\u064a\u0627. \u0648\u0633\u064a\u062c\u0645\u0639 \u0627\u0644\u0645\u0624\u062a\u0645\u0631 " +
    "\u0628\u064a\u0646 \u062e\u0628\u0631\u0627\u0621 \u0645\u0646 \u0643\u0627\u0641\u0629 \u0642\u0637\u0627\u0639\u0627\u062a \u0627\u0644\u0635\u0646\u0627\u0639\u0629 \u0639\u0644\u0649 " +
    "\u0627\u0644\u0634\u0628\u0643\u0629 \u0627\u0644\u0639\u0627\u0644\u0645\u064a\u0629 \u0627\u0646\u062a\u0631\u0646\u064a\u062a \u0648\u064a\u0648\u0646\u064a\u0643\u0648\u062f, \u062d\u064a\u062b " +
    "\u0633\u062a\u062a\u0645, \u0639\u0644\u0649 \u0627\u0644\u0635\u0639\u064a\u062f\u064a\u0646 \u0627\u0644\u062f\u0648\u0644\u064a \u0648\u0627\u0644\u0645\u062d\u0644\u064a \u0639\u0644\u0649 " +
    "\u062d\u062f \u0633\u0648\u0627\u0621 \u0645\u0646\u0627\u0642\u0634\u0629 \u0633\u0628\u0644 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u064a\u0648\u0646\u0643\u0648\u062f \u0641\u064a " +
    "\u0627\u0644\u0646\u0638\u0645 \u0627\u0644\u0642\u0627\u0626\u0645\u0629 \u0648\u0641\u064a\u0645\u0627 \u064a\u062e\u0635 \u0627\u0644\u062a\u0637\u0628\u064a\u0642\u0627\u062a " +
    "\u0627\u0644\u062d\u0627\u0633\u0648\u0628\u064a\u0629, \u0627\u0644\u062e\u0637\u0648\u0637, \u062a\u0635\u0645\u064a\u0645 \u0627\u0644\u0646\u0635\u0648\u0635 \u0648\u0627\u0644\u062d\u0648\u0633\u0628\u0629 " +
    "\u0645\u062a\u0639\u062f\u062f\u0629 \u0627\u0644\u0644\u063a\u0627\u062a.\n\n";
    /** arabic text */
    public static String ar4 = "\u0639\u0646\u062f\u0645\u0627 \u064a\u0631\u064a\u062f \u0627\u0644\u0639\u0627\u0644\u0645 \u0623\u0646 \u064a\u062a\u0643\u0644\u0651\u0645, \u0641\u0647\u0648 \u064a\u062a\u062d\u062f\u0651\u062b \u0628\u0644\u063a\u0629 \u064a\u0648\u0646\u064a\u0643\u0648\u062f\n\n";
    /** hebrew text */
    public static String he1 = "\u05d0\u05d9\u05e8\u05d5\u05e4\u05d4, \u05ea\u05d5\u05db\u05e0\u05d4 \u05d5\u05d4\u05d0\u05d9\u05e0\u05d8\u05e8\u05e0\u05d8:\n\n";
    /** hebrew text */
    public static String he2 = "Unicode \u05d9\u05d5\u05e6\u05d0 \u05dc\u05e9\u05d5\u05e7 \u05d4\u05e2\u05d5\u05dc\u05de\u05d9\n\n";
    /** hebrew text */
    public static String he3 = "\u05d4\u05d9\u05e8\u05e9\u05de\u05d5 \u05db\u05e2\u05ea \u05dc\u05db\u05e0\u05e1 Unicode \u05d4\u05d1\u05d9\u05e0\u05dc\u05d0\u05d5\u05de\u05d9 \u05d4\u05e2\u05e9\u05d9\u05e8\u05d9, \u05e9\u05d9\u05d9\u05e2\u05e8\u05da \u05d1\u05d9\u05df \u05d4\u05ea\u05d0\u05e8\u05d9\u05db\u05d9\u05dd " +
    "12\u05be10 \u05d1\u05de\u05e8\u05e5 1997, \u05d1\u05de\u05d9\u05d9\u05e0\u05e5 \u05e9\u05d1\u05d2\u05e8\u05de\u05e0\u05d9\u05d4. \u05d1\u05db\u05e0\u05e1 \u05d9\u05e9\u05ea\u05ea\u05e4\u05d5 \u05de\u05d5\u05de\u05d7\u05d9\u05dd \u05de\u05db\u05dc \u05e2\u05e0\u05e4\u05d9 \u05d4\u05ea\u05e2\u05e9\u05d9\u05d9\u05d4 " +
    "\u05d1\u05e0\u05d5\u05e9\u05d0 \u05d4\u05d0\u05d9\u05e0\u05d8\u05e8\u05e0\u05d8 \u05d4\u05e2\u05d5\u05dc\u05de\u05d9 \u05d5\u05d4\u05beUnicode, \u05d1\u05d4\u05ea\u05d0\u05de\u05d4 \u05dc\u05e9\u05d5\u05e7 \u05d4\u05d1\u05d9\u05e0\u05dc\u05d0\u05d5\u05de\u05d9 \u05d5\u05d4\u05de\u05e7\u05d5\u05de\u05d9, " +
    "\u05d1\u05d9\u05d9\u05e9\u05d5\u05dd Unicode \u05d1\u05de\u05e2\u05e8\u05db\u05d5\u05ea \u05d4\u05e4\u05e2\u05dc\u05d4 \u05d5\u05d1\u05d9\u05d9\u05e9\u05d5\u05de\u05d9\u05dd, \u05d1\u05d2\u05d5\u05e4\u05e0\u05d9\u05dd, \u05d1\u05e4\u05e8\u05d9\u05e1\u05ea \u05d8\u05e7\u05e1\u05d8 \u05d5\u05d1\u05de\u05d7\u05e9\u05d5\u05d1 " +
    "\u05e8\u05d1\u05be\u05dc\u05e9\u05d5\u05e0\u05d9.\n\n";
    /** hebrew text */
    public static String he4 = "\u05db\u05d0\u05e9\u05e8 \u05d4\u05e2\u05d5\u05dc\u05dd \u05e8\u05d5\u05e6\u05d4 \u05dc\u05d3\u05d1\u05e8, \u05d4\u05d5\u05d0 \u05de\u05d3\u05d1\u05e8 \u05d1\u05beUnicode\n\n";
    if you noticed this code, you will find that the data that he want to put it in a PDF file,he already know its unicode as in (ar1,ar2,ar3,.....) and when you run this code you will get a PDF file with an Arabic and hebrew language.
    that means he can convert the unicode to the equivalent character.
    but in my code that I put in the previous post does not do that.
    and this is my problem again:
    if you noticed these classes or objects :
    PdfPCell (class), table (object ), document (object)
    I used these classes from free library called (iText) if you know it.
    to help me store data that i retrieve it from database in a PDF file.
    my problem is when I used the above code as it is, it will stores the data that I retrieve it from database as "\u0030\u0039\u0061\u0041"
    and it didn't give me the equivalent word for this unicode.
    but if I changed the variable (w) in the following statement from the code:
    PdfPCell cell = new PdfPCell(new Phrase(w,f2));
    and put this string "\u0030\u0039\u0061\u0041" instead of it
    it will store the equivalent word for this unicode in the PDF file.
    what can I do now?
    and what is the problem in my code?
    is there any improvments can I do it ?
    please help
    Message was edited by:
    ahd292000

  • Unicode(String) to actual Unicode !

    Hi, i have an unicode data which is retrieved from database, the unicode is in String format(\u4eba\u53c2), how to make it to be actual unicode "\u4eba\u53c2". i have a problem where the unicode from database doesn't give me the actual character but the unicode string itself. Please comment on it . Thanks.
    _calv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi Calv,
    I'm pretty sure that the conversion from the ASCII string to Unicode is not available within the API. (If someone knows otherwise please jump in). However it should be fairly easy for you to program this conversion: for example, you could parse your string into the six character substrings that represent characters, strip off the \u, and then cast the sixteen bit integer into a Character.
    In case it's helpful, I am pasting a couple of methods I wrote to go in the opposite direction:
    returns a (ASCII) string that represents the specified character by a  unicode escape sequence
    static public String toUnicodeString(  char character) {
         short unicode = (short) character;
       char hexDigit[] = {
          '0', '1', '2', '3', '4', '5', '6', '7',
          '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
       char[] array = {hexDigit[( unicode >> 12) & 0x0f],hexDigit[( unicode >> 8) & 0x0f],
            hexDigit[( unicode >> 4) & 0x0f], hexDigit[ unicode & 0x0f] };
    String result = new String ("\\u" + new String (array));
       return result;
    returns a (ASCII)  string representing the java string argument:
    e.g. -> "\u1234\u5678"
    static public String toUnicodeString(  String  string) {
         String result = "\"";
         for (int   index =      0; index < string.length (); index++) {
              result = result +  toUnicodeString (string.charAt (index));
         result = result + "\"";
       return result;
    }   Regards,
    Joe

  • How do I get the proper UTF-8 NVARCHAR2 DB Value into a Java String?

    Hello, I have a mixed char 8.1.7 database with UTF-8 as my NLS
    charset. I used SQL Worksheet to enter test polish unicode
    characters 50309,50310... into an NVARCHAR2 column using
    insert...char(nnn using NCHAR_CS) and get the following result
    from DUMP(columnname,1016):
    Typ=1 Len=12 CharacterSet=UTF8:
    c4,85,c4,86,c4,87,c4,88,c4,89,c4,8a.
    Everything looks good.
    Now, how do I get them out into a Java String and verify that I
    have received the correct hex codes?
    I have tried:
    1. CHAR lChr = OracleResultSet.getCHAR(ColumnName, csUTF8); or
    and lChr.characterStreamValue();
    2. InputStream lIStr = arsResultSet.getBinaryStream(ColumnName);
    3. String lStr = (String)arsResultSet.getObject(ColumnName);
    and then:
    lStr.getBytes("UTF-8"); or lStr.toCharArray();
    I always get questions marks and negative byte values or the
    values: 261,262,263,264,265,266.
    I am using the latest 9.0.1. JDBC Thin drivers and the Oracle
    extensions: OracleResultSet, OracleStatement etc...
    Please let me know what class/method I need, to get the Oracle
    NVARCHAR2 unicode string from the result set into a Java string
    and what method to use to look at the underlying hex codes.
    TIA for any pointers.

    If I use in bdInt=sc.nextInt();a substring cannot be used.
    Does anyone know how I solve this question without substring? Perhapse something I've mentioned above
    sincerely h

  • Help on processing french character with java String class

    hi all
    i have a question about processing french character. i have a file that contains french characters such as �, when it is read in and assigned to a string variable, it becomes &#9577;, how can i preserver the french characters? thanks

    The following interfaces exist in the above
    - The database
    - Reading the data from the database
    - Writing the data using println.
    - Reading data from a file.
    You need to identifier exactly what data exists
    at each interface.the data in xml contains french characters. and i need to store it in the sql server. somehow when it was read in, it was changed to something else.
    Internally java keeps characters in unicode so you can
    definitely get that character into unicode. However
    just because it is in java does not mean that
    println() is going to display it. Because when
    println() runs it converts the unicode into a
    character set (which is determined by the computer,
    OS, and other factors.)
    So the first step is to determine the numeric value of
    the character in all of the interfaces above. For
    example it doesn't matter what you do in java if the
    character in the database is not what you think it is.
    Or if the driver converts it when it gets read.
    are u saying that i need to get the numeric value of the character first? how would i save it in the DB?

  • Setting compile date & time to a Java String variable

    I was wondering does the NetBeans IDE have a capability to grab the current compile date & time and set it to a Java String, updating it at each compile. I know you can set is in a template, but isn't that fixed once forever when the file is created.
    Just wondering.

    If you're using Ant you can have it maintain a file with the last build date in it, and that can be a .java file if you so desire.
    Applications should be completely recompiled before shipping or deployment so it doesn't really make sense to have a compile date per Java source file.

  • Maximum size of a Java String

    Hello
    Can anyone please tell me what would be the maximum size for a java string....
    Thanks
    Tapan

    You are asking the wrong questions. If you are going to have a really, really big string then the chances are you shouldn't be using strings.
    If you are trying to parse a file then you want to be reading it in chunks at a time.
    Tell us what you are trying to do and maybe we can suggest a better solution.
    See, I am a nice person. I just don't like people who are too lazy to writepublic static void main(String args[]) {
      System.out.println(Integer.MAX_VALUE);
    } That took me around 10 seconds.
    Ted.

  • Converting Oracle XML Query Result in Java String by using XSU

    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

    Hmmm.. Pretty basic just look at the example:
    OracleXMLQuery qry = new OracleXMLQuery(conn,"Select max(ps.datum) from preise ps where match='"+args[0]+"'");
    String xmlString = qry.getXMLString();
    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

  • Slow to convert Oracle 11g XMLType into Java String or Document

    After retrieving a result set from an Oracle 11g database, it takes roughly 75 seconds to convert the XMLType (this is a structured XML Storage, registered with an xsd) into either a java String or Document. I'm using Java 1.6, have the xdb.jar and xmlparserv2.jar
    This xsd is <100 lines and the xml document is also <100 lines.
    Sample code:
    oracle.xdb.XMLType xml = oracle.xdb.XMLType.createXML((oracle.sql.OPAQUE)rset.getObject("XMLDATA"));
    the other way, but still took just as long:
    XMLType xml = (XMLType)rset.getObject("XMLDATA");
    xml.getStringVal();
    or
    org.w3c.dom.Document doc = xml.getDocument();
    either way of the above ways takes just as long.

    If I put this value into the database table, I can
    see only the date. Time part is missing. Is this the
    problem with java.sql.Date or Oracle datatype Date?This is not a problem, this is the defined behaviour of the Date type. RTFAPI and have a look at Timestamp, while you're at it.

  • Java Add-in or unicode conversion first?

    Hi all.
    I have just performed a BW 3.5 (NW 6.40) to BI 7.0 (NW 7.0) NON-unicode upgrade. The next two things we want to do are unicode conversion and java add-in installation.
    I am wondering which of these actions should come first; Java add-in or unicode conversion?
    Any thought on this?
    Regards,
    Thomas

    It´s pretty straighforward using the sapinst.
    Make sure you patch up the AddIn to the same patchlevel your ABAP is running on (means,if you BIND support package 13 to the upgrade, upgrade the Java engine to SP13 as well after installation).
    Personal opinion:
    If we have the choice we don´t use the Java Addin but install the Java part on a separate system. The Addin adds more complexity and dependency to the system. On top of that it makes memory configuration and predictability of sizing very difficult.
    This is - however - my personal opinion, this may or may not be true for your environment.
    Markus

  • How many java String objects are created in string literal pool by executin

    How many java String objects are created in string literal pool by executing following five lines of code.
    String str = "Java";
    str = str.concat(" Beans ");
    str = str.trim();
    String str1 = "abc";
    String str2 = new String("abc").intern();
    Kindly explain thanks in advance
    Senthil

    virtuoso. wrote:
    jverd wrote:
    In Java all instances are kept on the heap. The "String literal pool" is no exception. It doesn't hold instances. It holds references to String objects on the heap.Um, no.
    The literal pool is part of the heap, and it holds String instances.
    [http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#22972]
    [http://java.sun.com/docs/books/jvms/second_edition/html/ConstantPool.doc.html#67960]
    You're referring to the JVM. That's not Java.It's part of Java.
    There is nowhere in Java where it is correct to say "The string literal pool holds references, not String objects."

  • Help:How to get a java String value from a C char array?

    Hi,everyone,could you help me?
    the following is a C struct that i want to recieve a short message:
    struct MO_msg{
    unsigned long long msgID;          //Message ID
    char      dest_id[21]; //Destination Mobile Phone Number
    char      service_id[10];     //
    Now I want to put the "dest_id " value of this struct into a Java String variable.But I dont know how to implement it!
    The following is a block of source code that i implement this functions.But it cant get a String value ,and throw out a Exception:
    java.lang.NullPointerException
    at java.lang.StringBuffer.append(StringBuffer.java:389)
    JNIEXPORT jint JNICALL Java_md_EMAP_thread_RubeMOTSSX_getMO
    (JNIEnv * env, jobject obj, jint connId, jobject mo){
         struct MO_msg MO;
         tssx_cmpp_api_debug_flag = 1;
         int result = CMPP_Get_MO((int)connId,&MO);
         if (result == 0){
              jclass cls = (*env)->GetObjectClass(env,mo);
              jfieldID msgId = (*env)->GetFieldID(env,cls,"msgId","J");
              jfieldID dest_Id = (*env)->GetFieldID(env,cls,"dest_Id","Ljava/lang/String;");
              jfieldID serviceId = (*env)->GetFieldID(env,cls,"serviceId","Ljava/lang/String;");          
              (*env)->SetLongField(env,mo,msgId,MO.msgID);               
              (*env)->SetCharField(env,mo,dest_Id,*destId);
              (*env)->SetCharField(env,mo,serviceId,MO.service_id);
         return result;
    Please help me!Thanks!

    bschauwe:Thank you for your help!
    Yes,just as you say,using NewString Or NewStringUTF can import a C char array into a Java String variable! But now I have another question,when i use these two functions ,i found that it cant deal with Chinese character!
    do you have such experiences to deal with another language charset?if you have ,can you tell me how to deal with it.

  • Having trouble converting array to spreadsheet string, storing the file and coverting back to array with complex numbers

    I am working with a network analyzer. I have arrays made of 5 columns the first consisting of an integer and the next four consisting of complex numbers. I am converting the array into a spreadsheet string and then saving the file using the write characters to a file VI. That seems to work well as when I open the file in Excel all the data is there. However when I try to reverse the process, open file and convert back to array, I loose some of the data. Specifically the imaginary parts of my complex numbers are all going to zero. I have narrowed down the problem to be in the conversion from spreadsheet string to array and vice versa. I
    think the problem may be with the 'format' input to the VI. I do not have an adequate resource for this so I am not sure what to put in to accomplish my task. Any takers?

    Hi Biz
    I don't think there is a direct way of converting a complex number to a
    string, so when you convert the array to a spreadsheet string, the
    numbers would be converted to real data.
    However, you could try separating the real and imaginary parts using the
    "Numeric: Complex to Re/Im" function, and then store these - either in
    separate files or in adjacent columns/rows in the same file. Then, when
    you read in the data again, use the "Numeric: Re/Im to Complex" function
    to put the two "halves" together.
    If you actually want Excel to interpret the numbers as imaginary, then
    you'll probably want to create a string for each complex number of the
    form "Re + Im*i" (after separating the Re and Im parts), by using
    "String:Format into String" with 2 numeric inputs and the format string
    "%f+%fi".
    Reading the data back into Labview then would require splitting the
    string into the 2 pieces by using "Stringcan from String" with 2
    numeric outputs (smae precision as original numbers specified by the 2
    Default Value inputs) and the same format string "%f+%fi", and then using
    the above-mentioned "Numeric: Re/Im to Complex" function. It worked for
    me, so if you can't follow what I am describing, send me an email and I
    can email you what I did (LV 5.1.1).
    Paul
    Biz wrote:
    > Having trouble converting array to spreadsheet string, storing the
    > file and coverting back to array with complex numbers
    >
    > I am working with a network analyzer. I have arrays made of 5 columns
    > the first consisting of an integer and the next four consisting of
    > complex numbers. I am converting the array into a spreadsheet string
    > and then saving the file using the write characters to a file VI. That
    > seems to work well as when I open the file in Excel all the data is
    > there. However when I try to reverse the process, open file and
    > convert back to array, I loose some of the data. Specifically the
    > imaginary parts of my complex numbers are all going to zero. I have
    > narrowed down the problem to be in the conversion from spreadsheet
    > string to array and vice versa. I think the problem may be with the
    > 'format' input to the VI. I do not have an adequate resource for this
    > so I am not sure what to put in to accomplish my task. Any takers?
    Research Assistant
    School of Physiotherapy, Curtin University of Technology
    Selby Street, Shenton Park, Western Australia, Australia. 6008
    email: [email protected]
    Tel. +61 8 9266 4657 Fax. +61 8 9266 3699
    "Everyone who calls on the name of the Lord will be saved." Romans 10:12
    "For all have sinned and fall short of the glory of God, and are
    justified freely by his grace through the redemption that came by Christ
    Jesus." Romans 3:23-4

  • How to convert Java string into XML one?

    With SAX I can parse an xml file, but I should create xml file by hands.
    Ok, it's simple, but how to encode java string into XML constant
    like "Hello & goodby" into "Hello & goodby" ?
    Is there a standard method for such special xml characters?

    If you are creating your XML "by hand" then just make sure your hands know that you have to do that. It isn't difficult to write a Java method to do it, if "by hand" means "in Java code". Otherwise your XML is not well-formed. And as far as I know there is no package that takes ill-formed XML and fixes it up.

Maybe you are looking for

  • How to Perform a "Clean Install" - Offline installer link not working...

    The thread containing - "How to Perform a Clean Install of Flash Player in Mac OS X" -  was an answer given by Mike M. several times in this forum. I attempted to access the "offline installer" link that was offered, but it does not seem to be workin

  • Help! Table not shown in browser!!!!!!

    I never had this problem. The JTable is not shown at all!!! The JTable is embedded in an applet. I had similar program done (posted the code here) for another dataset and it works perfectly well. I'm suspecting the renderers. Here is the relevant cod

  • Adobe Photoshop crashes!

    So I have had Photoshop CS3 for a while and then one day when I tried to access it again it decided to crash upon loading it. It has worked before and I have tried removing the preferences file but nothing seems to help. I have even looked all over t

  • Why are none of my midi controllers not working with my new MacBook Pro?

    I am running OS X 10.7.3 None of my M-Audio midi controllers are syncing with my new MacBook Pro. They are all class-compliant and willl work on Mac OS X without the need of a driver is what M--Audio has posted on there website for all of my controll

  • Attempting to sort recordset off our iseries

    I have a problem that I would appreciate assistance with.  I have successfuly created a recordset that pulls data off our iSeries.  I have created a table from the recordset, but upon the review of the content of the table by meeting attendees it was