Where can I find the source code for the Java library classes? I mean classes in rt.jar.
Platform: Windows.
Where can I find the source code for the Java library classes? I mean classes in rt.jar.
Platform: Windows.
For old versions of Java with separate JRE and JDK downloads, download the JDK. The sources for the public classes are in src.zip.
src.zip in the JDK installation, like he just said.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.
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.
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
If you only need to have a look at the source/implemenation, i would suggest using
Edit
GrepCode is even better
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.
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
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=