Java 我在哪里可以看到 Sun JDK 的源代码?

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

Where can I see the source code of the Sun JDK?

javalinked-list

提问by ashokgelal

I want to have a look at how Java implements LinkedList. Where should I go to look at the source code?

我想看看Java是如何实现LinkedList的。我应该去哪里查看源代码?

回答by Gustavo Rubio

回答by Bill Karwin

Install the Java SE Development Kit from http://java.sun.com/javase/downloads/index.jsp.

http://java.sun.com/javase/downloads/index.jsp安装 Java SE 开发工具包。

Once installed, you should find an archive called src.zipin the top of the JDK installation directory. The Java source code is in there.

安装后,您应该会src.zip在 JDK 安装目录的顶部找到一个名为的存档。Java 源代码在那里。

The file is java/util/LinkedList.java.

该文件是java/util/LinkedList.java.

update:You may also like to visit the online OpenJDK Source repository. See this answerbelow.

更新:您可能还想访问在线OpenJDK 源代码库。请参阅下面的这个答案

回答by Justin Yost

I would say start at the OpenJDK repository, but I don't see anything there for the LinkedList objects.

我会说从OpenJDK 存储库开始,但我没有看到 LinkedList 对象的任何内容。

回答by VonC

You have the source in the docjar:

您在docjar 中有源代码

LinkedList.java(from the openjdk-7)

LinkedList.java(来自openjdk-7

回答by Denis R.

As previously said, you have a src.zip file installed with Sun JDK if you have selected it during installation. Moreover, if you use eclipse and add a JDK to your JRE list, it will attach automatically the sources to the jar and if you try to open a class with Ctrl+Shift+T(Open Type), you type LinkedList, and it will show you the code of the class.

如前所述,如果您在安装过程中选择了 src.zip 文件,那么您将随 Sun JDK 一起安装。此外,如果你使用Eclipse,并添加一个JDK到你的JRE列表,它会连接自动来源的罐子,如果你试图打开一类Ctrl+ Shift+ T(开放式),键入LinkedList的,它会告诉你类的代码。

回答by Peter Lawrey

If you have a JDK, you can find the source in the src.zip file.

如果您有 JDK,则可以在 src.zip 文件中找到源代码。

If you have an IDE, you can just ctrl+clickor similar on the class/method you want to see the definition of.

如果你有一个 IDE,你可以在你想要查看定义的类/方法上加ctrl+click或类似的。

回答by fouding.zheng

The sources are hosted at hg.openjdk.java.net. You can find the library sources for a specific JDK version under src/share/classes. For example, the JDK 8 source for java.util.LinkedList is located at:

源代码托管在hg.openjdk.java.net 上。您可以在 下找到特定 JDK 版本的库源src/share/classes。例如,java.util.LinkedList 的 JDK 8 源代码位于:

hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/tip/src/share/classes/java/util/LinkedList.java

hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/tip/src/share/classes/java/util/LinkedList.java

You can follow the instructions hereto explore the source.

您可以按照此处的说明探索源代码。

回答by Rajesh

grepcode.comhas source code of almost all opensource projects. It also provides common IDE features like find usages, derived types, etc.

grepcode.com拥有几乎所有开源项目的源代码。它还提供常见的 IDE 功能,如查找用法、派生类型等。

Here you can find LinkedList source: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/util/LinkedList.java/

在这里你可以找到LinkedList源:http: //grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/util/LinkedList.java/

回答by HA S

The best way to view java source code is to install Intelli-J community edition. Create a new Java project and inside your project create a new class. Inside class if you want to see the source code of LinkedList, create a new LinkedList object as follows:

查看java源代码的最佳方式是安装Intelli-J社区版。创建一个新的 Java 项目并在您的项目中创建一个新类。在类里面如果想看LinkedList的源码,新建一个LinkedList对象如下:

public class LinkedListWatch{
   public static void main(String[] args){
    LinkedList linkedList = new LinkedList();

  }
}

Now ctrl + mouse left clickon LinkedListclass, will take you to LinkedList source code. You can explore many things and it could be very useful.

现在ctrl + mouse left clickLinkedList班,将带你到LinkedList的源代码。你可以探索很多东西,它可能非常有用。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

You can look at the implementation of Stack class also; very helpful.

您也可以查看 Stack 类的实现;很有帮助。

Enjoy searching java open source code.

享受搜索 Java 开源代码的乐趣。

回答by Arry

zGrepCode has an online directory of Java open source code. Here is the Sun Java classes available: https://zgrepcode.com/java/openjdk/10.0.2/java.base/sun/

zGrepCode 有一个 Java 开源代码在线目录。这是可用的 Sun Java 类:https: //zgrepcode.com/java/openjdk/10.0.2/java.base/sun/

And here is the LinkedListimplementation code. Hope it helps.

这是LinkedList实现代码。希望能帮助到你。