Java: conventions for using packages?

I come from the background of PHP, and due to the lack of namespaces in the past, I used the Zend Framework “package packages”. For example, if I have an abstract class Player and children Player_Human, Player_DumbComputer, Player_Minimax, etc., I would put Player in the main directory and put it in the / Player / directory. He tried to do something similar in Java, but I had a name clash - I have the blah.Player package and the blah.Player class. How can I avoid this? What is the common practice in this regard?

+3
source share
3 answers

Java package names are always lowercase, while class names always begin with an uppercase letter and are camel names (without underscores). So your structure should be:

- blah
|- Player.java
|- player
  |- HumanPlayer.java
  |- DumbComputerPlayer.java
  |- MinimaxPlayer.java
+4
source

From Code Conventions for the Java TM Programming Language :

Package naming conventions:

The unique package name prefix is ​​always written in lowercase ASCII letters and must be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of two English languages ​​that identify countries specified in ISO 3166 , 1981.

. , , , , .

:

. , . - ( , , URL HTML).

+6

Java makes extensive use of conventions for package names .

0
source

Source: https://habr.com/ru/post/1782757/


All Articles