java 如何找到java类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/972904/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:38:49  来源:igfitidea点击:

how to find java classes?

javaclass-library

提问by coobird

I am new to programming, I was wondering if there is a way to find the java classes I need for a particular thing other than asking people for them on forums? I have seen the APIs on sun website but there is no good search option to find the class that will work for me.

我是编程新手,我想知道是否有办法找到我需要的特定事物的 Java 类,而不是在论坛上向人们询问它们?我已经在 sun 网站上看到了 API,但是没有好的搜索选项可以找到适合我的类。

回答by coobird

If you're new to Java (or programming), it's going to be important to learn how to read and understand the documentation in order to become self-reliant -- it's the first step to getting less dependent from other people, and in most cases, will improve your learning and programming speed.

如果您不熟悉 Java(或编程),那么学习如何阅读和理解文档以变得自力更生非常重要——这是减少对他人依赖的第一步,并且在大多数情况下案例,将提高您的学习和编程速度。

The following are some tips and suggestions:

以下是一些提示和建议:

Get to know the Java API Specification.

了解Java API 规范

At first, the Javadoc format of the API Specification seem a little bit underpowered without any search ability, but I've found that to be that being able to browse the documentation with a browser to be very powerful.

一开始,API 规范的Javadoc 格式似乎没有任何搜索能力,但我发现能够用浏览器浏览文档是非常强大的。

Since the Javadocs are just HTML files, they can be easily viewed and navigated in a browser, and bookmarking pages are easy as well. Also, the API Specification is available for download, so it not necessary to always go to the web to get information.

由于 Javadoc 只是 HTML 文件,因此可以在浏览器中轻松查看和导航它们,并且为页面添加书签也很容易。此外,API 规范可供下载,因此不必总是去网上获取信息。

As the documentation is just web pages, using the Find feature of the browser can find information quickly in a page, and if that fails, using Google or your favorite search engine to find documentation is very fast and easy.

由于文档只是网页,使用浏览器的查找功能可以快速查找页面中的信息,如果找不到,使用谷歌或您喜欢的搜索引擎查找文档非常快速和容易。

Google (or your favorite search engine) is your friend.

Google(或您最喜欢的搜索引擎)是您的朋友。

Need information on the StringBuilderclass? Try the following query:

需要关于StringBuilder班级的信息?尝试以下查询:

stringbuilder java 6

stringbuilder java 6

The first result will be the Java API Specification page for the StringBuilderclass. The tip is to append the string "java 6" at the end of the query and that seems to bring the API Specification to the top most of the time.

第一个结果将是StringBuilder该类的 Java API 规范页面。提示是java 6在查询的末尾附加字符串“ ”,这似乎在大多数情况下将 API 规范置于首位。

Get comfortable with the structure of the API Specification.

熟悉 API 规范的结构。

The presentation structure of the Javadoctool is very nice and logical:

Javadoc工具的表示结构非常好且合乎逻辑:

+-----------+-------------------+
|           |                   |
|  Packages |                   |
|           |                   |
+-----------+      Details      |
|           |                   |
|  Classes  |                   |
|           |                   |
+-----------+-------------------+

The Javadoc is partitioned into three frames.

Javadoc 分为三个框架。

  • Top-left frame: Listing of all the packages of the Java platform API.
  • Bottom-left frame: Listing of all the classes in the selected package.
  • Right frame: Details of the currently selected package or class.
  • 左上框:Java 平台 API 的所有包的列表。
  • 左下框:所选包中所有类的列表。
  • 右框:当前选择的包或类的详细信息。

Generally, looking for a class starts from selecting a package from the top-left hand frame, then looking for the class in the bottom-left frame, and finally browsing through the details on the right hand frame. The idea is:

通常,查找类从左上角框中选择包开始,然后在左下角框中查找类,最后浏览右侧框中的详细信息。这个想法是:

Package -> Class -> Details

The details in the right hand frame for the classes and packages are also very structured. For classes, the structure are as follows:

