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 (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 Sun’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:
available on the web at:
optional Replicator mirror
Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : . If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Your face IP:[18.104.22.168]
|Feedback||You are visitor number 63,038.|