By source code , i mean the actual .java files packed up inside src.zip located in the jdk folder. Should i Import the entire thing into eclipse and see from there ?
If so , then How ? Or is it done some other way ?
edit 2 :
Jeremy's suggestion worked best. Only the ctrl key has to be pressed before taking the pointer to the class you want to see the code for.
edit 1:
From the suggestions i tried to import src.zip into eclipse by going into preferences. this is a snapshot of what i'm getting :
enter image description here
Its a major pain to search through because of the length of the list . I'm surely doing something wrong here ?
-
2If you're talking about the Java API...look it up online. You'll go through a lot less pain.Makoto– Makoto2013年09月21日 04:52:11 +00:00Commented Sep 21, 2013 at 4:52
-
online doc is better , the IDE provides doc view too when using methodsSrinath Ganesh– Srinath Ganesh2013年09月21日 04:53:47 +00:00Commented Sep 21, 2013 at 4:53
-
Umm , no , i mean the actual code of the stuff.Somjit– Somjit2013年09月21日 04:53:57 +00:00Commented Sep 21, 2013 at 4:53
-
possible duplicate of view java source codejimSampica– jimSampica2013年09月21日 05:03:30 +00:00Commented Sep 21, 2013 at 5:03
-
1There's no single source, it depends on the Java implementation, and there are many different implementations. For example, there's GNU's implementation and Android, to name two.Adam Rosenfield– Adam Rosenfield2013年09月21日 05:05:21 +00:00Commented Sep 21, 2013 at 5:05
3 Answers 3
You mentioned Eclipse.
Go to Preferences. In the left-hand menu, open Java and select Installed JREs. Select your JRE in the main pane and "Edit...". Find and select rt.jar. Click "Source Attachment...", "External File..." and navigate to src.zip. You might also want to set the Javadoc location to an appropriate location such as http://download.oracle.com/javase/7/docs/api/ (as a Javadoc URL).
Having done that, ctrl-click (or cmd-click on MacOS) will take you to the source code. You can also navigate directly to the source code by opening the JRE System Library under your project in the Package Explorer, and then opening rt.jar. (If source code isn't attached, you can still do that but when you try to open a class file or method/field therein, you'll end up seeing the Java byte code instead of the Java source.)
Don't forget, as commentators have said, that the API (Javadoc) is generally a better place to look than the source code. The source code can change; the API should not.
4 Comments
If your are using Eclipse IDE you can set the src using Source Attachment dialog. Follow the below procedure
In Eclipse, Select a JAR in the Package Explorer and choose
Properties> Java Source Attachment from the context menu or the Project menu
Java src Then you can browse the source code just like how you browse your own code.
If your are looking up to set the Java SDK source. You should follow the steps here.
3 Comments
ArrayList in Java 7. the src.zip has it , and i want to read it . If you could see my updated post , i'm posting a picture of what i'm getting.You can see the JDK (OpenJDK) source code online, using a service like grepcode.com.
You can use grepcode's search function or simple google a source file by adding the site's name before a class, for example grepcode java.lang.String.
OpenJDK 7 is the Java SE 7 reference implementation. You can't get the reference implementation for Java 6 this way because of it's license, but if you are interested in how things work in general, the OpenJDK 6 will be fine too.
4 Comments
ArrayList , and it showed me a whole bunch of options. What do i do if i just want to see the code for jdk 7's version of ArrayList ?