Java习题一
- 格式:doc
- 大小:42.00 KB
- 文档页数:9
1. 什么叫字节码?字节码和其他机器代码有什么不同? 答:是Java虚拟机执行的一种指令格式。 2. 什么Java虚拟机,其工作原理是什么? 答:Java虚拟机是一个想象中的机器,在实际的计算机上通过软件模拟来实现。Java虚拟机有自己想象中的硬件,如处理器、堆栈、寄存器等,还具有相应的指令系统。
3. 什么是Java API、JDK、JDK、JIT? 4. Java版本有哪几个,各适用与哪些解决方案? 5. Java虚拟机的运行过程包括哪几个步骤? 6. Java字节码的执行方式有哪两种? 7. javac.exe和java.exe的作用是什么? 8. 什么是环境变量?如何设置系统的环境变量? 9. path环境变量和classpath环境变量的作用是什么? 10. set path=c:\myjava;%path%;,其中%path%的作用什么? 11. 在环境变量的设置中“.”的作用是什么? 12. 阅读以下程序,回答问题: public class Test { public static void main(String [] args) { System.out.println(“Hello World!”); } } class AnoterTest { } ① 程序是否有错误?若有,错误原因是什么?有,少一个; ② 将文件保存为test.java,是否正确?不正确,文件名为Test.java ③ 若将类名前的public修饰符去掉,再将文件保存为test.java,是否正确?正确 ④ 编译通过后,执行 java test.class是否正确?不正确 java Test ⑤ 编译通过后,将生成几个类文件,其文件名分别是什么? ⑥ 若将System.out.println(“Hello World!”)改写成 System.out.println(“Hello World!”); 程序编译是否通过,若不通过,应该如何改写?不通过,“Hellow”+“World!” 13. Java程序的注释有几种类型,分别是什么? 14. 下面关于代码安全的说法哪些是对的? ① 程序执行过程中需要的所有类都是通过字节码校验程序装入的。 ② 代码的运行是由Java运行环境中的解释器完成的。 ③ 在运行时,字节码要经过装入、校验之后,才能在解释器中完成。 ④ 在缺省的安全配置条件下,Java Applet不能访问本地资源。 15. 下面程序的注释是否正确? public class Test { public static void main(String [] args) { System.out.println(“Hello World!”); /*System.out.print(); /*System.out.print();//打印一个空行*/ System.out.println(“This is the first program”);*/ } } 不对,注释不可以嵌套 16. 下面的Java的标识符是否正确?如有错误,说明原因。 ① _under_bar_ ② m828134 ③ 5t ④ Throw //关键字重复 ⑤ his_$account_*total //有特殊符号 ⑥ How old //有空格 17. 下面的表达式是否正确?如有错误,说明原因。 ① byte b=128; //超出 ② boolean b=null;//类型不匹配 ③ long l=0xffff; ④ Double d=0.923; ⑤ float f=0.95; //类型不匹配 ⑥ double d=.35D; ⑦ char c=’\r’; 18. 下面程序的运行结果是什么? public class Test { public static void main(String [] args) { boolean a=false; boolean b=true; boolean c=(a&&b)&&(!b); int result=c==false?1:2; } } ① c=false result=1 ② c=true result=2 ③ c=true result=1 ④ c=false result=2 ⑤ char c=’\r’; 19. 下面程序编译是否通过?若不通过,应该如何修改?说明错误原因。 public class Test { public static void main(String [] args) { byte b=135;//byte型最大到127,超出范围了 b=b+3;//b+3的结果是integer型,不能赋值给byte型 b=b+1;// 同上 System.out.println(b); } } 20. 下面程序是否会导致错误,若有,那行出错,原因何在? public class TestShort{ public static void main(String [] args) { String str=null; if((str!=null) && (str.length()>10)) { System.out.println("more than 10"); } else if((str!=null) & (str.length()<5)){ System.out.println("less than 5"); } else{ System.out.println("end"); } } } 编译没有错误,运行时将在第6行报空指针异常 21. 关于移位运算,下列哪些是正确的? ① 0000 0100 0000 0000 0000 0000 0000 0000<<5的运算结果是 1000 0000 0000 0000 0000 0000 0000 0000 ② 0000 0100 0000 0000 0000 0000 0000 0000<<5的运算结果是 1111 1100 0000 0000 0000 0000 0000 0000 ③ 1100 0100 0000 0000 0000 0000 0000 0000>>5的运算结果是 1111 1110 0000 0000 0000 0000 0000 0000 ④ 1100 0100 0000 0000 0000 0000 0000 0000>>>5的运算结果是 1111 1110 0000 0000 0000 0000 0000 0000 ⑤ 1100 0100 0000 0000 0000 0000 0000 0000>>>5的运算结果是 0000 0110 0000 0000 0000 0000 0000 0000 22. 下面程序编译是否通过,若不通过,哪行代码错误?原因何在? class TestScope { public static void main(String [] args) { int x=23; { int q=56; System.out.println("x is="+x); System.out.println("q is="+q); } q=x;//q未定义 System.out.println("x is="+x); } } 23. 某学校为新来的学生安排房间,假如有x个学生,每个房间可以住6个人,请用程序实现他们要住的房间数。(不考虑男女问题) 24. 执行String[] s=new Sting[10];后,下面哪个结论是正确的? ① s[10]为“”// 数组下标越界 ② s[9]=null ③ s[0]未定义// 是null ④ s.length=10 ⑤ s[0].length()=0// 空指针异常 25. 下面哪些语句是正确的? ① int a[][]=new int[][3]; ② int a[][]={{1,3},{2,3,4},{1,2}}; ③ String [][]s=new String[2][]; ④ String s[][]={{“can”, “I”},{ “help”, “you”}} ⑤ Int a[3]=new int[]{3,4,5}; 26. 下面哪些语句能够正确生成5个空字符串? ① String a[]=new String[5]; for (int i=0;i<5;a[i++]=“”); ② String []a={“”,“”,“”,“”,“”}; ③ String a[5]; ④ String[5] a; ⑤ String [] a=new String[5];for(int i=0;i<5;a[i++]=null); a[i]=null的结果为null,a[i]=””的结果是空字符串 27. 编写一个程序,用选择法对数组a[]={20,10,50,40,30,70,60,80,90,100}进行由大到小的排序。 public class P { public static void main(String[] args) { int[] a = {20,10,50,40,30,70,60,80,90,100}; for (int i = a.length - 1; i >= 0; i--) { for (int j = 0; j < i; j++) { if(a[j] > a[j+1]){ int temp; temp = a[j]; a[j] = a[j+1]; a[j+1] = temp;