To learn java, you must be able to use the help documentation. Here is a brief explanation of the help documentation.
Tools/Materials
JDK API 1.60
JDK 1.60
Steps/Method
Figure 1 shows HashSet as an example. ①: The inheritance relationship of the HashSet class; ②: Indicates the excuse for implementation; ③: Known subclasses; ④: The definition of this class in the source code can directly see who the class inherits and what excuse it needs to implement. ⑤: Class package in java;
In Figure 2. ① is the constructor of this class; ② is the return value of the method; find the corresponding method and click to enter the detailed description of the method
In the detailed method, it is written that the add method is inherited from the previous level and overridden. At this time, you can find the corresponding source code in the JDK to view. The source code is stored in the src compressed package in the JDK.
Find HashSet.java
under the java.util packageFind the add method source code after opening it
Watch the source code and see its implementation to help you learn java better
END
Precautions
If you want to view the source code, you need to install JDK. After installation, unzip the src file in the JDK directory!
API is just like a Chinese dictionary when learning Chinese characters. The basic classes you need to use when programming all exist in the API, and as time goes by, the number of these classes will increase.
Generally open the API, you can see three parts, upper left, lower left and right. The upper left part is all the packages, which is the largest part; then the lower left part is the specific content of the package you selected in the upper left part, generally including interfaces, classes, enumerations, exceptions, errors, etc. When you select a specific class in the lower left part, a specific explanation of the class will appear in the right part, followed by its construction methods, common methods, etc. Our main focus is on common methods.
When looking at the API, for example, if you want to find the String class, you first need to know where it is in the class, that is, which package it is in, and then you find the String class (in the java.lang package) through the connection. Then find the String class in the java.lang package, and then you can view the specific content of the String class. For example, when explaining String, it was said that String objects are immutable (this sounds a little more important than other nonsense), and then a general explanation of the methods of the String class was given. Next, you can look at the specific methods.
For example, if you want to compare a string, you need to use the equals(Object anObject) method. Its parameter is an object. The method explanation is: compare this string with the specified object.
Specific usage, such as String str = "a"; str.equals("b");
Because "a" is not equal to "b", this method returns false.
1: Open the help document
2: Click display, find the index, and see the input box
3: Know who you are looking for? Take Scanner as an example
4: Enter Scanner in the input box and press Enter
5: Look at the package
Classes under the java.lang package do not need to be imported, but all others need to be imported.
To import:
java.util.Scanner
6: Take a brief look at the explanation and description of the class, and don’t forget to look at the version of the class
7: Look at the structure of the class
Member variable field summary
Construction method Construction method summary
Member Method Method Summary
8: Learning construction methods
A: Create an object if there is a constructor
B: There is no constructor and the members may be static
9: Look at member methods
A: Left side
Whether it is static: If it is static, it can be called through the class name
Return value type: You can receive whatever others return.
B: Right
Look at the method name: Don’t write the method name incorrectly
Parameter list: Give people whatever they want; give them as many as they want
The above is the detailed content of How to read JAVA JDK help documentation. For more information, please follow other related articles on the PHP Chinese website!