views:

1295

answers:

8

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

A: 

Here:

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

Gustavo Rubio
+6  A: 

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.

Bill Karwin
+1  A: 

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

jtyost2
+2  A: 

I got it finally. Here is the direct link: http://www.java.net/download/jdk6/6u3/promoted/b05/jdk-6u3-fcs-src-b05-jrl-24_sep_2007.jar

askgelal
+1  A: 

You have the source in the docjar:

LinkedList.java (from the openjdk-7)

VonC
+1  A: 

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.

Denis R.
A: 

The JDK source code can be browsed online:
https://jdk-jrl-sources.dev.java.net

First you will need to register for a http://java.net account and apply for a Researcher project role on the JDK project:
https://jdk.dev.java.net/#started

You will receive an email when the role has been granted. Looking up the source code in Eclipse is certainly easier, but the online source repository can be useful when you don't already have the source code downloaded.

Also, it seems that some code (such as the native C code used to implement the AWT library) is available only in this repository and not included in the source code JAR file bundled with the JDK.

A: 

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.

Peter Lawrey