70

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

peterh
  • 11,875
  • 18
  • 85
  • 108
ashokgelal
  • 80,002
  • 26
  • 71
  • 84

10 Answers10

68

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.

anishpatel
  • 1,472
  • 1
  • 16
  • 23
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
20

You have the source in the docjar:

LinkedList.java (from the openjdk-7)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
11

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.

anishpatel
  • 1,472
  • 1
  • 16
  • 23
fouding.zheng
  • 281
  • 2
  • 5
4

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/

Rajesh
  • 1,911
  • 1
  • 22
  • 19
3

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.

Naveed S
  • 5,106
  • 4
  • 34
  • 52
Denis R.
  • 818
  • 1
  • 9
  • 15
3

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.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
2

Here:

http://hg.openjdk.java.net/

Gustavo Rubio
  • 10,209
  • 8
  • 39
  • 57
2

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.

Arry
  • 1,630
  • 9
  • 27
  • 46
1

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

Justin Yost
  • 2,340
  • 19
  • 31
0

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.

HA S
  • 1,129
  • 12
  • 10
  • This isn't useful if there is no attached source documents. Why would you even post this after reading the other answers that explain where to get the source documents? – superPhreshHackerKid Jul 25 '18 at 00:33
  • I am sure you missed something, I found it very convenient to look for Java source code inside Intellij, check my updated post for screenshots – HA S Jul 25 '18 at 01:18
  • This is fine for IntelliJ, but what about when you're using an IBM implementation of Java and they didn't include the Java source documents? Someone should download IntelliJ to view them? I disagree, they should do as Bill answered in '08; navigate to the src.zip to view / attach the source code. – superPhreshHackerKid Jul 25 '18 at 19:23
  • @superPhreshHackerKid You can do this in Eclipse and pretty much any IDE. Plus, you get to browse through the source code as you would with your project. That's far better than dealing with the src.zip yourself. – BaSsGaz Dec 24 '20 at 19:39