右侧框架中的类和包的详细信息也非常结构化。对于类,结构如下:

  • Class name
  • Inheritance hierarchy
  • Implemented interfaces
  • Related classes
  • Information on and description of the class; usage examples.
  • Field summary
  • Constructor summary
  • Method summary
  • Field/Constructor/Method details.
  • 班级名称
  • 继承层次
  • 已实现的接口
  • 相关类
  • 关于班级的信息和描述;用法示例。
  • 字段摘要
  • 构造函数总结
  • 方法总结
  • 字段/构造函数/方法详细信息。

When I'm looking for information on a method, I will scroll down to the Method Summary, find the method I want, and click on that method name which will jump to the Method Details.

当我在寻找一个方法的信息时,我会向下滚动到 Method Summary,找到我想要的方法,然后点击那个将跳转到 Method Details 的方法名称。

Also, everything about the class is documented in one page -- it may seem like it is too much information for one page, but it does make it easy to get all the information you need about the class from one location. In other documentation formats, it may be necessary to flip between multiple pages to get information about several methods in the same class. With the Javadoc format, it's all in one page.

此外,关于班级的所有内容都记录在一页中——这对于一页来说似乎是太多的信息,但它确实让您可以轻松地从一个位置获取有关该班级的所有信息。在其他文档格式中,可能需要在多个页面之间翻转以获取有关同一类中多个方法的信息。使用 Javadoc 格式,所有内容都在一页中。

Learn the Java Platform API

学习 Java 平台 API

The next step is to learn the important packages of the Java Platform API. This will aid in quickly finding classes from the huge collection of classes in the platform API.

下一步是学习Java Platform API 的重要包。这将有助于从平台 API 的庞大类集合中快速找到类。

Don't worry, take it slow -- you don't need to learn everything at once!

别担心,慢慢来——你不需要一次学习所有的东西!

Some packages of interest are:

一些感兴趣的包是:

  • java.lang-- Contains the classes such as String, System, Integer, and other that are automatically imported in every Java program.

  • java.util-- Contains the Java collections (such as List, Set, Mapand their implementations), Date, Randomand other utilitarian classes. This is probably the first package to go to in order to find classes that will be useful in performing common operations.

  • java.io-- Classes concerning with input and output, such as File, Readers and Writers and the various Streams.

  • java.awtand javax.swing-- For graphical user interfaces, Java uses Abstract Window Toolkit or Swing, and those two packages are used to deal with GUIs in Java.

  • java.lang-包含如类StringSystemInteger,和其他被自动在每一个Java程序中导入。

  • java.util-包含Java集合(如ListSetMap和它们的实现), DateRandom和其他实用类。这可能是第一个要查找对执行常见操作有用的类的包。

  • java.io-- 与输入和输出有关的类,例如FileReaders 和Writers 以及各种Streams。

  • java.awtjavax.swing-- 对于图形用户界面,Java 使用 Abstract Window Toolkit 或 Swing,这两个包用于处理 Java 中的 GUI。

Knowing where classes are and starting to get a feel of where to look in the vast amount of documentation will make it easier to find information. It will probably take a while to get used to it, but once you get a hang of it, it should be much easier, and you'll be able to find the information on your own.

了解类的位置并开始了解在大量文档中查找的位置将使查找信息变得更加容易。习惯它可能需要一段时间,但是一旦掌握了它,它应该会容易得多,并且您将能够自己找到信息。

Good luck!

祝你好运!

回答by Matthew Flaschen

It depeneds what you mean. E.g. if you want to know the location of an exact class like "Where was BufferedReader again?", I do a Google search on:

这取决于你的意思。例如,如果您想知道诸如“BufferedReader 又在哪里?”之类的确切类的位置,我会在 Google 上搜索:

site:java.sun.com BufferedReader

If you want to know how to do a task, e.g. "How can I read passwords from the terminal without echoing?" (java.io.Console), sometimes you can only figure it out for the first time by asking for advice.

如果您想知道如何执行任务,例如“如何在不回显的情况下从终端读取密码?” (java.io.Console),有时你只能通过征求意见来第一次弄清楚。

回答by OscarRyz

Most of the times if it is in the core of the language ( that is not a 3rd party library ) I use the following link:

大多数情况下,如果它是语言的核心(不是 3rd 方库),我使用以下链接:

http://java.sun.com/javase/6/docs/api/allclasses-frame.html

