In the Characters API of Java 19, I saw 2 methods:
The first one is applied to Java identifiers and the second one for Unicode identifiers.
However, I don't understand the differences between two types of identifiers.
Anyone can explain? And some example please.
A Java identifier is a sequence of characters that will be recognized as an Identifier symbol by a Java compiler. This is specified in the Java Language Specification; see JLS 3.8
A Unicode identifier is something else entirely. Unicode identifiers are specified by Unicode document UAX #31 - Unicode Identifier and Pattern Syntax. It states:
A common task facing an implementer of the Unicode Standard is the provision of a parsing and/or lexing engine for identifiers, such as programming language variables or domain names. There are also realms where identifiers need to be defined with an extended set of characters to align better with what end users expect, such as in hashtags.
To assist in the standard treatment of identifiers in Unicode character-based parsers and lexical analyzers, a set of specifications is provided here as a basis for parsing identifiers that contain Unicode characters. These specifications include:
- Default Identifiers: a recommended default for the definition of identifiers.
- Immutable Identifiers: for environments that need a definition of identifiers that does not change across versions of Unicode.
- Hashtag Identifiers: for identifiers that need a broader set of characters, principally for hashtags.
In other words, these are a common syntax for identifiers defined by Unicode for use in various Unicode standards and data products, and software that "consumes" those products ... in some sense. They may also be adopted by other programming languages.
Java has NOT adopted Unicode identifiers. However, Unicode identifiers are used in some Java SE libraries; e.g. in Java regexes defined by the Pattern
class. (See the "Unicode Support" section of the javadoc for examples.)
I just want to know in what case (context) we use Java identifier ? Unicode identifier ?
Obviously you use a Java identifier in Java source code, and you use Unicode identifier when you need to refer to a Unicode script, block, category ... or similar.
Likewise, you use these methods when writing code to parse or check (respectively) Java or Unicode identifiers ... for some purpose. I will leave it to you to think of practical use-cases1.
1 - If you can't think of any, it doesn't matter. I can't think of practical use-cases for unicycles2 ... that's no reason for them to not exist either as a concept or in reality.
2 - I don't count pizza delivery by unicycle as practical.