3

Does anyone happen to know where, if at all possible, I can take a look at the code of the java's built-in libraries?

I've tried Ctrl + Shift + B (which is the Netbeans' equivalence of Eclipse's Ctrl + Shift T) to "go to source", but I can only see the method header, and the body is always:

//compiled code
throw new RuntimeException("Compiled Code");

For instance, I'd see the following if I tried to view String.charAt(int)

public char charAt(int i)
{
    //compiled code
    throw new RuntimeException("Compiled Code");
}
One Two Three
  • 22,327
  • 24
  • 73
  • 114

4 Answers4

6

built-in libraries source code is available with jdk. For example on a windows box the jdk folder would contain src.zip which contain the sources for the built-in libraries

Hope this helps.

krishnakumarp
  • 8,967
  • 3
  • 49
  • 55
2

Sure, JDK is distributed with sources, you can conveniently open them in your IDE. Look for "src.jar".

It probably already is set up. In Eclipse, just try to Ctrl-Shift-T something like "java.lang.String".

A web search will also turn up nicely linked and formatted pages.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • I tried `Ctrl + Shift + B`, which is the Netbeans' equivalence of `Ctrl + Shift + T`, but I can only see the method header, where the body is `//compiled code` `throw new RuntimeException("Compiled Code");` – One Two Three Apr 13 '12 at 05:42
0

Google "java decompiler" and download it. You can see the source code for any class file in the libraries.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Chandra Sekhar
  • 18,914
  • 16
  • 84
  • 125
0

You can also use jad to decompile any .class file

naeemgik
  • 2,232
  • 4
  • 25
  • 47