华为面试题详解

来源:互联网 发布:淘宝开店怎么装修店铺 编辑:程序博客网 时间:2024/05/19 17:09

华为面试题详解(1-5)

1.
01 public class Test {
02 public static void changeStr(String str){
03 str="welcome";
04 }
05 public static void main(String[] args) {
06 String str="1234";
07 changeStr(str);
08 System.out.println(str);
09 }
10 }

此题结果为:1234;
比较简单分析下内存就行了.

2.
01 public class ForTest
02 {
03    
04     staticboolean foo(char c)
05     {
06       System.out.println(c);
07       return true;
08     }
09    
10     publicstatic void main(String[] args)
11     {
12       int i = 0;
13       for(foo('A');foo('B')&&(i<2);foo('C'))
14       {
15           i ++;
16           foo('D');
17       }
18     }
19 
20 }

此题结果为:ABDCBDCB

这道题考查的for循环的执行顺序.
for(int i = 0; i < 10; i ++)
{}
首先先执行int i = 0;注意这个只是初始化一次,
就是在第一次的时候.接着执行i < 10;
然后执行方法体{}里面的内容,最后才执行i++;

第二次及以后就直接执行i <10;然后方法体;最后
i ++;如此顺序直到结束为止.

3.
1. class A {
2. protected int method1(int a, int b) { return 0; }
3. }

Which two are valid in a class that extends class A? (Choosetwo)
A. public int method1(int a, int b) { return 0; }
B. private int method1(int a, int b) { return 0; }
C. private int method1(int a, long b) { return 0; }
D. public short method1(int a, int b) { return 0; }
E. static protected int method1(int a, int b) { return 0; }

此题考查的是继承重写问题.
当一个子类重写父类的方法时,重写的方法的访问权限
必须大于等于父类的访问权限.
在此题中父类中的方法访问权限为protected,子类只能是
protected或public.这时A是符合题意的.
由于选项C的形参和父类的不一样,没有重写的效果,所以
在子类出现也是没问题的.
所以此题选:AC

4.
1. public class Outer{
2. public void someOuterMethod() {
3. // Line 3
4. }
5. public class Inner{}
6. public static void main( String[]argv ) {
7. Outer o = new Outer();
8. // Line 8
9. }
10. }

Which instantiates an instance of Inner?
A. new Inner(); // At line 3
B. new Inner(); // At line 8
C. new o.Inner(); // At line 8
D. new Outer.Inner(); // At line 8//new Outer().new Inner()

此题选A.

内部类的实例化可以在普通方法里也可以在
static方法里实例化.
如下:

01 package com.test.a;
02 
03 public class Outer
04 {
05     Inner i =new Outer.Inner();
06    
07     publicvoid method()
08     {
09       new Inner();
10     }
11    
12     publicclass Inner{
13     }
14     publicstatic void main(String[] args)
15     {
16       Outer o = new Outer();
17       Inner i = o.new Inner();
18     }
19    
20     staticvoid a()
21     {
22       Outer o = new Outer();
23       Inner i = o.new Inner();
24     }
25 
26 }

5.
Which method is used by a servlet to place its session ID in a URLthat is written to the servlet’s response output stream?

(译:那个方法是servlet用于将其session ID入在一个URL中,该URL写入servlet的响应输出流)

A. The encodeURL method of the HttpServletRequest interface.

B. The encodeURL method of the HttpServletResponse interface.

C. The rewriteURL method of the HttpServletRequest interface.

D. The rewriteURL method of the HttpServletResponseinterface.

此题选B.

请看J2EE API关于此方法的说明:

Encodes the specified URL for use in the sendRedirect method or, ifencoding is not needed, returns the URL unchanged. Theimplementation of this method includes the logic to determinewhether the session ID needs to be encoded in the URL. Because therules for making this determination can differ from those used todecide whether to encode a normal link, this method is separatedfrom the encodeURL method. 
All URLs sent to the HttpServletResponse.sendRedirect method shouldbe run through this method. Otherwise, URL rewriting cannot be usedwith browsers which do not support cookies.


 

 

