What is the convention for word separator in Java package names?

Mobile Technologies Mobile Computing 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ How should one separate words in package names? Which of the following are correct? com.stackoverflow.my_package (underscore) com.stackoverflow.my-package (hyphens) com.stackoverflow.MyPackage (CamelCase) What is the general standard?

Posted on 16 Aug 2022, this text provides information on Mobile Computing related to Mobile Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ Here's what the official naming conventions document prescribes: Packages The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981. Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names. Examples com.sun.eng com.apple.quicktime.v2 edu.cmu.cs.bovik.cheese References java.sun.com - Code Conventions/Naming Note that in particular, anything following the top-level domain prefix isn't specified by the above document. The JLS also agrees with this by giving the following examples: com.sun.sunsoft.DOE gov.whitehouse.socks.mousefinder com.JavaSoft.jag.Oak org.npr.pledge.driver uk.ac.city.rugby.game The following excerpt is also relevant: In some cases, the internet domain name may not be a valid package name. Here are some suggested conventions for dealing with these situations: If the domain name contains a hyphen, or any other special character not allowed in an identifier, convert it into an underscore. If any of the resulting package name components are keywords then append underscore to them. If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component. References JLS 6.1 Package Names

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Mobile Technologies Links