J2EE课后习题题解
- 格式:doc
- 大小:120.00 KB
- 文档页数:17
一、多选题1.在Hibernate 主配置文件(hibernate.cfg.xml)中,以下哪个元素()为它的根元素。
A.<hibernate-configuration>元素B.<session-factory>元素C.<property>元素D.<mapping>元素E.<hibernate-mapping>元素2.在Hibernate 主配置文件(hibernate.cfg.xml)中,是通过哪个元素()来配置映射文件的。
A.<hibernate-configuration>元素B.<session-factory>元素C.<property>元素D.<mapping>元素E.<hibernate-mapping>元素3.下面关于Hibernate 的映射文件说法正确的有哪些()。
A.Hibernate 是以xml 格式的文件来指定对象与关系数据之间的映射B.在hibernate.cfg.xml文件中可以配置<mapping>元素的resource属性来指定映射文件C.配置映射文件时,需要遵循它对应的DTD 文件格式D.在映射文件中,<class>元素的<id>子元素只能出现一次E.<id>元素的<generator>子元素用来设定标识符生成器4.在Hibernate 的映射文件中,<id>元素的<generator>子元素用来设定标识符生成器,以下对常用的标识符生成器的用法说法正确的是()。
A.increment:适用于代理主键。
用于为long, short 或者int 类型生成唯一标识B.identity:适用于代理主键。
由底层数据库生成标识符C.sequence:适用于代理主键。
Hibernate 根据底层数据库的序列来生成标识符D.hilo:使用一个高/低位算法高效的生成long、short 或者int 类型的标识符E.seqhilo:使用一个高/低位算法来高效的生成long、short 或者int 类型的标识符,给定一个数据库序列(sequence)的名字5.Hibernate 采用xml 文件来配置对象—关系映射有哪些好处()。
专业:移动通信科目:J2EE架构设计与开发(下)一、单项选择题1.spring需要在()配置文件中进行配置A.applicationContext.xmlB.web.xmlC.webwork.xmlD.struts2.xml答案:B2.下列哪个struts2标签可以充当HTML中的文本框()A.<s:form>B.<s:textfield>C.<s:textArea>D.<s:checkbox>答案:B3.Web服务实现数据传递是以()方式进行的A.HTTP和htmlB.XML和HttpC.HTML和javaD.TXT答案:B4.对于以下程序,Customer对象在第()行变为持久化状态Customer c1=new Customer();c1.setName(\"Tom\");Session session1=sessionFactory.openSession();Transaction tx1 = session1.beginTransaction();session1.save(customer);mit();session1.close();A.line3B.line7C.line1D.line5答案:D5.下列关于Spring依赖注入的说法错误的是()A.依赖注入一般情况下由容器完成,不是应用代码完成的B.Spring只支持设值注入C.设值注入的方式用的多些D.依赖注入包括三种接口注入,设值注入,构造方法注入答案:B6.以下hql语句有误的是()A.“select id, studentName,* from Student as s“B.“select new Student(s.id, s.studentName) from Student as s“C.“select new Student(id, studentName) from Student”D.“select id, studentName from Student“答案:A7.假设某个bean要使用某种类型的资源,那么一般情况下应该把资源的释放放到bean的生命周期中()阶段A.初始化B.销毁C.使用D.定义答案:B8.下列哪一个类是让一个Action 类能够更快开始工作的基类()A.ValidateB.ActionContextC.ActionD.ActionSupport答案:D9.有关spring中配置数据源,下列说法正确的是()A.DataSource接口位于java.sql包中B.配置数据源的bean名字只能是dataSourceC.在一个spring配置文件中可以配置多个数据源D.DataSource就是一个数据库连接答案:D10.对于String类型的标识属性,最好选择哪一种主键生成器()A.assignedB.nativeC.uuidD.sequence答案:C11.当集合元素是基本数据类型和包装类、字符串和日期类型时,使用()标签表达数据列A.<element…./>B.<one-to-many…/>C.<many-to-many…/>D.<composite-element…/>答案:A12.下列关于企业级应用描述错误的是()A.企业应用中数据的一致性要求很高,所以必须有严格的事务性B.企业级应用对安全性要求很高C.企业级应用系统彼此之间是相互独立的,不需要和现有的D.企业级应用中的系统可能分布在不同的地方答案:A13.对于数组集合属性的映射,使用哪个标签()A.<array…./>B.<list…./>C.<set…./>D.<map…./>答案:A14.在持久化层,哪些状态不属于对象状态()A.游离状态B.独立状态C.持久化状态D.临时状态答案:B15.QBC查询中,表达模糊查询条件错误的是()A.Restrictions.ilike(“studentName”, “%1%”)B.Restrictions.ilike(“studentName”, “1%”)C.Restrictions.ilike(“studentName”, “1”)D.Restrictions.ilike(“studentName”, “%1”)答案:C16.事务隔离级别是由谁实现的()A.数据库系统B.JDBC驱动程序C.HibernateD.Java应用程序答案:A17.查询id在30到50之间的记录,并按照id降序排列()A. session.createCriteria(Student.class).add(Restrictions. between ("id", 30,50)) .addOrder(Order.desc("id")).list();B. session.createCriteria(Student.class).add(Restrictions. between ("id", 30,50)) .addOrder(Order.asc("id")).list();C. session.createCriteria(Student.class).add(Restrictions.in("id", 30,50)).addOrder(Order.desc("id")).list();D. session.createCriteria(Student.class).add(Restrictions.in("id", 30)).addOrder(Order.asc("id")).list();A.B.C.D.答案:B18.java中提供了支持国际化的类,其中包含Local、ResourceBundle及()A.MessageFormatB.DateFormatC.FormatD.NumberFormat答案:A19.以下哪种方法代表“大于等于”符号()A.Restrictions.le()B.Restrictions.lt()C.Restrictions.gt()D.Restrictions.ge()答案:D20.以下哪种主键生成器为自增长方式()A.identityB.nativeC.sequenceD.uuid答案:D21.QBC查询中,表达id >= 30条件正确的是()A.Restrictions. between (“id”, 30)B.Restrictions.ge(“id”, 30)C.Restrictions.gt(“id”, 30)D.Restrictions. in (“id”, 30)答案:B22.以下对切入点的声明错误的是()(注意:com.dao.impl为包名) A.@Before(“execution(* *(..))“)B.@Before(“execution(* com.dao.impl.*.*(..))“)C.@Before(“execution(* save*(..))“)D.@Before(“execution(* com.dao.impl.*(..))“)答案:D23.对象模型如下:public class Classes {private int id;private String classesName;private Set<Student> students;省略setters/getters}public class Student {private int id;private String studentName;private Classes classes;省略setters/getters}将上述对象模型转换成关系模型,用以下那个关联映射()A.1—>NB.N—>NC.1<—>ND.N<—>N答案:C24.依赖注入说法正确的是()A.依赖注入是面向对象技术的替代品B.依赖注入即是“面向接口”的编程C.依赖注入的使用会增大程序的规模D.依赖注入的目标是在代码之外管理程序组建间的依赖关系答案:B25.下列哪一个是能在一个Action执行的前后执行的代码()A.ognlB.ActionC.SpringD.Interceptor答案:D26.以下程序代码对Customer的name属性修改了两次:tx=session.beginTransaction();Customer c1=(Customer)session.load(Customer.class,new Long(1));c1.setName(\"Jack\");c1.setName(\"Mike\");mit();执行以上程序,Hibernate需要向数据库提交()条update语句A.2B.0C.3D.1答案:D27.某方法要求在事务中执行,如果已经在事务中,则直接调用,否则需开启事务才调用,事务的传播机制选哪项()A.PROPAGATION_REQUIRED_NEWB.PROPAGATION_SUPPORTSC.PROPAGATION_NESTED.PROPAGATION_REQUIRED答案:D28.下面()属于Hibernate映射文件中包含的内容A.主键生成策略B.属性数据类型信息C.Hibernate属性参数D.数据库连接信息答案:A29.设置某实例第一次被访问时支持延迟加载()A.lazy=falseB.default-lazy=trueC.lazy=trueD.default-lazy=false答案:C30.Customer类中有一个Set类型的orders属性,用来存放Order订单对象,在Customer.hbm.xml文件中,用哪个元素映射orders属性()A.<property>B.<one-to-many>C.<many-to-one>D.<set>答案:D31.以下不属于的ORM框架的是()A.OJBB.TopLinkC.SpringD.Hibernate答案:C32.下列哪个struts2标签可以充当HTML中<select>()A.<s:Iterator>B.<s:form>C.<s:select>D.<s:textfield>答案:C33.已知对象模型:public class Classes {private int id;private String classesName;private Set<Student> students;省略setters/getters}public class Student {private int id;private int score;private Classes classes;省略setters/getters}查找1到3班中成绩大于60的学生()A.B. session.createCriteria(Student.class).add(Restrictions.gt("score", 60)) .add(Restrictions.between("id",1,3)).createCriteria("classes").list();C. session.createCriteria(Student.class).add(Restrictions.gt("score", 60)) .createCriteria("classes").add(Restrictions.between("id",1,3)).list();D. session.createCriteria(Student.class).add(Restrictions.gt("score", 60)) .add(Restrictions.between("id",1,3)).list();A.选项放不下,在题干中B.session.createCriteria(Student.class).add(Restrictions.gt("score", 60))C.选项放不下,在题干中D.选项放不下,在题干中答案:A34.下面()不是由Struts提供的A.<html:errors>标签B.DynaForm类C.saveErrors方法的定义D.DispatchAction类答案:B35.关于struts2的校验,下列说法正确的是()A.类型转换出错时,struts2会自动的将错误信息保存在actionError中。
j2ee考试题及答案ejb1. 什么是EJB(Enterprise JavaBeans)?EJB是一种服务器端组件架构,用于开发和部署多层结构的、分布式的、面向对象的Java应用程序。
EJB组件提供了一种结构化的方法来创建可重用的、可伸缩的和事务性的业务逻辑。
2. EJB有哪些类型?EJB主要有三种类型:会话Bean(Session Beans)、实体Bean(Entity Beans)和消息驱动Bean(Message-Driven Beans)。
3. 会话Bean(Session Beans)的作用是什么?会话Bean代表与客户端的短暂交互,它们通常用于实现应用程序的业务逻辑,但不保存数据。
会话Bean可以是无状态的(Stateless)或有状态的(Stateful)。
4. 实体Bean(Entity Beans)和会话Bean(Session Beans)有什么区别?实体Bean代表业务实体,通常与数据库中的持久数据相关联,而会话Bean代表与客户端的短暂交互,不直接与持久数据关联。
5. 消息驱动Bean(Message-Driven Beans)的主要功能是什么?消息驱动Bean是一种特殊的EJB,用于处理来自消息队列的消息。
它们是无状态的,并且可以异步处理消息,这使得它们非常适合处理大量消息。
6. EJB容器提供哪些服务?EJB容器提供多种服务,包括事务管理、安全性、持久性、生命周期管理、并发控制和资源池。
7. EJB的事务属性有哪些?EJB的事务属性包括:Required、RequiresNew、Mandatory、Never、NotSupported和Supports。
8. 如何在EJB中处理异常?在EJB中,可以通过声明异常(declarative exception handling)和编程异常(programmatic exception handling)两种方式来处理异常。
1、简述J2EE的四层模型。
(1)运行在客户端机器上的客户层组件(2)运行在J2EE服务器上的Web层组件(3)运行在J2EE服务器上的业务逻辑层组件(4)运行在EIS服务器上的企业信息系统(Enterprise information system)层软件2、什么是对象持久化?即把数据(如内存中的对象)保存到可永久保存的存储设备中(如磁盘)。
3、简述一下OR MAPPING,为什么我们使用它?ORM(Object Relational Mapping)是一种为了解决面向对象与关系型数据库存在的互不匹配的现象的技术。
简单说:ORM是通过使用描述对象和数据库之间映射的元数据,将Java程序中的对象自动持久化到关系数据中。
本质上就是将数据从一种形式转换到另外一种形式。
原因:用它来架起对象和关系型数据库的桥梁,可解决对象层次的映射、对象关系的映射以及对象的持久化问题。
4、简述一下如何使用Hibernate实现对象持久化的过程(可画图或用伪码描述)STEP 1:创建Configuration对象。
在这一步中主要为了进行配置文件的装载操作,读取所有的配置文件并进行解析STEP 2: 创建SessionFactory对象。
通过创建好的Configuration对象可以创建一个sessionFactory对象的实例,同时是生成Session对象实例的工厂,他在整个应用中应该是唯一的。
STEP 3:创建Session对象。
Session对象类似于数据库的连接对象,可以理解为与数据库建立的一个连接,但是他的功能要比JDBC中的Connection对象丰富很多。
STEP 4:开始一个事务。
在Java中定义一个事务操作的开始,这是使用Hibernate进行持久化操作必不可少的步骤STEP 5:进行持久化操作。
在这个步骤中可以读取或者保存Java对象。
STEP 6:结束事务。
在操作完成之后还要进行显式的结束事务的操作。
1.1J2EE 框架第2阶段培训结课后的综合考试题(第1部分)试题答案1、选择题(每题1分,并且每题为单选,共10分)(1)假设在名称为helloapp的Web应用中有一个hello.jsp,它的文件路径如下:%CATALINA_HOME%/webapps/helloapp/hello/hello.jsp,那么在浏览器端访问hello.jsp 的URL是什么?(A) http://localhost:8080/hello.jsp(B) http://localhost:8080/helloapp/hello.jsp(C) http://localhost:8080/helloapp/hello/hello.jsp(D) http://localhost/helloapp/hello/hello.jsp(2)假设在helloapp应用中有一个HelloServlet类,它位于org.javathinker包下,那么这个类的class文件应该放在什么目录下?(A) helloapp/HelloServlet.class(B) helloapp/WEB-INF/HelloServlet.class(C) helloapp/WEB-INF/classes/HelloServlet.class(D) helloapp/WEB-INF/classes/org/javathinker/HelloServlet.class(3)假设在helloapp应用中有一个HelloServlet类,它在web.xml文件中的配置如下: <servlet><servlet-name> HelloServlet </servlet-name><servlet-class>org.javathinker.HelloServlet</servlet-class></servlet><servlet-mapping><servlet-name> HelloServlet </servlet-name><url-pattern>/hello</url-pattern></servlet-mapping>那么在浏览器端访问HelloServlet的URL是什么?(A) http://localhost:8080/HelloServlet(B) http://localhost:8080/helloapp/HelloServlet(C) http://localhost:8080/helloapp/org/javathinker/hello(D) http://localhost:8080/helloapp/hello(4)HttpServletRequest对象是由谁创建的?(A)由Servlet容器负责创建,对于每个HTTP请求, Servlet容器都会创建一个HttpServletRequest对象(B)由JavaWeb应用的Servlet或JSP组件负责创建,当Servlet或JSP组件响应HTTP 请求时,先创建HttpServletRequest对象(C)由JavaWeb应用程序负责创建,当Servlet或JSP组件响应HTTP请求时,先创建HttpServletRequest对象(D)由Servlet容器负责创建,只对第一个HTTP请求,Servlet容器才会创建出一个HttpServletRequest对象(5)欲从HTTP请求中获得用户的请求参数值,应该调用下面的哪个方法?(A)调用HttpServletRequest对象的getAttribute()方法(B)调用ServletContext对象的getAttribute()方法(C)调用HttpServletRequest对象的getParameter()方法(D)调用HttpServletRequest对象的getAttribute()方法(6)ServletContext对象是由谁创建的?(A)由Servlet容器负责创建,对于每个HTTP请求,Servlet容器都会创建一个ServletContext对象(B)由JavaWeb应用本身负责为自己创建一个ServletContext对象(C)由Servlet容器负责创建,对于每个JavaWeb应用,在启动时,Servlet容器都会创建一个ServletContext对象(D)由Servlet容器负责创建,只对第一个HTTP请求,Servlet容器才会创建一个ServletContext对象(7)jspForward1.jsp要把请求转发给jspForward2.jsp,应该在jspForward1.jsp中如何实现?(A) <a href="jspForward2.jsp">jspForward2.jsp </a>(B) <jsp:forward page="jspForward2.jsp" >(C) <a href="jspForward1.jsp">jspForward1.jsp </a>(D) <jsp:forward page="jspForward1.jsp" >(8)下面哪个说法是正确的?(A) 对于每个要求访问maillogin.jsp的HTTP请求,Servlet容器都会创建一个HttpSession对象(B)每个HttpSession对象都有唯一的ID。
J2EE简答题复习(含答案)1、forward和sendRedirect的区别forward是request的方法,sendRedirect是response的方法,使用forward延续之前的请求,地址栏地址不会转变,使用sendRedirect会开启新的请求,地址栏地址转换2、视图层调用了服务层好不好,该怎么办?不好,因为视图层和服务层之间还有控制层,不应该越级调用3、Service层的简介在内存中以对象的形式处理业务逻辑4、有人认为MVC模式对M的支持很弱,为什么?因为mvc模式的m中,只有对象的get、set和validate方法,只支持领域对象,广义上的m应该包括实体对象和服务对象5、普通的Action只有一个execute()方法,有何缺点,如何改进?只有一个execute()方法导致类的数目太多改进:把一个execute()方法变成多个方法,在url中加入某变量,在配置文件中设置参数,告知核心控制器调用哪个方法6、AOP能代替OOP吗?不能。
AOP侧重实现功能,而OOP侧重对象,AOP实现多种功能,并把这些功能植入各个对象,不能代替,应该两种结合起来使用7、何谓IOC控制反转,也叫DI,依赖注入,由容器为类注入某些对象,在配置文件中配置,类的实例要向容器申请。
8、Struts中自定义控制器的方法execute()的参数及解释public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {return mapping.findForward("error");}ActionMapping 作用就是帮助控制其将请求映射到操作ActionForm 作用就是接受和存储表单form中接受的数据(相当于bean)Request 请求Response 回复9、如何引入struts下载struts的jar包,在web.xml中以servlet的方式配置该类,来映射到某些类10、servletContext能否做购物车能,但是这种做法不提倡,servletContext相当于jsp中的application,会涵括整个项目的所有人的购物车信息,会使得结构复杂,对服务器而言,负担比较大1。
j2ee架构与程序设计学习通课后章节答案期末考试题库2023年1.请对Spring的通知类型进行简要说明参考答案:Spring中主要包含5种通知类型,分别是环绕通知,前置通知,后置通知,异常通知和返回通知。
其中,环绕通知表示在目标方法执行前后实施增强,可以应用于日志、事务管理等功能。
前置通知表示在目标方法执行前实施增强,可以应用于权限管理等功能。
后置通知表示在目标方法执行后实施增强,可以应用于关闭流、上传文件、删除临时文件等功能。
异常通知表示在方法抛出异常后实施增强,可以应用于处理异常记录日志等功能。
返回通知表示在目标类中添加一些新的方法和属性2.以下关于Spring AOP 的介绍错误的是。
()参考答案:虽然AOP是一种新的编程思想,采取横向抽取机制,是OOP的升级替代品3.关于AspectJ注解的介绍,说法错误的是。
()参考答案:@After用于定义后置通知,与@AfterReturning一样4.以下不是MyBatis核心对象的是()参考答案:SqlSessionFactoryWork5.mybatis框架的说法不正确有是()参考答案:mybatis框架不能访问数据库的存储过程6.正确的是()参考答案:以上都对7.请简述XML配置文件的根元素是中的常用元素及作用。
参考答案:1.id:id属性是元素的唯一标识符,Spring容器对Bean的配置和管理通过id属性完成,装配Bean时也需要根据id值获取对象。
:name属性可以为Bean指定多个名称,每个名称之间用逗号或分号隔开。
3.class:class属性可以指定Bean的具体实现类,其属性值为对象所属类的全路径。
4. scope:scope属性用于设定Bean实例的作用范围,其属性值有:singleton(单例)、prototype(原型)、request、session和globalsession。
8.请简述依赖注入的概念。
参考答案:依赖注入(Dependency Inject,缩写DI)就是由IoC容器在运行期间动态地将某种依赖资源注入对象之中。
j2ee开发习题和答案EJB,servletQ :1Which 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 interfaces.A Session bean can have no Local interface.When a client looks up for a stateful session bean in JNDI, same bean instance is returned every time.Q :2GivenBean1 --> Stateful session Bean's local interface of 'bean1' Bean2 --> Stateless Session Bean's local interface of 'bean2' and given:@EJB(beanName="bean1") Bean1 ref1;@EJB(beanName="bean1") Bean1 ref2;@EJB(beanName="bean2") Bean2 ref3;@EJB(beanName="bean2") Bean2 ref4;After injection has completed, what would be the output of the following code?System.out.println(ref1.equals(ref2));System.out.println(ref3.equals(ref4));Select Your Answer :A falsefalseB falsetrueC truefalseD 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.ejb.TimerObjectE 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 FooRemote,TimedObject{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 : @Stateless public class Foo implements FooRemote{@Resource TimerService timerService;@Timeoutpublic void maintenanceCall(){// maintenance appropriate Logic}public void ScheduleMaintenance(Integer carId, Date dayToBeScheduled){timerService.createTimer( dayToBeScheduled, carId.toString());}public void resceduleMaintenance(Integer carId, 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(Ibject obj:TimerService.getTimers()){Timer timer = (Timer) obj;if(timer.getInfo().equals(carId.toString()){timer = timerService.createTimer(rescheduleDate,carId.toString);}}B for(Ibject obj:TimerService.getTimers()){Timer timer = (Timer) obj;if(timer.getInfo().equals(carId.toString()){timer.cancel();timerService.createTimer(rescheduleDate,carId.toString);}}C for(Ibject obj:TimerService.getTimers()){Timer timer = (Timer) obj;if(timer.getInfo().equals(carId.toString())timer.reschedule(rescheduleDate);}Timer timer = timerService.getTimer(carId);timer.reschedule(rescheduleDate);Q :7Given a Timer scheduled as below:Calendar time = Calendar.getInstance();time.add(Calendar.DATE,15);Date initialExpiration = Timer timer =timerService.createTimer(time.getTime(),1000*60*60*24,"Ti mer1");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 Foo1@Statelesspublic class Foo implementsFooRemote{private Foo1 foo1;@Resource TimerService timerService;@PostConstructpublic void init(){ // block 1 }@PreDestorypublic void finish(){ // block 2 }// business methodpublic void doBusinessAction(){ // block3 }@EJBpublic setFoo1(Foo1 foo1){//Block 4this.foo1 = foo1;}}Which are the legal blocks to place following code:timerService.createTimer(expDate,"test Timer");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 modifier should be public)Q :11Which 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 have0 or more Local interfaces.C A session bean can have 0 or more remote interfaces.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?Select Your 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 :13In 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'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.Stateful session beans are lightweigh and fast as they are associated with single client and there is no overhead of object swapping.E.Stateless sesiion bean 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 interfaces 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.If a client invokes a method on bean's remote interface, given the client 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 :18I have a session bean which expose different methods on local and remote business interfaces as below.public interface myAppBaseInterface{public void keepMeReady();}@Remotepublic interface myAppRemote extends myAppBaseInterface{public ResultObj calculateForRemoteClients();}@Localpublic interface myAppLocal myAppBaseInterface{public void calculateForLocalClients(ResultObj obj);}Recently, during enhancing the project,in keepMeReady() method, I had to call another session bean's method passing current session bean's own object reference.How can I determine through which interface the client has made the call? Select Your Answer :/doc/ad13944721.html,ing getBusinessObjectInterfae method of SessionContext./doc/ad13944721.html,ing getBusinessInterface method of sessionContext/doc/ad13944721.html,ing getInvokedEJBObjectInterface method of SessionContext /doc/ad13944721.html,ing getInvokedBusinessInterface method of SessionContextE.Get the Business EJB object using getBusinessInterface() method and use instanceof operator to determine the interface.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 componentinterface 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.In the constructorB.Inthe setter method marked @ResourceC.In Method marked @PostConstructD.in Method marked @PreDestroyE.In Business methodF.All the aboveQ :22Which are the appropriate places for a stateful session bean to invoke getCallerPrincipal() methodof sessionContext?Select Your Answer :A.In the constructorB.In the setter method marked as @ResourceC.in Method marked @PostConstructD.in Business methodE.in the finalize methodQ :23If 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.RemoteExceptionB.NullPointerExceptionC.EJBExceptionD.java.rmi.NoSuchObjectExceptionE.javax.ejb.ObjectNotFoundExceptionQ :24What happens if a stateless session bean throws a System Exception (RuntimeException)?Select Your Answer :A.The bean instance will be killed.B.The bean instance is returned to the pool.C.There is no effect on the bean instanceQ :25Which of the following statements are true about stateless session bean creation?Select Your Answer :A.Stateless session beans are created when client tries to get reference using its remote or local interface.B.The PostConstruct method of a stateless session bean will be called only once during its life cycle.C.When 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 :26Identify correct syntax of defining a bean's PostConstruct method?Select Your Answer :A.MyBeanmyinitB.MyBeanmyinitC.MyBeanmyinitD.MyBeanmyinitE.None of the aboveQ :27In 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 interface method has to be marked as @WebMethodD.None of the above.Q :28In 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 method/doc/ad13944721.html,ing 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 newly constructed instance, after any dependency injection has been performed by the container and before the first business method is invoked on the bean.B.PostConstruct methods are invoked in an unspecified transaction and security context.C.PreDestroy methods execute after any method, annotated with the Remove annotation has completed.D.PreDestroy 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 SessionContext sessionContext;Socket cs;@EJB AnotherEJb myEjb;String description; java.sql.Connection conn;Select Your Answer :A.sessionContextB.csC. myEjbD.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 Your Answer :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.It depends upon the vendor implementation.E.None 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.If 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.If a client calls the method marked @Remove then on sessionbean then, 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 SessionSynchronization interface.D.None of the aboveQ :38Which of the following statements are true?Select Your Answer :A.When an extended persistence context is used inthe stateless session bean, the entities loaded will be active throughout bean's life.B.In the transaction scoped persistence context, theTransaction starts and ends within the scope of the method.C.If a bean has a definition as below:@PersistenceContext(unitName="test")then the persistence context is Extended.The stateful session bean can only use Extended persistence context.D.In the Extended persistence context, one need not required to call EntityManage.merge() call on entitiesQ :39Given 2 stateful session beans:Bean1and Bean2@Statefulpublic class Bean1 implements Bean1Remote,Bean1Local{@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.If Bean1 updates a db entity, Bean2's copy of the same entity will be discarded or detached.B. Its not legal to have EXTENDED context for same db by 2 session beans.C. In real when Bean1 gets instantiated and is in method-ready-state, both Bean1 and Bean2 instances share same persistence context.D.When Bean1 gets instantiated, a unique session will becreated for Bean2.E.If Bean1 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 InitialContext?Select Your Answer :A.This is the ejb bean's reference to get information from the container.B.How to get reference to InitialContext is vendor specific.C.InitialContext is used as particular 'node' on the JNDI virtual directory tree.D.InitialContext extends EJBContextE.InitialContext can be used to get reference to another Enterprise beanF.InitialContext can also be used to get deploy-time values for a bean, set by the deployerQ :41Which of the following events may cause a session bean to die?Select Your Answer :A.The client crashesB.The client calls method marked @RemoveC.The bean times outD.The bean throws System Exception1. What is wrong with the following code?( )public void doFilter(ServletRequest req, ServletResponse, res,FilterChain chain)throws ServletException, IOException { chain.doFilter(req, res);HttpServletRequest request = (HttpServletRequest)req;HttpSession session = request.getSession();if (session.getAttribute("login") == null) {session.setAttribute("login"”, new Login());}}a. The doFilter() method signature is incorrect; it should takeHttpServletRequest and HttpServletResponse.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 IllegalStateException.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("count");session.setAttribute("count", count++);b. HttpSession session = request.getSession();int count = (int) session.getAttribute("count");session.setAttribute("count", count++);c. HttpSession session = request.getSession();int count = ((Integer) session.getAttribute("count")).intValue();session.setAttribute("count", count++);d. HttpSession session = request.getSession();int count = ((Integer) session.getAttribute("count")).intValue();session.setAttribute("count", new Integer(count++));3. GivenBean1 --> Stateful session Bean's local interface of 'bean1' Bean2 --> Stateless Session Bean's local interface of 'bean2' and given:@EJB(beanName="bean1") Bean1 ref1;@EJB(beanName="bean1") Bean1 ref2;@EJB(beanName="bean2") Bean2 ref3;@EJB(beanName="bean2") Bean2 ref4;After injection has completed, what would be the output of the following code? ( ) System.out.println(ref1.equals(ref2));System.out.println(ref3.equals(ref4));A. falseB. falseC. t rueD. truefalse true false true4. Assume that the following servlet mapping is defined in the deployment descriptorof a web application: TestServlet Which of the following requests will not be serviced by TestServlet?()a. /hello.aspb. /gui/hello.aspc. /gui/hello.asp/bye.aspd. /gui/*.aspe. /gui/sales/hello.aspf./gui/asp。
1.什么事Servlet?什么是Servlet容器?它的主要作用是什么?答:1.Servlet 是一种在服务器上执行的 Java 技术组件。
2.Web 容器是一种运行时环境,管理 Web 应用程序的组件,如 Servlet、JSP Pages、筛选器和 Web 事件侦听器。
3. a.通信支持b.生命周期管理c.多线程支持d.声明性安全e.JSP 支持2.Web应用程序的部署描述文件名是什么?它是什么类型的文件?应该存放在什么目录中?答:1.war2.jar文件3.webapps3.什么是404错误?答:请求资源不存在服务器找不到指定的资源,请求的网页不存在。
4.什么是JSP页面?它与HTML页面有什么关系?答:在HTML中插入JAVA程序段和JSP标记.JSP页面是实现HTML页面嵌入代码和使用模板数据的一种技术。
HTML是JSP的基础,JSP在HTML中添加JAVA程序使原本静态网页变成动态网页.5.Servlet和JSP各适用什么场合?答:前者适合做逻辑处理,后者适合做页面呈现.6.简述Servlet的生命周期,生命周期方法有那几个?答:1.加载Servlet类2.创建Servlet实例3.调用init方法4.调用service方法5.调用destory方法Init service destory7.GET请求和POST请求有什么不同?答:前者:表单数据包含在HTTP请求的URL中,包含数据量较小后者:表单数据包含在HTTP请求的请求体中,包含数据量较大8.有哪几个作用域对象?如何在这些对象上设置获得属性?在什么作用域中对象可以被Servlet容器的所有的Web应用程序访问?答:requestsessioncontext设置: 对象.setAttribute(“key”,value)获取:对象.get Attribute(“key”)context9.JSP有哪些内置对象?分别有什么作用?答:10.试述JSP的工作方式。
《SQL Server2005数据库应用技术》习题参考答案习题 1一、选择题1.数据库是在计算机系统中按照一定的数据模型组织、存储和应用的()。
A. 命令的集合B. 数据的集合C. 程序的集合D. 文件的集合2.支持数据库的各种操作的软件系统是()。
A. 数据库系统B. 文件系统C. 操作系统D. 数据库管理系统3.()由计算机硬件、操作系统、数据库、数据库管理系统以及开发工具和各种人员(如数据库管理员、用户等)构成。
A. 数据库管理系统B. 文件系统C. 数据库系统D. 软件系统4.在现实世界中客观存在并能相互区别的事物称为()。
A. 实体B. 实体集C. 字段D. 记录5.在数据库设计的需求阶段中,业务流图一般采用()表示。
A. 程序结构图B. 数据流图C. 程序框架D. E-R图6.在数据库设计的()阶段中,用E-R图来描述信息结构。
A. 需求分析B. 概念结构设计C. 逻辑结构设计D. 物理结构设计二、思考题1、简述数据与信息之间的联系与区别。
2、简述数据库系统的设计流程。
3、社么是E-R图?E-R图由哪些要素构成?4、逻辑结构设计有哪些步骤?5、物理结构设计有哪些步骤?6、数据库的维护包括哪些工作?参考答案:一、选择题1-B 2-D 3-C 4-A 5-B 6-B二、思考题1、描述事物的符号称为数据,信息是就指对结果进行加工处理,并对人类社会实践和生产活动产生决策影响的数据。
数据是物理的,信息是观念性的,数据和信息密切相关,信息可以数据化,数据代表信息,两者既有联系又有区别。
2、数据库设计的流程包括六个阶段:需求分析、概念结构设计、逻辑结构设计、物理结构设计、数据库实施、数据库运行与维护。
3、E-R图是用来描述实体-联系的模型图。
E-R图的组成要素:表示实体的“矩形”、表示实体属性的“椭圆”、表示实体间联系的“菱形”。
4、逻辑结构设计步骤:(1)概念模型转化为关系模型。
(2)将关系模型转化为特定数据管理系统下的数据模型。
(3)数据模型进行优化(通常采用规范化理论),以提高数据库应用系统的性能。
5、物理结构设计步骤:(1)确定数据库的物理结构(存储结构、存储位置)。
(2)确定数据库的存取方法。
(3)对物理结构进行评价,评价的重点为时间和空间效率。
6、数据库的维护工作:对数据库的监测、分析和性能的改善;数据库转存和故障恢复;数据库的安全性、完整性控制;数据库的重组和重构造。
习题 2一、选择题1.SQL Server2005的操作中心是()。
A. Management StudioB. Enterprise ManagementC. Visual 2005D. 查询编辑器窗口2.注册至某服务器,表示该服务器()。
A. 已启动但未连接B. 已启动并且已连接C. 还未启动D. 还未连接3.对于大型企业而言,应该采用()版本的SQL Server2005。
A. 企业版B. 工作组版C. 开发者版D. 精简版二、思考题1、简述安装SQL Server2005所需的软硬件环境。
2、简述SQL Server2005各版本与操作系统之间的关系。
3、如何在SQL Server2005 Management Studio中增加一个数据库?4、如何创建一个查询,并保存脚本文件?参考答案:一、选择题1-A 2-B 3-A二、思考题软件环境:2、参考上表3、可利用“附加”数据库功能:(1)在【对象资源管理器】窗口中,右击【数据库】选项,弹出快捷菜单,选择【附加】选项,出现【附加数据库】对话框。
(2)单击【添加】按钮,出现【定位数据库文件】对话框。
从中选择要附加的数据库的主要数据文件,单击【确定】按钮,返回【附加数据库】对话框。
(3)单击【确定】按钮,即可把所选的数据库附加到当前SQL Server实例上4、(1)打开查询编辑器窗口。
在查询编辑器窗口中键入脚本,单击工具栏上的分析按钮,分析脚本语法,使其正确。
(2)按F5,或者单击工具栏上的执行按钮,执行脚本,或者也可以在菜单栏上的【查询】|【执行】。
(3)选择“文件”菜单中的【保存】命令,或单击工具栏的【保存】按钮,在打开的保存对话框转播中,选择存储位置,输入脚本文件名,单击“保存”即可保存脚本文件。
一、选择题1.一个数据库至少有()个文件。
A. 2B. 3C. 4D. 52.若要使用多个文件,为了便于管理,可以使用()。
A. 文件夹B. 文件组C. 复制数据库D. 数据库脱机3.在SQL Server中,用来显示数据库信息的系统存储过程是()。
A. sp_dbhelpB. sp_dbC. sp_helpD. sp_helpdb4.在SQL Server中,下列关于数据库的说法正确的是()。
A.一个数据库可以不包含事务日志文件B.一个数据库可以只包含一个事务日志文件和一个数据库文件C.一个数据库可以包含多个数据库文件,但只能包含一个事务日志文件D.一个数据库可以包含多个事务日志文件,但只能包含一个数据库文件二、思考题1、在SQL Server2005安装成功后,有哪些系统数据库?其用途分别是什么?2、数据库文件有哪些类型?其作用分别是什么?3、数据库如何扩容?有几种方法?3、SQL Server2005提供了哪两种创建数据库的方法?5、如何实现数据库的移植?有哪几种方法?参考答案:一、选择题1-A 2-B 3-D 4-B二、思考题1、系统数据库:master数据库:是SQL Server系统最重要的数据库。
记录SQL Server 系统的所有系统级信息。
model数据库:作为用户创建新数据库的模板。
msdb数据库:是代理服务器数据库。
它为报警、任务调度和记录操作员的操作提供存储空间。
tempdb数据库:记录了所有的临时表、临时数据和临时创建的存储过程等保存临时对象的一个工作空间。2、数据库文件类型:(1)主要数据文件:包含数据库的启动信息,并指向数据库中的其他文件。
主要数据文件的文件扩展名是.mdf。
(2)次要数据文件:是可选的,由用户定义并存储用户数据。
次要数据文件的文件扩展名是.ndf。
(3)事务日志文件:用于记录所有事务以及每个事务对数据库所做的修改。
3、可用通过修改现有数据库中数据文件的容量,或者增加数据文件扩容数据库。
有两种方法:一种是用Management Studio修改数据库属性修改数据文件的容量。
另一种是利用Alter Database语句修改数据库扩容。
4、可以利用“分离/附加”数据库,或利用“脱机”数据库移植数据库。
方法一:在Management Studio中,分离数据库——(复制)移植数据库文件——附加数据库方法二:在Management Studio中,设置数据库为“脱机”状态——(复制)移植数据库文件——附加数据库一、选择题1.在Transact-SQL语句中,删除表中数据的命令是()。
A.DELETE B.DROP C.CLEAR D.REMOVE2.在SQL Server2005中,更新表中数据的命令是()。
A.USE B.SELECT C.UPDATE D.DROP3.以下关于外键和相应的主键之间的关系的说法中,正确的是()。
A.外键不一定要与相应的主键同名B.外键一定要与相应的主键同名C.外键一定要与相应的主键同名而且唯一D.外键一定要与相应的主键同名,但并一定唯一4.在Transact-SQL语句中,修改表结构时应使用的命令是()。
A.UPDATE B.INSERT C.ALTER D.MODIFY5.要限制输入到列中的值范围,应使用()约束。
A.CHECK B.PRIMARY KEY C.FOREIGN KEY D.UNIQUE二、思考题1.什么是数据的完整性?数据完整性有哪些分类?2.数据约束有哪几种?分别实现何种数据完整性?3.默认值对象和默认约束有何区别?4.规则是什么?规则的作用是什么?5.什么是NULL值?它与0有何区别?6.如何删除默认值对象?参考答案:一、选择题1-A 2-C 3-A 4-C 5-A二、思考题1.数据的完整性是指数据的精确性和可靠性,主要用于保证数据库中数据的质量。
它是为防止数据库中存在不符合语义规定的数据和防止因错误信息的输入/输出造成无效操作或报错而提出的。
2.3.默认值对象是一种数据库对象,在数据库中创建默认值对象后,可以将其绑定到多个数据表的一个或多个列的应用;默认值约束只能用于约束一个表中的列。
4.规则(Rule)就是对存储在表中列或用户自定义数据类型的取值范围的规定或限制。
作用:规则类似于CHECK约束,是用来限制数据字段的输入值的范围,实现强制数据的域完整性。
5.NULL是一个特殊值,表示没有值或值不确定。
实际上,空字符和0都不是NULL,空字符是一个有效的字符,0是一个有效的数字。
6.第一步:解绑默认值:对于不需要再利用默认的列,可以利用系统存储过程对其解绑。
其语法格式如下:[EXECUTE] sp_unbindefault '表名.字段名'|'自定义数据类型名'第二步:在查询分析器中使用DROP语句删除默认值。
其语法格式如下:DROP DEFAULT default_name[,…n]习题 5一、选择题1.在Transact-SQL语句中,条件“年龄BETWEEN 15 AND 35”表示年龄在15岁至35岁之间,且()。
A.包括15岁和35岁B.不包括15岁和35岁C.包括15岁但不包括35岁D.包括35岁但不包括15岁2.下列聚合函数中正确的是()。
A.SUM(*) B.MAX(*) C.COUNT(*) D.A VG(*)3.查询员工工资信息时,结果按工资降序排列,下列语句中正确的是()。
A.ORDER BY 工资B.ORDER BY 工资DESCC.ORDER BY 工资ASC D.ORDER BY 工资DISTINCT4.在SQL Server2005中,下列关于通配符的操作中,范围最大的是()。
A.sname LIKE …abc#‟B.sname LIKE …abc_d%‟ C.sname LIKE …abc%‟D.sname LIKE …%abc%‟5.“SELECT 工号FROM 员工表WHERE 工资>1250”的功能是()A.查询工资大于1250元的记录B.查询1250号记录后的记录C.检索所有的职工号D.从“职工”关系中检索工资大于1250元的职工号二、思考题:1.在SELECT语句中可以存在哪几个子句?他们的作用分别是什么?2.在表与表之间可以使用哪几种连接方式?它们各自有何特点?3.LIKE匹配字符有哪几个?4.有几种连接表的方法?它们之间有什么区别?5.GROUP BY子句的作用是什么?HA VING子句和WHERE子句中的条件有什么不同?6.嵌套查询与相关子查询有何区别?参考答案:一、选择题1A 2-C 3-B 4-D 5-D二、思考题1.SELECT语句中可以存在以下子句(1)SELECT子句:指定查询返回的列。