Showing posts with label jad. Show all posts
Showing posts with label jad. Show all posts

Wednesday, 27 February 2008

Jad tricks

Hey guys,

No Java lesson for today, as I'm a bit busy (lazy :P). Instead I'll show you some cool tricks with Jad.

Sometimes when you try to decompile a class you see an error message saying "Class file version mismatch". But you can still go on and force Jad to decompile it using the -debug option:
jad -debug Test.class
Another common case is when there are many classes (like in qtj2) and you want to do a batch decompilation. The wildcard character can help a bit:
jad *.class
But this one is much cooler:
jad -r quangntenemy**/*.class

Thursday, 15 November 2007

Hello world!

Hey guys,

Today I will teach you how to write your first program in Java, compile it, and then decompile with jad.

Open your favourite text editor, and type (or copy&paste) the following code:
public class Hello {

public static void main(String[] args) {

System.out.println("Hello world!");

}

}
Save the code as Hello.java, and open a console window. Navigate to the directory where you saved the file and execute the following command to compile the program:
javac Hello.java
Hopefully the program will be compiled without any errors. You'll notice that another file named Hello.class will be created in the same directory. To run it, type the following command:
java Hello
Of course, the program will run and output "Hello world!" :)

Congratulations, you have successfully written, compiled and executed your first Java program. It is very simple, but probably you can use it as a template for other programs in the future.

Now it's time to decompile it and see how the code looks like. From the console, type
jad Hello.class
A new file named Hello.jad will be created. Have a look at it
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: Hello.java

import java.io.PrintStream;

public class Hello
{

public Hello()
{
}

public static void main(String args[])
{
System.out.println("Hello world!");
}
}
Almost the same as the original code. Cool huh? :)

Wednesday, 14 November 2007

Welcome

Hey guys,

As you all know, I have always wanted to write a Java applet tutorial, and many people have been waiting for it. But the tut has been delayed for so long. Simply because I didn't really know what I should include in the tutorial.

Basically an applet is just a Java application. So to solve it you just need to know Java. Therefore instead of a tutorial I decided to create a blog for it. Hopefully you'll find everything you need about Java here :)

In this first post I would like to equip you with all the tools and resources needed for solving Java applets.

Firstly to run Java applets you will need the Java Runtime Environment (JRE). It might have been shipped with your browser but it's always good to have the latest version. You can check your current version by typing this from a console:
java -version
But probably you will not just want to run Java applets, but to compile Java programs as well, to understand what the applets actually do. For this you will need the Java Development Kit (JDK), which also includes the JRE.

You can get the JDK from here: http://java.sun.com/javase/downloads/index.jsp. At the moment JDK 6 is what you need.

Java programs are compiled into Java bytecode, and you will need a decompiler to decompile the code back to Java language. There are many Java decompilers out there but jad is probably the best one. Most others decompilers use jad as the backend. The jad homepage is at http://www.kpdus.com/jad.html. You can also find the graphical frontends for jad and plugins for IDEs there too.

Talking about IDEs.. basically you can write Java programs using any text editor but a good IDE will make things easier. Here are the IDEs that I recommend:
  • JCreator: http://www.jcreator.com - an excellent lightweight IDE, get this if you are learning Java. Unfortunately it only runs on the Windows platform.
  • Eclipse: http://www.eclipse.org - an excellent heavyweight IDE, but probably you should not use it as a beginner, because it hides you from many essential things.
  • Netbeans: http://www.netbeans.org - also a heavyweight IDE offering similar features to Eclipse, but I prefer Eclipse because it's faster.
OK, now you basically have all the necessary things. It's time to start learning Java. Of course I'll help you but here are some resources that you'll probably find useful along the way: