How do I "decompile" Java class files? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
What program can I use to decompile a class file? Will I actually get Java code, or is it just JVM assembly code?
On Java performance questions on this site I often see responses from people who have "decompiled" the Java class file to see how the compiler optimizes certain things.

Update February 2016:
www.javadecompilers.com lists JAD as being:
the most popular Java decompiler, but primarily of this age only. Written in C++, so very fast.
Outdated, unsupported and does not decompile correctly Java 5 and later
So your mileage may vary with recent jdk (7, 8).
The same site list other tools.
And javadecompiler, as noted by Salvador Valencia in the comments (Sept 2017), offers a SaaS where you upload the .class file to the cloud and it returns you the decompiled code.
Original answer: Oct. 2008
The final release of JSR 176, defining the major features of J2SE 5.0 (Java SE 5), has been published on September 30, 2004.
The lastest Java version supported by JAD, the famous Java decompiler written by Mr. Pavel Kouznetsov, is JDK 1.3.
Most of the Java decompilers downloadable today from the Internet, such as “DJ Java Decompiler” or “Cavaj Java Decompiler”, are powered by JAD: they can not display Java 5 sources.
Java Decompiler (Yet another Fast Java decompiler) has:
Explicit support for decompiling and analyzing Java 5+ “.class” files.
A nice GUI:
It works with compilers from JDK 1.1.8 up to JDK 1.7.0, and others (Jikes, JRockit, etc.).
It features an online live demo version that is actually fully functional! You can just drop a jar file on the page and see the decompiled source code without installing anything.

There are a few decompilers out there... A quick search yields:
Procyon: open-source (Apache 2) and actively developed
Krakatau: open-source (GPLv3) and actively developed
CFR: open-source (MIT) and actively developed
JAD
DJ Java Decompiler
Mocha
And many more.
These produce Java code. Java comes with something that lets you see JVM byte code (javap).

To see Java source code check some decompiler. Go search for jad.
If you want to see bytecodes, just use javap which comes with the JDK.

I tried several, and Procyon seemed to work the best for me. It's under active development and supports many features of the latest versions of Java.
These are the others I tried:
CFR
Promising, but often failed method decompilation. I'll be keeping my eye on this one. Also actively developed with support for the latest Java features.
Krakatau
Takes a different approach in that it tries to output equivalent Java code instead of trying to reconstruct the original source, which has the potential of making it better for obfuscated code. From my testing it was roughly on par with Procyon, but still nice to have something different. I did have to use the -skip command-line flag so it wouldn't stop on errors. Actively developed, and interestingly enough it's written in Python.
JD-GUI
Worked, but Procyon's output was much better. Here's a page comparing Procyon output to the original and JD-GUI. JD-GUI is also available as an Eclipse plugin, which didn't work for me at all. Doesn't seem to be open source and development seems sporadic.
JAD
Worked, but only supports Java 1.4 and below. Also available as an Eclipse plugin. No longer under development.

I use JAD Decompiler.
There is an Eclipse plugin for it, jadeclipse. It is pretty nice.

Procyon includes a decompiler. It is FOSS.

Soot is an option for newer Java code. At least it has the advantage of still being recently maintained...
Also, Java Decompiler is a decompiler with both a stand-alone GUI and Eclipse integration.
Lastly, Jdec hasn't been mentioned, though it's not as polished as other options.

JD-GUI is really good. You could just open a JAR file and browse through the code as if
you are working on an IDE. Good stuff.

Here's a list of decompilers as of Feb 2015:
Procyon, open-source, https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler
CFR, free, no source-code available, http://www.benf.org/other/cfr/
JD, free for non-commercial use only, http://jd.benow.ca/
Fernflower, open-source, https://github.com/fesh0r/fernflower,
JAD – given here only for historical reason. Free, no source-code available, http://varaneckas.com/jad/
Outdated, unsupported and does not decompile correctly Java 5 and later.
You may test above-mentioned decompilers online, no installation required and make your own educated choice.
Java decompilers in the cloud: http://www.javadecompilers.com/

