Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I view source code of built-in classes in Java (e.g. BigInteger etc.)?

Tags:

java

For example, during some compilation errors, I get access to some built in source codes where the error has occured (maybe the perimeters were wrong in main). How can I access those same source codes manually? I am primarily interested in the BigInteger class.

like image 828
mrahh Avatar asked Mar 26 '14 08:03

mrahh


People also ask

How can I see the source code of a Java application?

The IDE's built-in Source Editor enables you to view, create, and edit your Java source code. Open the Source Editor window by double-clicking a node in the Projects window, Files window, or Navigator window. Alternatively, you can open the Source Editor by choosing File > New to create a new file.

How can I see inbuilt classes in Eclipse?

To get there, we go to the menu under Navigate > Open Type in Hierarchy or we use the shortcut: Ctrl + Shift + H on a PC or Cmd + Shift + H on a Mac. This dialog is similar to the Open Type dialog. Except for this time when we click on a class, then we get the Type Hierarchy view.

What is class in Oops Java?

A class is a user defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type.


2 Answers

The source code is included in the JDK. There is a src.zip somewhere. You can tell Eclipse to use that file, so you can jump to classes or method declarations even in the standard library.

When you install any JDK, you get src.zip in java/jdk folder. while opening any inbuilt file it will ask you to attach resource. You just need to browse to that location and supply once src.zip. After that when ever you click on java inbuilt class name it will show you the code.

like image 136
Joey Avatar answered Oct 05 '22 04:10

Joey


You can view the source code on the official openjdk site: http://openjdk.java.net/

I always have a copy of whatever jdk I'm working laying around, always nice to check on certain implementations etc.

like image 26
nablex Avatar answered Oct 05 '22 05:10

nablex