Subpackages tương tự sub-directories. Ví dụ: company có package com.apple.computers chứa file nguồn Dell.java, nó sẽ nằm trong chuỗi subdirectories:
....\com\apple\computers\Dell.java
Khi compile, compiler tạo file output khác nhau cho mỗi class, interface, enum định nghĩa trong đó. Tên cơ sở của output file là tên type, phần mở rộng là .class.
Ví dụ:
// File Name:Dell.java
package com.apple.computers;
public class Dell { }
class Ups { }
Compile file này với tùy chọn -d:
$javac -d.Dell.java
Các file sẽ compile như sau:
.\com\apple\computers\Dell.class .\com\apple\computers\Ups.class
Bạn có thể import tất cả class/interface trong \com\apple\computers\ như sau:
import com.apple.computers.*;