File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Converting class code back to source code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Converting class code back to source code" Watch "Converting class code back to source code" New topic

Converting class code back to source code

Doug Wolfinger

Joined: Jul 27, 2002
Posts: 18
Please help! I ran a program and redirected the output to a flat file, but I named that file the same as the program name. So I overwrote my program,, with the text of the output by saying java Selection > Anyone know the DOS command to convert the .class file back to the .java file?
EDIT: I'll try to find a decompiler at Isn't javap supposed to do this? It does something, but it doesn't create the .java file when I run it in \bin.
[ November 18, 2002: Message edited by: Doug Wolfinger ]
[ November 18, 2002: Message edited by: Doug Wolfinger ]
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
try a google search for "java decompiler".
I've used DJ before

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
javap is not a decompiler.

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
just downloaded and used mocha.
it is a basic tool.
it is a very cool tool.
i wish i had it a few year ago.

what i did to get mocha to work
1. downloaded
2. copied to c:\jdk1.3.1\lib
3. add c:\jdk1.3.1\lib\ to my CLASSPATH
4. from a dos prompt i typed
java mocha.Decompiler -v -o test63.class
*. a text file called test63.mocha is created
that's it...
[ November 20, 2002: Message edited by: Monty Ireland ]

Multi Platform Database Developer & DBA on E.S.T.
Doug Wolfinger

Joined: Jul 27, 2002
Posts: 18
Thanks, all. I have a beta Mocha installed but can't get it to work, so I used DJ. The decompilation was very pleasant but I noticed some disturbing things afterwards. For one thing, I couldn't get into my c:\ where the executable was located after the decompilation. It was alarming. The software locked up the c:\ somehow. So I closed Win Explorer and everything was fine when I reopened it. And I noticed that all class files had the DJ icon. I decided to get rid of it, and deleted the DJ files that made all the class files associate with it.
I didn't realize the source code would be neatly formatted by the decompiler, so that was a nice surprise.
If the new version of Mocha works I might go with that; it operates from the dos command line, so it should be less obtrusive.
[ November 19, 2002: Message edited by: Doug Wolfinger ]
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
try to find "jad" java decompiler
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Igor Ko:
try to find "jad" java decompiler

Jad's great -- very easy to use,
install it, put it in your %PATH% and call jad someClass.class and *poof* it write a someClass.jad for you. -- Just make sure you check out the known limitations of the product and realize you'll lose all comments from the code.

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
I agree. Here's the link:
subject: Converting class code back to source code
It's not a secret anymore!