Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

view java source code

Tags:

Is any way to view the actual code behind the default classes in Java (java.awt.*;, javax.swing.*;, etc) to see exactly what it is that is happening?

I don't mean just the documentation, or a list of methods, etc, but the source code itself in full detail (in other words, what could be used to create an exact copy of an entire method/class if copied and pasted into the code for a program in Java).

like image 696
scaevity Avatar asked Jun 09 '11 05:06

scaevity


People also ask

Where can I find Java source code?

Install the Java SE Development Kit from http://java.sun.com/javase/downloads/index.jsp. Once installed, you should find an archive called src. zip in the top of the JDK installation directory. The Java source code is in there.

How do I view source code in Eclipse?

Go to Windows->Preferences->Java->Installed JREs. Select Browse and navigate to the C:\Program Files\Java\jdk1. 6.0_21 directory. Eclipse will automatically find the source and associate it with the JDK classes.

What is the view in Java?

A View is a Java Class that inherits directly from the Java Object class, the root of the Java class hierarchy. Views are the basic building block for all Android GUI elements, and serve as the base class for all GUI widgets.

What is source code in Java?

Source code is the set of instructions and statements written by a programmer using a computer programming language. This code is later translated into machine language by a compiler.


2 Answers

The Java source code for all the API classes is shipped in the JDK installer in a file named src.zip. It's often just sitting in your install directory. Unzip it, and have a look.

If it's not there, you may have chosen not to install it; reinstall the JDK and watch for the "source code" option, making sure to include it.

like image 165
Ernest Friedman-Hill Avatar answered Oct 23 '22 10:10

Ernest Friedman-Hill


I frequently use http://docjar.com for this purpose.

Example: I want to see the source code for String. Search for the FQCN, java.lang.string (using the "Package/class Name" option). Click the result you want, then click the source link at the top of the page. Voila: http://www.docjar.com/html/api/java/lang/String.java.html

like image 45
Matt Ball Avatar answered Oct 23 '22 09:10

Matt Ball