Java Package

  1. One class per file.
  2. Class files can be organized into directories.
  3. Every file in a dir needs to declare package ‹dir name›; to make them into a package unit.
  4. The main program can refer to these classes by full name, like this: ‹dir name›.‹class name›.
  5. packages can be nested, the human programer still needs to specify the full relation in each file's package declaration. 
  6. To create a unit of code set, you create a “package” by putting class files in a directory, and each file must declare package ‹dirName›;
  7. Java's unit of code set, called “package”, can be nested. This means, that class files are placed in nested directories, and each class file must declare its full dir path, separated by dot: package dir1.dir2;.
  8. the “import” keyword is used to avoid typing long reference names to classes. And, it import classes, not packages. To import all classes in a dir, use the syntax idiosyncrasy of asterisk suffix. Example: import pacman.*;
  9. The Java lang has no concept of importing a package or nested package. The syntax import pacman.* imports all classes under pacman dir, but does not import classes in subdirectories of pacman dir, and import pacman.*.* is illegal syntax.
  10. Note that Java interfaces can also be put into a package, just like classes. Like classes, it should be one-interface-per-file.
  11. With technicality, in Java, every file is in some package. If the file didn't declare a package, it is then in a “default package”, which is a package without name.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值