scaevity
scaevity

Reputation: 4091

view java source code

Is any way to view the actual code behind the default classes in Java (java.awt.*;, javax.swing.*;, etc) to see exactly what it is that is happening?

I don't mean just the documentation, or a list of methods, etc, but the source code itself in full detail (in other words, what could be used to create an exact copy of an entire method/class if copied and pasted into the code for a program in Java).

Upvotes: 22

Views: 33518

Answers (6)

hexabunny
hexabunny

Reputation: 1415

I also find http://www.codeatlas.com to be a great place to look for JVM based source code in general. For example, if you are ever looking for how java.awt.ActionEvent is implemented you can find it here:

http://www.codatlas.com/project/L_fXVCOhW4_lzXEd3R5DNQ__/master/src/share/classes/java/awt/event/ActionEvent.java?keyword=ActionEvent&line=59

What's nice about it is that it gives an IDE like browsing experience by adding cross-reference and syntax highlighting.

Upvotes: 3

greenqy
greenqy

Reputation: 706

For those who use linux distributions, like ubuntu, archlinux, etc. You can always get openjdk source code via corresponding package management system. This means you can choose a faster mirror to get the source code.

For ubuntu users:

$ sudo apt-get install openjdk-7-source

For Archlinux users:

$ sudo pacman -S openjdk7-src

The source will be located in the $JAVA_HOME, somewhere like /usr/lib/jvm/java-7-openjdk/src.zip.

Other distributions will have likewise package names, so not listed here.

Upvotes: 1

Srujan Kumar Gulla
Srujan Kumar Gulla

Reputation: 5851

1) Use Eclipse to attach the source code in C:\users\program files\jdkx.x
2) Use GrepCode if you are just browsing the code and to save memory used by heavy weight eclipse on your machine

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 360016

I frequently use http://docjar.com for this purpose.

Example: I want to see the source code for String. Search for the FQCN, java.lang.string (using the "Package/class Name" option). Click the result you want, then click the source link at the top of the page. Voila: http://www.docjar.com/html/api/java/lang/String.java.html

Upvotes: 14

Alex Gitelman
Alex Gitelman

Reputation: 24732

src.zip usually comes with JDK.

Upvotes: 4

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81724

The Java source code for all the API classes is shipped in the JDK installer in a file named src.zip. It's often just sitting in your install directory. Unzip it, and have a look.

If it's not there, you may have chosen not to install it; reinstall the JDK and watch for the "source code" option, making sure to include it.

Upvotes: 26

Related Questions