0

After reading the question Java packages com and org and answers, I am still curious:

  1. Is there some strict rule that I can use only com edu and org?
  2. And, is it bad idea to create package starting with something else than this?

Say, I am fro, Czech Republic and I own PavelJanicek company, can I create package which would be imported like

 import cz.paveljanicek.usable.awesomeutils;

edit: Since one of answers supposes it should be possible, can I apply it also to new domain TLDs?

example:

import berlin.berlincity.touristguide.api;
Community
  • 1
  • 1
Pavel Janicek
  • 14,128
  • 14
  • 53
  • 77

5 Answers5

1

You should check out this link: Java Packages and Java Package namings

You should also look at similar topic

At last a quote to add:

If you're just doing personal projects where nobody else will use the code, then you can make up a package name that you like. Don't make up something that starts with com. or net. or other top-level domain though, because that would imply that you own the domain name (ie. using com.john as your package name just because your name happens to be John is not a good idea).

If you're going to give the code to anybody else, you should use a globally unique package name, which according to Java conventions means you should register and use a domain name.

Short: Use whatever you like :)

Community
  • 1
  • 1
ManyQuestions
  • 1,069
  • 1
  • 16
  • 34
  • This answer references good information- if you take a look over the answering guidelines ( http://stackoverflow.com/help/how-to-answer ) the community recommendation is to provide some context for links in case the site goes offline in future. – glenatron May 15 '14 at 13:09
  • @HarmLezz Updated some parts – ManyQuestions May 15 '14 at 13:14
1

You missed a lot of the information given in the answer. Here once again a snipped of what Sun defined:

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.

Today we have even more top-level domains. The important part is to choose the domain you own in reverse order. I suggest you should read the answer once again, slowly. The goal is to avoid naming conflicts by choosing unique namespaces. And because domain names are already owned by a single company / person, they are good candidates to choose.

Community
  • 1
  • 1
Harmlezz
  • 7,972
  • 27
  • 35
  • specifically out of curiosity: Do TLD names like 'ninja' or 'berlin' apply to the rule? – Pavel Janicek May 15 '14 at 13:09
  • I would guess, YES. You may as well read the rules outlined [here](http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html) – Harmlezz May 15 '14 at 13:11
1

yes, that's the way you have to do if you own paveljanicek. there are a lot of 'com' and 'org', but you can find many others; for example, logback logging library contains classes in package

ch.qos.logback....
Snorky35
  • 426
  • 6
  • 15
1

You can use whatever you want just honoring the Java limitations for identifiers.

Said that, usually is safe using Java conventions, but killerapp.gui.Main is a valid class identifier

Pablo Lozano
  • 10,122
  • 2
  • 38
  • 59
1

A package name is defined by the language specification as a succession of valid identifiers, separated by ..

So the convention (for unicity purposes) is to use your domain name but any valid identifier can be used. This is a valid package name too:

é.è.û.¥
assylias
  • 321,522
  • 82
  • 660
  • 783