所有 Java 标准类和方法的简单列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/871812/
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
Simple List of All Java Standard Classes and Methods?
提问by Roee Adler
I'm building a very simple Java parser, to look for some specific usage models. This is in no way lex/yacc or any other form of interpreter/compiler for puposes of running the code.
我正在构建一个非常简单的 Java 解析器,以寻找一些特定的使用模型。这绝不是用于运行代码的 lex/yacc 或任何其他形式的解释器/编译器。
When I encounter a word or a set of two words separated by a dot ("word.word"), I would like to know if that's a standard Java class (and method), e.g. "Integer", or some user defined name. I'm not interested in whether the proper classes were included/imported in the code (i.e. if the code compiles well), and the extreme cases of user defined classes that override the names of standard Java classes also does not interest me. In other words: I'm okay with false negative, I'm only interesting in being "mostly" right.
当我遇到一个单词或一组由点分隔的两个单词(“word.word”)时,我想知道它是标准的 Java 类(和方法),例如“Integer”,还是某个用户定义的名称。我对代码中是否包含/导入了正确的类不感兴趣(即代码是否编译良好),而且我对覆盖标准 Java 类名称的用户定义类的极端情况也不感兴趣。换句话说:我可以接受假阴性,我只对“大部分”正确感兴趣。
If there a place wher I could find a simple list of all the names of all Java standard classes and methods, in the form easily saved into a text file or database? (J2SE is okay, but J2EE is better). I'm familiar with http://java.sun.com/j2se/etc, but it seems I need a terrible amount of manual work to extract all the names from there. Also, the most recent JDK is not neccesary, I can live with 1.4 or 1.5.
如果有什么地方可以找到所有 Java 标准类和方法的所有名称的简单列表,并且可以轻松保存到文本文件或数据库中?(J2SE 可以,但 J2EE 更好)。我熟悉http://java.sun.com/j2se/等,但似乎我需要大量的手动工作才能从那里提取所有名称。此外,最新的 JDK 不是必需的,我可以使用 1.4 或 1.5。
Clarification: I'm not working in Java but in Python, so I can't use Java-specific commands in my parsing mechanism.
说明:我不是在 Java 中工作,而是在 Python 中工作,所以我不能在我的解析机制中使用 Java 特定的命令。
Thanks
谢谢
采纳答案by Eugene Yokota
回答by Peter Lawrey
To get all classes and methods you can look at the index on http://java.sun.com/javase/6/docs/api/index-files/index-1.html
要获取所有类和方法,您可以查看http://java.sun.com/javase/6/docs/api/index-files/index-1.html上的索引
This will be 10's of thousands classes and method which can be overwhelming.
这将是数以千计的类和方法的 10 个,这可能会让人不知所措。
I suggest instead you use auto-complete in your IDE. This will show you all the matching classes/methods appropriate based on context. e.g. say you have a variable
我建议您在 IDE 中使用自动完成功能。这将根据上下文向您显示所有匹配的类/方法。例如说你有一个变量
long time = System.
长时间=系统。
This will show you all the methods in System which return a long value, such as
这将向您展示 System 中返回 long 值的所有方法,例如
long time = System.nanoTime();
长时间 = System.nanoTime();
Even if you know a lot of the method/classes, this can save you a lot of typing.
即使您知道很多方法/类,这也可以为您节省大量输入。
回答by Uri
If you just want to create a list of all classes in Java and their methods (so that you can populate a database or an XML file), you may want to write an Eclipse-plugin that looks at the entire JavaCore model, and scans all of its classes (e.g., by searching all subtypes of Object). Then enumerate all the methods. You can do that technically to any library by including it in your context.
如果您只想创建 Java 中所有类及其方法的列表(以便您可以填充数据库或 XML 文件),您可能需要编写一个 Eclipse 插件来查看整个 JavaCore 模型,并扫描所有它的类(例如,通过搜索 Object 的所有子类型)。然后枚举所有方法。您可以通过将其包含在您的上下文中来从技术上对任何库执行此操作。
回答by Uri
IBM had a tool for creating XML from JavaDocs, if I am not mistaken: http://www.ibm.com/developerworks/xml/library/x-tipjdoc/index.html
IBM 有一个从 JavaDocs 创建 XML 的工具,如果我没记错的话:http: //www.ibm.com/developerworks/xml/library/x-tipjdoc/index.html
回答by macbirdie
There's also an option to either parse classlistfile from jre/lib folder or open the jsse.jarfile, list all classes there and make a list of them in dot-separated form by yourself.
还有一个选项是classlist从 jre/lib 文件夹解析文件或打开jsse.jar文件,在那里列出所有类并自己以点分隔的形式列出它们。
回答by Tim
When I encounter a word or a set of two words separated by a dot ("word.word"), I would like to know if that's a standard Java class (and method), e.g. "Integer", or some user defined name.
当我遇到一个单词或一组由点分隔的两个单词(“word.word”)时,我想知道它是标准的 Java 类(和方法),例如“Integer”,还是某个用户定义的名称。
If thats what you're after, you could do without a (limited) list of Java Classes by using some simple reflection: http://java.sun.com/developer/technicalArticles/ALT/Reflection/
如果这就是你所追求的,你可以通过使用一些简单的反射来避免(有限的)Java 类列表:http: //java.sun.com/developer/technicalArticles/ALT/Reflection/
try {
Class.forName("word.word");
System.out.println("This is a valid class!");
} catch (ClassNotFoundException e) {
System.out.println("This is not a valid class.");
}
Something like this should be enough for your purposes, with he added benefit of not being limited to a subset of classes, and extensible by any libraries on the classpath.
像这样的东西应该足以满足您的目的,他增加了不受限于类子集的好处,并且可以通过类路径上的任何库进行扩展。

