You can’t use classes in the default package from a named package. So except for tiny experiments, always put your classes in a named package of the form com.mindprod.xxx or org.hans.xxx i.e. your domain name backwards, all lower case. If you don’t have one, you can buy a domain for about a year. You don’t need a website. Failing that, borrow a branch of dyndns.org or other domain with the owner’s permission.
When a source file gets too large, you can split it up, and still have it behave much as if it were one file by declaring all the parts as belonging to the same package. In C++ terminology, all classes in the same package are friends of each other. You just add a line such package com.mindprod.business; at the top of each source *.java file. You use your website name backwards to ensure global uniqueness. The more qualification you have specified in your CLASSPATH the less qualification you are allowed to specify in your import statements. There is no redundancy permitted. It is not enough to simply have your class files on the classpath. They must be in particular locations or inside jars on the CLASSPATH with just the right embedded path information. If you can’t understand my handwaving, try reading
.Sun tends to put the core classes in the java.* package, the slightly more peripheral classes such as Swing and JavaMail in javax.* and the classes they don’t want users invoking directly in com.sun.*. The core distribution JDK contains all three types, though it excludes some of the javax and com.sun classes.
Traditionally packages have all lower case names, and like all Java names they are case sensitive. In contrast, Sun coding standards require classes to begin with a capital letter and ordinary variables and methods with a lower case letter. Embedded words are capitalised.
According to Sun’s Naming Conventions, you should choose your package name to match your website. e.g. com.mindprod or ca.mindprod with the TLD first. This ensures globally unique package naming.
If you can’t afford to register your domain, pick an obscure one, and check if it is already registered by someone else. If not, you can squat on it, with the possibility somebody might take it from you. Alternatively, use a domain with an illegal TLD (Top Level Domain) e.g. mindprod.programs or roedy.green so your package would be programs.mindprod.xxx or green.roedy.xxx.
When you decide to bring your existing work into alignment with this naming convention, make sure you update:
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.58] | |||
| You are visitor number 47,073. | |||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | ||
| http://mindprod.com/jgloss/package.html | J:\mindprod\jgloss\package.html | ||