阿里巴巴面试题

已知如下类定义:

class Base {

public Base (){ //... }

public Base ( int m ){ //... }

protected void fun( int n ){ //... }

}

public class Child extends Base{

// member methods

}

如下哪句可以正确地加入子类中?

1. private?void?fun(?int?n?){?//...}

2. void fun ( int n ){ //... }

3. protected void fun ( int n ) { //... }

4. public void fun ( int n ) { //... }

Question 47. (单选)

It is an important feature of the Java language that it always provides a default constructor to a class.

1. FALSE

2. TRUE

Question 48. (单选)

A class contained in a Java program file must have the same name as the file, except for the extension

1. FALSE

2. TRUE

Question 49. (单选)

Each method in a class must have a unique name.

1. FALSE

2. TRUE

Question 50. (单选)

When an instance of a class, or object, is specified as a parameter to a method, a reference to the said object is passed to the method.

1. FALSE

2. TRUE

Question 51. (单选)

All interface methods must be declared as public when implemented in a class.

1. FALSE

2. TRUE

Question 52. (单选)

Which of the following expressions will produce errors upon compilation?

(A) boolean a = (boolean) 1;

(B) boolean b = (false && true);

(C) float y = 22.3; (D) int x = (25 | 125)

1. (A) & (C)

2. (A)

3. (A), (C) & (D)

4. (A), (B) & (D)

Which lines of the following will produce an error?

1. byte a1 = 2, a2 = 4, a3;

2. short s = 16;

3. a2 = s;

4. a3 = a1 * a2;

1. Line 3 and Line 4

2. Line 1 only

3. Line 3 only

4. Line 4 only

5. Line 1 and Line 4

Question 54. (单选)

Which keyword can protect a class in a package from accessibility by the classes outside the package?

1. don't use any keyword at all (make it default)

2. private

3. protected

4. final

Question 55. (单选)

Which of the following statements are valid array declaration?

(A) int number();

(B) float average[];

(C) double[] marks;

(D) counter int[];

1. (B) & (C)

2. (A)

3. (A) & (C)

4. (D)

1. forward 和 redirect区别

1.从地址栏显示来说

forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来的,所以它的地址栏还是原来的地址.

redirect是服务端根据逻辑,发送一个状态码,告诉浏览器重新去请求那个地址.所以地址栏显示的是新的URL.

2.从数据共享来说

forward:转发页面和转发到的页面可以共享request里面的数据.

redirect:不能共享数据.

3.从运用地方来说

forward:一般用于用户登陆的时候,根据角色转发到相应的模块.

redirect:一般用于用户注销登陆时返回主页面和跳转到其它的网站等.

4.从效率来说

forward:高.

redirect:低.

2. servlet的几个方法 doget dopost区别

3. ArrayList里装了Person类对象,怎样根据Person类的属性年龄来排序

4. HashMap的键值是否可以是任意对象

面试总结

首先自我介绍

1. 面试官拿着你的简历,会挑其中的一个项目,然后让你说出这个框架的流程

2. 画出框架的流程图,会问每一个部分都是干什么用的

3. 针对2的问题,我们做的都是web项目,在那个框架中,servlet对应的是哪一个部分

4. 由前两个问题牵引出web.xml文件配置中都有哪些属性,以及他的作用

5. 对spring了解吗

6. spring的依赖注入方式有哪几种(注意不是spring的注入方式是依赖注入)

7. 有关事物的问题,做项目中做到哪些与事物有关的,事物是怎么控制的,怎么去写

8. 触发器,存储过程也说了一点

9. 项目开发中,如果遇到一个问题,你自己也不知道该用什么技术去解决,怎么去解决,该如何去查

10. 你有三年项目开发经验,觉得自己比别人有优势的地方在哪

11. 最后会问对他们公司有什么要了解的,给你个机会,让你去问问题

1,自我介绍,自己做过的项目,擅长的技术。

2,用过的框架,最擅长的那个?

3,所知道的MVC框架还有哪些?

4,经常去些什么样的网站,对自己将来有什么样的打算,规划。

5,喜欢技术吗,(喜欢)。举个例子来说明你喜欢技术。

6,以前项目中有没有加班,频率、加班时间长度。对加班的看法。

7,以前的项目主中要做什么内容,SE级别,还是开发。

8,在项目组怎样做项目,没有详细设计能做吗?

9,Struts用的什么版本。

10,Struts2用过吗?和Struts1有什么区别。

11,Spring的AOP了解吗,主要用在项目的那些方面。

12,以前的项目规模都是多大的。

1. 首先自我介绍

2. 问最熟悉的项目

3. 画出STRUTS框架响应jsp的流程图.

4. 针对2的问题,我们做的都是web项目,在那个框架中,servlet对应的是哪一个部分

5. 由前两个问题牵引出web.xml文件配置中都有哪些属性,以及他的作用

6. 对spring了解吗

7. spring的依赖注入方式有哪几种(注意不是spring的注入方式是依赖注入)

8. 有关事物的问题,做项目中做到哪些与事物有关的,事物是怎么控制的,怎么去写

9. Struts底层的相关知识

10. 项目开发中,如果遇到一个问题,你自己也不知道该用什么技术去解决,怎么去解决,该如何去查

11. 你有三年项目开发经验,觉得自己比别人有优势的地方在哪

12. 最后会问对他们公司有什么要了解的,给你个机会,让你去问问题

1. 首先自我介绍

2. 在你所用过的框架中你比较喜欢那个

3. 问你做过的这些项目中那个收获最大,收获到了什么

4. ibatis 和 Hibernate 的区别

5. servlet 的生命周期

6. spring 的两个主要特性(AOP 和IOC)

7. 说一下你所理解的J2EE是什么

8. 为什么说JBOSS 符合J2EE的要求,而TOMCAT 不符合J2EE的要求

9. Hibernate 的优点和缺点

10. 你认为在项目中最重要的是什么

11. 要是分给你的任务,你感到完成有困难,你会怎么办

12. 最后你对支付宝有什么要问的

这次去杭州支付宝面试,因为我的面试官是个开发主管,框架方面的技术问的很少,大部分都是根据问你项目而延伸的一些Sql , UML等问题,简历的项目当中如果有快钱的项目要好好准备下,对快钱的项目非常感兴趣。主要问题有以下:

1. 首先面试官自己自我介绍,然后让你自我介绍。

2. 哪家公司的?哪年出生的?哪年毕业的?工作几年了?这些问题都是在看你的回答是不是跟简历不一样,简历有没有作假。回答一定不要考虑。

3. 对于协力员工的看法?

4. 你的人生规划职业规划是怎么样的?

5. 对于项目加班有什么看法?你加班的极限是多少?

6. 熟悉一个新框架需要多长时间?(支付宝自己有个自己的框架)

7. 说出你认为对你影响最深的项目,并说出原因.

8. Oracle中的分页Sql怎么写?

9. 简单地向一个不懂计算机的人说明一下java的多态。

10. 说一下你知道的java设计模式。

11. struts,spring中应用了哪写java设计模式?

12. 说下spring的代理模式,画下spring代理模式的类图。

13. 快钱的项目中所担当的模块,根据你的回答就此展开一些问题。

14. 宝钢物流的项目的入库那个模块在开发中大致都用了哪些类?哪些接口?并画下UML图。

以上是主要的问题,还有些问题都是根据你的回答延伸的。

1 简单介绍自己

2 根据你的介绍提问

3 mvc开发模式有哪些模式

4 你的人生规划

5 业余爱好

6 最近所做的项目中除了你做的模块,还有哪些

7 你都去过哪做项目

总结:根据面试官不同,他可能喜欢的人也不同,这个面试官喜欢做事有计划的

你对Java的集合框架了解吗? 能否说说常用的类?

说说Hashtable与HashMap的区别: 源代码级别的区别呢?

平时用过的List有哪些? (除了ArrayList和LinkedList),ArrayList和LinkedList的区别?

ArrayList的特点,内部容器是如何扩充的?

Properties类的特点? 线程安全?

===============================================

平时使用过的框架有哪些? (我提到了Struts2)

请说一下Struts2的初始化?和类的创建?(从源代码角度出发)

据你了解,除了反射还有什么方式可以动态的创建对象?(我提到了CGLIB„„ 我以为他会接着问CGLIB,揪心中„„,结果他没问)

请说一下Struts2 是如何把Action交给Spring托管的?它是单例的还是多例? 你们页面的表单对象是多例还是单例?

请说一下你们业务层对象是单例还是多例的?

请说一下Struts2源代码中有哪些设计模式?

======================================================

请说一下,你觉得你最熟悉的技术特点? (我提到了并发编程)

请说一下线程安全出现的原因?

请说一下线程池的中断策略(4个)? 各有什么特点?

请说一下Tomcat配置不同应用的不同端口如何配置? 如何配置数据源? 如何实现动态部署?

请说一下Java常用的优化?

你了解最新的Servlet规范吗? 简单说一下?(我提到了推)

那请你说一下“推”是如何实现的?

线程安全下,StringBuffer与StringBuilder的区别? 它们是如何扩充内部数组容量的? (源代码)

请说一下Tomcat中的设计模式?(我提到观察者模式)

是否可以说说Java反射的相关优化机制? (我说我不太清楚„„ 他说没关系 - -!)

请说一些Mysql的常用优化策略?

因为我之前有提到过“推”,他可能对我的知识面比较感兴趣,要我说说平时都看些什么书,还了解一些什么其他的技术范畴。

(他首先提到SOA,我说有了解,并且是未来的趋势,还有提到云计算,我说有过一定了解,但是并未深究)

=====================================================

之后是几个职业方面的问题?

你觉得你的潜力? 你在团队中的位置? 你觉得跟团队中最好的还有哪些差距?你要花多少时间赶上他们?

你对阿里巴巴还有什么疑问吗? (我很囧的问了,“阿里巴巴的牛人平时都跟你们有互动吗?-----本意是指培训,但是话没说清楚„„”,囧了„„)

PS,下面是时候对问题的整理,里面纯粹仅限于个人浅见,如果有错误,还希望各位能指点一二。 ==================================================================

 你对Java的集合框架了解吗? 能否说说常用的类?

Java集合框架类图:

我常用的类:

HashMap,Hashtable,HashSet,ArrayList,Vector,LinkedList,Collections,Arrays;

 说说Hashtable与HashMap的区别(源代码级别)

1.最明显的区别在于Hashtable 是同步的(每个方法都是synchronized),而HashMap则不是.

2.HashMap继承至AbstractMap,Hashtable继承至Dictionary ,前者为Map的骨干, 其内部已经实现了Map所需 要做的大部分工作, 它的子类只需要实现它的少量方法即可具有Map的多项特性。而后者内部都为抽象方法,需要 它的实现类一一作自己的实现,且该类已过时

3.两者检测是否含有key时,hash算法不一致,HashMap内部需要将key的hash码重新计算一边再检测,而 Hashtable则直接利用key本身的hash码来做验证。

HashMap:

Java代码

1. int hash = (key == null) ? 0 : hash(key.hashCode());

2. -----

3. static int hash(int h) {

4. h ^= (h >>> 20) ^ (h >>> 12);

5. return h ^ (h >>> 7) ^ (h >>> 4);

6. }

Java代码

1. int hash = (key == null) ? 0 : hash(key.hashCode());

2. -----

3. static int hash(int h) {

4. h ^= (h >>> 20) ^ (h >>> 12);

5. return h ^ (h >>> 7) ^ (h >>> 4);

6. }

Hashtable:

Java代码

1. int hash = key.hashCode();

Java代码

1. int hash = key.hashCode();

4.两者初始化容量大小不一致,HashMap内部为 16*0.75 , Hashtable 为 11*0.75 HashMap:

Java代码

1. static final int DEFAULT_INITIAL_CAPACITY = 16;

2. static final float DEFAULT_LOAD_FACTOR = 0.75f;

3. public HashMap() {

4. this.loadFactor = DEFAULT_LOAD_FACTOR;

5. threshold=(int)(DEFAULT_INITIAL_CAPACITY*DEFAULT_LOAD_FACTOR);

6. table = new Entry[DEFAULT_INITIAL_CAPACITY];

7. init();

8. }

9. „„„„„„„„„„„„

Java代码

1. static final int DEFAULT_INITIAL_CAPACITY = 16;

2. static final float DEFAULT_LOAD_FACTOR = 0.75f;

3. public HashMap() {

4. this.loadFactor = DEFAULT_LOAD_FACTOR;

5. threshold=(int)(DEFAULT_INITIAL_CAPACITY*DEFAULT_LOAD_FACTOR);

6. table = new Entry[DEFAULT_INITIAL_CAPACITY];

7. init();

8. }

9. „„„„„„„„„„„„

Hashtable:

Java代码

1. public Hashtable() {

2. this(11, 0.75f);

3. }

4. -----

5. public Hashtable(int initialCapacity, float loadFactor) {

6. ..........

7. this.loadFactor = loadFactor;

8. table = new Entry[initialCapacity];

9. threshold = (int)(initialCapacity * loadFactor);

10. }

Java代码

1. public Hashtable() {

2. this(11, 0.75f);

3. }

4. -----

5. public Hashtable(int initialCapacity, float loadFactor) {

6. ..........

7. this.loadFactor = loadFactor;

8. table = new Entry[initialCapacity];

9. threshold = (int)(initialCapacity * loadFactor);

10. }

其实后续的区别应该还有很多, 这里先列出4点。

 平时除了ArrayList和LinkedList外,还用过的List有哪些?

ArrayList和LinkedList的区别?

事实上,我用过的List主要就是这2个, 另外用过Vector.

ArrayList和LinkedList的区别:

1. 毫无疑问,第一点就是两者的内部数据结构不同, ArrayList内部元素容器是一个Object的

数组,

而LinkedList内部实际上一个链表的数据结构,其有一个内部类来表示链表.

Java代码

1. (ArrayList)

2. private transient Object[] elementData;

3.

4. „„„„„„„„„„„„„„„„„„„„„„„„„„„„„„

5.

6. (LinkedList)

7. private transient Entry header = new Entry(null, null, null);/链表

8.

9. //内部链表类.

10.private static class Entry {

11. E element; //数据元素

12. Entry next; // 前驱

13. Entry previous;//后驱

14. Entry(E element, Entry next, Entry previous) {

15. this.element = element;

16. this.next = next;

17. this.previous = previous;

18. }

19.}

Java代码

20.(ArrayList)

21.private transient Object[] elementData;

22.

23.„„„„„„„„„„„„„„„„„„„„„„„„„„„„„„

24.

25.(LinkedList)

26.private transient Entry header = new Entry(null, null, null);/链表

27.

28.//内部链表类.

29.private static class Entry {

30. E element; //数据元素

31. Entry next; // 前驱

32. Entry previous;//后驱

33. Entry(E element, Entry next, Entry previous) {

34. this.element = element;

35. this.next = next;

36. this.previous = previous;

37. }

38.}

2. 两者的父类不同,也就决定了两者的存储形式不同。 ArrayList继承于 AbstractList,而

LinkedList继承于AbstractSequentialList. 两者都实现了List的骨干结构,只是前者的访问形式趋向于 “随机访问”数据存储(如数组),后者趋向于 “连续访问”数据存储(如链接列表)

Java代码

1. public class ArrayList extends AbstractList

2. ---------------------------------------------------------------------------------------

3. public class LinkedList extends AbstractSequentialList

Java代码

4. public class ArrayList extends AbstractList

5. ---------------------------------------------------------------------------------------

6. public class LinkedList extends AbstractSequentialList

3. 再有就是两者的效率问题, ArrayList基于数组实现,所以毫无疑问可以直接用下标来索引,

其索引数据快,插入元素设计到数组元素移动,或者数组扩充,所以插入元素要慢。LinkedList基于链表结构,插入元素只需要改变插入元素的前后项的指向即可,故插入数据要快,而索引元素需要向前向后遍历,所以索引元素要慢。

 ArrayList的特点,内部容器是如何扩充的?

上一点谈到了ArrayList的特点,这里略,重点来看其内部容器的扩充:

Java代码

1. public void ensureCapacity(int minCapacity) {

2. modCount++;

3. int oldCapacity = elementData.length;

4. if (minCapacity > oldCapacity) {

5. Object oldData[] = elementData;

6. //这里扩充的大小为原大小的大概 60%

7. int newCapacity = (oldCapacity * 3) / 2 + 1;

8. if (newCapacity

9. newCapacity = minCapacity;

10. //创建一个指定大小的新数组来覆盖原数组

11. elementData = Arrays.copyOf(elementData, newCapacity);

12. }

13. }

Java代码

1. public void ensureCapacity(int minCapacity) {

2. modCount++;

3. int oldCapacity = elementData.length;

4. if (minCapacity > oldCapacity) {

5. Object oldData[] = elementData;

6. //这里扩充的大小为原大小的大概 60%

7. int newCapacity = (oldCapacity * 3) / 2 + 1;

8. if (newCapacity

9. newCapacity = minCapacity;

10. //创建一个指定大小的新数组来覆盖原数组

11. elementData = Arrays.copyOf(elementData, newCapacity);

12. }

13. }

 Properties类的特点? 线程安全吗?

Properties 继承于Hashtable,,所以它是线程安全的. 其特点是: 它表示的是一个持久的属性集,它可以保存在流中或者从流中加载,属性列表的每一个键和它所对应的值都是一个“字符串” 其中,常用的方法是load()方法,从流中加载属性:

Java代码

// 将输入流转换成LineReader

load0(new LineReader(inStream));

}

private void load0(LineReader lr) throws IOException {

char[] convtBuf = new char[1024];

int limit;

int keyLen;

int valueStart;

char c;

boolean hasSep;

boolean precedingBackslash;

// 一行一行处理

while ((limit = lr.readLine()) >= 0) {

c = 0;

keyLen = 0;

valueStart = limit;

hasSep = false;

precedingBackslash = false;

// 下面用2个循环来处理key,value

while (keyLen

c = lr.lineBuf[keyLen];

// need check if escaped.

if ((c == '=' || c == ':') && !precedingBackslash) {

valueStart = keyLen + 1;

hasSep = true;

break;

} else if ((c == ' ' || c == '\t' || c == '\f')

&& !precedingBackslash) {

valueStart = keyLen + 1;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

keyLen++;

}

while (valueStart

c = lr.lineBuf[valueStart];

if (c != ' ' && c != '\t' && c != '\f') {

if (!hasSep && (c == '=' || c == ':')) {

hasSep = true;

} else {

break;

}

}

valueStart++;

}

String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);

String value = loadConvert(lr.lineBuf, valueStart, limit

- valueStart, convtBuf);

// 存入内部容器中,这里用的是Hashtable 内部的方法.

}

}

Java代码

// 将输入流转换成LineReader

load0(new LineReader(inStream));

}

private void load0(LineReader lr) throws IOException {

char[] convtBuf = new char[1024];

int limit;

int keyLen;

int valueStart;

char c;

boolean hasSep;

boolean precedingBackslash;

// 一行一行处理

while ((limit = lr.readLine()) >= 0) {

c = 0;

keyLen = 0;

valueStart = limit;

hasSep = false;

precedingBackslash = false;

// 下面用2个循环来处理key,value

while (keyLen

c = lr.lineBuf[keyLen];

// need check if escaped.

if ((c == '=' || c == ':') && !precedingBackslash) {

valueStart = keyLen + 1;

hasSep = true;

break;

} else if ((c == ' ' || c == '\t' || c == '\f')

&& !precedingBackslash) {

valueStart = keyLen + 1;

break;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

keyLen++;

}

while (valueStart

c = lr.lineBuf[valueStart];

if (c != ' ' && c != '\t' && c != '\f') {

if (!hasSep && (c == '=' || c == ':')) {

hasSep = true;

} else {

break;

}

}

valueStart++;

}

String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);

String value = loadConvert(lr.lineBuf, valueStart, limit

- valueStart, convtBuf);

// 存入内部容器中,这里用的是Hashtable 内部的方法.

put(key, value);

}

}

LineReader类,是Properties内部的类:

Java代码

public LineReader(InputStream inStream) {

this.inStream = inStream;

inByteBuf = new byte[8192];

}

public LineReader(Reader reader) {

this.reader = reader;

inCharBuf = new char[8192]; }

byte[] inByteBuf;

char[] inCharBuf;

char[] lineBuf = new char[1024];

int inLimit = 0;

int inOff = 0;

InputStream inStream;

Reader reader;

/**

* 读取一行

*

* @return

* @throws IOException

*/

int readLine() throws IOException {

int len = 0;

char c = 0;

boolean skipWhiteSpace = true;// 空白

boolean isCommentLine = false;// 注释

boolean isNewLine = true;// 是否新行.

boolean appendedLineBegin = false;// 加 至行开始

boolean precedingBackslash = false;// 反斜杠

boolean skipLF = false;

while (true) {

if (inOff >= inLimit) {

// 从输入流中读取一定数量的字节并将其存储在缓冲区数组inCharBuf/inByteBuf中,这里区分字节流和字符流

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

// 读取到的为空.

if (inLimit

if (len == 0 || isCommentLine) {

return -1;

}

return len;

}

}

if (inStream != null) {

// 由于是字节流,需要使用ISO8859-1来解码

c = (char) (0xff & inByteBuf[inOff++]);

} else {

c = inCharBuf[inOff++];

}

if (skipLF) {

skipLF = false;

if (c == '\n') {

continue;

}

}

if (skipWhiteSpace) {

if (c == ' ' || c == '\t' || c == '\f') {

continue;

}

if (!appendedLineBegin && (c == '\r' || c == '\n')) {

continue;

}

skipWhiteSpace = false;

appendedLineBegin = false;

}

if (isNewLine) {

isNewLine = false;

if (c == '#' || c == '!') {

// 注释行,忽略.

isCommentLine = true;

continue;

}

}

// 读取真正的属性内容

if (c != '\n' && c != '\r') {

// 这里类似于ArrayList内部的容量扩充,使用字符数组来保存读取的内容. lineBuf[len++] = c;

if (len == lineBuf.length) {

int newLength = lineBuf.length * 2;

if (newLength

newLength = Integer.MAX_VALUE;

}

char[] buf = new char[newLength];

System.arraycopy(lineBuf, 0, buf, 0, lineBuf.length);

lineBuf = buf;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

} else {

// reached EOL 文件结束

if (isCommentLine || len == 0) {

isCommentLine = false;

isNewLine = true;

skipWhiteSpace = true;

len = 0;

continue;

}

if (inOff >= inLimit) {

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

if (inLimit

return len;

}

}

if (precedingBackslash) {

len -= 1;

skipWhiteSpace = true;

appendedLineBegin = true;

precedingBackslash = false;

if (c == '\r') {

skipLF = true;

}

} else {

return len;

}

}

}

}

}

Java代码

public LineReader(InputStream inStream) {

this.inStream = inStream;

inByteBuf = new byte[8192];

}

public LineReader(Reader reader) {

this.reader = reader; inCharBuf = new char[8192];

}

byte[] inByteBuf;

char[] inCharBuf;

char[] lineBuf = new char[1024];

int inLimit = 0;

int inOff = 0;

InputStream inStream;

Reader reader;

/**

* 读取一行

*

* @return

* @throws IOException

*/

int readLine() throws IOException {

int len = 0;

char c = 0;

boolean skipWhiteSpace = true;// 空白

boolean isCommentLine = false;// 注释

boolean isNewLine = true;// 是否新行.

boolean appendedLineBegin = false;// 加 至行开始

boolean precedingBackslash = false;// 反斜杠

boolean skipLF = false;

while (true) {

if (inOff >= inLimit) {

// 从输入流中读取一定数量的字节并将其存储在缓冲区数组inCharBuf/inByteBuf中,这里区分字节流和字符流

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

// 读取到的为空.

if (inLimit

if (len == 0 || isCommentLine) {

return -1;

}

return len;

}

}

if (inStream != null) {

// 由于是字节流,需要使用ISO8859-1来解码

c = (char) (0xff & inByteBuf[inOff++]);

} else {

c = inCharBuf[inOff++];

}

if (skipLF) {

skipLF = false;

if (c == '\n') {

continue;

}

}

if (skipWhiteSpace) {

if (c == ' ' || c == '\t' || c == '\f') {

continue;

}

if (!appendedLineBegin && (c == '\r' || c == '\n')) {

continue;

}

skipWhiteSpace = false;

appendedLineBegin = false;

}

if (isNewLine) {

isNewLine = false;

if (c == '#' || c == '!') {

// 注释行,忽略.

isCommentLine = true;

continue;

}

}

// 读取真正的属性内容

if (c != '\n' && c != '\r') {

// 这里类似于ArrayList内部的容量扩充,使用字符数组来保存读取的内容. lineBuf[len++] = c;

if (len == lineBuf.length) {

int newLength = lineBuf.length * 2;

if (newLength

newLength = Integer.MAX_VALUE;

}

char[] buf = new char[newLength];

System.arraycopy(lineBuf, 0, buf, 0, lineBuf.length);

lineBuf = buf;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

} else {

// reached EOL 文件结束

if (isCommentLine || len == 0) {

isCommentLine = false;

isNewLine = true;

skipWhiteSpace = true;

len = 0;

continue;

}

if (inOff >= inLimit) {

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

if (inLimit

return len;

}

}

if (precedingBackslash) {

len -= 1;

skipWhiteSpace = true;

appendedLineBegin = true;

precedingBackslash = false;

if (c == '\r') {

skipLF = true;

}

} else {

return len;

}

}

}

}

}

这里特别的是,实际上,Properties从流中加载属性集合,是通过将流中的字符或者字节分成一行行来处理的。

 请说一下Struts2的初始化?和类的创建?(从源代码角度出发)

(我当时回答这个问题的思路我想应该对了, 我说是通过反射加配置文件来做的)

由于这个问题研究起来可以另外写一篇专门的模块,这里只列出相对简单的流程,后续会希望有时间整理出具体的细节: 首先,Struts2是基于Xwork框架的,如果你有仔细看过Xwork的文档,你会发现,它的初始化过程基于以下几个类: Configuring XWork2 centers around the following classes:- 1. ConfigurationManager 2. ConfigurationProvider

3. Configuration 而在ConfigurationProvider的实现类XmlConfigurationProvider 的内部,你可以看到下面的代码 Java代码

this(

}

Java代码

this(

}

同样的,Struts2的初始化也是这样的一个类,只不过它继承于Xwork原有的类,并针对Struts2做了一些特别的定制。 Java代码

1.

2. extends XmlConfigurationProvider {

3. public StrutsXmlConfigurationProvi

1 JDK5支持泛型,泛型是如何实现的,应用反射API操作泛型变量时,泛型还起作用吗?

2 Class.forName(

已知如下类定义:

class Base {

public Base (){ //... }

public Base ( int m ){ //... }

protected void fun( int n ){ //... }

}

public class Child extends Base{

// member methods

}

如下哪句可以正确地加入子类中?

1. private?void?fun(?int?n?){?//...}

2. void fun ( int n ){ //... }

3. protected void fun ( int n ) { //... }

4. public void fun ( int n ) { //... }

Question 47. (单选)

It is an important feature of the Java language that it always provides a default constructor to a class.

1. FALSE

2. TRUE

Question 48. (单选)

A class contained in a Java program file must have the same name as the file, except for the extension

1. FALSE

2. TRUE

Question 49. (单选)

Each method in a class must have a unique name.

1. FALSE

2. TRUE

Question 50. (单选)

When an instance of a class, or object, is specified as a parameter to a method, a reference to the said object is passed to the method.

1. FALSE

2. TRUE

Question 51. (单选)

All interface methods must be declared as public when implemented in a class.

1. FALSE

2. TRUE

Question 52. (单选)

Which of the following expressions will produce errors upon compilation?

(A) boolean a = (boolean) 1;

(B) boolean b = (false && true);

(C) float y = 22.3; (D) int x = (25 | 125)

1. (A) & (C)

2. (A)

3. (A), (C) & (D)

4. (A), (B) & (D)

Which lines of the following will produce an error?

1. byte a1 = 2, a2 = 4, a3;

2. short s = 16;

3. a2 = s;

4. a3 = a1 * a2;

1. Line 3 and Line 4

2. Line 1 only

3. Line 3 only

4. Line 4 only

5. Line 1 and Line 4

Question 54. (单选)

Which keyword can protect a class in a package from accessibility by the classes outside the package?

1. don't use any keyword at all (make it default)

2. private

3. protected

4. final

Question 55. (单选)

Which of the following statements are valid array declaration?

(A) int number();

(B) float average[];

(C) double[] marks;

(D) counter int[];

1. (B) & (C)

2. (A)

3. (A) & (C)

4. (D)

1. forward 和 redirect区别

1.从地址栏显示来说

forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来的,所以它的地址栏还是原来的地址.

redirect是服务端根据逻辑,发送一个状态码,告诉浏览器重新去请求那个地址.所以地址栏显示的是新的URL.

2.从数据共享来说

forward:转发页面和转发到的页面可以共享request里面的数据.

redirect:不能共享数据.

3.从运用地方来说

forward:一般用于用户登陆的时候,根据角色转发到相应的模块.

redirect:一般用于用户注销登陆时返回主页面和跳转到其它的网站等.

4.从效率来说

forward:高.

redirect:低.

2. servlet的几个方法 doget dopost区别

3. ArrayList里装了Person类对象,怎样根据Person类的属性年龄来排序

4. HashMap的键值是否可以是任意对象

面试总结

首先自我介绍

1. 面试官拿着你的简历,会挑其中的一个项目,然后让你说出这个框架的流程

2. 画出框架的流程图,会问每一个部分都是干什么用的

3. 针对2的问题,我们做的都是web项目,在那个框架中,servlet对应的是哪一个部分

4. 由前两个问题牵引出web.xml文件配置中都有哪些属性,以及他的作用

5. 对spring了解吗

6. spring的依赖注入方式有哪几种(注意不是spring的注入方式是依赖注入)

7. 有关事物的问题,做项目中做到哪些与事物有关的,事物是怎么控制的,怎么去写

8. 触发器,存储过程也说了一点

9. 项目开发中,如果遇到一个问题,你自己也不知道该用什么技术去解决,怎么去解决,该如何去查

10. 你有三年项目开发经验,觉得自己比别人有优势的地方在哪

11. 最后会问对他们公司有什么要了解的,给你个机会,让你去问问题

1,自我介绍,自己做过的项目,擅长的技术。

2,用过的框架,最擅长的那个?

3,所知道的MVC框架还有哪些?

4,经常去些什么样的网站,对自己将来有什么样的打算,规划。

5,喜欢技术吗,(喜欢)。举个例子来说明你喜欢技术。

6,以前项目中有没有加班,频率、加班时间长度。对加班的看法。

7,以前的项目主中要做什么内容,SE级别,还是开发。

8,在项目组怎样做项目,没有详细设计能做吗?

9,Struts用的什么版本。

10,Struts2用过吗?和Struts1有什么区别。

11,Spring的AOP了解吗,主要用在项目的那些方面。

12,以前的项目规模都是多大的。

1. 首先自我介绍

2. 问最熟悉的项目

3. 画出STRUTS框架响应jsp的流程图.

4. 针对2的问题,我们做的都是web项目,在那个框架中,servlet对应的是哪一个部分

5. 由前两个问题牵引出web.xml文件配置中都有哪些属性,以及他的作用

6. 对spring了解吗

7. spring的依赖注入方式有哪几种(注意不是spring的注入方式是依赖注入)

8. 有关事物的问题,做项目中做到哪些与事物有关的,事物是怎么控制的,怎么去写

9. Struts底层的相关知识

10. 项目开发中,如果遇到一个问题,你自己也不知道该用什么技术去解决,怎么去解决,该如何去查

11. 你有三年项目开发经验,觉得自己比别人有优势的地方在哪

12. 最后会问对他们公司有什么要了解的,给你个机会,让你去问问题

1. 首先自我介绍

2. 在你所用过的框架中你比较喜欢那个

3. 问你做过的这些项目中那个收获最大,收获到了什么

4. ibatis 和 Hibernate 的区别

5. servlet 的生命周期

6. spring 的两个主要特性(AOP 和IOC)

7. 说一下你所理解的J2EE是什么

8. 为什么说JBOSS 符合J2EE的要求,而TOMCAT 不符合J2EE的要求

9. Hibernate 的优点和缺点

10. 你认为在项目中最重要的是什么

11. 要是分给你的任务,你感到完成有困难,你会怎么办

12. 最后你对支付宝有什么要问的

这次去杭州支付宝面试,因为我的面试官是个开发主管,框架方面的技术问的很少,大部分都是根据问你项目而延伸的一些Sql , UML等问题,简历的项目当中如果有快钱的项目要好好准备下,对快钱的项目非常感兴趣。主要问题有以下:

1. 首先面试官自己自我介绍,然后让你自我介绍。

2. 哪家公司的?哪年出生的?哪年毕业的?工作几年了?这些问题都是在看你的回答是不是跟简历不一样,简历有没有作假。回答一定不要考虑。

3. 对于协力员工的看法?

4. 你的人生规划职业规划是怎么样的?

5. 对于项目加班有什么看法?你加班的极限是多少?

6. 熟悉一个新框架需要多长时间?(支付宝自己有个自己的框架)

7. 说出你认为对你影响最深的项目,并说出原因.

8. Oracle中的分页Sql怎么写?

9. 简单地向一个不懂计算机的人说明一下java的多态。

10. 说一下你知道的java设计模式。

11. struts,spring中应用了哪写java设计模式?

12. 说下spring的代理模式,画下spring代理模式的类图。

13. 快钱的项目中所担当的模块,根据你的回答就此展开一些问题。

14. 宝钢物流的项目的入库那个模块在开发中大致都用了哪些类?哪些接口?并画下UML图。

以上是主要的问题,还有些问题都是根据你的回答延伸的。

1 简单介绍自己

2 根据你的介绍提问

3 mvc开发模式有哪些模式

4 你的人生规划

5 业余爱好

6 最近所做的项目中除了你做的模块,还有哪些

7 你都去过哪做项目

总结:根据面试官不同,他可能喜欢的人也不同,这个面试官喜欢做事有计划的

你对Java的集合框架了解吗? 能否说说常用的类?

说说Hashtable与HashMap的区别: 源代码级别的区别呢?

平时用过的List有哪些? (除了ArrayList和LinkedList),ArrayList和LinkedList的区别?

ArrayList的特点,内部容器是如何扩充的?

Properties类的特点? 线程安全?

===============================================

平时使用过的框架有哪些? (我提到了Struts2)

请说一下Struts2的初始化?和类的创建?(从源代码角度出发)

据你了解,除了反射还有什么方式可以动态的创建对象?(我提到了CGLIB„„ 我以为他会接着问CGLIB,揪心中„„,结果他没问)

请说一下Struts2 是如何把Action交给Spring托管的?它是单例的还是多例? 你们页面的表单对象是多例还是单例?

请说一下你们业务层对象是单例还是多例的?

请说一下Struts2源代码中有哪些设计模式?

======================================================

请说一下,你觉得你最熟悉的技术特点? (我提到了并发编程)

请说一下线程安全出现的原因?

请说一下线程池的中断策略(4个)? 各有什么特点?

请说一下Tomcat配置不同应用的不同端口如何配置? 如何配置数据源? 如何实现动态部署?

请说一下Java常用的优化?

你了解最新的Servlet规范吗? 简单说一下?(我提到了推)

那请你说一下“推”是如何实现的?

线程安全下,StringBuffer与StringBuilder的区别? 它们是如何扩充内部数组容量的? (源代码)

请说一下Tomcat中的设计模式?(我提到观察者模式)

是否可以说说Java反射的相关优化机制? (我说我不太清楚„„ 他说没关系 - -!)

请说一些Mysql的常用优化策略?

因为我之前有提到过“推”,他可能对我的知识面比较感兴趣,要我说说平时都看些什么书,还了解一些什么其他的技术范畴。

(他首先提到SOA,我说有了解,并且是未来的趋势,还有提到云计算,我说有过一定了解,但是并未深究)

=====================================================

之后是几个职业方面的问题?

你觉得你的潜力? 你在团队中的位置? 你觉得跟团队中最好的还有哪些差距?你要花多少时间赶上他们?

你对阿里巴巴还有什么疑问吗? (我很囧的问了,“阿里巴巴的牛人平时都跟你们有互动吗?-----本意是指培训,但是话没说清楚„„”,囧了„„)

PS,下面是时候对问题的整理,里面纯粹仅限于个人浅见,如果有错误,还希望各位能指点一二。 ==================================================================

 你对Java的集合框架了解吗? 能否说说常用的类?

Java集合框架类图:

我常用的类:

HashMap,Hashtable,HashSet,ArrayList,Vector,LinkedList,Collections,Arrays;

 说说Hashtable与HashMap的区别(源代码级别)

1.最明显的区别在于Hashtable 是同步的(每个方法都是synchronized),而HashMap则不是.

2.HashMap继承至AbstractMap,Hashtable继承至Dictionary ,前者为Map的骨干, 其内部已经实现了Map所需 要做的大部分工作, 它的子类只需要实现它的少量方法即可具有Map的多项特性。而后者内部都为抽象方法,需要 它的实现类一一作自己的实现,且该类已过时

3.两者检测是否含有key时,hash算法不一致,HashMap内部需要将key的hash码重新计算一边再检测,而 Hashtable则直接利用key本身的hash码来做验证。

HashMap:

Java代码

1. int hash = (key == null) ? 0 : hash(key.hashCode());

2. -----

3. static int hash(int h) {

4. h ^= (h >>> 20) ^ (h >>> 12);

5. return h ^ (h >>> 7) ^ (h >>> 4);

6. }

Java代码

1. int hash = (key == null) ? 0 : hash(key.hashCode());

2. -----

3. static int hash(int h) {

4. h ^= (h >>> 20) ^ (h >>> 12);

5. return h ^ (h >>> 7) ^ (h >>> 4);

6. }

Hashtable:

Java代码

1. int hash = key.hashCode();

Java代码

1. int hash = key.hashCode();

4.两者初始化容量大小不一致,HashMap内部为 16*0.75 , Hashtable 为 11*0.75 HashMap:

Java代码

1. static final int DEFAULT_INITIAL_CAPACITY = 16;

2. static final float DEFAULT_LOAD_FACTOR = 0.75f;

3. public HashMap() {

4. this.loadFactor = DEFAULT_LOAD_FACTOR;

5. threshold=(int)(DEFAULT_INITIAL_CAPACITY*DEFAULT_LOAD_FACTOR);

6. table = new Entry[DEFAULT_INITIAL_CAPACITY];

7. init();

8. }

9. „„„„„„„„„„„„

Java代码

1. static final int DEFAULT_INITIAL_CAPACITY = 16;

2. static final float DEFAULT_LOAD_FACTOR = 0.75f;

3. public HashMap() {

4. this.loadFactor = DEFAULT_LOAD_FACTOR;

5. threshold=(int)(DEFAULT_INITIAL_CAPACITY*DEFAULT_LOAD_FACTOR);

6. table = new Entry[DEFAULT_INITIAL_CAPACITY];

7. init();

8. }

9. „„„„„„„„„„„„

Hashtable:

Java代码

1. public Hashtable() {

2. this(11, 0.75f);

3. }

4. -----

5. public Hashtable(int initialCapacity, float loadFactor) {

6. ..........

7. this.loadFactor = loadFactor;

8. table = new Entry[initialCapacity];

9. threshold = (int)(initialCapacity * loadFactor);

10. }

Java代码

1. public Hashtable() {

2. this(11, 0.75f);

3. }

4. -----

5. public Hashtable(int initialCapacity, float loadFactor) {

6. ..........

7. this.loadFactor = loadFactor;

8. table = new Entry[initialCapacity];

9. threshold = (int)(initialCapacity * loadFactor);

10. }

其实后续的区别应该还有很多, 这里先列出4点。

 平时除了ArrayList和LinkedList外,还用过的List有哪些?

ArrayList和LinkedList的区别?

事实上,我用过的List主要就是这2个, 另外用过Vector.

ArrayList和LinkedList的区别:

1. 毫无疑问,第一点就是两者的内部数据结构不同, ArrayList内部元素容器是一个Object的

数组,

而LinkedList内部实际上一个链表的数据结构,其有一个内部类来表示链表.

Java代码

1. (ArrayList)

2. private transient Object[] elementData;

3.

4. „„„„„„„„„„„„„„„„„„„„„„„„„„„„„„

5.

6. (LinkedList)

7. private transient Entry header = new Entry(null, null, null);/链表

8.

9. //内部链表类.

10.private static class Entry {

11. E element; //数据元素

12. Entry next; // 前驱

13. Entry previous;//后驱

14. Entry(E element, Entry next, Entry previous) {

15. this.element = element;

16. this.next = next;

17. this.previous = previous;

18. }

19.}

Java代码

20.(ArrayList)

21.private transient Object[] elementData;

22.

23.„„„„„„„„„„„„„„„„„„„„„„„„„„„„„„

24.

25.(LinkedList)

26.private transient Entry header = new Entry(null, null, null);/链表

27.

28.//内部链表类.

29.private static class Entry {

30. E element; //数据元素

31. Entry next; // 前驱

32. Entry previous;//后驱

33. Entry(E element, Entry next, Entry previous) {

34. this.element = element;

35. this.next = next;

36. this.previous = previous;

37. }

38.}

2. 两者的父类不同,也就决定了两者的存储形式不同。 ArrayList继承于 AbstractList,而

LinkedList继承于AbstractSequentialList. 两者都实现了List的骨干结构,只是前者的访问形式趋向于 “随机访问”数据存储(如数组),后者趋向于 “连续访问”数据存储(如链接列表)

Java代码

1. public class ArrayList extends AbstractList

2. ---------------------------------------------------------------------------------------

3. public class LinkedList extends AbstractSequentialList

Java代码

4. public class ArrayList extends AbstractList

5. ---------------------------------------------------------------------------------------

6. public class LinkedList extends AbstractSequentialList

3. 再有就是两者的效率问题, ArrayList基于数组实现,所以毫无疑问可以直接用下标来索引,

其索引数据快,插入元素设计到数组元素移动,或者数组扩充,所以插入元素要慢。LinkedList基于链表结构,插入元素只需要改变插入元素的前后项的指向即可,故插入数据要快,而索引元素需要向前向后遍历,所以索引元素要慢。

 ArrayList的特点,内部容器是如何扩充的?

上一点谈到了ArrayList的特点,这里略,重点来看其内部容器的扩充:

Java代码

1. public void ensureCapacity(int minCapacity) {

2. modCount++;

3. int oldCapacity = elementData.length;

4. if (minCapacity > oldCapacity) {

5. Object oldData[] = elementData;

6. //这里扩充的大小为原大小的大概 60%

7. int newCapacity = (oldCapacity * 3) / 2 + 1;

8. if (newCapacity

9. newCapacity = minCapacity;

10. //创建一个指定大小的新数组来覆盖原数组

11. elementData = Arrays.copyOf(elementData, newCapacity);

12. }

13. }

Java代码

1. public void ensureCapacity(int minCapacity) {

2. modCount++;

3. int oldCapacity = elementData.length;

4. if (minCapacity > oldCapacity) {

5. Object oldData[] = elementData;

6. //这里扩充的大小为原大小的大概 60%

7. int newCapacity = (oldCapacity * 3) / 2 + 1;

8. if (newCapacity

9. newCapacity = minCapacity;

10. //创建一个指定大小的新数组来覆盖原数组

11. elementData = Arrays.copyOf(elementData, newCapacity);

12. }

13. }

 Properties类的特点? 线程安全吗?

Properties 继承于Hashtable,,所以它是线程安全的. 其特点是: 它表示的是一个持久的属性集,它可以保存在流中或者从流中加载,属性列表的每一个键和它所对应的值都是一个“字符串” 其中,常用的方法是load()方法,从流中加载属性:

Java代码

// 将输入流转换成LineReader

load0(new LineReader(inStream));

}

private void load0(LineReader lr) throws IOException {

char[] convtBuf = new char[1024];

int limit;

int keyLen;

int valueStart;

char c;

boolean hasSep;

boolean precedingBackslash;

// 一行一行处理

while ((limit = lr.readLine()) >= 0) {

c = 0;

keyLen = 0;

valueStart = limit;

hasSep = false;

precedingBackslash = false;

// 下面用2个循环来处理key,value

while (keyLen

c = lr.lineBuf[keyLen];

// need check if escaped.

if ((c == '=' || c == ':') && !precedingBackslash) {

valueStart = keyLen + 1;

hasSep = true;

break;

} else if ((c == ' ' || c == '\t' || c == '\f')

&& !precedingBackslash) {

valueStart = keyLen + 1;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

keyLen++;

}

while (valueStart

c = lr.lineBuf[valueStart];

if (c != ' ' && c != '\t' && c != '\f') {

if (!hasSep && (c == '=' || c == ':')) {

hasSep = true;

} else {

break;

}

}

valueStart++;

}

String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);

String value = loadConvert(lr.lineBuf, valueStart, limit

- valueStart, convtBuf);

// 存入内部容器中,这里用的是Hashtable 内部的方法.

}

}

Java代码

// 将输入流转换成LineReader

load0(new LineReader(inStream));

}

private void load0(LineReader lr) throws IOException {

char[] convtBuf = new char[1024];

int limit;

int keyLen;

int valueStart;

char c;

boolean hasSep;

boolean precedingBackslash;

// 一行一行处理

while ((limit = lr.readLine()) >= 0) {

c = 0;

keyLen = 0;

valueStart = limit;

hasSep = false;

precedingBackslash = false;

// 下面用2个循环来处理key,value

while (keyLen

c = lr.lineBuf[keyLen];

// need check if escaped.

if ((c == '=' || c == ':') && !precedingBackslash) {

valueStart = keyLen + 1;

hasSep = true;

break;

} else if ((c == ' ' || c == '\t' || c == '\f')

&& !precedingBackslash) {

valueStart = keyLen + 1;

break;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

keyLen++;

}

while (valueStart

c = lr.lineBuf[valueStart];

if (c != ' ' && c != '\t' && c != '\f') {

if (!hasSep && (c == '=' || c == ':')) {

hasSep = true;

} else {

break;

}

}

valueStart++;

}

String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf);

String value = loadConvert(lr.lineBuf, valueStart, limit

- valueStart, convtBuf);

// 存入内部容器中,这里用的是Hashtable 内部的方法.

put(key, value);

}

}

LineReader类,是Properties内部的类:

Java代码

public LineReader(InputStream inStream) {

this.inStream = inStream;

inByteBuf = new byte[8192];

}

public LineReader(Reader reader) {

this.reader = reader;

inCharBuf = new char[8192]; }

byte[] inByteBuf;

char[] inCharBuf;

char[] lineBuf = new char[1024];

int inLimit = 0;

int inOff = 0;

InputStream inStream;

Reader reader;

/**

* 读取一行

*

* @return

* @throws IOException

*/

int readLine() throws IOException {

int len = 0;

char c = 0;

boolean skipWhiteSpace = true;// 空白

boolean isCommentLine = false;// 注释

boolean isNewLine = true;// 是否新行.

boolean appendedLineBegin = false;// 加 至行开始

boolean precedingBackslash = false;// 反斜杠

boolean skipLF = false;

while (true) {

if (inOff >= inLimit) {

// 从输入流中读取一定数量的字节并将其存储在缓冲区数组inCharBuf/inByteBuf中,这里区分字节流和字符流

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

// 读取到的为空.

if (inLimit

if (len == 0 || isCommentLine) {

return -1;

}

return len;

}

}

if (inStream != null) {

// 由于是字节流,需要使用ISO8859-1来解码

c = (char) (0xff & inByteBuf[inOff++]);

} else {

c = inCharBuf[inOff++];

}

if (skipLF) {

skipLF = false;

if (c == '\n') {

continue;

}

}

if (skipWhiteSpace) {

if (c == ' ' || c == '\t' || c == '\f') {

continue;

}

if (!appendedLineBegin && (c == '\r' || c == '\n')) {

continue;

}

skipWhiteSpace = false;

appendedLineBegin = false;

}

if (isNewLine) {

isNewLine = false;

if (c == '#' || c == '!') {

// 注释行,忽略.

isCommentLine = true;

continue;

}

}

// 读取真正的属性内容

if (c != '\n' && c != '\r') {

// 这里类似于ArrayList内部的容量扩充,使用字符数组来保存读取的内容. lineBuf[len++] = c;

if (len == lineBuf.length) {

int newLength = lineBuf.length * 2;

if (newLength

newLength = Integer.MAX_VALUE;

}

char[] buf = new char[newLength];

System.arraycopy(lineBuf, 0, buf, 0, lineBuf.length);

lineBuf = buf;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

} else {

// reached EOL 文件结束

if (isCommentLine || len == 0) {

isCommentLine = false;

isNewLine = true;

skipWhiteSpace = true;

len = 0;

continue;

}

if (inOff >= inLimit) {

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

if (inLimit

return len;

}

}

if (precedingBackslash) {

len -= 1;

skipWhiteSpace = true;

appendedLineBegin = true;

precedingBackslash = false;

if (c == '\r') {

skipLF = true;

}

} else {

return len;

}

}

}

}

}

Java代码

public LineReader(InputStream inStream) {

this.inStream = inStream;

inByteBuf = new byte[8192];

}

public LineReader(Reader reader) {

this.reader = reader; inCharBuf = new char[8192];

}

byte[] inByteBuf;

char[] inCharBuf;

char[] lineBuf = new char[1024];

int inLimit = 0;

int inOff = 0;

InputStream inStream;

Reader reader;

/**

* 读取一行

*

* @return

* @throws IOException

*/

int readLine() throws IOException {

int len = 0;

char c = 0;

boolean skipWhiteSpace = true;// 空白

boolean isCommentLine = false;// 注释

boolean isNewLine = true;// 是否新行.

boolean appendedLineBegin = false;// 加 至行开始

boolean precedingBackslash = false;// 反斜杠

boolean skipLF = false;

while (true) {

if (inOff >= inLimit) {

// 从输入流中读取一定数量的字节并将其存储在缓冲区数组inCharBuf/inByteBuf中,这里区分字节流和字符流

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

// 读取到的为空.

if (inLimit

if (len == 0 || isCommentLine) {

return -1;

}

return len;

}

}

if (inStream != null) {

// 由于是字节流,需要使用ISO8859-1来解码

c = (char) (0xff & inByteBuf[inOff++]);

} else {

c = inCharBuf[inOff++];

}

if (skipLF) {

skipLF = false;

if (c == '\n') {

continue;

}

}

if (skipWhiteSpace) {

if (c == ' ' || c == '\t' || c == '\f') {

continue;

}

if (!appendedLineBegin && (c == '\r' || c == '\n')) {

continue;

}

skipWhiteSpace = false;

appendedLineBegin = false;

}

if (isNewLine) {

isNewLine = false;

if (c == '#' || c == '!') {

// 注释行,忽略.

isCommentLine = true;

continue;

}

}

// 读取真正的属性内容

if (c != '\n' && c != '\r') {

// 这里类似于ArrayList内部的容量扩充,使用字符数组来保存读取的内容. lineBuf[len++] = c;

if (len == lineBuf.length) {

int newLength = lineBuf.length * 2;

if (newLength

newLength = Integer.MAX_VALUE;

}

char[] buf = new char[newLength];

System.arraycopy(lineBuf, 0, buf, 0, lineBuf.length);

lineBuf = buf;

}

if (c == '\\') {

precedingBackslash = !precedingBackslash;

} else {

precedingBackslash = false;

}

} else {

// reached EOL 文件结束

if (isCommentLine || len == 0) {

isCommentLine = false;

isNewLine = true;

skipWhiteSpace = true;

len = 0;

continue;

}

if (inOff >= inLimit) {

inLimit = (inStream == null) ? reader.read(inCharBuf)

: inStream.read(inByteBuf);

inOff = 0;

if (inLimit

return len;

}

}

if (precedingBackslash) {

len -= 1;

skipWhiteSpace = true;

appendedLineBegin = true;

precedingBackslash = false;

if (c == '\r') {

skipLF = true;

}

} else {

return len;

}

}

}

}

}

这里特别的是,实际上,Properties从流中加载属性集合,是通过将流中的字符或者字节分成一行行来处理的。

 请说一下Struts2的初始化?和类的创建?(从源代码角度出发)

(我当时回答这个问题的思路我想应该对了, 我说是通过反射加配置文件来做的)

由于这个问题研究起来可以另外写一篇专门的模块,这里只列出相对简单的流程,后续会希望有时间整理出具体的细节: 首先,Struts2是基于Xwork框架的,如果你有仔细看过Xwork的文档,你会发现,它的初始化过程基于以下几个类: Configuring XWork2 centers around the following classes:- 1. ConfigurationManager 2. ConfigurationProvider

3. Configuration 而在ConfigurationProvider的实现类XmlConfigurationProvider 的内部,你可以看到下面的代码 Java代码

this(

}

Java代码

this(

}

同样的,Struts2的初始化也是这样的一个类,只不过它继承于Xwork原有的类,并针对Struts2做了一些特别的定制。 Java代码

1.

2. extends XmlConfigurationProvider {

3. public StrutsXmlConfigurationProvi

1 JDK5支持泛型,泛型是如何实现的,应用反射API操作泛型变量时,泛型还起作用吗?

2 Class.forName(


相关内容

  • 阿里巴巴待遇究竟有多好?如何才能到阿里巴巴上班?
  • 这个问题,其实是很多年轻人的梦想,阿里巴巴不仅待遇好,环境也是十分不错的.阿里巴巴的总部的园区又名淘宝城,规划的占地面积29万平方米,包括了员工主办公区.食堂.健身房.报告厅和影视放映厅等日常办公休闲的基础设施.阿里巴巴这家公司的精彩,你永远无法假装看不见,天生自带主角光环的人物设定,让这家公司的一 ...

  • 深度揭秘阿里巴巴人力资源体系:牛逼的团队是如何建立的?
  • [本文主要标题] 1.阿里巴巴是怎么面试的? 2.阿里巴巴闻味官是怎么回事? 3.阿里巴巴职级怎么设置? 4.阿里巴巴内部怎么晋升? 5.阿里巴巴如何做培训的? 阿里巴巴是怎么面试的? 2009年,我在北京创业,做自己的公司.有一天接到一个电话说"天机老师,您想不想到杭州工作", ...

  • 校园招聘面试心得与总结
  • 校园招聘面试心得与总结---BAT .网易.蘑菇街 2015年12月1日 | 1370人围观 | 0人评论 之前实习的时候就想着写一篇面经,后来忙就给忘了,现在找完工作了,也是该静下心总结一下走过的路程了,我全盘托出,奉上这篇诚意之作,希望能给未来找工作的人一点指引和总结, 也希望能使大家少走点弯路 ...

  • DENA,京东,美团,百度,今日头条,网易,腾讯实习面试总结
  • 简历未过筛选:百度(糯米后台),今日头条(后台开发) 面试挂了的:美团(网页爬虫开发) 收到的offer: DENA(大数据系统后台) 京东(JAVAer) 网易(云存储) 腾讯(SNG的云计算后台) 至于为什么会面这么多公司,主要是考虑到我不考研,想着通过实习找到喜欢做的,然后争取转正,以后好少走 ...

  • 外贸类面试求职技巧
  • 1:守时我是放在第一位的,最好是约定时间提前15分钟左右到面试公司. 一般公司的面试人员不是特地为你一个人服务的.迟到肯定是不好的,而你提前一两个小时跑去面试公司也是很不合适的一件事情,我见过好几个早早来到公司等待面试,而人事经理因为有其他事情要处理,最后面试人员不得不等上一两个小时的尴尬问题,这样 ...

  • 阿里巴巴和华为笔试和面试题[1]
  • 软件测试工程师面试题 阿里巴巴旗下各公司测试笔试和面试如下: 支付宝:        B2B:   笔试题: 根据下图,写出所有的备选流和输出流各个路径 类似下面这篇文章 给出需求设计测试用例: 给出一段需求文档画出流程流程图,并设计出测试用例,例子是留言板功能,从用户登陆到发送消 ...

  • 外贸人员的面试技巧
  • 外贸人员的面试技巧 丽丽在一个外贸公司工作近一年了,看到公司不断有人离开,又不断的有人进来.而新来的面试的人所具备的求职技巧和基本功底普遍缺乏一些面试准备.很多人来面试,以为带上一个英文的四,六级证书就可以了,实在很让人无语.如果想做一个合格的外贸业务员,仅仅有张英文的文凭是很不够的.英文文凭现在对 ...

  • 大学生就业季 求职故事还没结束
  • 因为身材高挑,小陈看上去显得过于瘦弱.今天面对笔者讲述自己的求职经历,她一脸疲倦.她说,一切就像电影般充满戏剧性变化. 小陈是浙江工业大学应届毕业生,刚开始找工作时梦想着能进入媒体.然而实现这个梦想并不容易,她只好放宽视野,去应聘一些公司的网站编辑等岗位,终于等来了面试通知. "第一次接到 ...

  • 4是我的幸运数字
  • 4是我的幸运数字, 我一直是这么觉得的, 这个4月发生了3件事让 标签Tags: 我感觉印象深刻,1:生日,2:腾讯实习生,3:一见钟情于一个女生,1和3不是今天的重点,直接直奔主题吧. 因为3面的时候学姐跟我说, 面试后写面经会提高rp, 如果能过3面一定要写写, 明天是腾讯实习生最后的HR 面试 ...

  • 阿里巴巴电话面试题目
  •  你对Java的集合框架了解吗? 能否说说常用的类? Java集合框架类图: 我常用的类: HashMap,Hashtable,HashSet,ArrayList,Vector,LinkedList,Collections,Arrays;  说说Hashtable与HashMap的区别(源代码级 ...