6.
Which two are equivalent? (Choose two)
A. <%= YoshiBean.size%>
B. <%= YoshiBean.getSize()%>
C. <%=YoshiBean.getProperty("size")%>
D. <jsp:getProperty id="YoshiBean"param="size"/>
E. <jsp:getProperty name="YoshiBean"param="size"/>
F. <jsp:getProperty id="YoshiBean"property="size"/>
G. <jsp:getProperty name="YoshiBean"property="size"/>此题考查的是JavaBean在jsp中的取值方式.
其中C和G效果是一样的.
所以此题选G.

7.
Which of the following statements regarding the lifecycle of asession bean are correct? 
1. java.lang.IllegalStateException is thrown ifSessionContext.getEJBObject() is invoked when a stateful sessionbean instance is passivated. 
2. SessionContext.getRollbackOnly() does not throw an exceptionwhen a session bean with bean-managed transaction demarcation isactivated. 
3. An exception is not thrown whenSessionContext.getUserTransaction() is called in the afterBeginmethod of a bean with container-managedtransactions. 
4. JNDI access to java:comp/env is permitted in all theSessionSynchronization methods of a stateful session bean withcontainer-managed transaction demarcation. 
5. Accessing resource managers in theSessionSynchronization.afterBegin method of a stateful session beanwith bean-managed transaction does not throw an exception.


第二部分:
概念题
1.              描述Struts体系结构?对应各个部分的开发工作主要包括哪些?

在Struts的体系结构中,模型分为两个部分:系统的内部状态和可以改变状态的操作(事务逻辑)。内部状态通常由一组ActinformBean表示。根据设计或应用程序复杂度的不同,这些Bean可以是自包含的并具有持续的状态,或只在需要时才获得数据(从某个数据库)。大型应用程序通常在方法内部封装事务逻辑(操作),这些方法可以被拥有状态信息的bean调用。比如购物车bean,它拥有用户购买商品的信息,可能还有checkOut()方法用来检查用户的信用卡,并向仓库发定货信息。小型程序中,操作可能会被内嵌在Action类,它是struts框架中控制器角色的一部分。当逻辑简单时这个方法很适合。建议用户将事务逻辑(要做什么)与Action类所扮演的角色(决定做什么)分开。  
  
2)视图(View)    
视图主要由JSP建立,struts包含扩展自定义标签库(TagLib),可以简化创建完全国际化用户界面的过程。目前的标签库包括:BeanTags、HTML tags、Logic Tags、Nested Tags 以及Template Tags等。  
  
3)控制器(Controller)    
在struts中,基本的控制器组件是ActionServlet类中的实例servelt,实际使用的servlet在配置文件中由一组映射(由ActionMapping类进行描述)进行定义。对于业务逻辑的操作则主要由Action、ActionMapping、ActionForward这几个组件协调完成的,其中Action扮演了真正的业务逻辑的实现者,ActionMapping与ActionForward则指定了不同业务逻辑或流程的运行方向。struts-config.xml文件配置控制器。

2.   XML包括哪些解释技术,区别是什么?

包括:DOM(Document Object Modal)文档对象模型,SAX(Simple API forXML)。DOM是一次性将整个文档读入内存操作,如果是文档比较小,读入内存,可以极大提高操作的速度,但如果文档比较大,那么这个就吃力了。所以此时SAX应用而生,它不是一次性的将整个文档读入内存,这对于处理大型文档就比较就力了

3.   JSP有哪些内置对象和动作?它们的作用分别是什么?

JSP共有以下9种基本内置组件:
request 用户端请求,此请求会包含来自GET/POST请求的参数
response 网页传回用户端的回应 
pageContext 网页的属性是在这里管理 
session 与请求有关的会话期 
application servlet 正在执行的内容
out 用来传送回应的输出
config servlet的构架部件
page JSP网页本身 
exception 针对错误网页,未捕捉的例外 
常用的组件:request、response、out、session、application、exception

原创粉丝点击