// PROGRAM SAVED AS willsmith.java
int x=100 ,y=200 ;
public static void main(String args)
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 )
- It is an operating system environment variable used by the operating system searching for the executable files related to Java .
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
- 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 ?
4.Can we write more than one class in a Java program ?