How to Detect CJK in Java
Since Java programming language is a widely-used, open source technology, incorporation and integration of foreign languages into the program is quite common, such as Chinese, Japanese and Korean (CJK.) These languages use special characters and images that differ from the English alphabet letters, therefore it is necessary to use a special third-party tool, such as CJK Key software, to decode them in Java. Detection of these characters can also be done by employing certain Java classes: InputStreamReader and OutputStreamWriter.
Instructions
-
-
1
Download and install the Java Runtime Environment (JRE) to your system from Java.com. JRE will enable you to run the CJK Key application and load the Java applet automatically, which will prompt you for your CJK username and password. You must register if you are a first-time user of the KEY server.
-
2
Enter your desired login name, password, real name and email address, and then hit "Submit" to complete your KEY applet registration. You must also download Microsoft CJK fonts to work with the Chinese, Japanese and Korean languages. The required Chinese fonts namely Pinyin with Tones, and Chinese character font, will be automatically provided by the KEY software.
-
-
3
Input the following codes to automate the discovery of CJK characters in your Java strings.
The code below will return "true" if the string S contains double-byte characters:
public boolean containsDoubleByte(String s) {
for (int i=0;i<s.length(); i++) {
if (isDoubleByte(s.charAt(i)) {
return true;
}
}
return false;
}
The following code will return "true" if the string C is a double-byte characters:
public boolean isJapanese(char c) {
if (c >= '\u0100' && c<='\uffff') return true;
return false;
// simpler: return c>'\u00ff';
}
-
1
Tips & Warnings
You may work on other projects while waiting for the CJK Key server to install, which will take about 20-30 minutes to complete. The complete samples of Java coding that can be used to automate your CJK characters discovery are available at Seba Ulyssis' site.
References
Resources
- Photo Credit Comstock/Comstock/Getty Images