http://java.sun.com/javase/6/docs/api/allclasses-frame.html

Which list all the classes in Java SE.

其中列出了 Java SE 中的所有类。

To know if the class may work or not I try by pressing Ctrl-F and guess what class would be the appropiate.

要知道该课程是否可行,我尝试按 Ctrl-F 并猜测适合的课程。

Eventually with time, when you get used to the classes there are, the search will be easier.

最终,随着时间的推移,当您习惯了那里的课程时,搜索将变得更加容易。

For instance, let's say you want to use an array:

例如,假设您想使用一个数组:

Ctrl+F Array yields:

Ctrl+F 数组产生:

Array 
Array 
ArrayBlockingQueue 
ArrayDeque 
ArrayIndexOutOfBoundsException 
ArrayList 
Arrays 
ArrayStoreException 
ArrayType 
ArrayType 

I click on each one and see the documentation. Some of them make no sense, some of them are exactly what I need.

我点击每一个并查看文档。其中一些毫无意义,其中一些正是我所需要的。

Sometimes it may not work very straight forward. Lets way how to create a Window:

有时它可能不会很直接地工作。让我们来看看如何创建一个窗口:

Ctrl+F don't show JFrame which is the correct answer, but it is just matter of tunning your sense :)

Ctrl+F 不显示 JFrame 哪个是正确答案,但这只是调整您的感觉的问题:)

I hope this helps.

我希望这有帮助。

回答by toolkit

I would recommend a book such as Java In A Nutshellwhich is an excellent reference for the Java SE API (note that it covers Java 5 only, but that should be OK for most needs)

我会推荐一本书,例如Java In A Nutshell,它是 Java SE API 的极好参考(请注意,它仅涵盖 Java 5,但应该可以满足大多数需求)

回答by Humphrey Bogart

The Java tutorials, http://java.sun.com/docs/books/tutorial/, and the Java API, http://java.sun.com/javase/6/docs/api/, are essential resources to find out how to do something and with what classes.

Java 教程http://java.sun.com/docs/books/tutorial/和 Java API http://java.sun.com/javase/6/docs/api/是查找的基本资源了解如何做某事以及使用什么课程。

回答by Robert Munteanu

  • Are you looking for java libraries? Try google search , e.g. database connection pool java
  • Are you looking for classes inside the core java libraries? Install an IDE and look for classes, e.g. in Eclipsetry Ctrl-Shift-T and type names: LinkedList. Note that in Eclipse you can also use wildcards, such as *Listto get all classes with names ending in List;
  • Looking for a specific class inside a package? Try Sonatype's Maven repository, click advanced search, and in the new drop-down select class name.
  • 您在寻找 Java 库吗?尝试谷歌搜索,例如数据库连接池java
  • 您是否正在寻找核心 Java 库中的类?安装 IDE 并查找类,例如在Eclipse 中尝试 Ctrl-Shift-T 并键入名称:LinkedList。请注意,在 Eclipse 中,您还可以使用通配符,例如*List来获取名称以 List 结尾的所有类;
  • 在包中寻找特定的类?尝试使用Sonatype 的 Maven 存储库,单击高级搜索,然后在新的下拉列表中选择类名。

回答by mkamowski

I like to use DocJar.

我喜欢使用DocJar

There is even a plugin for eclipse but I have not tried it yet.

甚至还有一个 eclipse 插件,但我还没有尝试过。

http://eclipse-plugins.2y.net/eclipse/plugin_details.jsp?id=959

回答by akf

I agree that the tutorials are good and search engines in general are great (but they now all lead you back to SO). Besides the forums, one resource not to miss is the programmers around you. If you are part of a dev team or in a class, you can get the answers you need or you can collaborate on the search. It is often easier for a human to help you if you are not exactly sure you understand what it is you are looking for.

我同意教程很好,搜索引擎总体上也很棒(但它们现在都带你回到 SO)。除了论坛,一个不容错过的资源就是你身边的程序员。如果您是开发团队或班级的一员,您可以获得所需的答案,也可以协作进行搜索。如果您不确定自己是否了解您正在寻找的东西,那么人们通常会更容易帮助您。