• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Java Class Sources

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic