Java package

To make classes easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups of related classes into packages. The package represents a specific directory structure. From within a package, all classes can access each other's members. From outside a package, only public and protected classes, methods, and variables may be accessed.

Companies invert their internet address for their package names, such as: com.company.package. Name collisions that occur within a single company need to be handled by elaborating on the package name. For example, a region or a project name can be incorporated into a package name like this: com.company.region.package.

The Java package prefix on the first page of the Web Interaction wizard, Specify a Name and Location for your Web Interaction, can be used to specify a prefix for the package name. The default value is retrieved from the Default Java package prefix defined in the New Dynamic Web Project wizard when the Struts feature is selected. You can also set your preference in Window > Preferences > Web Tools > Struts and JSF Preferences.

The Web Interaction wizard generates classes organized into three packages:
  • .actions - for Action classes
  • .beans for program call data beans
  • .forms - for Action Form beans.

If the Java package prefix is blank, then the Web Interaction wizard creates three packages for you. These packages are actions, beans, and forms.

At the same time that the package is created in the Java Resources folder, it is also created within the classes folder under WEB-INF. The package in the source folder will contain all of the .java source files generated by the Web Interaction wizard. The package in the classes folder will contain all of the compiled java .class files generated by the wizard.