Java programming things 73--jdk documentation use

Source: Internet
Author: User

Java programming things 73--jdk documentation use

Chen yuefeng

From: http://blog.csdn.net/mailbomb

Chapter 9 usage of JDK documentation

As mentioned above, a programming language consists of three parts: language syntax, development tools, and a set of basic functions. Java syntax and development tool JDK have already been introduced. This chapter will introduce the basic functions provided by Java.

For any programming language, a set of basic functions that have been compiled will be provided. This basic function released together with the language is generally called the application programming interface (API, application Programming Interface). It is also called a function library in a process-oriented language.
Library), which is also called a class library (Class
Library ).

This set of functions will be provided in specialized documents. In j2se development, this set of documents is called JDK documents. For example, the basic function of Windows is called Windows
API, and the document that consists of functions related to VB and VC development is called msdn.

This set of functions is the basic development technology that needs to be learned in the process of learning program design.

9.1 JDK document overview

The JDK document contains a description of all general class structures released to programmers in JDK. This document is a required reference for learning j2se programming, this document is provided by Sun in the form of a free HTML document. Of course, you can also download the chm format document prepared by others.

The JDK document is not released along with JDK. to use this document, go to the Sun website to download it. The latest JDK document is:

Http://java.sun.com/javase/downloads? Intcmp = 1, 1281

Select "Java SE 6 documentation" to download the file.

At the beginning of 06, Sun organized a specialist to translate the jdk5.0 document into Chinese. If it is difficult to read English, you can use the Chinese document:

Http://gceclub.sun.com.cn/chinese_java_docs.html

Note: It is recommended that you read the English documentation, because it can both exercise your English Reading Ability and read the latest documentation.

Note: The version of the document used is best matched with the JDK version used.

JDK documentation is provided in the form of a Web file compressed package. After downloading, you only need to decompress the package. You can decompress the package to any path as needed.

9.2 JDK document structure

Open the index.html file in the API directory in the jdkdocument directory to open the document structure, as shown in the following figure:

JDK
API document Diagram

In this document, the area in the upper left corner of the page shows a list of all the package names in the jdk api, and the area in the lower right corner shows all the class structures by default. If you select the corresponding package name, only information about interfaces, classes, exceptions, and errors in the package is displayed. Details are displayed on the right side of the page. When the corresponding class is selected, the details of the class are displayed.

For example, when you select the string class in the Java. lang Package, the displayed interface is as follows:

Document structure of the string class

The class document contains the following parts: class inheritance and inheritance, class declaration, class function description, attribute list, constructor list, and method list. Each attribute, constructor, and method in the class internal structure contains a hyperlink. You can click this link to view more details.

9.3 use syntax for classes and interfaces

In the JDK document, you can easily view the role of each class and the internal structure of the class, such as the constructor, attribute, and method. In the actual development process, you need to use the corresponding class according to the project requirements.

The specific class or interface to use and how to use the class or interface are the requirements of development technology. This section only summarizes the syntax knowledge related to the use of classes and interfaces.

Whether you use a class or interface, you must first introduce this structure. The syntax format is as follows:

Import
Package name. Class Name | *;

Note: "|" indicates the link or.

Note: The system automatically introduces classes and interfaces in the Java. lang package. Therefore, classes and interfaces in the package can be used without reference.

9.3.1 class syntax

There are only three methods used for the classes found in the JDK document: Inherit the class, use the class object, and call the static attributes or static methods in the class. The following describes the syntax related to these three usage methods.

9.3.1.1 syntax of the inherited class

If you use the classes provided in the JDK document in an inherited way, the corresponding syntax format is as follows:

1. Constructor

The first thing to note is that the constructor is not inherited. That is to say, the constructor In the subclass is not associated with the parameter list of constructor in the parent class.

If the inherited class, that is, the class provided in the JDK document, has a default constructor (that is, the constructor without parameters), the constructor of the subclass is automatically called internally, no special code is required.

If no default constructor exists in the inherited class, the constructor must be written in the subclass, in addition, you need to use the super keyword in the first line of the subclass constructor to call the corresponding constructor in the parent class. When using the super call, you must also input the corresponding parameters.

If the parent class does not provide a public or protected modifier, the class cannot be inherited.

2. attributes and Methods

After a class is inherited, all attributes and methods in the class are inherited. In the subclass, these structures can be used just like the declared attributes and methods.

Note: In the JDK document, only covered methods are listed separately in the Document. Uncovered attributes and rules are displayed below the attribute and method list.

The last syntax related to inheritance is that if the inherited class is an abstract class, it must overwrite the abstract methods in the parent class. Otherwise, the declared class must be declared as an abstract class.

9.3.1.2 use class objects

If you use classes by creating objects, this method is the most commonly used method, the syntax format is as follows:

1. Constructor

Declare the object first, and then use the New Keyword and constructor to create the object. When there are many constructor methods, call the constructor of the appropriate parameter list as needed. Read the parameter list carefully when calling the constructor.

Format:

Class Name
Object Name = new Constructor (parameter );

2. attributes and Methods

After the object is created, you can call the attributes and methods provided by the class through this object.

The syntax format for calling properties and methods is:

Object Name. Attribute or object name. Method (parameter)

9.3.1.3 static attributes and static methods of the call class

Static attributes and static methods in the call class. The Syntax provides a simple format:

Class Name. Static Property name and class name. Static Method Name (parameter)

Note: For static attributes and static methods inside the class, it is not recommended to use Object Name. Static attribute name and Object Name. Static Method Name for calling.

9.3.2 interface syntax

The interfaces provided in the JDK document are generally used in two ways: declare the object of the interface, implement the interface, and inherit the interface. The Interface Usage is simpler than the class. The following describes the relevant syntax formats.

9.3.2.1 declare an interface object

For some interfaces, You need to declare an interface object and create it using the method provided in JDK or the corresponding subclass constructor. However, you must first declare the interface object.

Syntax format:

Interface Name
Object Name;

9.3.2.2 implementation Interface

Another more common method of using interfaces is to declare a class to implement interfaces. A class can implement any number of interfaces and use the implements keyword. If an interface contains abstract methods, the abstract method must be overwritten; otherwise, it must be declared as an abstract class.

9.3.2.3 inherited Interface

You can also declare an interface that inherits the existing interfaces in the JDK document. The interface inheritance interface supports multi-inheritance and can be inherited using the extends keyword.

 

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.