1 / 20

Using the Java programming language compiler

Using the Java programming language compiler. Review of relevant material from previous lectures. From previous lectures:. A computer can only execute machine instruction codes (binary numbers) Writing algorithms in machine instruction codes is extremely tedious.

cachet
Download Presentation

Using the Java programming language compiler

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using the Java programming language compiler

  2. Review of relevant material from previous lectures • From previous lectures: • A computer can only execute machine instruction codes (binary numbers) • Writing algorithms in machine instruction codes is extremely tedious

  3. Review of relevant material from previous lectures (cont.) • People have invented a number of English-like languages that is highly suitable for writing algorithms • People have also written computer applications that translate algorithm written in a programming language into machine instructions • These languages are called (high level) programming languages • These applications are called compilers

  4. How to write an algorithm that a computer can execute • The hard way: You will hate your professor if he/she make you do this.... (and yet, the pioneers in Computer Science had done this... we must be grateful to them) • Write the algorithm (yourself) in machine instruction (binary numbers)

  5. How to write an algorithm that a computer can execute (cont.) • The easy way: • Write the algorithm (yourself) in a programming language (using an editor like gedit) • Translate the program using a compiler into machine instructions (The translated program is stored in a computer file) • Let the computer execute the translated program in machine instructions (This translated program is an computer application because it can be run by a computer)

  6. How to write an algorithm that a computer can execute (cont.) • Pictorially: • (An application is a file that contains machine instructions (which can be executed by a computer))

  7. Using the Java compiler • The name of the Java compiler (application) is: • javac

  8. Using the Java compiler (cont.) • A Java program (= a computer algorithm written in the Java programming language) is first written and stored in a file The name of the file must end with the characters: The ending of a filename is called the file extension and it is commonly used to identify the kind of file. • .java

  9. Using the Java compiler (cont.) • The following command will translate a Java program into machine code: The Java compiler javac will store the translated machine codes into a file name ProgramFileName.class • UNIX prompt>> javac ProgramFileName.java

  10. Using the Java compiler (cont.) • Example:

  11. Using the Java compiler (cont.) • Example Program: (Demo above example)   • The Hello.java Prog file: http://mathcs.emory.edu/~cheung/Courses/170/Syllabus/02/Progs/Hello.java     • What to do: • Right click of the link and save in some scratch directory • Change current directory to that scratch directory • Compile Hello.java with javac Hello.java

  12. The Java machine language • The translated machine code produced by the Java compiler javac is called: • Java bytecode

  13. The Java machine language • Java bytecodes are executed by a Java machine --- a computer that executes machine instructions in Java bytecodes However, no such Java machine has ever been built In other words: • There does not exist a physical computer (machine) that can execute Java byte codes

  14. The Java virtual machine • Emulators: Emulators are also known as virtual machines (Because they do the same thing as a real machine, but is not a physical machine) • Emulators are (special) computer programs that emulate the exact behavior of a machine or entity

  15. The Java virtual machine (cont.) • Java virtual machine: (A Java virtual machine is an emulator) • A Java virtual machine is a computer program (application) than can execute an algorithm written in Java bytecode

  16. The Java virtual machine (cont.) • The name of this computer application is: • java

  17. Executing the translated Java program with a Java virtual machine • Suppose the program containing the Java bytecode is called: This program can be executed by the Java virtual machine java by executing the following command: ProgramFileName.class java ProgramFileName

  18. Executing the translated Java program with a Java virtual machine (cont.) • Note: • You must omit the extension .class • The Java virtual machine java will append the extension .class to its argument

  19. Executing the translated Java program with a Java virtual machine (cont.) • Example:

  20. Executing the translated Java program with a Java virtual machine (cont.) • Example Program: (Demo above code)   • Hello.java Prog file: http://mathcs.emory.edu/~cheung/Courses/170/Syllabus/02/Progs/Hello.java • What to do:           • Right click on the link ans save in some scratch directory • Change current directory to that scratch directory • Compile Hello.java with: &nsbp; javac Hello.java • Then execute the Java bytecode Hello.class with:   java Hello

More Related