There are a few programs you can use. You will get the actual Java code, but sometimes the code will have been obfuscated so methods are named by one letter or number or a random mix of letters and numbers.
DJ Decompiler
Mocha

Most decompilers for Java are based on JAD. It's a great tool, but unfortunately hasn't been updated for a while and does not handle Java 1.5+ classes very well. I have not seen any tools that will properly handle 1.5+ classes.

Take a look at cavaj.

All of the JAD links listed so far far seem to be broken, so I found this site. Works great (for Linux, at least)! On Ubuntu 11.10 I had to download the static one for whatever reason.
http://www.varaneckas.com/jad

JAD is one that works and is simple.
Also, if you just want to see the methods, use javap.

If you want to see how the Java compiler does certain things, you don't want decompilation, you want disassembly. Decompilation involves transforming the bytecode into Java source, meaning that a lot of low level information is lost, and if you're wondering about compiler optimization, this is probably the very information you're interested in.
Anyway, I happen to have written an open source Java disassembler. Unlike Javap, this works even on highly pathological classes, so you can see what obfuscation tools are doing to your classes as well. It can also do decompilation, though I wouldn't recommend it.

JAD doesn't work for me (Ubuntu 11.10 issue) so I've moved forward and sopped on JODO. At least it has Open Java source code and been able to decompile my .class properly.
I recommend to check out 'branches/generic' branch first. The trunks is not stable.

On IntelliJ IDEA platform you can use Java Decompiler IntelliJ Plugin. It allows you to display all the Java sources during your debugging process, even if you do not have them all. It is based on the famous tools JD-GUI.

With AndroChef Java Decompiler you can decompile apk, dex, jar and java class-files. It's simple and easy. AndroChef JD is based on FernFlower. You can evaluate it in 10 free uses.
AndroChef supports Java language features like generics, enums and annotations. According to some studies, AndroChef Java Decompiler is able to decompile 98.04% of Java applications generated with traditional Java compilers - a very high recovery rate. It is simple but powerful tool that allows you to decompile Java and Dalvik bytecode (DEX, APK) into readable Java source.

For OSX I recommend: jarzilla or JD-GUI
They both allow you to view jar,war,etc. file content and decompiles any class files inside of them.
Jarzilla: https://code.google.com/p/jarzilla/
JD-GUI: http://jd.benow.ca/

Related

Is there a compelling case for compiling Groovy from source on Java 8 for packaging?

The title pretty much says it all. I'm working on a largeish software project that recently upgraded to Java 8. We want to incorporate the latest version of Groovy (2.4.1) for some aspects of the project. I'm creating an RPM for internal deployment purposes (for various reasons that I won't go into here, we don't want to use GVM or other means to install), and I'm wondering if anyone can offer a compelling argument for compiling from source using Java 8 versus grabbing the binary/sdk distribution. It seems like a bit of a tossup to me and I'm currently leaning in favor of the convenience of the binary distribution, but I'd like to hear what others have to say.
I would always recommend using pre-built binaries unless you have to make changes. The overhead of maintaining the source, and keeping it compiled is not worth the benefits (if there are any). Compiling from source should always be a last resort.

What is sjavac, who is it for and how do I use it?

