java中选 import,Java中的 import

failing to get upper/lower case precisely correct in the import statement package and classnames.

failing to get upper/lower case precisely correct in the matching directories and *.java names. See classpath for more details.

failing to name each source module as X.java where X is the name of the public class defined in that source file.

Your imports must be accessible via the CLASSPATH.

Mismatch of CLASSPATH and import. The more qualification you specify in the CLASSPATH, the less you are allowed to specify in the import statement. You may not specify a directory both in the import and in the CLASSPATH. The import gives the lower levels of qualification the CLASSPATH the higher. Another way of stating this is your CLASSPATH should point to the directory just above the one named for your package’s highest level of qualification.

Wildcards are not as wild as you might expect causing you to fail to import each package branch separately. import java.awt.*; does not automatically import java.awt.event.* as well. You must separately import java.awt.event.*.

You can’t use wildcards on partial names, e.g. import java.awt.Text*;

You can teach your IDE to handle your imports for you. This save a great deal of mindless busywork.

It is a good idea to avoid wildcards, unless you have a very large number of classes. The list of explicit imports is great documenation on just what sorts of thing the class is doing/could potentially do.

If you have a class name used in more than one package, you will save yourself a lot of grief if you always fully qualify references to it, rather than relying on import. The computer may understand but, your fellow programmers will often be confused by the lack of qualification. Beware of java.util.List and java.awt.List.

Never use a classname (either in your package or in your anonymous package) that is also used in some other package. You are just begging for trouble. In theory the purposes of packages is to protect against name clashes, but as soon as you use import that protection is gone.

Package names should be pure lower case. Class names should begin with an upper case letter. Violating this convention will confuse the heck out of anyone trying to decipher your code.

You can write simple programs leaving out the package statement. However, this should only be used for programs that fit on one page. 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.

You must not import classes in the same package as the current class. If you are using the default nameless package, you must not import any other classes in the default package.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值