Carefully touch the "documents" and "packages" in Java programming

Source: Internet
Author: User
Tags date define command line html tags net version touch window
Programming
What is a package Java package (Package) actually refers to the directory, which is to better manage Java classes (class) and Interfaces (Interface). The Java language package can be used by another Java development package. If we want to refer to a class in a package, use the Import keyword to mark it. For example: Import java.util.date=new date hint: Import Java.util. means that all public classes and interfaces in Java.util are introduced into the current package.  The  match here can be called into multiple class names.  The common Java Standard Package JDK provides us with a number of standard Java classes and interfaces that are necessary to write Java programs, know the classes and interfaces that each package contains, and are familiar with these classes and interfaces as basic skills that every Java programmer should master. Common packages in Java are: Java.applet, java.awt, JAVA.I, Java.lang, java.net, and Java.util, and so on. The java.applet contains classes and interfaces for designing small applications (applets); java.awt is a window Toolbox package (awtabstract window Toolkit) with some GUI-interface-related classes java.io package support input and output, such as file input stream class: FileInputStream; Java.lang contains threads, exceptions, systems, integers, and other related classes, is the default load in Java program a package; java.net this class supports TCP/IP network protocols  , and contains the socket class and URL-related classes, which are to be used in network programming; Java.util contains common classes of programs, such as Datedictionary, and so on. In addition to some of the standard packages mentioned above, there are many other packages, such as database programming, we may need to use java.sql package, write network program will also use Java.rmi package (Rmiremote method invocation) and so on.  In addition, the Javax. package is a number of standard package extensions, commonly used packages are: Javax.swing, Javax.sound. Do it yourself. Packages in Java can be created by themselves.  We can put many functions similar to the class and interface in the same package, for easy management and use. The basic method of creating a package 1. Define the public class; 2. Add "package package name" to the first sentence; 3. Place the Java file generated class in a directory with the package name Directory name 4. "Import Package name" can be used in other programsAccess to all public classes in this package. Package creation and use//filenameb.java package com.chen.test//Define a package public class b//define a class public void Addint iint j//two number sum and lose The code above System.out.printlni+j is to create a simple package: com.chen.test, we name this file B.java. Now run javac-d c\ B.java compile the package (the command generates the Com\chen\test directory under C Disk and saves the compilation results in B.class).  Now that we have entered the C\com\chen\test directory, we can see that the compiled class file is also included.  OK, now that the package has been created, what you need to do is set the c\com\chen\test in your environment variable CLASSPATH. How to call a package now we use a small program to invoke the package created above://filenamea.java import com.chen.test.//introduces the package public class Apublic static void Ma just created  Instringargsb test = new btest.add68//use Add to invoke a custom package to save the above Java code as C\a.java and then compile: Javac C\a.java. Tip: For package file B.java, you can not compile  and just put it in the C\com\chen\test directory.  Note that the A.java and B.java two files cannot be placed in the same directory, making an error. Java Documents and Javadoc in addition to packages, Java documentation is a very important concept in Java programming. A Java document is a help document for Java programs. In general, we first write the help document and then use tool Javadoc to generate the appropriate documentation. Javadoc is a document generation tool provided by JDK that uses Java compiler javac to parse declarations and document annotations in the source file of a program code, and by default generates a set of HTML documents to describe classes, inner classes, interfaces, constructors, methods, and fields. The Javadoc annotation begins with "/" and ends with "/", which can contain plain text, HTML tags, and Javadoc tags. Javadoc only handlesComments in the source file before class/interface definitions, methods, fields, constructors, ignoring comments elsewhere. Master Javadoc Now let's use an example to illustrate the significance of the Javadoc tag:/ my Javadoc test program--javadoctest @author warton2003 XI ' an test<--this can be embedded in Html For HTML annotation --> @version 0.1 2004/01/01/public class Javadoctest/ in Main to use string  @see #main java.lang.str ing/static String Sdisplay/ display Javadoc test  @param args command-line arguments  @return no return value /public static void Mainstri ng Argssdisplay =″javadoc Test ″system.out.printlnsdisplay In this Java program, a large number of Javadoc tags, text, and HTML tags are used. The Javadoc tags start with "/", indicating that these are comments in Java code.  The mark at the beginning of "@" is the Javadoc tag. There are two types of Javadoc tags: standalone (Standalone) and inline (Inline) tags. Independent markers are those common tags, such as @param, @return, and @author.  ; Another type of tag is an inline tag  this tag takes the form of a  @tag   It allows developers to create hyperlinks from the comments section to other Javadoc pages or elsewhere on this page.  Tip: The proper use of Javadoc tags in Java source programs is a necessary annotation habit that will help Javadoc automatically generate complete formatting API documentation in source code files.  OK, let's take a look at how Javadoc generates beautiful documents! Save the above code to Javadoctest.java and compile it. Run: javadoc-private-d doc-auth or-version Javadoctest.java this time,  The Javadoc program generates a DOC directory based on Javadoctest.java, which has a lot of HTML files, which is the API help document that Javadoc generates. JavADOc command line Syntax light uses tags and does not make good use of the functionality provided by Javadoc, it must be able to use its command line.  Finally, let me introduce you to the simple Javadoc command. The command line syntax for Javadoc is as follows: Javadoc options packagenames sourcefiles @files  tip: For general applications, we only need to use the command line generation of Javadoc Yourjavafile.java to help Help the document on the line.  If you need to customize the Help document to use the parameters, you can usually use the Javadoc help command to view the Javadoc documentation. In summary, Javadoc provides the full specification of the API documentation functionality.  In software project management and development, the rational use of Javadoc can not only reduce the document workload in development, improve efficiency, but also very conducive to future software modification and maintenance. Some detailed instructions for the Javadoc tag: @author Specify the author item in the build document, you can specify multiple author. In the code to the left, author also adds an HTML tag to link the URL.  are HTML tags, <----> is an HTML annotation.  @version Specify version information. @see tags are more complex. @see ″string″ adds a text entry to "string" without creating any links. @see label produces a link using an HTML tag.  @see Package.class#member Label.  @param tags are used to describe parameters.  @return tag is used to describe the return value. @link is an inline tag, the usual format for inline tags is:  @linkpackage. Class#member Label Hint: The label is the text in the middle of the annotation, and the package.class#member points to a specific class or method. Here are some examples: linking to the same class of properties, using: @link #key link to the same class of methods, using:  @link #getcomponentatintgetcomponentat link to other classes, using @linkjava.util.map map    


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.