Reputation: 45
I'm a beginner in Java programming language, and I have a problem that I don't know how to solve. I need to represent special characters like "Ψ", "∑", "Θ", "Ξ", ",", "ß". how can I do it?
Update: Thanks for the answers, sorry for not detail a little bit more the question, so here i go. I'm trying make 7Bit alphabet, this is for encoding PDU for sent "SMS". http://pastebin.com/NtY1aWTR Here the class in java.
If the user enter character the method handle the value in 7Bits from the HashMap. For example : If the user enter " Votaguz " The result is: 1010110 1101111 1110100 1100001 1100111 1110101 1111010 But when the user try write something how : " Θ " [OMEGA] The Answer is: null null
Upvotes: 2
Views: 4337
Reputation: 8360
Java works with the Unicode character set internally, so can represent any of a vast range of characters. A character set is an arbitrary collection of "ideal characters", and doesn't really say anything about how those characters should be represented in memory, on disk, on the network, or anywhere else.
Java supports Unicode by using the UTF-16 encoding in memory – so most characters are represented by a 16-bit value but certain characters need 32 or more bits. Character encodings map a specific character set into the bytes (or other values) that represent them. Not all character encodings are capable of encoding all the characters in the Unicode character set. US-ASCII, for example, uses exactly 7 bits per character, and can only therefore represent 128 different characters.
In some cases, for example in html documents, it is possible to control which character encoding should be used. In other circumstances, the encoding to be used is assumed and cannot easily be changed.
It looks like the 7-bit encoding you are working with may be limited to 128 different characters too. Unless you can get that encoding changed, you are stuck with whatever 128 character set it supports.
Upvotes: 0
Reputation: 56822
Some options:
Type them on the keyboard, for example ß on a german keyboard.
Use a compose sequence, for example [compose] [s] [s] gives ß on my Linux machine. On MS-Windows it is usually [Alt[2][2][5]].
Copy and paste them from the character picker (or some other source) into the editor.
Look up their character codes at unicode.org, then use \uXXXX or generate them as characters in your application. Java char
are 16 bit and String
consists of 16 bit chars, so you get the Unicode base plane for free. (Some ancient scripts like hieroglyphics have character codes > 65536 in Unicode, these are not directly supported.)
For best effect use an editor and a console capable of using UTF-8, for example Eclipse.
Upvotes: 0
Reputation: 75426
If the characters are present in the encoding used on your platform (frequently codepage 1252 on Windows, corresponding to ISO-Latin-1) you can use them directly in your source code.
If you do not want to mess with codepage compatability you should represent characters outside standard ASCII (as those you have there) as \Uxxxx where xxxx is the hexadecimal representation for the Unicode value of the character you want. Tedious but portable.
Upvotes: 0
Reputation: 93197
Well those chars are in the unicode charset, so you can use them as is in your application. You might want to give additional informations and a use case to have a more precise answer.
Resources :
Upvotes: 3