CS401 | sw engineering
  • outline
  • projects
  • syllabus
  • links

Java Compilation & Interpretation

 

 

STEP 1: Compilation from source (.java fies) to class files (*.class)

STEP 2: Run: Use these classfiles are used to "run" your Java application. This is done through what is called a Java Virutal Machine as shown below.

 

 

 

STEP 1: Compilation

Java source code compiles into machine-independent "bytecode format". This format was developed by Sun Microsystems to be at a higher-level than machine code so that it could be interpreted (instead of executed) on different types of machines with the same compiled file. Every class that is defined will create its own class file: for example if you have a class called Dog the compiler will create a file called Dog.class

Source Filename Convention

  • You will have one or more files named like filename.java You SHOULD set filename = the class name that is contained in this file.

Output Filename Convention

  • For each class contained in a file filename.java a seperate class file will be produced called classname.class.

    For example, if you have a file called mybank.java and it contains definitions for two classes called Checking, and Savings, the following two files will be produced by the compiler: Savings.class and Checking.class

How to Compile

  • With IntelliJ use Build->Build Project (also note if you run the code using Run->Run or Debug menu options if it has not been compiled it will compile first)

    • Command line compilation --- not recommended --should use our designated IDE.

            %  javac  filename.java             

NOTE: We will be using an IDE and then menus/buttons are used for compiling(building) and running your code

 

STEP 2: Run with JVM = Java Virtual Machine (or sometimes called "The Interpreter")

 

JVMs are programs that must be installed on the machine you wish to run your application on (and are specific to that OS). Their job is at run time to convert the bytcode into the actual OS commands.

 

 

 

 

A JVM converts that OS-neutral (platform independent) bytcode (class files) into platform specific commands that are directly excuted by the machines CPU.

 

 

 

IDE

  • Using IntelliJ IDE: Run->Run or Run->Debug

 

Command Line

  • java fileName  
               
  • where fineName is the class file containing the Main Application Class

cs401:sw engineering

  • home
  • outline
  • projects
  • syllabus
  • links