COMPILING AND EXECUTING THE JAVA PROGRAM


// PROGRAM SAVED AS willsmith.java

class Willsmith

    int x=100  ,y=200 ;

    public static void main(String args[])

  {

    void printData()

     {

         System.out.println(” the val of x is :”+x+ “\n the val of y is :” +y);

      }

  }

}

In order to compile and execute the Java program we need to go the command prompt and ensure the path and classpath are settings are done by typing the following command

                           echo %path%  ( to ensure the path )


            echo %classpath% ( to ensure the classpath )

PATH : 

  • It is an operating system environment variable used by the operating system searching for the executable files related to Java .

CLASSPATH :

  • It is the Java environment variable used by the Java compiler searching for the “.class ” files 

JAVAC ( UTILITY PROGRAM) :

  • It is  a utility program which is used to compile the Java programs during compilation the Java compiler will create the “.class ” files for all the classes existed in the program .

               SYNTAX : javac willsmith.java

JAVA :

 
  • It is also a utility program which is used to execute the Java programs , while using Java utility the JVM will ensure that the exixtency of the “.class ”  file in the current directory .
  • If the specified “.class ” file is not existed in the current directory then you will get an exception that .

“Exception in thread “main”.java.lang.NoclassDefFoundError”

If the .class file is existed then the JVM will search for the signature of “public static void main(String args[])”


If it is not existed then you will  get an exception that


” Exception in thread”main” java.kang.NoSuchMethodError:main”


IMPORTANT QUESTIONS

1.In order to compile program does we require a main method ?

A. “No” (by using static modifier which we will discuss later).


2.Is it mandatory to maintain the program name exactly with the class name ?

A. “no” untill unlesss the class modifier is public ?


3.In order to execute the Java program does we required the main method ?

A. yes


4.Can we write more than one class in a  Java program ?

A. yes

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: