華為JAVA(面試問題及答案節)


 
華為 JAVA 面試題
(后記:我沒想到華為面試題是不尋常,,至少對我這種鳥來說是這樣。對我個人來說。看看這樣的題。可能比看《Think In Java》都還要好。因為這里面有很多的東西,都是我們平時沒有太在意,或者是只是懂一點皮毛而已,通過做一下這樣的練習。把自己不知道、不熟悉的知識點,利用這個機會好好的鞏固一下。

這些答案是我自己做的,有一些是從網上來的,有一部是自己做的,並且還有一部份沒有做完。我不敢保證都對,所以請你在引用的時候。務必通過自己核對一下。

當然。我既然能夠把這些答案放在這里,那說明我肯定是自己檢驗了一遍的,也不是那么恐怖的)

QUESTION NO: 1
public class Test1 {
 
    public static void changeStr(String str){
        str= "welcome" ;
    }
    public static void main(String[] args) {
 
        String str= "1234" ;
        changeStr(str);
        System. out .println(str);
    }
}
// 輸出結果: 1234
// 這里雖然是一個靜態方法。但是里面的變量是一個局部變量,
// 所以這里不因為是靜態方法。就誤認為里面的變量也是靜態變量了
 
 
QUESTION NO:2
public class Test2 {
    static boolean foo( char c) {
       System. out .print(c);
       return true ;
    }
    public static void main(String[] argv) {
       int i = 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; }
public class B extends A{
    /**
      * @param args
      */
   
    //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; }
   
    /**
      * 總結:類的繼承中。如果要想重載父類的方法。必須要和父類中的返回類型、可見性等等都要操作一致
      * 否則。程序就會報錯。一定遵守子類要遵從於父類的原則
      * 而我選擇的答案居然是 private int method1 static protected int
      * 我選擇第一個的錯誤理由是:因為原來為保護的,如果我這里設為 public ,那么就擴展了其原來的可見性
      * 本來原來就是對包外不可見的。現在變成對包外可見的了,所以就選擇的是 private
      * 選擇第二個的錯誤理由是:都是保護的。這里只是變成了靜態的而已
      */
   
    // 這里是寫了一個重載方法,因為參數類型不一致,不會報錯
    private int method1( int a, long b) { return 0; }
   
    // 可見性可以增大,但是不能夠縮小,正確
    public int method1( int a, int b) { return 0; }
   
    public static void 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()
答案如下:
public class Outer {
    public void someOuterMethod() {
       // Line 3
       new Inner(); // 放在這里不出錯
    }
    public class Inner {
    }
 
    public static void main(String[] argv) {
       Outer o= new Outer();
       // Line 8
       //o 不能夠被解釋成為一種類型,出錯
       //new o.Inner();
       /**
         * 下面兩種用法,都報下面的錯誤:
         * No enclosing instance of type Outer is accessible.
         * Must qualify the allocation with an enclosing instance
         * of type Outer(e.g. x.new A() where x is an instance of Outer)
         */    
       //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 類進行描述)進行定義。

對於業務邏輯的操作則主要由ActionActionMappingActionForward這幾個組件協調完成的,其中Action扮演了真正的業務邏輯的實現者,ActionMappingActionForward則指定了不同業務邏輯或流程的運行方向。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';
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM