Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Class Sources  RSS feed

 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anywhere that i can view the sources of the API classes. I want to learn how these things work. Such as javax.swing.event classes like actionlisteners.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look in the directory where your JDK is installed, there is a file called src.zip that has the source files of all of the classes (some methods are marked native so you won't find their source code) in the API.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever I want to look at the source, I use an ide called GEL (its the only thing I use it for) - it has Search/Go To Class e.g. select ActionListener and the
source code is displayed.

Classes not in src.zip are decompiled, then displayed
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other IDEs, like Eclipse, can also automatically show you the source code of the JDK classes. In Eclipse you need to attach the source to the JRE by doing this:

- Go to Window / Preferences... / Java / Installed JREs
- Click on the JRE you want to attach the source to
- Click the Edit... button
- From the list of JARs, select rt.jar
- Click on the button Source Attachment...
- Enter the location of src.zip in the JDK directory
- Click OK a few times to close the windows

Now Eclipse will show you the source for the JDK classes if you put the caret on a JDK class and press F3. Likewise you can attach the Javadoc API documentation to a JRE.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!