有事点这里!

当前位置: 首页 >> IT技术 >> 面试大全 >> 面试时候经常会问的一些问题6

面试时候经常会问的一些问题6

[ 来自:不祥 作者:网络收集 阅读:0 时间:2008-2-2 22:37:38 ]

Q199 Which of the following are methods within the String class.
1) substring()
2) startsWith()
3) toString()
4) toUpperCase()
5) indexOf()

Q200 True or False.
APPLET tags must appear between BODY and /BODY tags.
1) True
2) False

ANSWER:
1. 1,2
Answers 3, 4 and 5 are incorrect because these operations requires that an int (c) be converted to a boolean, or the boolean be converted to an int. Both of these conversions are illegal.
2. 5
A constructor cannot be abstract, final, native, static or synchronized. Refer to the Java Language Specification (section 8.6.3, version 1.0).
3. 4
In general, all components are resized and only retain their preferred height in the NORTH region. However, the CheckBox is not deformable, so it retains it's preferred size.
4. 1,3,4
5. 1
6. 3
When a File class is constructed, it simply creates a handle to a File object. No files are created on the local harddisk.
As the JDK API documentation points out, the File class is "an abstract representation of file and directory pathnames".
The File class also contains directory separator attributes, which are platform specific. Therefore, the directory separator used is irrelevant.

Also, since the File class simply creates a reference to a file object, no exception is thrown if the file already exists on the disk.
7. 1,4,5
Answer 1 is correct, because in read mode, the file must exist if any other operations are to be performed on it.
The RandomAccessFile is not compatible with the Stream or reader/writer classes, so Answer 3 is incorrect.
8. 3
Strings are immutable, and so they cannot be modified. However, as the JDK API documentation will show, the String class has a replace() method, so answer 1 is incorrect.
If line 2 read as "s = s.replace('d', 'q')" then a new object would be created and assigned to s. The value of this new String object would be "abcqefgh". However, as line 2 is presented, no new object is created, and so 's' remains unchanged.
9. 1,5
10. 2
I came across the statement during my study for the exam, and simply noted it as fact. I never really looked too deeply into it - so please don't email me for an explanation :-)
11. 1,4,5

Therefore, Answer 1 is correct, because class B attempts to override method() to be less public (ie, protected to "friendly").

Answer 2 is incorrect, because a protected variable or method is always available to child classes (this is the purpose of the protected keyword).

Answer 3 is incorrect, because all the information needed to verify this code is available at compile time.

Answers 4 and 5 are correct because adding either "public" or "protected" to line 7 actually moves it higher up the access hierarchy (ie, more public than friendly).

12. 1
13. 2
14. 1
15. 3
16. 2
The rule for accessing methods and variables in a class hierarchy is as follows:

-the object reference is used when accessing variables (so the value of b.x is therefore 2).

