ashokgelal
ashokgelal

Reputation: 81528

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

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

Answers (10)

Arry
Arry

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

HA S
HA S

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.

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.

Upvotes: 0

fouding.zheng
fouding.zheng

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

Bill Karwin
Bill Karwin

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

Rajesh
Rajesh

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

Peter Lawrey
Peter Lawrey

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

Denis R.
Denis R.

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

VonC
VonC

Reputation: 1324248

You have the source in the docjar:

LinkedList.java (from the openjdk-7)

Upvotes: 20

Justin Yost
Justin Yost

Reputation: 2340

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

Upvotes: 1

Gustavo Rubio
Gustavo Rubio

Reputation: 10747

Here:

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

Upvotes: 2

Related Questions