0

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 ?

asked Sep 21, 2013 at 4:50
6
  • 2
    If you're talking about the Java API...look it up online. You'll go through a lot less pain. Commented Sep 21, 2013 at 4:52
  • online doc is better , the IDE provides doc view too when using methods Commented Sep 21, 2013 at 4:53
  • Umm , no , i mean the actual code of the stuff. Commented Sep 21, 2013 at 4:53
  • possible duplicate of view java source code Commented Sep 21, 2013 at 5:03
  • 1
    There'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. Commented Sep 21, 2013 at 5:05

3 Answers 3

2

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.

answered Sep 21, 2013 at 5:06
Sign up to request clarification or add additional context in comments.

4 Comments

So far , I'm getting a HUGE list of all the things in there. And its really painful to search through them. Also , where exactly do i ctrl + click ?
Nevermind , Figured that i had to 1st hit ctrl then drag the pointer to the stuff i want to see the code of. Problem solved :)
@SomjitNag you should learn at least the basic shortcuts and capabilities of your ide - it will save you hours (literally).
Very true. I'll be looking more into eclipse's bells and whistles now on . Thanks for all the help. :)
2

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.

answered Sep 21, 2013 at 5:05

3 Comments

I was trying out what you said before you made the edit. Can you explain how this is different from your 1st suggestion ?
First I misunderstood that you wanted to attach JAVA SDK src to eclipse. Please let me know if that's what you are trying to do.
As an example , i want to read the source for 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.
1

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.

answered Sep 21, 2013 at 5:04

4 Comments

I went there , typed in 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 ?
@assylias : Yes , but while that's true , my question was how to go about viewing it. I can open things up individually in notepad and see them too , but I was hoping for something more eye-friendly , and easily searchable.
@SomjitNag The search results show matching class names, but there often are multiple projects with different implementations of the class. See the top search result, "openjdk" is the one you'll want, next to it are the links to the source for the versions 6 and 7.
@SomjitNag what I meant is that you can view the jdk code directly in your ide so there is no need to search on grepcode or openjdk websites.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.