-the underlying object is used when accessing methods (so the method called is actually the method defined in Subclass, and in Subclass, x =3).
17. 1
18. 2
19. 2
20. 1,2,3
1. 3
22. 1
23. 1
24. 1
25. 4
26. 1,4,5
Answer 1 is correct, because x is declared as private to class A and is therefore not available to any other class (even subclasses).
Answer 3 is totally meaningless, but sounds vaguely plausible!
Answer 4 is correct, because the only problem with the code is the attempt to reference the variable x.
Answer 5 is correct (see answer 4).
27. 3
28. 2,3,4,5
29. 1
Answer 2 is incorrect, since the {} defines an empty method (but still a method) so it is not abstract.
Abstract methods cannot be static, so answer 3 is incorrect.
Abstract and final are almost opposite in meaning and therefore do not form a valid keyword combination (final means a method can't be overridden, abstract means a method must be overridden), so answer 4 is incorrect.
30. 2
31. 4
Interfaces cannot have constructors, only classes have constructors.
Answer 2 is a valid statement when dealing with classes, but not in the context of the code in the question.
Answer 5 is totally untrue, but potentially confusing :-)
32. 1
33. 1,2,4
34. 1
Answer 2 is incorrect, because booleans can't have integer values (in this case, "1").
Answer 3 is an meaningless statement.
Answer 5 is incorrect, attempting to confuse C/C++ and Java ways of defining true and false boolean values.
35. 2,4
36. 2
37. 2
38. 1,2
39. 3
40. 1
41. 2
42. 3
43. 1,3
44. 1,2,3
45. 2
46. 1,2,4,5
47. 1
48. 2
49. 1.4
50. 3,4
Answer 1 is incorrect, because a class can have final methods and variables without the need for the entire class to be final.
Answer 2 is incorrect, because the type of error in this code is detectable at compile time.
Answer 5 is invalid. Final can be applied to primitives.
51. 4
52. 1
53. 1,2,3,4,5
54. 2
55. 2.3
56. 3
57. 1,3,4
58. 3,5
59. 1,3,4,5
60. 5
61. 3
62. 4
63. 1,4
64. 4
65. 2,3
66. 1,3,4,5
67. 5
68. 2
69. 4
70. 5
71. 4
72. 2
73. 3
74. 2
75. 1
76. 1
77. 4
78. 3
79. 2
80. 3
81. 3
82. 3
83. 1,2,5
84. 5
85. 4
86. 2,3
There are several things wrong with this code:
- class A must be declared as abstract, since method() is declared as abstract
- if class A is declared as abstract, then the code will compile correctly
- if the abstract declaration of method() in class A is removed, the code will compile (however, the entire line 2 must now read as follows:
int method(){}
In other words, a method body must now be supplied since the method is no longer abstract.
87. 3
88. 2,5
89. 3
90. 2
91. 1
92. 3,4,5
93. 2,3,5
94. 1,5
95. 2,3
96. 3.
97. 1,2
98. 2
The instanceof operator can be used as follows:
- on classes to see if a particular class is derived from another (ie, is an instance of)
- on interfaces to see if a class implements a particular interface
99. 1,3,4
100. 1,2,3,4,5
101. 1,2,3,4,5
102. 2,3,4
103. 2
104. 1,2,5
105. 4
106. 3,4,5
107. 4,5
108. 3
109. 1,3,5
110. 3
111. 1
112. 4
113. 1
114. 4
115. 2
1 will not compile, because 123 defaults to type int, and there is no constructor of the Byte class which takes type int as a parameter.
2 compiles correctly, because a parseable string is a valid parameter for the Byte constructor.
3 fails to compile, because there is no no-args constructor for the Byte class.
4 fails to compile. While the cast to an int is valid, the same reasons as Answer 1 apply.
5 fails to compile, because the value 0x123 is a hex value, and equates to a decimal value of 291. This is not within the valid range for the Byte value.
116. 2
117. 2,4
118. 1,5
119. 2
120. 2,3
121. 1,2
122. 1
123. 2
124. 2,4
125. 3,4,5
126. 1,2,3
127. 1
Thanks to Prasad for rightly pointing out that Answer 2 above also works for a container which uses the Flow Layout manager (even though it doesn't have a "Center" area").
This can be explained by the fact that a container such as a Panel inherits from java.awt.Container, which has a method with a signature as follows:
add(String, Component)
However, while this is symantically correct (ie, it will compile and function correctly), it can't be considered as a valid answer since Flow layout doesn't have the concept of a "Center" area - at least, that's my opinion :-)
However, this raises an interesting point - where possible, you should use static class variables, where a choice is available - eg, use BorderLayout.NORTH instead of "NORTH" when adding components to a container. This will ensure that any errors are trapped at compile time, rather than at run-time :-)
128. 2
129. 3
130. 3
131. 5
132. 1
133. 3
134. 3
135. 1,2,4,5
136. 4,5
137. 1
138. 1
139. 1
140. 1
141. 3
142. 1,2
143. 3
144. 5
145. 1,2,3,4
146. 1,2,3
147. 4
148. 1
149. 2
150. 1
151. 3
152. 1,2,3,4,5
153. 2
154. 2
155. 1
156. 2
157. 1,2,3,4
158. 1
159. 1,3
160. 1
161. 1
162. 2
163. 2
164. 1,2,5
165. 1,2,4
166. 2
167. 1
168. 1
169. 1
170. 1,2,3
171. 1
172. 1
173. 1
174. 3
175. 2
176. 1
177. 4
178. 3
179. 1,2,4,5
180. 2,3,5
181. 3,4
182. 1,3,4
183. 2,4,5
184. 1,2,3
185. 3
186. 1
187. 1
188. 3
189. 2,5
190. 3
191. 5
192. 2,4
193. 4
194. 3
195. 4
196. 2
197. 4
198. 3
199. 1,2,3,4,5
200. 1

SCJP 模拟考试题, 笔试常考

http://beansoft.java-cn.org/download/scjp_emulator.zip 700KB Java 1.4 版本

是我很早以前买的一本英文 SCJP 辅导书里面所附带的代码.
下载后解压缩得到几个 JAR 文件 下载后 Windows 下可以双击运行, 点击最大化后, 然后点击 Mark 按钮就可以看到正确答案和解释了.
Linux/Windows 下都通过命令行键入
java -jar Final.jar 这样的命令即可运行.

现在的 Java 笔试题 的基础部分(core java)很多都是从类似这样的英文题里面抽取出来的, 基本上熟悉之后笔试题会答的很漂亮.
界面截图:


再转载: 阅读完此贴你才可以大胆的高薪工作!http://bbs.tarena.com.cn/topic.cgi?forum=1&topic=10848&show=0
大家找工作就要面试,有面试就有对付面试的办法。以下一些题目来自我朋友痛苦的面试经历,他给我总结了一下,我拿来和大家分享!提这些问题的公司包括IBM, E*Trade, Siebel, Motorola, SUN, 以及其它大小公司。   
面试是没什么道理可讲的,它的题目有的不合情理、脱离实际。有在纸上写的,有当面考你的,也有在电话里问的,给你IDE的估计很少(否则你赶快去买彩票, 说不定中)。所以如果你看完此文后,请不要抱怨说这些问题都能用IDE来解决。你必须在任何情况下准确回答这些问题,在面试中如果出现一两题回答不准确很有可能你就被拒之门外了。   当然这些都是Java的基本题,那些面试的人大多数不会问你Hibernate有多先进,Eclipse的三个组成部分,或command design pattern,他们都是老一辈了,最喜欢问的就是基础知识。别小看了这些基础,我朋友水平挺可以的,结果就栽在一道基础知识的问题上,和高薪无缘。
希望这些知识点对大家有所帮助,愿大家从达内出来后都能找到高薪的工作!


第一,谈谈final, finally, finalize的区别。   final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。finally是异常处理语句结构的一部分,表示总是执行。finalize是Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等。  

第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 可以继承其他类或完成其他接口,在swing编程中常用此方式。  

第三,Static Nested Class 和 Inner Class的不同,说得越多越好(面试题有的很笼统)。 Static Nested Class是被声明为静态(static)的内部类,它可以不依赖于外部类实例被实例化。而通常的内部类需要在外部类实例化后才能实例化。  

第四,&和&&的区别。 &是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and).  

