How to Find the Java Jdk Source Code

Where can I find the Java JDK source code?

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.

How do I view a specific Java source code file from the JDK in IntelliJ?

You can use Navigate -> Go to class... :

Sample Image

and then type in ClassLoader to find it (make sure scope is set to 'All Places'):

Sample Image

The default mapping is Ctrl + N (but I'm using the Eclipse keymap, so for me it's mapped to Ctrl+Shift+T)

Native methods' implementation in jdk source code?

Searching the OpenJDK Mercurial Repository online is indeed always a bit difficult. There are some mirrors of the JDK source code on GitHub, which has a far better search functionality - for example:

https://github.com/openjdk-mirror/jdk7u-jdk/search?utf8=%E2%9C%93&q=isReachable0

Quite often you can "guess" from parts of the paths of the result where you have to look in the original OpenJDK repo, here, this would be

http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/82b276590b85/src/windows/native/java/net/Inet4AddressImpl.c#l416

(for Windows - other implementations can be found by browsing into the corresponding paths of the respective OS)

Where can I find the JDK 1.5 source code?

The name Java can be applied to many different components that work together. It might mean the "Java Virtual Machine" to some, the "Java Language Specification" to others, "Java compilers" to many, and "Java language libraries" to quite a few.

If you want the source code to the Java virtual machine (JVM) for Java5, it is available; but, not under an open source license. The first "open source" copy of Java was released with "Java 6". If you want Java5 source code, you needed to sign up for a "Java Researcher License Agreement" which provided you access to the source code for the JVM for (at least Java5). Having the source code of the JVM is completely unnecessary in writing code for the Java5 environment.

If you want the source code for the Java Language Specification for Java5, it is a text document (typically published as a book or on-line set of web pages). While it might allow you to understand if a compiler should complain with an error under certain circumstances, again it is not necessary to write a program for the Java5 environment.

If you want the Java5 compiler, it can be downloaded in the oracle archives of old releases of the Java development toolkit. If you want write a program for Java5, downloading and using this offering is generally best-practice for developing Java5 programs. Alternatively you may configured a compatible compatible compiler (Java6 / Java7) to emit Java5 code.

If you want the Java5 language libraries, they are included with the Java5 development kit. The Java6 and Java7 development kit offerings provide language libraries that go to great efforts to be compatible with Java5 source code; however, newer libraries also include newer features and operations which a stock Java5 virtual machine will not be able to reference. Again, there are techniques to safely use a backwards-compatible version of Java (6/7); however, one doesn't need to apply any extra care if they base their development off a Java5 development kit. The "source code" for the language libraries was included in the source code for the JVM under the Java Research License Agreement, to the degree that SUN was allowed to include such source code.

While SUN has licensed a number of technologies from other companies in a manner where they can be freely distributed with Java5, SUN did not necessarily own all of the technologies in Java5 outright. As such, even under the Java Researcher License Agreement, some of the source code is not available (although the compiled libraries are). Open source projects (like OpenJDK) were quick to implement these missing "holes" with open-source libraries to get a fully functional open-source Java stack; but, that is Java6+ (not Java5).

How to download OpenJDK 8 source code from java.net

First of all. Oracle JDK is in essence OpenJDK because Oracle handed over (nearly) the whole stuff over to OpenJDK. Oracle JDK can be seen as one VM based on OpenJDK as there are others. What is stopping this month is the free availability of OracleJDK-updates, etc. but that has no effect on the other VMs out there.

The source can be accessed (including newer versions after Oracle stops their free support) at the Mercurial Repositories at http://hg.openjdk.java.net. The sources you're looking for should be available at http://hg.openjdk.java.net/jdk/jdk/tags

Edit: Because you asked in a later comment in your question: You can download the source of a given project by clicking onto one of the links on the left side of the page showing the names of archive-files (bz2, zip tar) at the start-page of a given tag.

Edit2: Because you asked for Java 1.8.0_192 (I assume b26), you can use http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/archive/996dd3ce1ec5.zip. Here are the steps to get to it: From the main page go to the Project jdk8u (http://hg.openjdk.java.net/jdk8u). Select jdk8u-dev->JDK (http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/). Click on "Tags" (http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/tags), select "jdk8u192-b26 " (http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/rev/996dd3ce1ec5) and click on one of the archive-formats on the left, e.g. ZIP (see above).

How to rebind JDK Source Code to my IDE?

I wrote this question to be a modified duplicate of Where to find Java JDK Source Code?. That was closed because of being off topic, but I think this is a very relevant question.

Short answers

If you're working with Oracle's Java, all you need to do is install a JDK of the Java package you are working with, and then set up your IDE to use that JDK to support its projects. The "src.zip" is prepackaged, and your IDE (or at least Eclipse) should be able to display the source files in it on its own.

If you are working with the open JDK, all you need to know is that the JDK, its Javadocs, and its source code are each in their own rpm. You to get the source code for the java version you're working with, you merely need to find and install the java-1.X.X-openjkd-src. 1.8 adds "-debug" to the name. Once you've done that, just restart your IDE, and it should pick up the source files while reloading its projects.

Oracle

If you are working with Oracle's Java, you need to make sure you are developing against a JDK, not a JRE. Here is an example site, which allows you to download the JDK for JavaSE: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

You'll want to accept the license agreement and then pull the appropriate JDK for the system you want to install it on. In my case, I'm installing on 64 bit Linux, so I downloaded jdk-8u121-linux-x64.rpm.

Once downloaded, run the installer. That done, look for where the installer actually put its files. On Linux, you can use this command to find what you installed...

rpm -qa | grep jdk

...and this to look up its information (in my case, using jdk1.8.0_121.

rpm -qi jdk1.8.0_121

You can look in the Relocations field to get an idea for where to start, or you can Change the -i parameter to -l to get a full listing of the files actually installed.

You may be able to do as little as register this newly installed JDK with your IDE, and it will be smart enough to know where to find the source code. However, if that doesn't get the job done, you can find the src.zip file by grepping the full list of files installed like this:

$ rpm -ql | grep 'src.zip'
/usr/java/jdk1.8.0_121/src.zip

Now just point your IDE at that zip file, and you're good.

Open JDK

The only trick to finding the source code for open JDK is to realize that they install their source code in a different package than the basic JDK.

So using your package manager of choice, look for the available jdk packages. Look at the one you have installed and are working with, and find the pacakge with the same name and the -src extension.

So if you've got java-1.8.0-openjdk, you should be able to find java-1.8.0-openjdk-src. Install that package, restart your IDE, and you should be able to view then source code.



Related Topics



Leave a reply



Submit