Where can I find the Java JDK source code?

Java

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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

Solution 3 - Java

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.

Solution 4 - Java

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

Solution 5 - Java

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.

Solution 6 - Java

This file is contained in the standard JDK download. Also your Linux system probably has the JDK in the repository. In my Ubuntu Linux, the file is located in /usr/lib/jvm/java-6-sun-1.6.0.20/src.zip.

Solution 7 - Java

In JDK 8, the source can be found in <JDK installation directory>/src.zip. Now in some intermediate releases this ZIP file was missing, but again it is available.

Enter image description here

Make sure that you select the source as well from the installation wizard.

Solution 8 - Java

Here the official link for the JDK source: <http://www.oracle.com/technetwork/java/javase/downloads/index.html>

(You may need to scroll to the bottom of the page.)

Solution 9 - Java

Well, I opened terminal in my Mac and typed:

echo $JAVA_HOME

Then I got the directory, went there and found src.zip.

Solution 10 - Java

Yes!! I got it!

I downloaded the Java Developer Kit (JDK) from sun.com for Linux. There was file src.zip in. But first I uninstalled all Java packages with Synaptic.

Solution 11 - Java

The official link no longer offers the original source code. The official link and casual Google searches will land you with OpenJDK.

OpenJDK causes problems with an Android build unless the build script files are modified. The original package can be found here:

sudo add-apt-repository "deb http://ppa.launchpad.net/ferramroberto/java/ubuntu oneiric main"

This repository still has the sun-java6-source package.

Credit: Installing sun-java-6 with apt-get in Linux

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartijn CourteauxView Question on Stackoverflow
Solution 1 - JavaJon SkeetView Answer on Stackoverflow
Solution 2 - JavaamertkaraView Answer on Stackoverflow
Solution 3 - Javauser4229245View Answer on Stackoverflow
Solution 4 - JavaXortyView Answer on Stackoverflow
Solution 5 - JavaMisterEdView Answer on Stackoverflow
Solution 6 - JavavbezhenarView Answer on Stackoverflow
Solution 7 - JavadvsakgecView Answer on Stackoverflow
Solution 8 - JavafrewperView Answer on Stackoverflow
Solution 9 - JavapeteryView Answer on Stackoverflow
Solution 10 - JavaMartijn CourteauxView Answer on Stackoverflow
Solution 11 - JavaJitendra KulkarniView Answer on Stackoverflow