Showing posts with label development tools. Show all posts
Showing posts with label development tools. Show all posts

Friday, April 15, 2011

Decompile Java Class file using decompilers.

Byte codes generated by javac compiler can again be converted into java source. For this we need a decompiler tool. Decompilers are the utilities that generate the source code from input java class file. A Decompiler knows about the structure of a Java class and parse it to generated Java source code.
Java decompilers will not give the exact Java source file from which class was generated and executed by Java Virtual Machine. But most of the structure will be maintained.

JAD: Java Decompiler

A lot of Decompilers are available in the market to decompile a class file. We will use one of the free decomipler called JAD.

I have used a simple Hello World java class to demonstrate JAD decompiler. Following is the code of HelloWorld.java file.
public class HelloWorld {
    public static void main(String args[]) {
        String fooBar = "Hello World from Java.";
        System.out.println(fooBar);
    }
}
Use following output when we use command line utility JAD to decompile our class file.
$> jad HelloWorld.class
Parsing HelloWorld.class... Generating HelloWorld.jad
The source file output of JAD is in file with .jad extension. You can change the extension to .java.
Following is the source that you get after decompillng our HelloWorld.class file.
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: HelloWorld.java
 
import java.io.PrintStream;
 
public class HelloWorld
{
 
public HelloWorld()
{
}
 
public static void main(String args[])
{
String s = "Hello World from Java.";
System.out.println(s);
}
}

Note that the string variable that we used in our original Java class was fooBar and it got changed into s.

Thursday, March 31, 2011

Tools for converting c to java source

There are tools which provides opportunity to translate C-code sources into Java classes. Some of them are listed below:
  • Jazillian: Jazillian is a tool that translates from C source code to Java source code. The Java code that it produces is highly maintainable: it looks like hand-written code.
  • C to Java converter: Some time ago I needed to convert one C program to Java. It is tedious and not interesting job to do. So I developed C to Java converter. I can not say, that it is fully functional or have no bugs. But you may find it useful to use this tool first, before making changes by hand.
  • C2J converter: C2J converter provides opportunity to translate C-code sources into Java classes.

Friday, March 4, 2011

Starting rmi registry

To start the registry, Windows users should do the following (assuming that your java\bin directory is in the current path):-
start rmiregistry 
To start the registry, Unix users should do the following:-
rmiregistry &

Friday, February 25, 2011

Generating a Stub


UNIX
% javah -stubs HelloWorld
DOS shell (Windows 95/NT)
C:\> javah -stubs HelloWorld

Running javah


UNIX
% javah HelloWorld
DOS shell (Windows 95/NT)
C:\> javah HelloWorld

Compiling Java Code


UNIX
% javac HelloWorld.java
% javac Main.java
DOS shell (Windows 95/NT)
C:\> javac HelloWorld.java
C:\> javac Main.java
Macintosh
[PENDING: Macintosh instructions]

Chitika