Where can I find the Java JDK source code? [closed]

I would like to see what a method in the Java API does. So I want the JDK source code.

Before I reinstalled Linux I had the src.zip package with all the official source code in it. I just had to tell Eclipse where this file is and I could see the code. But now I don't have the file anymore...

Where can I find it?


You haven't said which version you want, but an archive of the JDK 8 source code can be downloaded here, along with JDK 7 and JDK 6.

Additionally you can browse or clone the Mercurial repositories: 8, 7, 6.


Chances that you already got the source code with the JDK, is a matter of finding where it is. In that case, the JDK folder doesn't contain the source code:

sudo apt-get install openjdk-7-source

OS X folks, search in Homebrew formulas.

In Ubuntu, the command above would put your source file under:

/usr/lib/jvm/openjdk-7/

The good news is that Eclipse will take you there already (how to bind Eclipse to the Java source code):

Follow the orange buttons

Enter image description here

Enter image description here

Enter image description here


Sadly, as of this writing, despite their own documentation readme, there is no src.zip in the JDK 7 or 8 install directories when you download the Windows version.

Note: perhaps this happens because many of us don't actually run the install .exe, but instead extract it. Many of us don't run the Java install (the full blown Windows install) for security reasons...we just want the JDK put someplace out of the way where potential viruses cannot find it.

But their policy regarding the Windows .exe (whatever it truly is) is indeed nuts, however, the src.zip DOES exist in the Linux install (a .tar.gz). There are multiple ways of extracting a .tar and a .gz, and I prefer the free "7Zip" utility.

  1. download the Linux 64 bit .tar.gz
  2. use 7-Zip to uncompress the .tar.gz to a .tar
  3. use 7-Zip to extract the .tar to the installation directory
  4. File src.zip will be waiting for you in that installation directory.
  5. pull it out and place it where you like.

Oracle, this is really beyond stupid.


I had this problem with my Ubuntu.

All I needed to do to get sources for my Java installation was:

sudo apt-get install sun-java6-source

The JDK 1.6 I'm currently using on OS X v10.8 (Mountain Lion) did not come with a src.zip either, and as far as I can tell there is no supported Mac OS X JDK for 1.6 available anymore.

So I downloaded the OpenJDK source (using the links from the accepted answer (+1)) then ran:

cd ~/Downloads
mkdir jdk6src
cd jdk6src
tar xf ../openjdk-6-src-b27-26_oct_2012.tar.gz
cd jdk/src/share/classes
jar cf /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/src.jar *

(Your file names and paths may vary...)

Associate that src.jar with the appropriate Java platform in your IDE and you should be good to go.

There are some discrepancies between the OpenJDK source and the JDK I'm currently running (line numbers don't match up in the debugger, for one), but if all you want is a zip/jar to point your IDE to for the relatively few cases you need to peek at some code to understand how something works, then this should do the trick.