36

Where can I find the source code for the Java library classes? I mean classes in rt.jar.

Platform: Windows.

2
  • when you install the jdk there is an option to also install the sources. after that you will find them in the src.zip just as said below Commented Feb 13, 2010 at 17:44
  • where is the source code of tools.jar Commented Aug 29, 2013 at 6:47

8 Answers 8

32

For old versions of Java with separate JRE and JDK downloads, download the JDK. The sources for the public classes are in src.zip.

Sign up to request clarification or add additional context in comments.

4 Comments

i have jdk1.6. can you tell me the path where it lies.
It's in src.zip in the JDK installation, like he just said.
i don't have it in the installation folder.
Then you probably downloaded the JRE, not the JDK. That's the case if you don't have a /bin directory.
20

Here's the browsable source code for OpenJDK 7.

Update: As of June 2018 grepcode seems to be down. Here you can find an alternative.

Update^2: As of October 2020, the two previous links do not work. View it at OpenJDK and vote up the answer by Nosrep, which I got it from.

1 Comment

Both links are down as of Oct-2020. See answer by Nosrep. The link mentioned in his answer is working fine. hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes
8

Sources are in src.zip located in the installation folder:

  • On Windows, the JDK includes src.zip by default if I remember well.

  • On a Linux distro, you may have to install the sun-java6-source package.

  • On Mac, you'll have to download the Developer Documentation. Have a look at this answer.

1 Comment

Could not find SecretKey Interface looking there :-/
6

As almost all the suggestions seem to be either grepcode or zgrepcode which are both down, I found one from OpenJDK here: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/classes/

Edit: a more complete version of all OpenJDK projects and JDK 6-15 can be found here: https://hg.openjdk.java.net/

Edit Edit: Apparently there's a jdk Github repository now, dunno if it was created after this answer or I just couldn't find it; either way: https://github.com/openjdk/jdk

Harder to find classes than in the mercurial repository for me at least, but for example here is the ArrayList file: https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/ArrayList.java

Or, yknow just use search

Comments

5

If you only need to have a look at the source/implemenation, i would suggest using

Docjar

Edit

GrepCode is even better

GrepCode

1 Comment

This is a wonderful resource for quickly browsing an implementation.
3

You can directly browse the code online here for Java : https://zgrepcode.com/java/openjdk/10.0.2/

It is a great tool also for browsing most of the open source projects as it gives you internal linking to classes.

Comments

1

As mention above, most of the source files can be found by downloading the SDK. However for some classes you can find the source code (javax.ssl etc') for I suggest adding the jad eclipse plugin that will decompile any class without using external site such as Docjar. Jad eclipse info: http://jadclipse.sourceforge.net/wiki/index.php/Main_Page

Comments

1

There is also grepcode.com (not sure how old this site is, perhaps this answer is an update for new solutions now), sample query:

http://grepcode.com/search?query=java.lang.Math.sin&start=0&entity=type&n=

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.