There has been some buzz about a tool called sjavac on the OpenJDK mailing lists. Also, there are two related JEPs: JEP 139: Enhance javac to Improve Build Speed and JEP 199: Smart Java Compilation, Phase Two.
My questions are:
What exactly is the sjavac tool?
Who is it intended for?
How do I use it?
Disclaimer: Self answered question. Just wanted to bring the knowledge of this tool to the StackOverflow community and to create a reference to future sjavac FAQ.
What exactly is the sjavac tool?
The sjavac tool is an (allegedly smart) wrapper around javac, developed at Oracle and intended to provide the following features:
incremental compiles - recompile only what's necessary
parallel compilation - utilize more than one core during compilation
keep compiler in a hot VM - reuse a JIT'ed javac instance for consecutive invocations
When recompiling a set of source files, javac looks at the timestamps of the .java and .class files to determine what to keep and what to recompile. This is incredibly crude and can be devastating for large code bases. In addition to the timestamps sjavac inspects the public API of the dependencies to judge which files need to be recompiled.
Sjavac also attempts to split up the compilation into multiple invocations of javac. In other words, it brings a high level of parallelism to the build process.
Finally, the sjavac tool is split in a client part and a server part which allows you to leave sjavac running in the background, JIT'ed and ready for use in consecutive calls.
Who is it intended for?
People who are working on large projects and frequently recompiles the code base during development are encouraged to try out sjavac. (Be aware however that the tool is currently under development and there are still open issues.)
How do I use it?
The tool is not yet shipped with the OpenJDK, so you'll have to get it from the OpenJDK jdk9/dev repository. Also, there is no launcher in place yet, so you invoke it with java com.sun.tools.sjavac.Main.

Where can I find the JDK 1.5 source code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Where can I find the entire source code for JDK 1.5 to download? I am unable to find the exact link on the oracle site; the link provided only goes in circles.
The name Java can be applied to many different components that work together. It might mean the "Java Virtual Machine" to some, the "Java Language Specification" to others, "Java compilers" to many, and "Java language libraries" to quite a few.
If you want the source code to the Java virtual machine (JVM) for Java5, it is available; but, not under an open source license. The first "open source" copy of Java was released with "Java 6". If you want Java5 source code, you needed to sign up for a "Java Researcher License Agreement" which provided you access to the source code for the JVM for (at least Java5). Having the source code of the JVM is completely unnecessary in writing code for the Java5 environment.
If you want the source code for the Java Language Specification for Java5, it is a text document (typically published as a book or on-line set of web pages). While it might allow you to understand if a compiler should complain with an error under certain circumstances, again it is not necessary to write a program for the Java5 environment.
If you want the Java5 compiler, it can be downloaded in the oracle archives of old releases of the Java development toolkit. If you want write a program for Java5, downloading and using this offering is generally best-practice for developing Java5 programs. Alternatively you may configured a compatible compatible compiler (Java6 / Java7) to emit Java5 code.
If you want the Java5 language libraries, they are included with the Java5 development kit. The Java6 and Java7 development kit offerings provide language libraries that go to great efforts to be compatible with Java5 source code; however, newer libraries also include newer features and operations which a stock Java5 virtual machine will not be able to reference. Again, there are techniques to safely use a backwards-compatible version of Java (6/7); however, one doesn't need to apply any extra care if they base their development off a Java5 development kit. The "source code" for the language libraries was included in the source code for the JVM under the Java Research License Agreement, to the degree that SUN was allowed to include such source code.
While SUN has licensed a number of technologies from other companies in a manner where they can be freely distributed with Java5, SUN did not necessarily own all of the technologies in Java5 outright. As such, even under the Java Researcher License Agreement, some of the source code is not available (although the compiled libraries are). Open source projects (like OpenJDK) were quick to implement these missing "holes" with open-source libraries to get a fully functional open-source Java stack; but, that is Java6+ (not Java5).
Java 1.5 is not open source. Quoting Wikipedia:
On November 13, 2006, Sun released much of Java as free and open source software, (FOSS), under the terms of the GNU General Public License (GPL). On May 8, 2007, Sun finished the process, making all of Java's core code available under free software/open-source distribution terms, aside from a small portion of code to which Sun did not hold the copyright.
As far as I can remember it was possible to get the source code for research purposes (our university had access to the source code with a special agreement with Sun) but I don't think that it will be possible to get it from Oracle.
Before the open sourcing there were several free implementation of the JVM and of the core classes. Look at http://en.wikipedia.org/wiki/Free_Java_implementations for examples.
visit the
oracle archive