第五,HashMap和Hashtable的区别。 HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空(null)键值(key),由于非线程安全,效率上可能高于Hashtable.  

第六,Collection 和 Collections的区别。   Collection是集合类的上级接口,继承与他的接口主要有Set 和List.Collections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作。  

第七,什么时候用assert。 1.4新增关键字(语法),用于测试boolean表达式状态,可用于调试程序。使用方法 assert <boolean表达式>,表示如果表达式为真(true),则下面的语句执行,否则抛出AssertionError。另外的使用方式assert < boolean表达式>:<other表达式>,表示如果表达式为真,后面的表达式忽略,否则后面表达式的值用于AssertionError的构建参数。注意编译时要增加-source 1.4 参数,否则报错。]运行时要增加 -ea参数,否则assert行被忽略  

第八,GC是什么? 为什么要有GC?   GC是垃圾收集的意思(Gabage Collection),内存处理是编程人员容易出现问题的地方,忘记或者错误的内存回收会导致程序或系统的不稳定甚至崩溃,Java提供的GC功能可以自动监测对象是否超过作用域从而达到自动回收内存的目的,Java语言没有提供释放已分配内存的显示操作方法。   

第九,String s = new String("xyz");创建了几个String Object? 两个  

第十,Math.round(11.5)等於多少? Math.round(-11.5)等於多少? Math.round(11.5)==12Math.round(-11.5)==-11round方法返回与参数最接近的长整数,参数加1/2后求其floor.  

第十一,short s1 = 1; s1 = s1 1;有什么错? short s1 = 1; s1 = 1;有什么错? short s1 = 1; s1 = s1 1; (s1 1运算结果是int型,需要强制转换类型)short s1 = 1; s1 = 1;(可以正确编译)  

第十二,sleep() 和 wait() 有什么区别? sleep是线程类(Thread)的方法,导致此线程暂停执行指定时间,给执行机会给其他线程,但是监控状态依然保持,到时后会自动恢复。调用sleep不会释放对象锁。wait是Object类的方法,对此对象调用wait方法导致本线程放弃对象锁,进入等待此对象的等待锁定池,只有针对此对象发出notify方法(或notifyAll)后本线程才进入对象锁定池准备获得对象锁进入运行状态。  

