关键词 > 159.234

159.234 OBJECT-ORIENTED PROGRAMMING Tutorial 1

发布时间:2023-06-13

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

159.234 OBJECT-ORIENTED PROGRAMMING

Tutorial 1 Solution

Task 1: Review the content of Lecture 02, answer the following questions:

1.   What is the difference between a "compiler" and an "interpreter"?

Compilers and interpreters have similar functions: They take a program written in some programming language and translate it into machine language. A compiler does the translation all at once. It produces a complete machine language program that can then be executed. An interpreter, on the other hand, just translates one instruction at a time, and then executes that instruction immediately. (Java uses a compiler to translate java programs into Java Bytecode, which is a machine language for the imaginary Java Virtual Machine. Java Bytecode programs are then executed by an interpreter.)

2.    If you have the source code for a Java program, and you want to run that program, you will need both a compiler and an interpreter. What does the Java compiler do, and what does the Java interpreter do?

The Java compiler translates Java programs into a language called Java bytecode. Although bytecode is like machine language, it is not the machine language of any actual computer. A Java interpreter is used to run the compiled Java bytecode program. (Each type of computer needs its own Java bytecode interpreter, but all these interpreters interpret the same bytecode language.)

3.   Java is a "platform-independent language." What does this mean?

A Java program can be compiled once into a Java Bytecode program. The compiled program can then be run on any computer that has an interpreter for the Java virtual machine. Other languages must be re-compiled for each platform on which they are going to run. The point about Java is that it can be executed on many different types of computers without being recompiled.