Compiling multiple Java packages with TextMate

I've recently been converted to TextMate as a diverse and powerful programmer's tool. But it appears to be lacking in Java support. So, I've been trying to mess around with the supplied Java bundle (Compile & Run) but it only contains one line:
javamate_bootstrap.sh
I can't find this file on my machine, but it appears to only work for simple Java classes (ie, classes not contained within a package).
First of all, why is TextMate so useless for Java programming, and secondly (and most importantly) : Does anyone know of a bundle I can use, or have instructions on how to create one for larger scale Java development in TextMate?
Thanks in advance.
First of all, why is TextMate so useless for Java programming
Mostly because there are three free (free as in beer) java IDE's, IntelliJ IDEA, NetBeans and Eclipse that almost all professional java developers use. Any one of them will give you all the functionality you want out of TextMate and much, much more. Given that, there's not much demand for java features in TextMate or BBEdit, or Notepad++, etc. That's not to say people don't use them. They definitely do, but not in a high enough volume to make it worth it to the maintainers to add features to make java development easier.

Java in Visual Studio 2010?

Is there any way to manage/debug/compile Java projects in Visual Studio 2010?
Before you answer, please read this topic.
I'm a little late to the party, but it looks like someone has started adding support. From the description, right now it only does syntax highlighting and basic navigation within a single file. However, in the Q&A section the author mentions plans to add compilation and debugging support later in the year.
The short answer - No.
The long answer - No, because the supposed intellisense support for Java that the blog entry referred to, in the question, relies on J# support. I believe it has been quite sometime since Microsoft has discontinued J# - VS2008 does not have it.
In the long run, you're better off learning how to use Eclipse/Netbeans/IntelliJ IDEA or any other IDE for the purpose of managing Java projects.
Sure. Visual Studio works with any language so long as someone takes the time to write the plug-ins for it. Heck, Mainsoft has already added JVM debugging support to Visual Studio. They just don't support the language.
The only problem is YOU are going to have to be the one who writes it.
I won't lie to you. It won't be easy and fan-boys on both sides will hate you for it. But if you pull it off I can at least offer you some money to write about how you did it.
No, although, I long for the day when VS might possibly support building Java applications. I don't think I have yet found an IDE as fully featured. Personally, if VS supported Java development, then I would trash my installation of Eclipse and Netbeans. ... so tired of wonky Java IDEs....
Cyberduck is written in Java and developed in Visual Studio 2010, though it requires IKVM, an implementation of Java for Mono and the Microsoft .NET Framework. Here are the build instructions.
C++ syntax highlighting looks pretty good for Java. Turn this on in Options->Text Editor->File Extension.
Extension: java
Editor: Microsoft Visual C++
Now reopen a .java file and see pretty colors.
I will advise to go for Eclipse, if you have to do at least 25% Java coding. Otherwise VS is good as well. But I like Eclipse for C++ as well as Java.
A new plugin is currently being developed named IntegraStudio,
aiming at full Java development under VS. It currently supports:
IntelliSense for Java (comparable to standard C++ IntelliSense in VS)
build with Ant or Maven
direct Ant / Maven project view in Solution Explorer
Java debugger with container visualization
support for VS browsing features (Class View, Code definition, etc.)
Class View works also for classes in JARs (including standard library)
browsing Maven repositories
JDK: 1.6 - 1.8
It uses standard JDK tools and targets the real Java platform (it
is not a .NET platform solution, as VJ# was).
At the moment of writing this, the IntegraStudio plugin is beta.
It does not yet contain advanced Eclipse features, however many
of them are in current roadmap (e.g. code refactorings and quick fixes).
You can find it on Visual Studio gallery:
http://visualstudiogallery.msdn.microsoft.com/588fb167-d18c-4e61-8aeb-30baeddb00da
The product official website is:
http://www.softerg.com/integra
Current docs (with large number of screenshots):
http://www.softerg.com/integra/docs/pages/is_intro.htm

Categories

Resources