If the following program is saved in file named "HelloWorld.java", what are the commands for compiling it and running it.
// HelloWorld.java class HelloWorld { public static void main(String s[]) { System.out.println("Hello World"); } }
javac HelloWorld java HelloWorld
javac HelloWorld java HelloWorld.java
javac HelloWorld.java java HelloWorld.java
javac HelloWorld.java java HelloWorld
Correct Answer : D
As the file name is HelloWorld.java we must compile it using HelloWorld.java that is javac HelloWorld.java.
The class having main method is named HelloWorld. In order to run we need to give the class name having main method. So we run it using class name i.e., java HelloWorld.