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

JavaLinked List

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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

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

The file is java/util/LinkedList.java.

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

Solution 2 - Java

You have the source in the docjar:

LinkedList.java (from the openjdk-7)

Solution 3 - Java

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/jdk8u/jdk8u/jdk/file/tip/src/share/classes/java/util/LinkedList.java

You can follow the instructions here to explore the source.

Solution 4 - Java

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

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

Solution 5 - Java

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.

Solution 6 - Java

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

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

Solution 7 - Java

Solution 8 - Java

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/

And here is the LinkedList implementation code. Hope it helps.

Solution 9 - Java

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

Solution 10 - Java

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:

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

  }
}

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

enter image description here enter image description here

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

Enjoy searching java open source code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionashokgelalView Question on Stackoverflow
Solution 1 - JavaBill KarwinView Answer on Stackoverflow
Solution 2 - JavaVonCView Answer on Stackoverflow
Solution 3 - Javafouding.zhengView Answer on Stackoverflow
Solution 4 - JavaRajeshView Answer on Stackoverflow
Solution 5 - JavaDenis R.View Answer on Stackoverflow
Solution 6 - JavaPeter LawreyView Answer on Stackoverflow
Solution 7 - JavaGustavo RubioView Answer on Stackoverflow
Solution 8 - JavaArryView Answer on Stackoverflow
Solution 9 - JavaJustin YostView Answer on Stackoverflow
Solution 10 - JavaHA SView Answer on Stackoverflow