华为面试题详解

华为面试题详解(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     static boolean foo(char c)
05     {
06         System.out.println(c);
07         return true;
08     }
09     
10     public static 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? (Choose two)
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       public void method()
08       {
09               new Inner();
10       }
11        
12       public class Inner{
13       }
14       public static void main(String[] args)
15       {
16               Outer o = new Outer();
17               Inner i = o.new Inner();
18       }
19        
20       static void 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 URL that 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 HttpServletResponse interface.

此题选B.

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

Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from the encodeURL method. 
All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with 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 a session bean are correct? 
1. java.lang.IllegalStateException is thrown if SessionContext.getEJBObject() is invoked when a stateful session bean instance is passivated. 
2. SessionContext.getRollbackOnly() does not throw an exception when a session bean with bean-managed transaction demarcation is activated. 
3. An exception is not thrown when SessionContext.getUserTransaction() is called in the afterBegin method of a bean with container-managed transactions. 
4. JNDI access to java:comp/env is permitted in all the SessionSynchronization methods of a stateful session bean with container-managed transaction demarcation. 
5. Accessing resource managers in the SessionSynchronization.afterBegin method of a stateful session bean with bean-managed transaction does not throw an exception.


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

在Struts的体系结构中,模型分为两个部分:系统的内部状态和可以改变状态的操作(事务逻辑)。内部状态通常由一组Actinform Bean表示。根据设计或应用程序复杂度的不同,这些Bean可以是自包含的并具有持续的状态,或只在需要时才获得数据(从某个数据库)。大型应用程序通常在方法内部封装事务逻辑(操作),这些方法可以被拥有状态信息的bean调用。比如购物车bean,它拥有用户购买商品的信息,可能还有checkOut()方法用来检查用户的信用卡,并向仓库发定货信息。小型程序中,操作可能会被内嵌在Action类,它是struts框架中控制器角色的一部分。当逻辑简单时这个方法很适合。建议用户将事务逻辑(要做什么)与Action类所扮演的角色(决定做什么)分开。  
  
2)视图(View)    
视图主要由JSP建立,struts包含扩展自定义标签库(TagLib),可以简化创建完全国际化用户界面的过程。目前的标签库包括:Bean Tags、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 for XML)。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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huangleijay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值