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? :)

No comments: