17/12/24 --------- Q)How to develop and run a Java program? DIAGRAM Step 1:- Write the program code (Source code) Step 2:- Save the source code(source file creation) =>We can give any name to the Java source file. But, its extension should be ".java". For eg. addition.java Step 3:- Compile the source code Step 4:- Execute/Run the Java program Q)Java program to display Hello World ! on the console. class HelloWorld{ public static void main(String a[]){ System.out.println("Hello World !"); } } Q)How to compile a Java program? =>By using "javac" command. javac For eg. javac one.java Q)What happens in the background when "javac" command is executed? =>"javac" command is given to the Operating System. =>OS invokes the Java compiler. =>Java compiler does the following things. 1)Makes a full read of the source code of the source file 2)verifies the syntactical correctness of the source code Case i:- Errors are there =>Compiler reports those errors and it doesn't perform compilation(translation) Case ii:- No errors are found =>Java compiler translates Java source code into byte code and it creates one or more class files. Note:- Java compiler creates as many .class files as there are classes in the source code Q)How to run a Java program? =>by using "java" command. java For eg. java HelloWorld Note:- Initial class is that class in which, main method is defined. Q)What happens in the background when "java" command is executed? =>"java" command is given to the OS. =>OS invokes the JVM =>JVM does the following things. 1)Loads the initial class (class file) into RAM 2)Calls the main method and the program's execution starts.