Reputation: 81528
I want to have a look at how Java implements LinkedList. Where should I go to look at the source code?
Upvotes: 70
Views: 92865
Reputation: 1690
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.
Upvotes: 2
Reputation: 1247
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.
You can look at the implementation of Stack class also; very helpful.
Enjoy searching java open source code.
Upvotes: 0
Reputation: 281
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.
Upvotes: 11
Reputation: 562320
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.
Upvotes: 68
Reputation: 1941
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/
Upvotes: 4
Reputation: 533500
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.
Upvotes: 3
Reputation: 818
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.
Upvotes: 3
Reputation: 1324248
You have the source in the docjar:
LinkedList.java (from the openjdk-7)
Upvotes: 20
Reputation: 2340
I would say start at the OpenJDK repository, but I don't see anything there for the LinkedList objects.
Upvotes: 1