3.原生類中的資料類型均可任意轉換。( )
答案:錯誤
(後記:沒有想到華為的面試題就是非同一般,很多題不是一眼就能夠看得出來,至少對我這種鳥來說是這樣。對我個人來說,看看這樣的題,可能比看《Think In Java》都還要好,因為這裡面有很多的東西,都是我們平時沒有太在意,或者是只是懂一點皮毛而已,通過做一下這樣的練習,把自己不知道、不熟悉的知識點,利用這個機會好好的鞏固一下。這些答案是我自己做的,有一些是從網上來的,有一部是自己做的,並且還有一部份沒有做完,我不敢保證都對,所以請你在引用的時候,務必通過自己核對一下。當然,我既然能夠把這些答案放在這裡,那說明我肯定是自己檢驗了一遍的,也不是那麼恐怖的)
QUESTION NO: 1
publicclass Test1 {
publicstaticvoid changeStr(String str){
str="welcome";
}
publicstaticvoid main(String[] args) {
String str="1234";
changeStr(str);
System.out.println(str);
}
}
//輸出結果:1234
//這裡雖然是一個靜態方法,但是裡面的變數是一個局部變數,
//所以這裡不因為是靜態方法,就誤認為裡面的變數也是靜態變數了
QUESTION NO:2
publicclass Test2 {
staticboolean foo(char c) {
System.out.print(c);
returntrue;
}
publicstaticvoid main(String[] argv) {
int i = 0;
//for(65;88&&(i<2);67)
for (foo('A'); foo('B') && (i < 2); foo('C')) {
i++;
foo('D');
}
}
}
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; }
publicclass B extends A{
//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; }
//這裡是寫了一個重載方法,因為參數類型不一致,不會報錯
privateint method1(int a, long b) { return 0; }
//可見度可以增大,但是不能夠縮小,正確
publicint method1(int a, int b) { return 0; }
publicstaticvoid main(String[] args) {
// TODO Auto-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()
答案如下:
publicclass Outer {
publicvoid someOuterMethod() {
// Line 3
new Inner();//放在這裡不出錯
}
publicclass Inner {
}
publicstaticvoid main(String[] argv) {
Outer o= new Outer();
// Line 8
//o不能夠被解釋成為一種類型,出錯
//new o.Inner();
//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所示: