J2SE阶段练习题
j2se第一次考试
一、单选题(本大题15小题,每小题2分,共30分)1.下列语句执行后,变量a、c的值分别是( )。
int x=182;int a,c;c=x/100;a=x%10;A) 1,2 B) 2,1 C) 1.82, 2 D) 100,822.下面哪个表达式可用得到x和y的最大值( )?A) x>y?y:x B) x<y?y:x C) x>y?(x+y):(x-y) D) x==y?y:x;3. 应用程序的main方法中有以下语句,则输出的结果是( )。
String s1="0.5",s2="12";double x=Double.parseDouble(s1);int y=Integer.parseInt(s2);System.out.println(x+y);A) 12.5 B) 120.5 C) 12 D) “12.5”5. 应用程序的main方法中有以下语句,则输出的结果是( )。
double x=1234.1234567;DecimalFormat form1 = new DecimalFormat("0000.0");System.out.println("PI="+form1.format(x));A) PI=1234.1 B) PI=1234C) PI=1234.1235 D) PI=1234.06.下列程序段执行后的结果是( )。
String s=new String("abcdefg");for(int i=0;i<s.length();i+=2){System.out.print(s.charAt(i));}A) aceg B) ACEG C) abcdefg D) abcd7. 应用程序的main方法中有以下语句,则输出的结果是( )。
int[] x={122,33,55,678,-987};int max=x[0];for(int i=1;i<x.length;i++){if(x[i]>max)max=x[i];}System.out.println(max);A) 678 B) 122 C) -987 D) 338.下列语句序列执行后,k 的值是( )。
Java软件开发工程师职业技能培训J2SE 第一阶段考试题
J2SE 第一阶段考试题(每位同学以自己的姓名作为Word文档的文件名)一、问答题(请直接在Word文档中写出自己的答案,每题4分,共40分)1、什么是Java中的类?什么是Java中的对象?如何定义类和对象(用简单的代码加以说明)?2、什么是Java中的继承?如何定义某个类的子类(用简单的代码加以说明)?3、什么是Java中的多态?如何实现Java中的多态(用简单的代码加以说明)?4、什么是Java中的接口?如何实现Java中的接口(用简单的代码加以说明)?5、什么是Java中的线程?如何产生出自己的线程类(用简单的代码加以说明)?6、什么是Java中的异常?如何产生出自己的异常类(用简单的代码加以说明)?7、什么是Java中的对象序列化和反序列化技术?如何实现对象的序列化和反序列化技术(用简单的代码加以说明)?8、请解释“JDBC”的含义是什么?JDBC API中的“Statement”、“PrepareStatement”和“CallableStatement”三个类之间有什么区别?9、请用具体的XML文档示例说明什么是格式良好(Well-formed XML)的XML文档?什么是有效(Validator XML)的XML文档?10、请说明Java IO包中的FileInputStream和FileOutputStream类的主要功能是什么?二、编程题(请将所编程的各个程序拷贝到Word文档中,每题10分,共60分)1、请用具体的Java代码编程定义出下面图中各种形式的“人”类(每个类中的成员方法和属性自己规定,并将所写的程序代码拷贝到Word文档中以便检查)2、假设在C:\Java目录中有一个myFile.txt 文件,请编程实现读出该myFile.txt 文件中的内容Java程序(将所写的程序代码拷贝到Word文档中,并将执行的结果拷屏到Word文档中以便检查)3、给定某个网站的主机名为“”,请编程实现打印输出该网站IP地址的Java程序(将所写的程序代码拷贝到Word文档中,并将执行的结果拷屏到Word文档中以便检查)4、设计一个实现对下面的EBook数据库表进行CRUD-----“增(CREATE)、删(DELETE)、改(UPDATE)、查(READER)”操作的J2SE程序。
j2se基础知识测试题
j2se基础知识测试题共50道题,每道题2分,总分100分,80分为合格。
注意,所有题目均为多项选择题。
1.在JAVA中,下列哪些说法是正确的()A.java源文件的扩展名为.javaB.写好的java源程序可以直接运行C.编写的源程序必须先编译后才能运行D.程序员可以读懂扩展名为.class的文件2.在java中,关于数组描述正确的是()A.数组中的索引下标从1开始B.存储在数组当中的数据都属于同一数据类型C.通过数组名.length()能获得数组的长度D.数组的最大索引下标是数组的长度减13.下列标识符哪个是合法的()A.classB.$abcC.1234D._name4.下面程序的输出结果是什么( )int[] arr = new int[10];System.out.println(arr[0]);A.编译不通过B.运行时出错C.输出nullD.输出05.下面哪些赋值语句是正确的?( )A. long test = 012;B. float f = -412;C. int other = (int) true;D. double d = 0x12345678;E. byte b = 128;6.下面哪个语句正确地声明一个整型的二维数组( )A. int a[][] = new int[][];B. int b[10][10] = new int[][];C. int c[][] = new int[10][10];D. int []d[] = new int[10][10];7.下面哪些函数是public void aMethod(){...}的重载函数?( )A. void aMethod( ){...}B. public int aMethod(int a, float b){...}C. public void aMethod (){...}D. public float aMethod (int m){…}8.下列代码运行的结果是( )public static void main(String[] args) {int x = 4;int y = 5;if(x++>4 & ++y>5) {x++;}System.out.println("x=" + x + ",y=" + y);}A. x=4,y=5B. x=4,y=6C. x=5,y=6D. x=6,y=69.尝试运行下面的代码会发生什么?( )public class Test {public static void main(String[] args) { boolean m = true; if (m = false) {System.out.println("true");} else {System.out.println("false");}}}A. 输出字符串”true”B. 输出字符串”false”C. 编译时错误D. 运行时错误10.在Java中,下列语句不能通过编译的有( )A. String s= “join”+ 3;B. int a= “join”+3;C. int a= …a?+5;D. float f=5+5.5;11.设 a = 3,则表达式 (--a )<<="">A. 16B. 8C. 24D. 1212.下面关于java中包的说法正确的是( )A. 在java中可以使用import语句导入包B. 在java中可以使用package语句导入包C. 位于同一个包中的类,不需要导包就可以直接访问D. 不同的包中可以出现类名相同的类13.以下代码段的输出结果是?()public class MyClass{public static void main(String argv[]){int i;int j;outer: for (i = 1; i < 3; i++)inner: for(j = 1; j < 3; j++) {if (j == 2)continue outer;System.out.println("Value for i = " + i + " Value for j = " +j); }}}A. Value for i = 1 value for j = 1B. Value for i = 2 value for j = 1C. Value for i = 2 value for j = 2D. Value for i = 3 value for j = 114.编译并运行以下代码将发生什么?()public static void main(String args[]){ char digit = 'a';for (int i = 0; i < 10; i++){switch (digit){case 'x' :{int j = 0;System.out.println(j);}default :{int j = 100;System.out.println(j);}}}System.out.println(i);}A. 输出11次100B. 输出10次100,然后抛出运行期异常C. 编译错误,因为变量i不能在main() 方法中被声明2次D. 编译错误,因为变量j不能在main() 方法中被声明2次E. 以上都不对15.下列关于 html 的说法哪些是正确的? ( )A. Html就是超文本标记语言的简写,是最基础的网页语言B. Html代码不用区分大小写C. Html 是由 xml 发展而来的D. Html中所有的标签都必须要有开始标签和结束标签16.在Java中,用来跳出循环的关键字为( )A. returnB. continueC. breakD. exit17.下列关于 tcp 协议的描述正确的有( )A. tcp协议是sun公司制定的协议B. tcp是基于ip协议的一种连接协议C. tcp协议面向无连接D. tcp协议面向连接18.在web页面中,经常需要使用javascript进行表单验证,现假设对用户名的限定为字母数字或下划线,以下的正则表达式哪些可以完成这样的限定?()A. [a-z0-9_]B. \wC. [a-zA-Z0-9_]19.下列关于接口的说法正确的是( )A. 接口中所有的方法都是默认抽象的B. 接口是一种特殊的java类,所以也可以定义构造函数C. 接口中的方法前面必须要加上publicD. 一个类只能extends继承一个父类,但是可以实现多个接口20.运行以下代码片段,输出结果是?()class X {Y b = new Y();X() {System.out.print("X");}}class Y {Y() {System.out.print("Y");}}public class Z extends X {Y y = new Y();Z() {System.out.print("Z");}public static void main(String[] args) {new Z();}}A. ZB. YZC. XYZ21.下面程序的输出结果是什么( )Set set= new HashSet();set.add("aaa");set.add("bbb");set.add("aaa");System.out.println(set.size());A. 编译不通过B. 运行时出错C. 输出3D. 输出222.下列选项中关于Java中super关键字的说法正确的是()A. super关键字是在子类对象内部指代其父类对象的引用。
J2E考试1.0版
仅供参考。
不保证正确性。
排版也较乱。
没时间再整理了。
一、填空题:1、javaEE全称JavaPlatform,Enterprise Edition,即Java平台企业版2、JSF:全称JavaServer Faces,是一种用于构建Web应用程序的新标准Java框架.3、JPA:全称Java Persistence API.,JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中。
4、EJB:全称是Enterprise JavaBean(企业版的JavaBean),是基于Java的服务器端的组件框架技术。
从EJB3.0版本后开始加入注解。
JPQL ——Java Persistence Query Language(面向对象查询语言)5、托管Bean一般由属性和方法组成。
6、实体管理器的Flush方法可以立即提交JPA的修改到数据库。
7、Action事件应返回的数据类型String(字符串)。
8、Data Table 的Var 属性的含义:该属性指定一个变量名,该<h:data table…/>元素内部即可通过该变量访问当前正在迭代输出的数据行。
9、JSF框架所使用的标签不需要配置直接在页面上调动。
二、判断题:1、JSF是IBM公司开发的?×2、JSF页面的后缀名可以是PHP、HTML ?√3、JSF和JPA的框架可以使用不同类型的数据库?√三、简单题:1、JSF的6个生命周期及其生命周期事件:P110(1)恢复视图阶段:(2)应用请求值阶段:(3)处理输入校验阶段:(4)更新模型的值阶段:(5)调用应用阶段:(6)生成响应阶段:2、JSF的事件模型,并具体事件来说明。
P1203、EntityManager是如何执行数据库存储过程的?P4884、Query的语法、语句、构造、5、JPQL和SQL有点类似。
好处是:开发者无须重新学一门复杂的查询语言,开发者可以直接把已有的SQL经验应用到JPQL查询上,最大的区别在于,SQL是面向关系数据库的查询语言,因此SQL操作的对象是数据表,数据列,而JPQL操作的对象是实体对象,实体属性。
J2SE 知识点巩固提高题
J2SE 知识点巩固提高题选择题解答方式:1. 写出答案2. 写出做出选择的理由3. 简略书写相关知识点要点Question 1Click the Exhibit button.1. public class A {2.3. static int counter = 0;4.5. public static int getInstanceCount() {6. return counter;7. }8.9. public A() {10. ++counter;11. }12.13. }Given this code from Class B:25.A a1 =new A();26. A a2 =new A();27. A a3 =new A();28. System.out.printIn(A.getInstanceCount() );What is the result?A. Compilation of class A fails.B. Line 28 prints the value 3 to System.out.C. Line 28 prints the value 1 to System.out.D. A runtime error occurs when line 25 executes.E. Compilation fails because of an error on line 28.Question 241. Given:10. class One {11. public One foo() { return this; }12. }13. class Two extends One {14. public One foo() { return this; }15. }16. class Three extends Two {17. // insert method here18. }Which two methods, inserted individually, correctly complete the Three class? (Choose two.)A. public void foo() { }B. public int foo() { return 3; }C. public Two foo() { return this; }D. public Three foo() { return this; }E. public Object foo() { return this; } 重写方法返回值不能比父类广。
J2SE最常见的面试题
1.面向对象的特征有哪些方面1)抽象2)继承3)封装4)多态2.什么是类与对象?类是具有共同特征实体的封装,对象是类的一个实例。
3.什么是属性与方法?描述对象静态状态的,就是对象的属性。
另一类是描述对象的动作,就是对象的方法。
4.String是最基本的数据类型吗?不是。
基本数据类型有:byte, char, int, short, long, float, double, boolean.String类是final类型,不能继承,不能修改。
5.int 和 Integer 有什么区别?Java 提供两种不同的类型:引用类型和原始类型(或内置类型)。
int是java的原始数据类型,Integer是java为int提供的封装类。
Java为每个原始类型提供了封装类。
6.运行时异常与一般异常有何异同?异常表示程序运行过程中可能出现的非正常状态,运行时异常表示虚拟机的通常操作中可能遇到的异常,是一种常见运行错误。
java编译器要求方法必须声明抛出可能发生的非运行时异常,但是并不要求必须声明抛出未被捕获的运行时异常。
9.说出ArrayList,Vector,LinkedList的存储性能和特性。
ArrayList和Vector采用顺序结构存储数据,检索元素速度快,但不适合于动态修改它的元素(如:增加删除元素),Vector是非线程安全的,ArrayList是线程安全的。
LinkedList采用链式方式存储数据,检索元素时需要进行前向或后向遍历,但插入元素时只需要记录本项的前后项即可,所以插入速度较快。
10.Collection 和Collections的区别。
Collection是集合类的上级接口,继承与他的接口主要有Set 和List。
Collections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作。
11.&和&&的区别。
&是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and)。
J2SE
J2SE试题姓名:得分:1、Java JDK中调试器的命令是 ( )。
A. javacB. javaC. jdbD. javah2、运行jar文件中class文件需要在java命令后面加的参数为()。
A. -cp B -g C -d D -verbose3、下面哪项在java中是不合法的标识符?()A. $userB. pointC. You&meD. _endline4、下列哪一项不是Java保留字?()A. sizeofB. superC. abstractD. break5、下列哪个布局管理器中的按钮位置有可能会根据Frame的大小改变而改变?()A. BorderLayoutB. CardLayoutC. GridLayoutD. FlowLayout6、下面哪些java语句会导致无限循环?( )I、 while (true) i = 0;II、 while (false) i = 1;III、 while (!false) i = 0;A、III onlyB、I and III onlyC、I onlyD、I, II and III7、下面是Example.java文件的完整代码,请找出会产生编译错误的行()。
1) class BaseClass {2) public String str;3) public BaseClass(){4) System.out.println(“ok”);}5) public BaseClass(String s){6) str=s;}}7) class SubClass extends BaseClass{8) }9) public class Example{10) public void method(){11) SubClass s=new SubClass(“hello”);12) BaseClass b=new BaseClass(“world”);13) }14) }A. 7B. 10C. 11D. 128、可以在下面代码段point x处写入的是()。
J2SE复习
1、J2SE _Exception部分--Java异常是指Java提供的用于处理程序中错误的一种机制。
--所谓错误是指在程序运行的过程中发生的一些异常事件(如:除0溢出,数组下标越界,所要读取的文件不存在)。
--设计良好的程序应该在异常发生时提供处理这些错误的方法,使得程序不会因为异常的发生而阻断或产生不可预见的结果。
--Java程序的执行过程中如出现异常事件,可以生成一个异常类对象,该异常对象封装了异常事件的信息并将被提交给Java运行时系统。
这个过程称为抛出(throw)异常。
--当Java运行时系统接收到异常对象时,会寻找能出来这一异常的代码,并把当前异常对象交给其处理,这一过程称为捕获(catch)异常。
异常的分类:--J2SDK中定义了很多异常类,这些类对应了各种各样可能出现的异常信息。
Throwable--Error--ExceptionError:称为错误,由Java虚拟机生成并抛出,包括动态链接库失败,虚拟机错误等,程序对其不做处理。
Exception:所有异常类的父类,其子类对应了各种各样可能出现的异常事件,一般需要用户显示的申明或捕获。
Runtime Exception:一类特殊的异常,如被0除,数组下标越界越界等,其产生比较频繁,处理麻烦,如果显示的申明或捕获将会对程序的可读性和运行效率影响很大。
因此由系统自动检测并将他们交给缺省的异常处理程序。
(用户可不必对其进行处理)异常的捕获和处理:--try代码段包含可能产生例外的代码。
--try代码段后跟有一个或多个catch代码段--买个catch代码段申明其能处理的一种特定的异常并提供处理方法--当异常发生时,程序会终止当前的流程,根据获取异常的类型去执行相应的catch代码段--finally段的代码无论是否发生异常都有执行。
catch语句:--在catch语句块中是对异常进行处理的代码,每个try语句块可以伴随一个多多个catch语句,用于处理可能产生不同类型的异常对象--在catch中申明的异常对象,封装了异常事件发生的信息。
j2se程序开发题目及答案(精华版)
1:题目:判断101-200之间有多少个素数,并输出所有素数。
程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。
public class lianxi02 {public static void main(String[] args) {int count = 0;for(int i=101; i<200; i+=2) {boolean b = false;for(int j=2; j<=Math.sqrt(i); j++){if(i % j == 0) { b = false; break; }else { b = true; }}if(b == true) {count ++;System.out.println(i );}}System.out.println( "素数个数是: " + count);}}第2】古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?//这是一个菲波拉契数列问题public class lianxi01 {public static void main(String[] args) {System.out.println("第1个月的兔子对数: 1");System.out.println("第2个月的兔子对数: 1");int f1 = 1, f2 = 1, f, M=24;for(int i=3; i<=M; i++) {f = f2;f2 = f1 + f2;f1 = f;System.out.println("第" + i +"个月的兔子对数: "+f2);}}}第3】题目:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。
精编2020年JAVASE综合考核题库完整版188题(含答案)
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?public class Example {public static void main(String[] args) {double d = -11.1;double d1 = method(d);System.out.println(d1);}}"答案: AA.floor()B.ceil()C.round()D.abs()2."关于以下代码正确的说法是:1.public class Example {2. int x = 0;3.4. public Example(int inVal) throws Exception {5. if (inVal != this.x) {6. throw new Exception(""Invalid input"");7. }8. }9.10. public static void main(String[] args) {11. Example t = new Example(4);12. }13.}"答案:A.代码在第1行编译错误B.代码在第4行编译错误C.代码在第6行编译错误D.代码在第11行编译错误3."现有如下代码:public class Example {public static void main(String[] args) {try {System.out.println(""before"");doRisyThing();System.out.println(""after"");} catch (Exception e) {System.out.println(""catch"");}System.out.println(""done"");}public static void doRisyThing() throws Exception{//this code returns unless it throws an Exception}}该代码可能的执行结果有哪些?"答案:A.before catchB.before after doneC.before catch doneD.before after catch4."下列代码的执行结果是?class Example {private void method1() throws Exception {throw new RuntimeException();}public void method2() {try {method1();} catch (RuntimeException e) {System.out.println(""Caught Runtime Exception"");} catch (Exception e) {System.out.println(""Caught Exception"");}}public static void main(String[] args) throws IOException { Example a = new Example();a.method2();}}"答案:A.代码编译失败B.输出Caught Runtime ExceptionC.输出Caught ExceptionD.输出Caught Runtime Exception和Caught Exception5."以下代码的输出结果是什么?选择所有的正确答案。
J2SE面试笔试题大汇总
121、什么是web容器答:给处于其中的应用程序组件(JSP,SERVLET)提供一个环境,使JSP,SERVLET直接跟容器中的环境变量交互,不必关注其它系统问题。
主要有WEB服务器来实现。
例如:TOMCAT,WEBLOGIC,WEBSPHERE等。
该容器提供的接口严格遵守J2EE规范中的WEB APPLICATION 标准。
我们把遵守以上标准的WEB服务器就叫做J2EE中的WEB容器。
122、什么是EJB容器答:Enterprise java bean 容器。
更具有行业领域特色。
他提供给运行在其中的组件EJB各种管理功能。
只要满足J2EE规范的EJB放入该容器,马上就会被容器进行高效率的管理。
并且可以通过现成的接口来获得系统级别的服务。
例如邮件服务、事务管理123、什么是JNDI答:(Java Naming & Directory Interface)JAVA命名目录服务。
主要提供的功能是:提供一个目录系统,让其它各地的应用程序在其上面留下自己的索引,从而满足快速查找和定位分布式应用程序的功能。
124、什么是JMS答:(Java Message Service)JAVA消息服务。
主要实现各个应用程序之间的通讯。
包括点对点和广播。
125、什么是JTA答:(Java Transaction API)JAVA事务服务。
提供各种分布式事务服务。
应用程序只需调用其提供的接口即可。
126、什么是JAF答:(Java Action FrameWork)JAVA安全认证框架。
提供一些安全控制方面的框架。
让开发者通过各种部署和自定义实现自己的个性安全控制策略。
RMI/IIOP:(Remote Method Invocation /internet对象请求中介协议)他们主要用于通过远程调用服务。
例如,远程有一台计算机上运行一个程序,它提供股票分析服务,我们可以在本地计算机上实现对其直接调用。
当然这是要通过一定的规范才能在异构的系统之间进行通信。
精编JAVASE综合模拟考试188题(含标准答案)
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对2."给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?1.public class Example {2. public static void main(String[] args) {3. double x[] = { 10.2, 9.1, 8.7 };4. int i[] = new int[3];5. for (int a = 0; a < x.length; a++) {6.7. System.out.println(i[a]);8. }9. }10.}"答案:CA.i[1] = ((int)Math.min(x[a]));B.i[1] = ((int)Math.max(x[a]));C.i[1] = ((int)Math.ceil(x[a]));D.i[1] = ((int)Math.floor(x[a]));3."以下代码执行结果是?public class Example {public static void main(String[] args) {System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY));}}"答案:AA.输出NaNB.打印输出InfinityC.运行时异常,因为NaN不是有效的参数D.运行时异常,因为Infinity不是有效的参数4.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set5.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化6.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set7.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()8.创建一个只能存放String的泛型ArrayList的语句是哪项?答案:BA.ArrayList<int> al = new ArrayList<int>();B.ArrayList<String> al = new ArrayList<String>();C.ArrayList al = new ArrayList<String>();D.ArrayList<String> al = new List<String>();9."下列代码执行后的输出是哪项?public class Example {public static void main(String[] args) {List<String> al = new ArrayList<String>();al.add(""1"");al.add(""2"");al.add(""2"");al.add(""3"");System.out.println(al);}}"答案:A.[1,2,3]B.[1,2,3,3]C.[1,2,2,3]D.[2,1,3,2]10."现有:list是一个合法的集合引用getCollection()返回一个合法集合的引用,以下语句哪些是合法的?" 答案:CA.for(Object o : list)B.for(Object o : getCollection())C.for(Object o : list.iterator())D.for(Iterator I;list.iterator();i.hasNext())11.构造方法可以使用哪个访问权限修饰符?答案:AA.publicB.protectedC.privateD.都可以12."现有:public class Example {public static void main(String[] args) {TreeSet<String> s = new TreeSet<String>();s.add(""one"");s.add(""two"");// 插入代码处for (String s2 : sorted) {System.out.print(s2 + "" "");}}}和四个代码片段:s1:SortedSet sorted = s.tailSet(s.first());s2:SortedSet<String> sorted = s.tailSet(s.first());s3:SortedSet sorted = (SortedSet)s.tailSet(s.first());s4:SortedSet sorted = (SortSet<String>)s.tailSet(s.first());分别插入到插入代码处,哪项可以编译?"答案:A.S2B.S2和S3C.S2和S4D.S2、S3和S413.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()14."以下代码执行结果是?public class Example {public static void main(String[] args) {TreeMap<String, String> map = new TreeMap<String, String>(); map.put(""one"", ""1"");map.put(""two"", ""2"");map.put(""three"", ""3"");displayMap(map);}static void displayMap(TreeMap map) {Collection<String> c = map.entrySet();Iterator<String> i = c.iterator();while (i.hasNext()) {Object o = i.next();System.out.print(o.toString());}}}"答案:A.onetwothreeB.123C.one=1three=3two=2D.onethreetwo15."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();16."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出17.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法18."现有:f是一个File类实例的合法引用fr是一个FileReader类实例的合法引用br是一个BufferedReader类实例的合法引用如下代码:String line = null;//插入代码处System.out.println(line);}哪一行代码插入到插入代码处将循环一次输出文本文件的一行?" 答案:A.while((line = f.read())!=null){B.while((line = fr.read())!=null){C.while((line = br.read())!=null){D.while((line = br.readLine())!=null){19.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型20."现有:String s = ""write a line to a file"";w.print(s + ""\n"");哪一个是对的?"答案:A.w既可以是PrintWriter类型,也可以是BufferedWriter类型B.w既不可以是PrintWriter类型,也不可以是BufferedWriter类型C.w可以是PrintWriter类型,但不可以是BufferedWriter类型D.w既可以是BufferedWriter类型,也可以是PrintWriter类型21.以下哪些描述是正确的?答案:A.InputStream和OutputStream类是基于字节流的B.ObjectInputStream类和ObjectOutputStream类不支持序列化的对象C.Reader和Writer是基于字符流的D.Reader类和Writer类是支持对象序列化的首选22.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有23."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo24."给出以下代码:class Example {public static void main(String[] args) throws IOException {try {methodA();} catch (IOException e) {System.out.println(""caught IOException"");}catch (Exception e) {System.out.println(""caught Exception"");}}}如果methodA()方法抛出一个IOException异常,则该程序的运行结果是什么?" 答案:A.无内容输出B.代码编译失败C.输出caught IOExceptionD.输出caught Exception25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26."现有如下代码:public class Example {public static void main(String[] args) {try {int x=Integer.parseInt(""42a"");//插入代码处System.out.println(""oops"");}}}在插入代码处插入哪些语句可以在运行后输出oops?"答案:CA. } catch (IllegalArgumentException e) { (非法参数异常)B.} catch (IllegalStateException c) {C. } catch (NumbelFormatException n) {D.} catch (ClassCastException c) {27.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String28.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前29."请问以下代码的直接执行结果是?class Example{public static void main(String[] args) {try {System.out.println(args[0]);System.out.println(""I'm nomal"");if (true)return;} catch (Exception ex) {System.out.println(""I'm exception"");if (true)return;} finally {System.out.println(""I'm finally."");}System.out.println(""Out of try."");}}"答案:AA."I'm exceptionI'm finally."B.代码不能编译通过,因为最后一条语句位于return后,不可到达C.代码编译通过,但运行时输出异常信息D."I'm nomalI'm finally."30."现有代码如下:public class Example {void topGo() {try {middleGo();} catch (Exception e) {System.out.println(""catch"");}}void middleGo() throws Exception {go();System.out.println(""late middle"");}void go() throws Exception {throw new Exception();}public static void main(String[] args) {Example example = new Example();example.topGo();}}该代码的执行结果是?"答案:BA.输出late middleB.输出catchC.输出late middle catchD.输出catch late middle31."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {try {throw new Exception();} catch (Exception e) {try {throw new Exception();} catch (Exception e2) {System.out.println(""inner"");}System.out.println(""middle"");}System.out.println(""out"");}}"答案:DA.inner outerB.middle outerC.inner middle outerD.编译失败32."现有如下代码:public class Example {public static void main(String[] args) {// a new Example().topGo();}void topGo() {// bmiddleGo();}void middleGo() {// cgo();System.out.println(""late middle"");}void go() {// dthrow new Exception();}}为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?" 答案:BA.dB.c和dC.b、c和dD.a、b、c和d33."下面代码的执行结果是?class Example extends Utils {public static void main(String[] args) {try {System.out.print(new Example().getlnt(""42""));} catch (Exception e) {System.out.println(""Exc"");}}int getlnt(String arg) throws Exception {return Integer.parseInt(arg);}}class Utils {int getlnt() {return 42;}}"答案:BA.NFExcB.42C.42NFExcD.编译失败34."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {double d1 = -0.5;System.out.println(""Ceil d1="" + Math.ceil(d1));System.out.println(""Floor d1="" + Math.floor(d1));}}"答案:BA.输出Ceil d1=-0.0 Floor d1=-1.0B.输出Ceil d1=0.0 Floor d1=-1.0C.输出Ceil d1=-0.0 Floor d1=-0.0D.输出Ceil d1=0.0 Floor d1=0.035."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性36."以下代码的输出结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.round(Float.MAX_V ALUE));}}"答案:BA.输出Integer.MAX_V ALUEB.输出一个最接近Float.MAX_V ALUE的整数C.编译失败D.运行时输出异常信息37."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try38."以下代码中,如果test()方法抛出一个NullPointException异常时,打印输出什么内容?class Example {public static void main(String[] args) throws IOException {try {test();System.out.println(""Message1"");} catch (ArrayIndexOutOfBoundsException e) {System.out.println(""Message2"");}finally{System.out.println(""Message3"");}}}"答案:A.打印输出Message1B.打印输出Message2C.打印输出Message3D.以上都不对39."以下代码执行结果是?public abstract class Example extends Base {public abstract void method();}class Base {public Base() throws IOException {throw new IOException();}}"答案:A.代码编译失败,因为非抽象类不能被扩展为抽象类B.代码编译失败,因为必须提供一个可以抛出或可以不抛出IOException异常的构造器C.代码编译失败,以in为必须提供一个可以抛出IOException异常或其子类的构造器D.代码编译成功40."现有如下代码:public class Example {public static void main(String[] args) {try {System.out.println(""before"");doRisyThing();System.out.println(""after"");} catch (Exception e) {System.out.println(""catch"");}System.out.println(""done"");}public static void doRisyThing() throws Exception{//this code returns unless it throws an Exception}}该代码可能的执行结果有哪些?"答案:A.before catchB.before after doneC.before catch doneD.before after catch41."下列代码的执行结果是?class Example {private void method1() throws Exception {throw new RuntimeException();}public void method2() {try {method1();} catch (RuntimeException e) {System.out.println(""Caught Runtime Exception"");} catch (Exception e) {System.out.println(""Caught Exception"");}}public static void main(String[] args) throws IOException { Example a = new Example();a.method2();}}"答案:A.代码编译失败B.输出Caught Runtime ExceptionC.输出Caught ExceptionD.输出Caught Runtime Exception和Caught Exception42."以下代码的输出结果是什么?选择所有的正确答案。
01_J2SE初级技术面试题目及答案
构造器Constructor是否可被override?
构造器Constructor不能被继承,因此不能重写Overriding,
但可以被重载Overloading。
19
Java中,是否支持多继承?
Java不支持多继承,可多层次继承。
20
Java中,请说明final关键字的使用?
final在类之前:表示该类是最终类,表示该类不能再被继承。
接口实质并不类,其中只包含常量及抽象方法的定义;
28
静态变量和实例变量有何区别?
用static修饰的变量叫静态变量。静态变量不需要new出对象引用来调用,它可以直接用类名直接调用。当然用对象引用也能调它,只是不需要。
实例变量则必须用对象引用进行调用。
静态变量在内存空间中只有一份,也永远只有一份。大家共享。
2.continue: continue语句,只能在循环中使用让封闭循环进行下一次迭代;遇到该语句时,跳过循环体中剩余的语句,控制权传递给重新初始化步骤;在while循环和do…while循环中,程序控制权传递个条件测试语句;在for循环中,continue影响循环的增量部分,然后执行条件测试;
10
如何获取java中数组的长度?
数组名.length;数组的属性
11
类方法能不能调用实例方法?
不能;
12
顺序查询与折半查询的区别?
1.顺序查找是一种最基本和最简单的查找方法。它的思路是,从表中的第一个元素开始,将给定的值与表中逐个元素的关键字进行比较,直到两者相符,查到所要找的元素为止。否则就是表中没有要找的元素,查找不成功。对于表中记录的关键字是无序的表,只能采用这种方法。
final在方法之前:表示该方法是最终方法,该方法不能被任何派生的子类覆盖。
j2ee开发习题和答案EJB,servlet.doc
Q :lWhich of the following statements are correct regarding the stateful session beanSelect Your Answer:They allow PostConstruct, PreDestroy callback methods.A session bean has to always implement the intrefaces annotated with @Local and @Remote to Dspecify the local and and remote in terfaces ・A Session bean can have no Local interface.When a die nt looks up for a stateful sessio n bea n in JNDI, same bea n instance is retur ned every time.Q :2GivenBea nl ~> Stateful sessi on Bea n's local in terface of 'beanl1Bea n2 ~> Stateless Sessi on Bea n f s local in terface of *bea n2‘and given:@EJB(beanName=H beanl H) Beanl refl;@EJB(beanName="beanl") Beanl ref2;@EJB(beanName=H bean2") Bean2 ref3;@EJB(beanName=,,bean2n) Bean2 ref4;After injection has completed, what would be the output of the following code?System.out.pri ntln (refl.equals(ref2));System.out.printl n(ref3.equals(ref4));Select Your Answer:A false falseB false trueC true falseD true trueQ :3EJB supports scheduling system called Timer Service.Which interface must implemented by an enterprise bean to be able to be scheduled ?Select Your Answer:A java.util.TimerB javax.util.TimerC javax.ejb.TimerD javax.ejbJimerObjectE java.util.TimerObjectQ :4Which of the following stateless bean definitions are correct to be able to be scheduled?Select Your Answer:A import javax.ejb.*;@Statelesspublic ClassFoo implements FooRemoteJimedObject{public void ejbTimeout(Timer timer){//logic }}B import javax.ejb.*;@Statelesspublic class Foo implements FooRemote{@Timeoutpublic String ejbTimeout(Timer timer){ // logic }}C import javax.ejb.*;@Statelesspublic class Foo implements FooRemote{@Timeoutpublic void fnTimeout(Timer timer){ // logic }}D import javax.ejb.*;@Statelessublic class Foo implements FooRemote{@Timedoutpublic void fnTimeout(Timer timer){ // logic }}Q :6Given a Car EJB used to schedule perticular car for Maintenance, which is being scheduled as below : (©Statelesspublic class Foo implements FooRemotef@Resource TimerService timerService;@Timeoutpublic void maintenanceCall(){// maintenanee appropriate Logic}public void ScheduleMaintenance(lnteger carld, Date dayToBeScheduled){timerService.createTimer( dayToBeScheduled, carld.toString());}public void resceduleMaintenance(lnteger carld, Date rescheduleDate){//Block 1 }}What are the appropriate code to be inserted in //Block 1 to reschedule a car maintenance to a new time?Select Your Answer:A for(lbject obj:TimerService.getTimers()){Timer timer = (Timer) obj;if(timer.getlnfo().equals(carld.toString()){timer = timerService.createTimer(rescheduleDate,carld.toStri ng);}}B for(lbject obj:TimerService.getTimers()){Timer timer = (Timer) obj;if(timer.getlnfo().equals(carld.toString()){timer.cancel();timerService.createTimerfrescheduleDate.carld.toString);}}C for(lbject obj:TimerService.getTimers()){Timer timer = (Timer) obj;if(timer.getlnfo().equals(carld.toString())timer.reschedule(rescheduleDate);}Timer timer = timerService.getTimer(carld);timer.reschedule(rescheduleDate);Q :7Given a Timer scheduled as below:Calendar time = Calendar.getlnstance();time.add(Calendar.DATE J5);Date initialExpiration 二Timer timer =timerService.createTimer(time.getTime(),1000*60*60*24/"Timerl");what will be the result of calling timer.getNextTimeout()?Select Your Answer:A The Date returned is the time when the timer will be off first time・B The Date returned is the time when timer is off next time.C The Date returned is the time remaining until the timer is off next time.D None of the aboveQ :9Given 2 Session beans, Foo and Fool@Statelesspublic class Foo implementsFooRemote{private Fool fool;@Resource TimerService timerService;@PostC on structpublic void init(){ // block 1}@PreDestorypublic void finish(){ // block 2 }// business methodpublic void doBusinessAction(){ // block3 }@EJBpublic setFool(Fool fool){//Block 4this.fool = fool;}}Which are the legal blocks to place following code:timerService.createTimerfexpDate/^est Timer'1);Select Your Answer:A block 1B block 2C block 3D block 4E block 5Q :10Which of the following statements about @PostConstruct callback method of an EJB are true?Select Your Answer:A It must return voidB It can or can't have parametersC It should not throw any checked exceptionsD It can define 0-n number of PostConstructcallback methodsE It should be a public method.(access mod讦ier should be public)Q :llWhich of the following statements about session beans are true?Select Your Answer:A A session bean can have no Local and Remote interfaces.B A session bean can haveO or more Local interfaces.C A sessio n bean can have 0 or more remote in terfaces.D An interface can be marked both as remote and local.Q :12Which of the following statements about EJB programming are true according to EJB Specs?SelectYour Answer:A An EJB can declare,read and update static fieldsB EJB should not use java.io package in attempt to access files and directories in the file system.C EJB can listen to a socket or accept connections.D None of the aboveQ :13ln EJB 3.0, the deployment descriptor in ejb-jar file (ejb-jar.xml) is optional.Select Your Answer: True FalseQ :14Which of the following statements about session beans are true?Select Your Answer:A.Session beans can f t represent db dataB.Session beans can't access db dataC.Session beans are ususally used to define interaction between other beansD.Session beans usually contain business logic.E.Stateless session beans have longer life than stateful session beansQ :15Which of the following statements are true?Select Your Answer :A.Stateful session beans can have timeout period and remove methods.B.The stateless session beans can't have timeout period.C.Stateless session beans can have remove method.For Server, when client removes a stateless session bean, there is no effect.D.StatefuI session beans are lightweigh and fast as they are associated with single die nt and there is no overhead of object swappi ng. E.Stateless sesii on bea n can not have instance variables・ They can only have static and final fields・Q :16Which of the following statements are true about remote and local interfaces of a sessionbean?Select Your Answer:A.Remote in terfaces can also be marked as Local.B .If a client invokes a method on bean's remote interface, given the client and server are running in different VM, the parameter values and return values are passed by Value.(They are copied)C」f a die nt invokes a method on bea n's remote in terface, give n the die nt and server are running on same VM, the parameter values and return values are passed by Reference.D.One can define a common base interface for Remote and Local interface if they share same methods.E.Entity Beans can be used as parametrs and Return values to remote and local interfaces.Q :17A session bean's remote method threw a EJBException. What doyou think might be the reasons? Select Your Answer:A.The session bean processing might have thrown a RuntimeExceptionB.The session bean processing might have thrown an Application Exception.C.The session bean might have thrown a checked Exception, which was caught and again wrapped into a EJBException・D.The container might have thrown some exceptionE.The session bean might have thrown a non RuntimeException.Q :18l have a session bean which expose different methods on local and remote business interfaces as below.public in terface myAppBasel nterface{public void keepMeReadyf);}(©Remotepublic in terface myAppRemote exte nds myAppBasel nterface{public ResultObj calculateForRemoteClients();}@Localpublic in terface myAppLocal myAppBaselnterface{public void calculateForLocalClients(ResultObj obj);}Recently, during enhancing the project,in keepMeReady() method, I had to call another session bean's method passing curre nt session bea rTs own object reference.How can I determi ne through which in terface the die nt has made the call? Select Your Answer:ing getBusinessObjectlnterfae method of SessionContext.ing getBusinesslnterface method of sessionContexting getlnvokedEJBObjectlnterface method of SessionContexting getlnvokedBusinessInterface method of SessionContextE.Get the Business EJB object using getBusinesslnterface() method and use instan ceof operator to determi ne the in terface ・Q :19Which of the following rules are true about session beans.Select Your Answer:A.Business methods must not be declared final or static.B.Arguments and return types for remote component interface methods must be legal RMI-IIOP types.C.One must not declare any application exceptions that were not declared in remote or local interfaces for that matching business method.D.The session bean class can be abstract but not final.E.The Bean class cant have superclasses.Q :21Which are the appropriate places for a stateless session bean to invoke getCallerPrincipal() method of sessionContext? Select Your Answer:A」n the con structor B」n the setter method marked @ Resource C」n Method marked @PostC on struct D.in Method marked @PreDestrov E」n Business method F.AII the aboveQ :22Which are the appropriate places for a stateful session bean to invoke getCallerPrincipal() method of sessionContext?Select Your Answer:A」n the constructor B」n the setter method marked as @ResourceC.in Method marked @PostConstruct D・in Business method E.in the finalize methodQ :23lf a client makes call to a session bean object, which has been already removed by the container, which exception will be thrown?Select Your Answer:A.java.rmi.RemoteExcepti onB.NullPoi nterExcepti onC.EJBExceptionD.java.rmi.NoSuchObjectExceptionE.iavax.eib.ObiectNotFo un dExcepti onQ :24What happens if a stateless session bean throws a System Exception (RuntimeException)?Select Your Answer:A.The bea n in stance will be kille d・B.The bean instance is returned to the pool.C.There is no effect on the bean instaneeQ :25Which of the following statements are true about stateless session bean creation?Select Your Answer:A.Stateless sessi on bea ns are created whe n die nt tries to get ref ere nee using its remote or local in terface.B.The PostConstruct method of a stateless session bean will be called onlv once during its life cvcle. CM/hen client invokes the business method, the stateless session bean will be pulled from pool. D.SessionContext's client specific methods can be accessed only when bean is executing its business method.Q :26ldentify correct syntax of defining a bean's PostConstruct method?Select Your Answer:A.<enterprise-bea ns><session-bean><ejb-name> MyBean v/ejb-name〉<post-c on struct-method-name>myinit</post-c on struct-method-name></sessi on-bea n></e nterprise ・bea ns>B.<e nterprise ・bea ns><sessi on><ejb-name> MyBean v/ejb-name〉<post-c on struc-method>myinit</post-c on struct-method></sessio n></e nterprise-bea ns>C.<enterprise-bea ns><sessi on〉<ejb-name> MyBean </ejb-name〉<post-construct><life-cycle-callback-method>myi nitv/life-cycle-callback-method></post-c on struct></sessio n></e nterprise ns>D・venterprise・beans>vsession>veib-name> MvBean v/eib・name>vpost・construct>vlifecvclicallback・method>mvinitv/lifecvcle・callback・method>v/post・construct>v/session>v/enterprise・beans>E.None of the aboveQ :27ln case of session bean, that implements a web service, how to define a webservice interface?Select Your Answer:A.A web service interface is not required to be defined.B.A web service interface has to be marked as @WebServiceC. A web service in terface method has to be marked as @WebMethodD.None of the above・Q :28ln EJB 3, how can a client get reference to a session bean's remote or local interface?Select Your Answer:A.Through the dependency injectionB.By calling create methoding lookup mechanismD.Directly instantiating the beanQ :29Which of the following are correct statements about the Life Cycle Callback Methods for Stateful Session Beans?Select Your Answer :A.PostConstruct methods are invoked on the newlv constructed instance,after anv dependency injection has been performed bv the container and before the first business method is invoked on the bean.B.PostConstruct methods are invoked in an unspecified transaction and securitv context.C.PreDestrov methods execute after anv method^ annotated with the Remove annotation has completed.D.PreDestrov methods are invoked in an unspecified transaction and security context.Q :30Given a session bean with following instance fields, which object can be successfully passivated and reactivated?@Resource Sessi onCon text sessi on Context;Socket cs;@EJB AnotherEJb myEjb;String description; java.sql.Connection conn;Select Your Answer:A.sessionContextB.csC. mvEibD.connE.StringQ :32A container may passivate a stateful session bean instance only when the instance is not in a transaction.Select Your Answer :A.TRUEB.FALSE, as the Transaction will end when called business method ends.Q :34A stateful session bean is involved in a transaction. The transaction has taken a long time, and reached the timeout period of the session bean. What willhappen to the session bean once the timeout period has crossed and the bean is still in the transaction?Select YourAnswer:A.The transaction will be rolled back and instance will be discarded・B.The transaction will be stopped at that moment when bean timesout・ All changes already done will be committed and the bean instance will be discarded・C.Timeout will not affect the transaction and session bean.D」t depe nds upon the ven dor impleme ntation.E.N one of the aboveQ :35Which of the following statements about @PreDestroy method are true?Select Your Answer:A.This method should not return any valueB.The method can not have anyparametersC.A bean can have 0・n methods marked as @PreDestroyD」f a stateful Session bean is in method-ready-state and if it times out, the container always calls @Predestroy method before discarding the bean instance.E」f a client calls the method marked @Remove then on sessionbean them after executing the Remove method container always calls @Predestroy method before discarding the bean instance,Q:37Which of the followingstatements are true about implementing javax.ejb.SessionSynchronization interface by session beans?Select Your Answer:A.This helps session beans to get synchronized with the http client's session.B.This helps session beans to synchronize their state withother session beans sharing same data.C.A stateless session bean cannot implement SessionSvnchronization interface・D.None of the aboveQ :38Which of the following statements are true?Select Your Answer:A.When an exte nded persiste nee con text is used inthe stateless sessi on bean, the en tities loaded will be active throughout bearfs life.B」n the transaction scoped persistence context,the Transaction starts and ends within the scope of the method.C」f a bean has a definition as below:@Persiste nceC on text( un itName=,,test n)then the persiste nee con text is Exte nded ・The stateful sessi on bea n can only use Exte nded persiste nee con text ・D」n the Extended persistence context,one need not required to call EntitvManage.mergeO call on entitiesQ :39Given 2 stateful session beans:Beanl and Bean2@Statefulpublic class Beanl implements BeanlRemote’BeanlLocal{@EJB Bean2Local bean2;@PersistenceContext(unitName="testdb,,/type="EXTENDED")private EntityManager entityManager;}@Statefulpublic class Bean2 implements Bean2Remote,Bean2Local{@PersistenceContext(unitName="testdb,'/type="EXTENDED")private EntityManager entityManager;}Which of the following statements are true?Select Your Answer:A」f Beanl updates a db entity, Bean2*s copy of the same entity will be discarded or detached.B. Its not legal to have EXTENDED con text for same db by 2 sessi on bea ns.C・ In real when Beanl gets instantiated and is in method・readv・state» both Beanl and Bean2 instances share same persistence context.D.When Beanl gets instantiated, a unique session will be created for Bean2.E.lf Beanl times out, the Bean2 session will not be affected. This session remains in the server until Bean2 times out.Q :40Which of the following statements are true about lnitialContext?Select Your Answer:A.This is the ejb bea n's ref ere nee to get informatio n from the con tainer.B.How to get reference to Initialcontext is vendor specific.C」nitialContext is used as particular'node' on the JNDI virtual directory tree.D」n itialC on text exte nds EJBC on textE」nitialContext can be used to get reference to another Enterprise beanF.lnitialContext can also be used to get deplov・time values for a bearu set bv the deploverQ :41Which of the following events may cause a session bean to die?Select Your Answer:A.The die nt crashesB.The client calls method marked @RemoveC.The bean times outD.The bean throws Svstem Exception1.What is wrong with the following code? ( )public void doFilter(ServletRequest req, ServletResponse, res, FilterChain chain) throws ServletException, lOException { chain.doFilter(req, res);HttpServletRequest request = (HttpServletRequest)req;HttpSession session = request.getSession();if (session.getAttributeC'login1') == null) {session.setAttribute("login",,/ new Login());}}a.The doFilter() method sig nature is in correct; it should take HttpServletRequest and HttpServletResp onse.b.The doFilter() method should also throw FilterException.c.The call to chain.doFilter(req, res) should be this.doFilter(req, res, chain).d.Accessing the request after chain.doFilter() results in an HlegalStateException.e.Nothing is wrong with this filter.2.Which of the following code snippets, when inserted in the doGet() method, will correctly count the number of GET requests made by a user? ( )a.HttpSession session = request.getSession();int count = session.getAttribute(H count H);session.setAttributeC'count舄count++);b.HttpSession session 二request.getSessionf);int count = (int) session・getAttribute「count");session.setAttribute(H count11, count++);c.HttpSession session = request.getSession();int count = ((Integer) session.getAttribute(H count,,)).intValue();session.setAttribute(H count舄count++);d.HttpSession session = request.getSession();int count = ((Integer) session.getAttribute(,f count,l)).intValue();session.setAttribute(l,count ll/ new lnteger(count++));3.GivenBea nl -> Stateful sessi on Bea rfs local in terface of 'bea nl'Bean2 -> Stateless Session Bean's local interface of *bean2"and given:@EJB(beanName="beanl") Beanl refl;@EJB(beanName=,l beanl H) Beanl ref2;@EJB(beanName=”bean2") Bean2 ref3;@EJB(beanName=t,bean2n) Bean2 ref4;After injection has completed, what would be the output of the following code? ( ) System.out.pri ntln (refl.equals(ref2));System.out.println(ref3.equals(ref4));A. falseB. falseC. trueD. truefalse true false true4. Assume that the following servlet mapping is defined in the deployment descriptor of a web application: <servlet-mappingxservlet-name>TestServlet</servlet-namex/servlet・mappi ng>Which of the following requests will not be serviced by TestServlet? ( )a. /hello.aspb./gui/hello.aspc・ /gui/hello.asp/bye.asp d. /gui/*.aspe. /gui/sales/hello.aspf. /gui/asp。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
添加两个get方法,能够取得两个新添加属性的值
一个构造方法,调用父类的构造方法,并且能够初始化新添加的两个属性
1.定义两个类Dog,SmallDog,SmallDog继承Dog
说明一:关于Dog
两个属性,狗的名字(dogName,String),狗的年龄(dogAge,int)
一个方法,dogWalk(),打印一句话简单描述狗走路的样子
一个构造方法,无参数,在此构造方法中初始化dogName,dogAge
说明一:关于Transport
两个属性,速度(speed,int)载重量(load,float)
两个get方法,能够取得两个属性的值
一个构造方法,能够初始化这两个属性
一个show()方法,调用俩个get方法,取得两个属性的值并打印
说明二:关于Vehicle
继承Transport
一个实现增长薪水的的方法raiseSalary,传递一个double类型的薪水增长率
7.定义一个类Manager(经理)继承类Employee(雇员)
添加一个属性,奖金(bonus,double)
添加一个set方法能够设置bonus属性的值
在构造方法中调用父类的构造方法,并初始化bonus为0
重写dogWalk(),打印一句话具体描述小狗走路的样子,在测试类main方法中调用dogWalk(),看看和第二题中的调用效果是否有变化
3.定义一个类BankAccount(银行帐户)
属性有"账号"、"储户姓名"、"储户身份证号"、"日期"、"金额"、"余额"、"累计余额",属性要求是私有的
重写父类的getSalary方法,在子类的getSalary方法中调用父类的getSalary方法,返回添加了奖金的全部薪水
最后,在测试类main方法中生成汽车类和飞机类的对象
6.定义一个类Employee(雇员)
三个属性,雇员姓名(name,String),薪水(salary,double),开始雇佣时间(hireDay,Date)
一个构造方法,带参数,初始化各个属性,
对于每个属性添加一个set和get方法
方法有"存款"、"取款"、"查询"、"计算利息",方法要求(学生)
属性:姓名,学号,性别,专业,班级,籍贯,入学时间,学业状况,属性要求是私有的
方法:入学,升级,留级,毕业,方法要求是公有的
5.定义一个交通工具类(Transport)和它的两个子类;汽车类(Vehicle)和飞机类(Airplane)
一个show()方法,调用父类的show()方法打印speed和load两个属性,调用新添加的两个get方法取得wheels和weight属性的值并打印
说明三:关于Airplane
和说明二的要求一致,只要求新添加的两个属性为发动机类型(enginertype,String)发动机数量(enginers,int)
说明二:关于SmallDog
继承Dog,不添加任何属性和方法
最后,在测试类中的main方法中生成SmallDog类的对象,访问属性dogName和dogAge,并打印出他们的值;调用dogWalk(),看看效果
2.在第1题的基础做修改
说明:关于SmallDog
添加两个set方法分别能够设置属性dogName和dogAge的值,在测试类中的main方法中调用这两个方法为属性设置值,再次访问这两个属性并打印看看和第二题的打印输出是否相同