简体   繁体   English

如何找到java类?

[英]how to find java classes?

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? 我是编程的新手,我想知道是否有办法找到我需要的特定事物的java类,而不是在论坛上向人们询问? I have seen the APIs on sun website but there is no good search option to find the class that will work for me. 我在sun网站上看过API,但没有很好的搜索选项可以找到适合我的课程。

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. 由于Javadocs只是HTML文件,因此可以在浏览器中轻松查看和导航它们,并且书签页面也很容易。 Also, the API Specification is available for download , so it not necessary to always go to the web to get information. 此外, API规范可供下载 ,因此无需始终访问Web以获取信息。

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. 谷歌(或您最喜欢的搜索引擎)是您的朋友。

Need information on the StringBuilder class? 需要有关StringBuilder类的信息? Try the following query: 请尝试以下查询:

stringbuilder java 6

The first result will be the Java API Specification page for the StringBuilder class. 第一个结果将是StringBuilder类的Java API Specification页面。 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. 提示是在查询结尾附加字符串“ java 6 ”,这似乎使API规范在最顶层。

Get comfortable with the structure of the API Specification. 熟悉API规范的结构。

The presentation structure of the Javadoc tool 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. 左上角框架:列出Java平台API的所有包。
  • Bottom-left frame: Listing of all the classes in the selected package. 左下框:列出所选包中的所有类。
  • Right frame: Details of the currently selected package or class. 右框架:当前所选包或类的详细信息。

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. 当我正在寻找有关方法的信息时,我将向下滚动到方法摘要,找到我想要的方法,然后单击将跳转到方法详细信息的方法名称。

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 Platform API

The next step is to learn the important packages of the Java Platform API. 下一步是学习Java Platform API的重要包。 This will aid in quickly finding classes from the huge collection of classes in the 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.lang - 包含在每个Java程序中自动导入的类,如StringSystemInteger和其他类。

  • java.util -- Contains the Java collections (such as List , Set , Map and their implementations), Date , Random and other utilitarian classes. java.util - 包含Java集合(如ListSetMap及其实现), DateRandom和其他功利类。 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 , Reader s and Writer s and the various Stream s. java.io - 与输入和输出有关的类,例如FileReaderWriter以及各种Stream

  • java.awt and 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.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! 祝好运!

It depeneds what you mean. 它取决于你的意思。 Eg 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, eg "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),有时你只能通过征求意见才能弄明白。

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: 大多数时候,如果它是语言的核心(不是第三方库),我使用以下链接:

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: 让我们来看看如何创建一个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. 我希望这有帮助。

  • Are you looking for java libraries? 你在寻找Java库吗? Try google search , eg database connection pool java 尝试谷歌搜索,例如数据库连接池java
  • Are you looking for classes inside the core java libraries? 你在核心java库中寻找类吗? Install an IDE and look for classes, eg in Eclipse try Ctrl-Shift-T and type names: LinkedList . 安装IDE并查找类,例如在Eclipse中尝试Ctrl-Shift-T并输入名称: LinkedList Note that in Eclipse you can also use wildcards, such as *List to get all classes with names ending in List; 请注意,在Eclipse中,您还可以使用通配符(例如* List)来获取名称以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. 尝试使用Sonatype的Maven存储库 ,单击高级搜索,然后在新的下拉列表中选择类名。

我推荐一本书,例如Java In A Nutshell ,它是Java SE API的一个很好的参考(请注意,它仅涵盖Java 5,但对大多数需求来说应该没问题)

Java教程http://java.sun.com/docs/books/tutorial/和Java API http://java.sun.com/javase/6/docs/api/是查找的重要资源如何做某事和什么类。

I like to use DocJar . 我喜欢使用DocJar

There is even a plugin for eclipse but I have not tried it yet. 甚至有一个日食插件,但我还没有尝试过。

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

I agree that the tutorials are good and search engines in general are great (but they now all lead you back to SO). 我同意这些教程很好,一般来说搜索引擎都很棒(但现在它们都会引导你回到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. 如果您不确定自己了解自己在寻找什么,那么人们通常会更容易帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM