Execute a simple Java Console application

How to execute a simple java console program, with a main function?

Sometimes whe need to build a simple java program to test some concept/code/whatever.

So the code is something like (grabbed from stackoverflow for my quick reference):

Sun’s tutorial contains a complete demonstration, but here’s another one from scratch. You need two files:


public class Test {

   public static void main(String[] args){
      System.out.println("Hello world");
Then create a Manifest.mf file with the following content:

Manifest-version: 1.0
Main-Class: Test

Then compile the Java source file and create the jar file:

javac Test.java
jar cfm test.jar Manifest.mf Test.class
java -jar test.jar


Hello world

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.