第十三,Java有没有goto? 没有  很十三的问题,如果哪个面试的问到这个问题,我劝你还是别进这家公司。(完)(job.sohu.com)

第十四,数组有没有length()这个方法? String有没有length()这个方法?数组没有length()这个方法,有length的属性。String有有length()这个方法。

第十五,Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型?方法的重写Overriding和重载Overloading是Java多态性的不同表现。重写Overriding是父类与子类之间多态性的一种表现,重载Overloading是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding)。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被"屏蔽"了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(Overloading)。Overloaded的方法是可以改变返回值的类型。

第十六,Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?Set里的元素是不能重复的,那么用iterator()方法来区分重复与否。equals()是判读两个Set是否相等。equals()和==方法决定引用值是否指向同一对象equals()在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。

第十七,给我一个你最常见到的runtime exception。ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterformatException, SecurityException, SystemException, UndeclaredThrowableException, UnmodifiableSetException, UnsupportedOperationException

第十八,error和exception有什么区别?error 表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出。不可能指望程序能处理这样的情况。exception 表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。

第十九,List, Set, Map是否继承自Collection接口?List,Set是Map不是

第二十,abstract class和interface有什么区别?声明方法的存在而不去实现它的类被叫做抽象类(abstract class),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建abstract 类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。Abstract 类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。接口(interface)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义static final成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,instanceof 运算符可以用来决定某对象的类是否实现了接口。

第二十一,abstract的method是否可同时是static,是否可同时是native,是否可同时是synchronized?都不能

第二十二,接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)?接口可以继承接口。抽象类可以实现(implements)接口,抽象类是否可继承实体类,但前提是实体类必须有明确的构造函数。

第二十三,启动一个线程是用run()还是start()?启动一个线程是调用start()方法,使线程所代表的虚拟处理机处于可运行状态,这意味着它可以由JVM调度并执行。这并不意味着线程就会立即运行。run()方法可以产生必须退出的标志来停止一个线程。

第二十四,构造器Constructor是否可被override?构造器Constructor不能被继承,因此不能重写Overriding,但可以被重载Overloading。

第二十五,是否可以继承String类?String类是final类故不可以继承。

第二十六,当一个线程进入一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法?不能,一个对象的一个synchronized方法只能由一个线程访问。

第二十七,try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后?会执行,在return前执行。

第二十八,编程题: 用最有效率的方法算出2乘以8等於几?有C背景的程序员特别喜欢问这种问题。2 << 3

第二十九,两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对?不对,有相同的hash code。

第三十,当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递? 是值传递。Java 编程语言只由值传递参数。当一个对象实例作为一个参数被传递到方法中时,参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变,但对象的引用是永远不会改变的。

第三十一,swtich是否能作用在byte上,是否能作用在long上,是否能作用在String上?switch(expr1)中,expr1是一个整数表达式。因此传递给 switch 和 case 语句的参数应该是 int、 short、 char 或者 byte。long,string 都不能作用于swtich。

第三十二,编程题: 写一个Singleton出来。Singleton模式主要作用是保证在Java应用程序中,一个类Class只有一个实例存在。一般Singleton模式通常有几种种形式:第一种形式: 定义一个类,它的构造函数为private的,它有一个static的private的该类变量,在类初始化时实例话,通过一个public的getInstance方法获取对它的引用,继而调用其中的方法。public class Singleton {  private Singleton(){}  //在自己内部定义自己一个实例,是不是很奇怪?  //注意这是private 只供内部调用  private static Singleton instance = new Singleton();  //这里提供了一个供外部访问本class的静态方法,可以直接访问    public static Singleton getInstance() {    return instance;      } } 第二种形式: public class Singleton {   private static Singleton instance = null;  public static synchronized Singleton getInstance() {  //这个方法比上面有所改进,不用每次都进行生成对象,只是第一次       //使用时生成实例,提高了效率!  if (instance==null)    instance=new Singleton();return instance;   } } 其他形式:定义一个类,它的构造函数为private的,所有方法为static的。
一般认为第一种形式要更加安全些


奥运您知道

动漫情报

影视广场

IT技术

相关文章

QQCAT(www.qqcat.com),资源信息,免费观看。本站所有信息均来自网上,如损害到您的利益,请及时联系我们!
QQCAT版权所有©2007