What are connecting characters in Java identifiers?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
In the Java programming language, identifiers are used as names for various elements such as variables, classes, methods, and interfaces. It's imperative to understand the rules and conventions that govern how these identifiers can be constructed. A lesser-known concept related to identifiers in Java is that of "connecting characters."
Java Identifiers: The Basics
Identifiers in Java must adhere to certain rules:
- Must start with a letter: An identifier can begin with a letter (A-Z or a-z), a currency character (such as
$or¥), or a connecting character such as_. - Can include letters and digits: After the first character, identifiers can contain letters, digits (0-9), currency characters, or connecting characters.
- Cannot be a keyword: Java keywords cannot be used as identifiers.
- Case sensitivity: Identifiers are case-sensitive. For example,
Variableandvariableare distinct.
Understanding Connecting Characters in Java
Connecting characters in Java typically refer to those characters which can be used in the composition of an identifier but do not start the identifier. These characters often serve to "connect" different parts of the word or phrase within an identifier. The most common connecting character in Java is the underscore (_).
Technical Explanation
Java identifiers take into account the Unicode standard, which defines a slew of such connecting characters. In Unicode terms, a connecting character is any character whose category is Pc (Punctuation, Connector). According to the Unicode Standard, some examples include:
- U+005F Low Line (
_) - U+203F Undertie (
‿) - U+2040 Character Tie (
⁀)
Example Code
Here's an example of using a connecting character in a Java program:
Common Practices
The underscore (_) is the most practical and supported connecting character in Java source code. While Java theoretically supports other Unicode connector punctuations, usage is often limited due to lack of support from programming environments and readability concerns.
Summary Table
| Aspect | Details |
| Starting a Java Identifier | Letters, Currency Characters, Connecting Characters |
| Commonly Used Connector | Underscore _ |
| Other Connectors | Unicode Pc category (e.g., ‿, ⁀) |
| Readability | Prefer underscore for better readability and support |
| Unicode Support | Java supports Unicode identifiers, but environment support may vary |
Practical Advice
- Clarity and Convention: Given that Java encourages readable and maintainable code, the underscore is used most often when a connecting character is needed. Avoid using obscure Unicode connecting characters, as they can lead to confusion.
- IDE and Tool Support: Not all IDEs or version control systems properly display or manage nonstandard Unicode characters. Stick to ASCII-compatible characters where possible to ensure consistency across development environments.
- Identifier Conventions: In Java, naming conventions are vital. Typically, camel case is preferred for variables and methods (e.g.,
myVariableName), while the underscore is reserved for constants (MY_CONSTANT).
Conclusion
Connecting characters may not be frequent topics of discussion when learning Java, but they do play a role in the creation and readability of identifiers. By understanding these characters and employing best practices, developers can maintain clear and consistent codebases. Always prioritize readability and tool support to ensure your code is understandable and manageable across all development environments.
Related reading
- What are functional interfaces used for in Java 8?
- What are major differences between C and Java?
- What are major differences between C and Java?
- What are Runtime.getRuntime.totalMemory and freeMemory?
- What are spring-boot-starter jars?
- What are static factory methods?
- What are the -Xms and -Xmx parameters when starting JVM?
- What are the advantages and disadvantages of using feign over RestTemplate

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.