
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to use sub-package in Java?
Subpackages are similar to sub-directories. Consider an example. The company had a com.apple.computers package that contained a Dell.java source file, it would be contained in a series of subdirectories like this −
....\com\apple\computers\Dell.java
At the time of compilation, the compiler creates a different output file for each class, interface, and enumeration defined in it. The base name of the output file is the name of the type, and its extension is .class.
For example −
// File Name:Dell.java package com.apple.computers; public class Dell { } class Ups { }
Now, compile this file as follows using -d option −
$javac -d.Dell.java
The files will be compiled as follows −
.\com\apple\computers\Dell.class .\com\apple\computers\Ups.class
You can import all the classes or interfaces defined in \com\apple\computers\ as follows −
import com.apple.computers.*;
- Related Articles
- How to use classes in other package in Java
- How to access Java package from another package
- How to use the Time package in Lua programming?
- How to use functions from another package in Golang?
- How to run Java package program
- How to find package explorer in Java eclipse project?
- How to put two public classes in a Java package.
- How do I write package names in Java?
- How to import classes from within another directory/package in Java?
- How to use the sub process module with pipes on Linux?
- How to delete folder and sub folders using Java?
- overriding method different package in java
- How to resolve "Could not find or load main class package" in Java?
- How to add a sub-document to sub-document array in MongoDB?
- Accessing a Java class in other package.

Advertisements