English
For Packagers
Java is a programming language which is usually compiled into bytecode for JVM (Java Virtual Machine). For more details about the JVM and bytecode specification see link:http://docs.oracle.com/javase/specs/jvms/se8/html/index.html[JVM documentation].
Example Java Project
To better illustrate various parts of Java packaging we will dissect simple Java ``Hello world'' application. Java sources are usually organized using directory hierarchies. Shared directory hierarchy creates a namespace called `package` in Java terminology. To understand naming mechanisms of Java `packages` see link:http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html[Java package naming conventions].
Let's create a simple hello world application that will execute following steps when run:
Ask for a name
Print out ``Hello World from'' and the name from previous step
To illustrate certain points we artificially complicate things by creating:
`Input` class used only for input of text from terminal
`Output` class used only for output on terminal
`HelloWorldApp` class used as main application
Directory listing of example project
$ find .
.
./Makefile
./src
./src/org
./src/org/fedoraproject
./src/org/fedoraproject/helloworld
./src/org/fedoraproject/helloworld/output
./src/org/fedoraproject/helloworld/output/Output.java
./src/org/fedoraproject/helloworld/input
./src/org/fedoraproject/helloworld/input/Input.java
./src/org/fedoraproject/helloworld/HelloWorld.java
In this project all packages are under `src/` directory hierarchy.
HelloWorld.java listing
include::example$java_project/src/org/fedoraproject/helloworld/HelloWorld.java[]
Java packages
org/fedoraproject/helloworld/input/Input.java
org/fedoraproject/helloworld/output/Output.java
org/fedoraproject/helloworld/HelloWorld.java
Although the directory structure of our package is hierarchical, there is no real parent-child relationship between packages. Each package is therefore seen as independent. Above example makes use of three separate packages:
`org.fedoraproject.helloworld.input`