Carefully touch "Documents" and "Pack" in Java Programming

xiaoxiao2021-03-06  21

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 DateDictionary, 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 (RMiRemote 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 //filenameb.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.printlni 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.add6 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 # mainjava.lang.string  / static string sdisplay  /   Show javadoc test  @ param args command line parameter  @ Return no return value  / public static void mainstring args  sdisplay = "javadoc test"  system.out.printlnsdisplay   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.

转载请注明原文地址:https://www.9cbs.com/read-39920.html

New Post(0)