One of the advantage of using Java is that it is open source which means that we can go and see the source code of any class in JDK. When we download the JDK, the source code for Java is shipped by the name of src.zip and is placed at the root of the JDK folder. If we open the src.zip file, we can see all the top level packages like java, javax, com and org etc.

When developing a Java application, we have to refer to the source code of a class or method to see how a particular API is working. Since we can’t open the src.zip file and browse for the required file every time, IDE’s such as eclipse allow us to attach the source code inside the Java project.

The following series of screenshots show how to attach and then use the JDK source code browsing in Eclipse IDE. Here I am using Eclipse Indigo and JDK 1.7.

  • 1) Open your application and select a Java class like String in the source code as shown below:

  • 2) Press F3 or Ctrl+Left-Click on the selected keyword (String in this case). The String class shall be opened with a button to attach the source code for this class.

  • 3) Press the “Attach Source” button and choose an External file which in our case is the src.zip file located in the JDK installation folder.

  • 4) After choosing the src.zip and pressing the OK button, the source code for String class will be shown as below:

  • 5) Now you can see the source code of any method or class present in the JDK by pressing selecting and pressing F3 key for the specific method or class.

Reference

1) http://java.dzone.com/articles/attaching-java-source-eclipse
2) http://www.vogella.com/articles/Eclipse/article.html#classpath_jarsource
3) http://www.javacodegeeks.com/2011/08/eclipse-how-attach-java-source.html

Attach JDK source in Java application in Eclipse admin Eclipse
One of the advantage of using Java is that it is open source which means that we can go and see the source code of any class in JDK. When we download the JDK, the source code for Java is shipped by the name of src.zip and is placed...
<p>One of the advantage of using Java is that it is open source which means that we can go and see the source code of any class in JDK. When we download the JDK,<strong> the source code for Java is shipped by the name of src.zip</strong> and is placed at the root of the JDK folder. If we open the src.zip file, we can see all the top level packages like java, javax, com and org etc. When developing a Java application, we have to refer to the source code of a class or method to see how a particular API is working. Since we can't open the src.zip file and browse for the required file every time, IDE's such as eclipse allow us to attach the source code inside the Java project. <strong>The following series of screenshots show how to attach and then use the JDK source code</strong> browsing in Eclipse IDE. Here I am using Eclipse Indigo and JDK 1.7.</p> <ul><li> <p> 1) Open your application and select a Java class like String in the source code as shown below: <img src="http://www.javaexperience.com/wp-content/uploads/2012/10/Java-class-selection.jpg" alt="" title="Java class selection" width="257" height="22" class="alignnone size-full wp-image-1171" /> </p> </li> <li> <p>2) Press F3 or Ctrl+Left-Click on the selected keyword (String in this case). The String class shall be opened with a button to attach the source code for this class. <img src="http://www.javaexperience.com/wp-content/uploads/2012/10/Attach-Source-code.jpg" alt="" title="Attach Source code" width="200" height="252" class="alignnone size-full wp-image-1172" /> </p> </li> <li> <p>3) Press the "Attach Source" button and choose an External file which in our case is the src.zip file located in the JDK installation folder. <img src="http://www.javaexperience.com/wp-content/uploads/2012/10/select-src-e1351607709661.jpg" alt="" title="select src" width="535" height="311" class="alignnone size-full wp-image-1173" /> </p> </li> <li> <p>4) After choosing the src.zip and pressing the OK button, the source code for String class will be shown as below: <img src="http://www.javaexperience.com/wp-content/uploads/2012/10/JDK-source-code-e1351607768452.jpg" alt="" title="JDK source code" width="535" height="407" class="alignnone size-full wp-image-1174" /> </p> </li> <li> <p>5) Now you can see the source code of any method or class present in the JDK by pressing selecting and pressing F3 key for the specific method or class.</p> </li> </ul> <h2>Reference</h2> 1) http://java.dzone.com/articles/attaching-java-source-eclipse 2) http://www.vogella.com/articles/Eclipse/article.html#classpath_jarsource 3) http://www.javacodegeeks.com/2011/08/eclipse-how-attach-java-source.html