Wednesday, January 13, 2016

Topic 2: Java program compilation and execution

  • To compile the java program, execute the compiler, javac, specifying the name of the source file on the command line. 

  • The javac compiler creates a file called SourceFileName.class that contains the bytecode version of the program which is the intermediate representation of the program with instructions that Java Virtual Machine will execute. 

     

    When Java source code is compiled, each individual class is put into its own output file named after the class and using the .class extension. This is why it is a good idea to give our Java source files the same name as the class they contain.

  • To actually run the program, we must use the Java application launcher, called java. To do so, pass the class name as a command-line argument. 

     

    When we execute using java, we are actually specifying the name of the class that we want to execute. It will automatically search for a file by that name with .class extension and execute the bytecode instructions contained in the specified class.


Click for NEXT article


Please feel free to correct me by commenting your suggestions and feedback.

No comments:

Post a Comment