How to make Java Application?


All the Java programs can be divided into two groups – Applications and Applets. The basic difference is that Application can be executed at command (DOS) prompt and Applet executes in a Browser. Here, we are concerned with Java Application.

There are three steps to write Java Application – Writing source code, Compilation and Execution.

I. Writing Source Code for Java Application

Java comes with many IDEs to write the source code. For simplicity, we use notepad editor to write the source code.

Open command prompt and open a file as follows.

C:\snr> notepad Demo.java

The above statement opens a notepad on the file name Demo.java. The extension of every Java file should be .java like you have .C for every C program.

import java.lang.*;
public class Demo
{
  public static void main(String args[])
  {
    System.out.println("Hello World");
    System.out.println("Best Wishes of the Day");
    System.out.println("I am writing Java Application");
  }
}

Java ApplicationOutput Screenshot on Java Application

II. Compilation of Java Application

Next step is to compile the above file called Demo.java containing source code. Come to the command prompt and type.

C:\snr> javac Demo.java

javac stands for Java Compiler. It is an instruction to compiler to compile the file called Demo.java. If no errors exist, after compilation, the compiler generates a file Demo.class. Demo.class is the executable file equivalent to .exe file of C-lang. Demo.class file contains bytecode that makes Java platform-independent.

III. Execution of Java Application

After generating .class file, next step is execution.

C:\snr> java Demo

In the above statement, java is the execution command which executes and gets output at command prompt. See the above Screenshot.

A similar example is available, read for more: Java Example Compilation Execution

Leave a Comment

Your email address will not be published.