<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    我思故我強

    第一部分:聲明和訪問控制(練習題)

    第一部分:聲明和訪問控制

    • 知道怎么樣聲明、創建和初始化各種類型的數組
    • 知道怎么樣聲明類、內部類、方法、成員變量、靜態變量和方法內部變量,并會使用合法的修飾符(如public,final,static,abstract,等等)。了解這些修飾符單獨使用或組合使用的含義,并且知道它們對于包作用域的影響。
    • 了解類的構造器(constructor)
    • 給定一個方法,能判斷它的合法返回類型

    §1.1.1    

    In the following pieces of code, A and D will compile without any error. True/False?

    A: StringBuffer sb1 = "abcd";

    B: Boolean b = new Boolean("abcd");

    C: byte b = 255;

    D: int x = 0x1234;

    E: float fl = 1.2;

     

    Choices:

    A. True

    B. False

    ―――――――――――――――――――――――――――――――

    答案 B. The code segments B and D will compile without any error. A is not a valid way to construct a StringBuffer, you need to creat a StringBuffer object using "new". B is a valid construction of a Boolean (any string other than "true" or "false" to the Boolean constructor will result in a Boolean with a value of "false"). C will fail to compile because the valid range for a byte is -128 to +127 (ie, 8 bits,signed). D is correct, 0x1234 is the hexadecimal representation in java. E fails to compile because the compiler interprets 1.2 as a double being assigned to a float (down-casting), which is not valid. You either need an explicit cast (as in "(float)1.2") or "1.2f", to indicate a float.

     

     

     

    §1.1.2      

    What will be the result of executing the following code?

    Given that Test1 is a class.

    1. Test1[] t1 = new Test1[10];

    2. Test1[][] t2 = new Test1[5][];

    3. if (t1[0] == null)

    4. {

    5.t2[0] = new Test1[10]

    6.t2[1] = new Test1[10]

    7.t2[2] = new Test1[10]

    8.t2[3] = new Test1[10]

    9.t2[4] = new Test1[10]

    10. }

    11. System.out.println(t1[0]);

    12. System.out.println(t2[1][0]);

    Choices:

    a. The code will not compile because the array t2 is not initialized in an unconditional statement before use.

    b. The code will compile but a runtime exception will be thrown at line 12.

    c. The code will compile but a runtime exception will be thrown at line 11.

    d. None of these.

    ―――――――――――――――――――――

    D is correct. Though we cannot use local variables without initializing them (compilation error), there is an exception to it. In case of arrays initialization is supposed to be complete when we specify the leftmost dimension of the array. The problem occurs at runtime if we try to access an element of the array which has not been initialized (specification of size). In the question above the array t2 is initialized before use, therefore there will be no problem at runtime also and the lines 11 and 12 will both print null.

     

    §1.1.3      

    Which declarations of identifiers are legal?

     A. $persons

      B. TwoUsers

      C. *point

      D. this

        E. _endline

      

      答案 A,B,E

      

      解析 Java的標識符可以以一個Unicode字符,下滑線(_),美元符($)開始,后續字

    符可以是前面的符號和數字,沒有長度限制,大小寫敏感,不能是保留字。

     

    §1.1.4      

    Which of the following answer is correct to express the value 8 in octal number?

      A. 010

      B. 0x10

      C. 08

      D. 0x8

     

      翻譯

      下面的哪些答案可以用以表示八進制值8。

      答案 A

     

      解析  八進制值以0開頭,以0x開頭的為十六進制值,八進制中不能出現數字8,最大只有7。

     

    §1.1.5      

    Which are not Java keywords?

      A. TRUE

      B. sizeof

      C. const

      D. super

      E. void

     

      翻譯

      哪些不是Java關鍵字。

     

      答案 A,B

     

      解析

       A:不是,Java中有true,但是這也不是關鍵字而是字面量(literal)。

     B:不是,Java中不需要這個操作符,所有的類型(原始類型)的大小都是固定的。

     C、D、E都是,需要說明的是const是java中未被使用的關鍵字。

     

    §1.1.6      

    Which statements about Java code security are true?

      A. The bytecode verifier loads all classes needed for the execution of a program.

      B. Executing code is performed by the runtime interpreter.

      C. At runtime the bytecodes are loaded, checked and run in an interpreter.

      D. The class loader adds security by separating the namespaces for the

    classes of the local file system from those imported from network sources.

     

    ――――――――――――――

    答案 BCD

     

    §1.1.7      

      題目:下面有關java代碼安全性的敘述哪些是對的。

      A. 字節碼校驗器加載查詢執行需要的所有類。

     

      B. 運行時解釋器執行代碼。

     

      C. 在運行時,字節碼被加載,驗證然后在解釋器里面運行。

     

      D. 類加載器通過分離本機文件系統的類和從網絡導入的類增加安全性。

     

      SL275中描述的Java程序運行的過程是這樣的:類加載器(class loader)加載程序運行所需要的所有類,它通過區分本機文件系統的類和網絡系統導入的類增加安全性,這可以限制任何的特洛伊木馬程序,因為本機類總是先被加載,一旦所有的類被加載完,執行文件的內存劃分就固定了,在這個時候特定的內存地址被分配給對應的符號引用,查找表(lookuo table)也被建立,由于內存劃分發生在運行時,解釋器在受限制的代碼區增加保護防止未授權的訪問;然后字節碼校驗器(byte code verifier)進行校驗,主要執行下面的檢查:類符合JVM規范的類文件格式,沒有違反訪問限制,代碼沒有造成堆棧的上溢或者下溢,所有操作代碼的參數類型都是正確的,沒有非法的數據類型轉換(例如將整型數轉換成對象類型)發生;校驗通過的字節碼被解釋器(interpreter)執行,解釋器在必要時通過運行時系統執行對底層硬件的合適調用。后三個答案是SL275中的原話。

    §1.1.8      

    Which fragments are correct in Java source file?

      A. package testpackage;

      public class Test{//do something...}

     

      B. import java.io.*;

      package testpackage;

      public class Test{// do something...}

     

      C. import java.io.*;

      class Person{// do something...}

      public class Test{// do something...}

     

      D. import java.io.*;

      import java.awt.*;

      public class Test{// do something...}

     

    ------------------------

    答案 ACD

     

    §1.1.9      

    Which of the following statements are legal?

      A. long l = 4990;

      B. int i = 4L;

      C. float f = 1.1;

      D. double d = 34.4;

      E. double t = 0.9F.

    ----------------------------

    答案 ADE

     

    posted on 2009-10-16 11:37 李云澤 閱讀(283) 評論(0)  編輯  收藏 所屬分類: 面試筆試相關的SCJP認證學習

    主站蜘蛛池模板: 国产一级大片免费看| 亚洲国产精品免费在线观看| 国产一级高清免费观看| 亚洲另类精品xxxx人妖| 成人在线免费看片| 亚洲精品无码久久久久久久 | 黄网站色视频免费观看45分钟| 国产大片线上免费看| 美女裸免费观看网站| 亚洲伊人久久成综合人影院| 美女的胸又黄又www网站免费| 亚洲成人一区二区| 97在线免费观看视频| 久久青青成人亚洲精品| 国产国产成年年人免费看片| 国产精品国产亚洲区艳妇糸列短篇| 永久中文字幕免费视频网站| 国产亚洲女在线线精品| 亚洲综合色视频在线观看| 中文日本免费高清| 久久久久亚洲精品无码蜜桃| 免费毛片a在线观看67194| 亚洲av无码有乱码在线观看| 亚洲国产日韩在线观频| 国产午夜无码精品免费看| 亚洲黄色免费在线观看| 最近免费中文字幕视频高清在线看| 精品免费AV一区二区三区| 久久久久一级精品亚洲国产成人综合AV区| 久久精品免费大片国产大片| 亚洲视频在线免费观看| 免费观看美女裸体网站| a级毛片免费观看在线| 亚洲成人在线免费观看| 免费av一区二区三区| 亚洲国产美女精品久久久久| 国产成人啪精品视频免费网| 久久精品免费一区二区三区| 亚洲综合色丁香婷婷六月图片 | 拍拍拍无挡视频免费观看1000| 亚洲狠狠狠一区二区三区|