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 (Java Development Kit) 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 Oracle’s Naming Conventions, you should choose your package name to match your website, e. g. com.mindprod or ca.mindprod with the TLD (Top Level Domain) 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 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:
This page is posted
Optional Replicator mirror
|no blog for this page||Canadian
Your face IP:[188.8.131.52]
You are visitor number|