Compiling and Running a Java Application

Compiling and Running a Java Application

To compile and run the program you need the JDK distributed by Sun Microsystems. The JDK contains documentation, examples, installation instructions, class libraries and packages, and tools. Download an editor like Textpad/EditPlus to type your code. You must save your source code with a .java extension. The name of the file must be the name of the public class contained in the file.

Run the following code in notepad

public class HelloWorld 
{
     public static void main(String[] args) 
     {
          System.out.println("Hello World");
     }
}

Steps for Saving, Compiling and Running a Java

Step 1: Save the file with .java Extension.

Strict Note: You must save the file with the ClassName. Since our class name in the above code is HelloWorld, Give the File name as HelloWorld.java & Save as type All Files as shown below

How to Save a Java Program.

Step 2: Compile the file from DOS prompt by typing javac <filename with extension>.

Step 3: Successful Compilation, results in creation of .class containing byte code

Step 4: Execute the file by typing java <filename without extension>

Compilation and Execution of Java Program

Illustration for the above screen shot

cd desktop –> changing our current directory to desktop (Assume our HelloWorld.java file is saved in desktop)

javac HelloWorld.java –> Compiling the HelloWorld.java file and it will create HelloWorld.java if everything went right.

java HelloWord –> Running / Executing the HelloWorld.class file

JAVA DEVELOPMENT KIT

The Java Developer’s Kit is distributed by Sun Microsystems. The JDK contains documentation, examples, installation instructions, class libraries and packages, and tools

JAVADOC

The javadoc tool provided by Sun is used to produce documentation for an application or program,

JAR FILES

A jar file is used to group together related class files into a single file for more compact storage, distribution, and transmission. Good luck and get started with your coding journey

LEAVE A REPLY

Please enter your comment!
Please enter your name here