`
datoplay
  • 浏览: 1614300 次
文章分类
社区版块
存档分类
最新评论

华为的JAVA面试题

 
阅读更多

为的JAVA面试题

(后记:没有想到华为的面试题就是非同一般,很多题不是一眼就能够看得出来,至少对我这种鸟来说是这样。对我个人来说,看看这样的题,可能比看《Think In Java》都还要好,因为这里面有很多的东西,都是我们平时没有太在意,或者是只是懂一点皮毛而已,通过做一下这样的练习,把自己不知道、不熟悉的知识点,利用这个机会好好的巩固一下。这些答案是我自己做的,有一些是从网上来的,有一部是自己做的,并且还有一部份没有做完,我不敢保证都对,所以请你在引用的时候,务必通过自己核对一下。当然,我既然能够把这些答案放在这里,那说明我肯定是自己检验了一遍的,也不是那么恐怖的)

QUESTION NO: 1

publicclassTest1 {

publicstaticvoidchangeStr(String str){

str="welcome";

}

publicstaticvoidmain(String[] args) {

String str="1234";

changeStr(str);

System.out.println(str);

}

}

//输出结果:1234

//这里虽然是一个静态方法,但是里面的变量是一个局部变量,

//所以这里不因为是静态方法,就误认为里面的变量也是静态变量了

QUESTION NO:2

publicclassTest2 {

staticbooleanfoo(charc) {

System.out.print(c);

returntrue;

}

publicstaticvoidmain(String[] argv) {

inti = 0;

//for(65;88&&(i<2);67)

for(foo('A');foo('B') && (i < 2);foo('C')) {

i++;

foo('D');

}

}

}

/*

What is the result?

A. ABDCBDCB

B. ABCDABCD

C. Compilation fails.

D. An exception is thrown at runtime.

//输出结果是:ABDCBDCB

分析:FOR循环里面讲究的条件要为真,与你的判断式是什么没有关系

就像这里,虽然是打印的字母,但是却不是false,所以可以执行

第一次进行循环:

foo('A')打印字母A,(注:这里不是false条件就默认为true条件)

foo('B')打印字母B,i=0,比较(i < 2),条件为true,进行循环体,foo('D')打印D

foo('C')打印字母C

第二次循环:

foo('B')打印B,i=1,比较(i < 2)为true,进行循环体,foo('D')打印D

foo('C')打印字母C

第三次循环:

foo('B')打印字母B,i=2,比较(i < 2)为false,退出循环,得结果

*/

QUESTION NO: 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; }

publicclassBextendsA{

/**

*@paramargs

*/

//can not reduce the visibility of the inherited method from A

//即不能够使从类A中继续来的方法的可见性降低

//private int method1(int a, int b) { return 0; }

//This static method cannot hide the instance method from A

//静态方法不能够隐藏继承于A的实例

//static protected int method1(int a, int b) { return 0; }

//返回类型与A中的该方法不一致

//public short method1(int a, int b) { return 0; }

/**

*总结:类的继承中,如果要想重载父类的方法,必须要和父类中的返回类型、可见性等等都要操作一致

*否则,程序就会报错。一定遵守子类要遵从于父类的原则

*而我选择的答案居然是privateintmethod1和staticprotectedint

*我选择第一个的错误理由是:因为原来为保护的,如果我这里设为public,那么就扩展了其原来的可见性

*本来原来就是对包外不可见的,现在变成对包外可见的了,所以就选择的是private

*选择第二个的错误理由是:都是保护的,这里只是变成了静态的而已

*/

//这里是写了一个重载方法,因为参数类型不一致,不会报错

privateintmethod1(inta,longb) {return0; }

//可见性可以增大,但是不能够缩小,正确

publicintmethod1(inta,intb) {return0; }

publicstaticvoidmain(String[] args) {

//TODOAuto-generated method stub

}

}

QUESTION NO: 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()

答案如下:

publicclassOuter {

publicvoidsomeOuterMethod() {

// Line 3

newInner();//放在这里不出错

}

publicclassInner {

}

publicstaticvoidmain(String[] argv) {

Outer o=newOuter();

// Line 8

//o不能够被解释成为一种类型,出错

//new o.Inner();

/**

*下面两种用法,都报下面的错误:

*NoenclosinginstanceoftypeOuterisaccessible.

*Mustqualifytheallocationwithanenclosinginstance

*oftypeOuter(e.g.x.newA()wherexisaninstanceofOuter)

*/

//new Outer.Inner();

//new Inner();

}

}

QUESTION NO: 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.

QUESTION NO: 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"/>

QUESTION NO: 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 是MVC的一种实现,它将 Servlet和 JSP 标记(属于 J2EE 规范)用作实现的一部分。Struts继承了MVC的各项特性,并根据J2EE的特点,做了相应的变化与扩展。Struts的体系结构与工作原理如下图2所示:

 

  1)模型(Model)  

  在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

4、SQL问答题

SELECT * FROM TABLE

SELECT * FROM TABLE

WHERE NAME LIKE '%%' AND ADDR LIKE '%%'

AND (1_ADDR LIKE '%%' OR 2_ADDR LIKE '%%'

OR 3_ADDR LIKE '%%' OR 4_ADDR LIKE '%%' )

的检索结果为何不同?

答:

我做了一下测试,在ACCESS里面,用它的查询,这样会和在MYSQL得到不同的结果,各位不妨试试,我昨天就是在ACCESS里用SQL查询,得到的结果为空,就是没有记录;而在MYSQL里面,条件为空的记录不显示,其它的都显示。

5、SQL问答题

表结构:

1、表名:g_cardapply

字段(字段名/类型/长度):

g_applyno varchar 8;//申请单号(关键字)

g_applydate bigint 8;//申请日期

g_state varchar 2;//申请状态

2、表名:g_cardapplydetail

字段(字段名/类型/长度):

g_applyno varchar 8;//申请单号(关键字)

g_name varchar 30;//申请人姓名

g_idcard varchar 18;//申请人身份证号

g_state varchar 2;//申请状态

其中,两个表的关联字段为申请单号。

题目:

1、查询身份证号码为440401430103082的申请日期

Select g_cardapply.g_ applydate from g_cardapply, g_cardapplydetail where g_cardapplydetail.g_idcard=’’ and g_cardapply.g_applyno=g_cardapplydetail.g_applyno

2、查询同一个身份证号码有两条以上记录的身份证号码及记录个数

3、将身份证号码为440401430103082的记录在两个表中的申请状态均改为07

Update g_cardapply. g_state=’07’, g_cardapplydetail .g_state

4、删除g_cardapplydetail表中所有姓李的记录

------------------------******测试******-----------------

create database mianshi

use mianshi;

create table g_cardapply(

g_applyno varchar(8),

g_applydate bigint,

g_state varchar(20)

)

go

create table g_cardapplydetail(

g_applyno varchar(8),

g_name varchar(30),

g_idcard varchar(18),

g_state varchar(20)

)

1、select a1.g_applydate from g_cardapply as a1 inner join g_cardapplydetail a2 on

a1.g_applyno=a2.g_applyno where a2.g_idcard="123" ;

2、select g_idcard,count(g_idcard) from g_cardapplydetail

group by g_idcard having count(g_idcard)>=2;

3、update g_cardapply set g_state=603 from g_cardapply as g_d inner join g_cardapplydetail as g_c on

g_d.g_applyno=g_c.g_applyno and g_idcard='123';更新第一个表的g_state

update g_cardapplydetail set g_state=603 where g_idcard='123';

/**
* JAVA访问Access数据库
* 因为没有像访问其它数据库的驱动程序
* 所以只能够通过ODBC的形式访问
* 示例表:create table user(id int,name char(50),age int),id为自增型
*/
import java.sql.*;
public class Access_Conn {

public Connection getConn() {
//test为配置的数据源名
String url = "jdbc:odbc:test";
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url, "", "");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public static void main(String[] arg)
{
Access_Conn con=new Access_Conn();
Connection conn=con.getConn();
try {
Statement st=conn.createStatement();
st.execute("insert into user(name,age) values('test',20)");
ResultSet rs=st.executeQuery("select * from user");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try {
if(conn!=null)
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}

每新建一个类上面都会有一行注释:

/**
* @author 马海宝 E-mail:rigger21@126.com
* @version 创建时间:2007-8-30 下午04:58:52
* 类说明
*/

感觉这个应该很好,多个人一起开发的时候能够看见谁是谁的, 我就想这个怎么弄的,上网一找还真有,但是自己配置就是错误的, 找了半天都是这样的,我晕了。 怎么回事情,难道真是大家说的人品的事情吗? 我就不信这个邪了。我必须弄出来,我上网大量的搜索,但是还是那样,只能自己改了。试了好半天,最终上天终于不负我这有心人,我终于修改成功了,操作步骤和大家分享一下:

window->preference->java->code styple->code template 当你选择到这部的时候就会看见右侧有一个框显示出code这个选项,你点开这个选项,点一下他下面的New Java files 然后你点edit按钮,把他的内容换成你的就可以了:(例如)

${filecomment}
${package_declaration}
/**
* @author 陈红华 E-mail:cenghonho@126.com
* @version 创建时间:${date} ${time}
* 类说明
*/
${typecomment}
${type_declaration}

最后点apply ----> OK 成功。。

另外补充说明一点,在点了edit弹出来的编辑窗口的左下脚有一个“Insert Variable”按钮,点击那里就会显示当前模板中可以引用变量,就不会像我一样到处找变量的定义了。

Eclipse插件集中营

分类:Eclipse2007-01-23 22:255722人阅读评论(0)收藏举报

http://www.tusc.com.au/tutorial/html/index.html
利用Eclipse,LOMBOZ plugins,JBoss开发J2EE教学的文章(En)很精彩

1.? lomboz.301.zip 与emf-sdo-runtime-2.0.0.zip(著名的开发J2ee的插件)

下载网址:http://forge.objectweb.org/project/showfiles.php?group_id=97?  

http://www.objectlearn.com/

Lomboz 可以做很多事情,是使用 Eclipse+JBoss 做 J2EE 的首选。

2.MyEclipse,最好的J2EE开发框架

下载Myeclipse userId: ylfly? password: *******
http://www.myeclipseide.com/ContentExpress-display-ceid-47.html
MyEclipse的注册码:
for eclispe3.0版的:
IceCraft
VAR7ZL-819-56-54678656108018950
for eclispe2.1版的:
IceCraft
VAR7ZL-719-56-54678657538454123

3.Log4j或者Apache commons Logger最得力的助手就是 Log4e:
??? 官方网站:http://log4e.jayefem.de/
??? 下载连接:http://log4e.jayefem.de/download/de.jayefem.log4e_0.5.5.zip

4. Easy Struts支持Struts的插件 (0.64版只支持Eclipse2.X)
是开放源代码组织sourceforge.net上的一个项目,目前最新的版本是0.64,

http://sourceforge.net/project/showfiles.php?group_id=54542&package_id=49230

http://easystruts.sourceforge.net/

5. TomcatPlugin 支持Tomcat插件
http://www.sysdeo.com/eclipse/tomcatPlugin.html


6.Hibernate Synchronizer
Hibernate Synchronizer is a free Eclipse plugin code generation tool to be used with the Hibernate persistence framework. The plugin will automatically generate java code when your hibernate mapping files are modified. Objects are created with generated code in an abstract base class and a user-modifiable extension class so user code does not get deleted when the generation is performed.
http://www.binamics.com/hibernatesync/
https://sourceforge.net/project/showfiles.php?group_id=99370
HibernateSynchronizer-2.1.25-Eclipse3M6.zip?? 只支持到M7

7. SWT Designer 使GUI更cool,更in,更happy!
http://www.swt-designer.com/?? 14天

8. XML Editor & XSLT Debugger 编辑XML的插件
http://www.oxygenxml.com/

8.1支持Eclipse 3.0 的XML插件
http://www.xmlbuddy.com/

8.2XML Viewer
Version: 1.1.7
http://tabaquismo.freehosting.net/ignacio/eclipse/xmlview/index.html


9.UML Tool for Eclipse
http://www.visual-paradigm.com/download.php?shortName=sdeec

9.1 UML插件 Omondo的(支持eclipse 3.0 的studio 1.0 只试用20天)
http://www.omondo.com/
useId :ylfly password:*******

9.2EclipseUML2? is Eclipse tools

http://www.eclipse.org/uml2/

10.Eclipse加速插件KeepResident

http://suif.stanford.edu/pub/keepresident/

原理:利用两个 Windows API - SetProcessWorkingSetSize 与 VirtualLock (适用于 Windows 平台)。

切换时果然快很多。

官方建议最小值设定在 100 MB,最大值 250 MB 左右。

11.RMI Plugin for Eclipse 1.6.0 for Eclipse 3.0
http://www.genady.net/rmi

12其它插件

perl插件http://e-p-i-c.sf.net/updates
C#插件?http://www.improve-technologies.com/alpha/updates/site.xml
C插件???http://update.eclipse.org/tools/cdt/releases/new
Hex插件http://ehep.sourceforge.net/update

13.Eclipse插件使用links目录的用法:
 假设把插件安装在d:/myplugin目录中,则myplugin的目录结构一定要是这样的:
  d:/myplugin/eclipse/plugins/插件 及 d:/myplugin/eclipse/features/插件
  例如安装EclipseME插件到d:/myplugin目录中,则目录结构

d:/myplugin/eclipse/plugins/eclipseme_0.4.5。
  再假设eclipse安装在d:/eclipse目录中,则在eclipse目录中创建名称为links的目录,在links目

录中建立一个link文件,比如myplugin.link,该文件内容为path=d:/myplugin。
  启动eclipse,插件即安装上了,如果想暂时不启动插件,只需把myplugin.link文件删除即可。
补充说明:
 1. 插件可以分别安装在多个自定义的目录中。
 2. 一个自定义目录可以安装多个插件。
 3. link文件的文件名及扩展名可以取任意名称,比如myplugin.txt,goodplugin都可以。
 4. link文件可以有多行path=插件目录,对应多个自定义插件目录,每一行的path参数都将生效。
 5. 在links目录也可以有多个link文件,每个link文件中的path参数都将生效。
 6. 插件目录可以使用相对路径,如果我们把myplugin目录创建在eclipse安装目录中,如上例中的

d:/eclipse目录中,则只需设置path=myplugin即可。

14.Eclipse tools

1).ALL SDK bundle (includes Source, Runtime and Docs for EMF, XSD, and SDO).
?
2).The Graphical Editing Framework (GEF) allows developers to take an existing application

model and quickly create a rich graphical editor.

3).UML2 is an EMF-based implementation of the UML 2.0 metamodel for the Eclipse platform.

http://www.eclipse.org/emf/
http://www.eclipse.org/gef/
http://www.eclipse.org/uml2/

15.plug-in网址:

http://www.eclipse-plugins.info/eclipse/index.jsp

http://www.eclipse-workbench.com/jsp/

http://eclipse-plugins.2y.net/eclipse/index.jsp(非常非常著名的插件更新网站)

http://www.crionics.com/products/opensource/eclipse/eclipse.jsp(分类清楚)

http://www.eclipseplugincentral.com/

16.调试JSP时,在tomcat里改/conf/server.xml

??????? docbase="C:/eclipse/workspace/MyJ2EEProject/myweb"

????????? workDir="C:/eclipse/workspace/MyJ2EEProject/j2src" />

docBase="D:/workspace/myJSP/test"
path="/test" reloadable="true" workDir="D:/workspace/myJSP/j2src"/>

j2src不要改动

17.CVS---并发版本系统(中文手册)v1.12.9
http://cvsdoc-zh.gro.clinux.org/cvsdoc/zh_CN/html/index.html
http://cvsdoc-zh.gro.clinux.org
另一个CVS手册:
http://www.chedong.com/tech/cvs_card.html

18.Preferences无法显示新安装的插件的解决办法

删除C:/eclipse/configuration/org.eclipse.update下的platform.xml文件,重新启动Eclipse


19.评价

当前世界上最新最实用的IDE环境Eclipse。加上分析设计工具eclipseUML、MVC构架的Struts、

对象数据绑定构架OJB,Web系统的自动单元测试工具JUnit和HttpUnit,还有最普及的数据库MySQL,最

流行的版本管理服务器CVS,和支持Java/JSP/servlet的最佳Web引擎tomcat ,jboss。

20.Eclipse的许可证是怎样的?
现在Eclipse相关的许可证是大多数基于Common Public License (CPL),CPL是一个为Open Source

Initiative (OSI)所认可的许可证。由于Eclipse Foundation的建立,Eclipse的许可证将逐渐趋向于使

用Eclipse Public License (EPL),EPL是一个与CPL相类似的许可证,正在进行OSI的认证工作。此外,

Eclipse还涉及到多个开源项目和各类许可证,主要有 Apache Software License、IBM Public License

、Metro Link Public License和Mozilla Public License。个人无需太关心许可证的问题,企业在使用

Eclipse进行开发之前,最好请法律界人士研究一下。

各许可证的网址是:

http://www.eclipse.org/legal/cpl-v10.html

http://www.eclipse.org/legal/epl-v10.html

http://www.apache.org/licenses/LICENSE

http://oss.software.ibm.com/developerworks/opensource/license10.html

http://www.opengroup.org/openmotif/supporters/metrolink/license.html

http://www.mozilla.org/MPL/MPL-1.1.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics