• Post Reply Bookmark Topic Watch Topic
  • New Topic

source code for pre defined methods  RSS feed

 
Suyash Gulati
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.Is there any way by which i can see what is happening inside pre defined methods.
i.e. can i see there source code?
if yes please tell me the command for it!

2.Somewhere i learned how to see the content of a pre defined class i.e. by using:

javap java.io.classname

but i dont know what javap means!
can anyone tell me this as well?
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In fact the JDK comes with the source code in a zip file for all the classes.

The "javap" command disassembles the class files. here
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "predefined methods", you mean the standard libraries that come with Java? As K. Tsang has said, it comes with the JDK download. Mine was under:

C:\Program Files\Java\jdk1.8.0_05\src.zip

In Windows, the folder will unzip automatically. Then you can look at the .java file with anything from Notepad to an IDE.

But if you don't have the .java (source) file but only the .class (compiled) file, you can use javap as explained.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought the javap tool displayed the bytecode, not the source code.
If you mean standard J2SE classes, all the well‑known ones are in the src.zip file, as two people have already told you. The zip file is divided into folders and its structure corresponds to the package names of the classes.
 
Scott Winterbourne
Ranch Hand
Posts: 116
2
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I thought the javap tool displayed the bytecode, not the source code.

In fact the javap command does display the bytecode, not source code. If you use javap FileName, it will show you the bytecode of the class definitions. If you use javap FileName -verbose it will show you all of the bytecode for the class members as well.
 
Suyash Gulati
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you everyone!
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!