Please wait ......

Java Program - The execution flow diagram

Know the major steps involved in the execution cycle of a Java program.


 

Now let us write a simple program in Java to print current date and time.

  • Open a text editor (like notepad in Windows or gedit in Ubuntu) and type the program below (Hint: Double click on the below code to select and copy)
import java.util.Date;

public class CurrentDatePrinter {

    public static void main(String[] args) {
        System.out.println(new Date());
    }
}

 

  • Save the file as CurrentDatePrinter.java in any folder (Example: C:\skillrack\training\CurrentDatePrinter.java)

 

Compile the Java program using the compiler provided by JDK and create class files:

Open command prompt and type the command javac C:\skillrack\training\CurrentDatePrinter.java

This will create a file CurrentDatePrinter.class under C:\skillrack\training folder.

IMPORTANT:
This class file acts as the input to JVM. JVM interprets the class file and executes the program.

Ensure you navigate to C:\skillrack\training folder in the command prompt.

To execute the program type the command java  CurrentDatePrinter

Video Link: Watch the video explaining the above steps.