What is the package in Java (package) is actually a directory, which is to better manage the Java class (Class) and interfaces (Interface). The java language package can be used by another Java development package. If we want to reference the classes in a package, use the Import keyword to indicate it. For example: import java.util. Date = new date iPort java.util. indicates that all public classes and interfaces in java.util are introduced to the current package. The match here can be transferred into multiple class names. Commonly used Java standard package JDK provides us with a lot of standard Java classes and interfaces, which are necessary to write Java programs, know that the classes and interfaces included in each package, and familiar with these classes and interfaces are each Java The basic skills of programmers should master. Java usually used in Java.applet, java.awt, java.i, java.lang, java.net, and java.util, etc. The Java.applet contains some types of design minor applications (Applets); java.aw is a window toolbox (AWT BSTRACT Window Toolkit), which is some GUI interface related classes; Java.IO packet support input Output, such as file input streaming: fileInputstream, etc.; java.lang contains classes related to thread, exception, system, integer, etc., is a package that is loaded in the Java program; java.net supports TCP / IP network protocol, and The class containing the socket class and the URL is the use of the network programming; java.util contains the utility classes of some programs, such as DateDictionary, and more. In addition to some of the standard packs mentioned above, there are many other packages, such as database programming, we may need to use java.sql package, write network programs and use the java.rmi package (RMiRemote Method Invocation, etc. . In addition, Javax. is extension of some standard packs, common packages are: javax.swing, javax.sound. The package you have to create a package Java is you can create yourself. We can put a lot of features similar to the same features in the same package to facilitate management and use. Basic ways to create a package 1. Define the public class; 2. First sentence plus "package"; 3. Place the Class generated by the Java file is placed in the directory named directory name. 4. In other programs " IMPORT package name You can access all public classes in this package. Create and use //filenameb.java package com.chen.test // Define a package public class b // Define a class public void add int jma // two numbers And, and output system.out.printlni jma. The code above is to create a simple package: com.chen.test, we name this file B.java. Run Javac -D C / B.java compile this package (this command generates a COM / CHEN / TEST directory under the C drive, and saves the compile results in B.Class). Now we entered the C / COM / CHEN / TEST directory to see compilation and generated Class files are also included. OK, now this package has been created, then you need you to do it in your environment variable ClassPath in your environment variable.
How to call the package now to call the package created above with a small program: //filename a.java import com.chen.test. // Introduced the original package PUBLIC CLASSTRING PUBLIC VOID Main ARGS B Test = New B Test.add6 8 // Use ADD Cable Custom Pack to save the top Java code as c / a.java, then compile: Javac C / a.java. Tip: For package files B.java, you can only put it in the C / COM / CHEN / TEST directory. It should be noted that A. Java and B.java two files cannot be placed in the same directory so that it will be wrong. Java documents and Javadoc In addition to the package, Java documents are also a very important concept in Java programming. The Java document is the help document for the Java program. In general, let's write a help documentation and use tool javadoc to generate a corresponding document. Javadoc is a document generating tool provided by JDK. It uses Java Compile Javac to grammarize the declaration and document comments in the program code source file, and generate a set of HTML documents by default to describe classes, internal classes, interfaces, Construction functions, methods and domains. Javadoc comments start with "", end with " /", can contain normal text, HTML tag, and Javadoc tags. Javadoc only handles the comments before the class / interface definition, method, domain, and constructors before the source file, ignore the comments of other places. Master Javadoc now use one routine to illustrate the meaning of Javadoc tag: / j @ Author Warton2003 Xi'an Test < - here can be embedded in HTML This sentence is HTML Note -> @ Version 0.1 2004/01/01 / public class javadoctest / @ @ See # mainjava.lang.string / static string sdisplay / Show javadoc test @ param args command line parameter @ Return no return value / public static void mainstring args sdisplay = "javadoc test" system.out.printlnsdisplay In this Java program, a large number of Javadoc tags, text, and HTML tags are used. Javadoc marks start with "/ ", indicating that these are comments for Java code. The mark started by "@" is JavaDoc tag. The Javadoc marks have two: Standalone tags and inline tags. Independent markers are those common tags, such as @ param, @ return, and @Author, etc.; another type of tag is the inline mark This tag is used in the form of @ tag it allows developers to create hyperlinks The comment section is linked to other Javadoc pages or elsewhere on this page. Tip: Using Javadoc tags correctly in the Java source program is a very necessary annotation habit, will help Javadoc automatically generate a complete format API document with source code files. OK, then let's take a look at how Javadoc generates a beautiful document! Save the above code to JavadOCtest.java and compile.
Run: javadoc -private -d doc -auth or -version javadoctest.java, the Javadoc program generates a doc directory according to JavadOCtest.java, there are many HTML files, which are the API help documentation generated by Javadoc. Javadoc command line syntax will use tags to use the functions provided by Javadoc, you must use its command line. Finally, introduce you to the simple javadoc command. Javadoc's command line syntax is as follows: Javadoc Options PackageNames SourceFiles @files Tip: For general applications, we only need to use the command lines such as Javadoc YourJavafile.java to help documents. If you need to customize the help document, you will use the parameters. In general, you can use the Javadoc Help command to view Javadoc's help documentation. In short, Javadoc provides a full-specific API document function. In software project management and development, Javadoc can not only reduce the amount of document work at the time of development, but also improve efficiency, but also very beneficial to future modifications and maintenance. Some detailed descriptions of Javadoc tags: @Author specifies the "Author" item in the generation of documents, you can specify multiple authors. In the left code, an HTML tag is added behind, which is used to link the URL. They are HTML tags, < ----> is HTML comment. @Version Specify version information. @See tags are more complicated. @see "String" Adds a text item for "String" and does not generate any links. @see label generates a link using an HTML tag. @see package.class # member label. @Param tag used to describe parameters. The @returN tag is used to describe the return value. @LINK is the inline mark, the usual format of the inline tag is: @linkPackage.class#member Label Tip: Label is a text in the middle of the comment, Package.class # Member points to a specific class or method. Here are some examples: Link to the same class, use: @ link # key Link to the same class, use: @Link # getcomponentatint GetComponentat Link to other classes, use @ linkjava.util.map MAP