java 我如何阅读java文档?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2576709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i read java documentation?
提问by David
I'm looking for some advice on how to go about reading the online documentation of various packages classes and methods for java.
我正在寻找一些关于如何阅读 java 的各种包类和方法的在线文档的建议。
i mean all this stuff: http://java.sun.com/javase/6/docs/api/
我的意思是所有这些东西:http: //java.sun.com/javase/6/docs/api/
采纳答案by BalusC
And indeed, read it only when needed. For the remnant, go through a tutorial. Usually Googling "[keyword] tutorial site:oracle.com" yields enough results.
事实上,只有在需要时才阅读它。对于剩余部分,请阅读教程。通常谷歌搜索“[关键字]教程站点:oracle.com”会产生足够的结果。
Updateto take the following as an example for which you'd like to find the Javadoc:
更新以将以下内容作为您想要查找 Javadoc 的示例:
someString.split("\.");
Here someStringis an instance of java.lang.String. Assuming that you'd like to start up from the API documentation root(I myself rather prefer to type just "java.lang.string javase api site:oracle.com" in Firefox's address bar to get it straight for me (if you feel lucky and didn't already have it in browser history), or to just check it in my IDE), then scroll in the main frame to the java.langpackageand click the link, then in the class summary check the Stringclassand click the link, then in the method summary check the split()methodand click the link.
这someString是 的一个实例java.lang.String。假设您想从API 文档根目录启动(我自己更喜欢在 Firefox 的地址栏中键入“java.lang.string javase api site:oracle.com”来直接为我获取它(如果您觉得幸运的是,浏览器历史记录中还没有它),或者只是在我的 IDE 中检查它),然后在主框架中滚动到java.lang包并单击链接,然后在类摘要中检查String类并单击链接,然后在方法摘要中检查split()方法并单击链接。
The Javadoc of the Java SE API is concise, but pretty complete and provides links to other javadocs where you expect them to be. For example, at the bottom of the String#split()javadoc you see a "See Also" link to the Patternclass, which in turn explains that regex stuff in the class' introduction.
Java SE API 的 Javadoc 简明扼要,但非常完整,并提供了指向您期望的其他 javadoc 的链接。例如,在String#split()javadoc的底部,您会看到指向Pattern该类的“另请参阅”链接,该链接反过来解释了该类介绍中的正则表达式内容。
回答by codenheim
Read it as needed. As in, in the context of a project. Documentation is largely a need based format, not a concepts teaching format.
根据需要阅读它。就像在项目的上下文中一样。文档主要是一种基于需求的格式,而不是一种概念教学格式。
Otherwise, if you want to actually readsomething to learn the SDK for example, read a teaching book.
否则,如果你想真正阅读一些东西来学习 SDK,例如阅读教学书籍。
回答by Russell Leggett
Imagine the javadoc as browsing albums in itunes. The top left frame is a list of packages. Thats like a list of artists. Selecting one of those changes what is shown in the bottom left frame. The bottom left frame is a list of Classes/Interfaces in the package selected above it. Thats like selecting an artist and showing the list of albums. You can then select one of the classes/interfaces and a detailed view of it will appear in the main frame. Thats like the track list for the selected album.
将 javadoc 想象成在 iTunes 中浏览专辑。左上角的框架是一个包列表。这就像一个艺术家名单。选择其中之一会更改左下角框架中显示的内容。左下方的框架是在其上方选择的包中的类/接口列表。这就像选择艺术家并显示专辑列表一样。然后,您可以选择其中一个类/接口,它的详细视图将出现在主框架中。这就像所选专辑的曲目列表。
ITunes analogy aside, the main frame details show all of the public and protected information needed to interact with that class or interface. At the top it shows the inheritance hierarchy, and a description of the class. Below that is a summary of all the fields, constructors, and methods that are public or protected on the class. You can click a link on any of those to jump to a full description. At the bottom of the summary is a list of all the inherited methods.
撇开 iTunes 的类比不谈,主框架详细信息显示了与该类或接口交互所需的所有公共和受保护信息。在顶部,它显示了继承层次结构和类的描述。下面是类上所有公共或受保护的字段、构造函数和方法的摘要。您可以单击其中任何一个的链接以跳转到完整说明。摘要的底部是所有继承方法的列表。
Any classes that are referenced in a javadoc such as argument or return types will be links. If you click the link, it will navigate to the javadoc for that class. In this way is is pretty easy to navigate through all of the classes needed to figure out what is going on. It isn't exactly pretty, but it works. Being html, you can even open links in a new tab, and therefore easily open all related classes at once.
javadoc 中引用的任何类(例如参数或返回类型)都将是链接。如果单击该链接,它将导航到该类的 javadoc。通过这种方式,可以很容易地浏览所有需要弄清楚发生了什么的类。它并不完全漂亮,但它有效。作为 html,您甚至可以在新选项卡中打开链接,因此可以轻松地一次打开所有相关类。
One last tip - there are some extra options at the top of the detail pane. One that I use a lot are the Frames/No Frames links. This will add or remove the package and class frames on the left. If you open other classes in new tabs, or sometimes if you find a class using google, you will wind up on a page with no extra frames. Just click the Frames tag and they'll get added to the page.
最后一个提示 - 详细信息窗格顶部有一些额外的选项。我经常使用的一个是 Frames/No Frames 链接。这将添加或删除左侧的包和类框架。如果您在新选项卡中打开其他课程,或者有时如果您使用 google 找到课程,您将在一个没有额外框架的页面上结束。只需单击 Frames 标签,它们就会被添加到页面中。
回答by Daniel
The most helpful thing for me learning the Java SE APIs was to do "The Java Tutorials". It covers pretty much the whole of Java SE, in a much more organised manner than the JavaDocs. After you read the bits you're interested in, the JavaDocs will make more sense on their own.
对我学习 Java SE API 最有帮助的事情是做“ The Java Tutorials”。它几乎涵盖了整个 Java SE,比 JavaDocs 更有条理。在您阅读了您感兴趣的部分之后,JavaDocs 将更有意义。
Usually I read the JavaDocs for bits I'm interested in through the IDE. I use Netbeans, which automatically displays JavaDoc as part of its code-completion. That way, I can partially type a class or method name that I'm thinking of using, and then browse through the JavaDocs of the suggestions until I find what I want.
通常我会通过 IDE 阅读 JavaDocs 以获取我感兴趣的位。我使用 Netbeans,它会自动显示 JavaDoc 作为其代码完成的一部分。这样,我可以部分键入我想使用的类或方法名称,然后浏览建议的 JavaDocs,直到找到我想要的。
回答by Mike J
I second all the above confused users. As for myself coming from an avid background of using Windows API for VB classic, the Java API is not enlightening.
我对上述所有困惑的用户表示支持。至于我来自使用 Windows API for VB classic 的狂热背景,Java API 并不具有启发性。
Yes, the Java API provides ample information about itself, what each class does and the structure of it all; but, for anything useful during development it's pretty much deterring from rather than referring to solutions and usable code.
是的,Java API 提供了关于它自己、每个类的作用以及所有结构的大量信息;但是,对于在开发过程中有用的任何东西,它几乎都在阻止而不是参考解决方案和可用代码。
Consider that anyone new to Java hardly can recall or memorize what functions are a part of every package. Then to find a method, function, class or already defined term used is a nightmare.
考虑到 Java 新手几乎无法回忆或记住每个包中包含哪些函数。然后找到使用的方法、函数、类或已经定义的术语是一场噩梦。
Regarding Java's API docs: It's one thing being different and exceptionally specific to the environment and language; it's a whole different ball game when it's more focused on simply being different despite being incoherent to beginners' eyes.
关于 Java 的 API 文档:环境和语言的差异和特殊性是一回事;这是一个完全不同的球类游戏,当它更专注于简单地与众不同时,尽管对初学者的眼睛来说不连贯。
I believe people will find the steps to beginning coding much simplified by a major overhaul of Java's disorganized API documentation layout.
我相信人们会发现通过对 Java 杂乱无章的 API 文档布局进行大修,开始编码的步骤会大大简化。
回答by Steven Schlansker
The JavaDoc is merely a references. It's great for answering a question of the form "what does this (class / method) do?" but is terrible for just about anything else.
JavaDoc 只是一个参考。非常适合回答“这个(类/方法)做什么?”形式的问题。但对于其他任何事情来说都是可怕的。
If you're confused by the JavaDoc, you should pick up a book or find an online tutorial. Use the documentation as a reference to answer specific questions only, and maybe you won't be as confused.
如果您对 JavaDoc 感到困惑,您应该拿起一本书或查找在线教程。仅使用文档作为参考来回答特定问题,也许您不会感到困惑。
回答by John
Imagine that you have a String, and you're trying to work out how to convert it to uppercase. Look at the javadoc for String, at http://java.sun.com/javase/6/docs/api/java/lang/String.html(or from your link above, just scroll down to find String in the lower left list.
想象一下,您有一个字符串,并且您正试图弄清楚如何将其转换为大写。查看字符串的 javadoc,位于http://java.sun.com/javase/6/docs/api/java/lang/String.html(或从上面的链接中,向下滚动以在左下方找到 String列表。
You'll find there's a method there called toUpperCase(). You can click on it to find the details. And you'll see all the other methods there, that describe the sorts of things you can "do" to a String.
你会发现那里有一个方法叫做toUpperCase(). 您可以单击它以查找详细信息。你会在那里看到所有其他方法,它们描述了你可以对字符串“做”的事情。
And there's a list of constructors as well, which tell you how you can "create" a string object.
还有一个构造函数列表,它告诉你如何“创建”一个字符串对象。
Maybe it's not too hard for a String, so try something more complex: How do you create a BufferedOutputStream?
也许对于 String 来说并不太难,所以尝试一些更复杂的事情:如何创建 BufferedOutputStream?

