SCJP认证套题解析之二

来源:java认证发布时间:2012-11-12 13:05:47java认证视频


 
31Given the following code fragment:
    1) String str = null;
    2) if ((str != null) && (str.length() > 10)) {
    3)   System.out.println("more than 10");
    4) } 
    5) else if ((str != null) & (str.length() < 5)) {
    6)        System.out.println("less than 5");
    7)      }
    8)      else { System.out.println("end"); }
Which line will cause error?
A. line 1
B. line 2
C. line 5
D. line 8
(c)
题目:给出下面的代码片断:

哪些行将导致错误。
此题需要将代码仔细看清楚,查询没有逻辑错误,if …else的使用没有问题,也没有拼写错误,错误在于第5行的“与”操作符的使用,逻辑操作符(logical operator)的“与”应该是&&,而&是位逻辑操作符(bitwise logical operator)的“与”,使用的对象不一样,逻辑操作符的“与”的左右操作数都应该是布尔型(logical boolan)的值,而位逻辑操作符的左右操作数都是整型(integral)值。
 
32、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)
题目:下面有关java代码安全性的叙述哪些是对的。
A.      字节码校验器加载查询执行需要的所有类。
B.      运行时解释器执行代码。
C.      在运行时,字节码被加载,验证然后在解释器里面运行。
D.     类加载器通过分离本机文件系统的类和从网络导入的类增加安全性。
SL275中描述的Java程序运行的过程是这样的:类加载器(class loader)加载程序运行所需要的所有类,它通过区分本机文件系统的类和网络系统导入的类增加安全性,这可以限制任何的特洛伊木马程序,因为本机类总是先被加载,一旦所有的类被加载完,执行文件的内存划分就固定了,在这个时候特定的内存地址被分配给对应的符号引用,查找表(lookuo table)也被建立,由于内存划分发生在运行时,解释器在受限制的代码区增加保护防止未授权的访问;然后字节码校验器(byte code verifier)进行校验,主要执行下面的检查:类符合JVM规范的类文件格式,没有违反访问限制,代码没有造成堆栈的上溢或者下溢,所有操作代码的参数类型都是正确的,没有非法的数据类型转换(例如将整型数转换成对象类型)发生;校验通过的字节码被解释器(interpreter)执行,解释器在必要时通过运行时系统执行对底层硬件的合适调用。后三个答案是SL275中的原话。
 
33、Given the following code:
    public class Person{
       static int arr[] = new int[10];
       public static void main(String a[]) {
          System.out.println(arr[1];)
       }
    }
Which statement is correct?
A. When compilation some error will occur.
B. It is correct when compilation but will cause error when running.

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答