-->

2007年9月28日 星期五

Homework 9/21/2007

Due 9/28/2007 at 11:59 a.m.

"tell me and I'll forget; show me and I may remember; involve me and I'll understand"

1. Explain bytecode, JVM

Bytecode is the intermediate representation of Java programs just as assembler is the intermediate representation of C or C++ programs. The most knowlegable C and C++ programmers know the assembler instruction set of the processor for which they are compiling. This knowledge is crucial when debugging and doing performance and memory usage tuning. Knowing the assembler instructions that are generated by the compiler for the source code you write, helps you know how you might code differently to achieve memory or performance goals. In addition, when tracking down a problem, it is often useful to use a debugger to disassemble the source code and step through the assembler code that is executing.

參考頁面 IBM :
http://www-128.ibm.com/developerworks/ibm/library/it-haggar_bytecode/

JVM ( Java Virtual Machine )
Java為了做到能夠跨平臺
所以他不能像C/C++那種語言一樣
將其程式碼編成相對於機器上的機器碼( 或是Assembly Code )
所以他採用了中介碼( byte code )
為了達到能夠執行跨平台的Java程式
Sun必須提供每種機器相對應的虛擬機器( Virtual Machine )
Virtual Machine這個程式能夠將Java的.class檔轉換成他平台上所了解的機器碼

參考頁面 奇摩知識 :
http://tw.knowledge.yahoo.com/question/?qid=1105050109771

2. Explain class, object

class ( 類別 ) :

在物件導向程式設計中,類別是很重要的觀念。
類別可以繼承類別。
類別必須宣告成物件才能使用( 執行 ),除非此類別的型態是static。

object ( 物件 ) :

一般來說類別必須要宣告物件( Object ),才能使用( 執行 )。

參考頁面 Java 入門 :
http://java.fromtw.com/java/java1.html#wathisjava

3. Reading Assignments:
Read 1.1, 1.2, 1.3 of Textbook


4.1 Write a Java program as follows:

Let i=2;
Print i;
Print 2 * (i++);
Print i;


Ans: 2, 4, 3

4.2 Write a Java program as follows:

Let i=2;
Print i;
Print 2 * (++i);
Print i;


Ans: 2, 6, 3

4.3 Write a Java program as follows:

Let m=7, n=2;
Print (double) m/n;
Print m/ (double)n;


Ans: 3.5, 3.5

0 COMMENT: