<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小明思考

    Just a software engineer
    posts - 124, comments - 36, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    有點難度的java筆試題

    Posted on 2012-11-07 09:46 小明 閱讀(2541) 評論(3)  編輯  收藏 所屬分類: 開發日志
    以下是我在上一家公司出的java筆試題,有些難度,感興趣的同學可以做做看。

    ---Question---

    1.What is the output of the following program? 

    public class Foo {

           public static void main(String[] args){

                  Map<byte[], String> m = new HashMap<byte[], String>();

                  byte[] key = "abcd".getBytes();

                  m.put(key, "abcd");

                  System.out.println(m.containsKey(key));

                  System.out.println(m.containsKey("abcd"));

                  System.out.println(m.containsKey("abcd".getBytes()));

           }

    }

    a) true,true,false b)true,false,false c)true,true,true d) false,false,false e)Program throws an exception

     

    2. What is the proper string filled in the following program?

    Public class Foo {

           public static void main(String[] args) {

                  String s=”1\\2\\3\\4”;

                  //split the string with “\”

                  String []result = s.split(“____”);

                  for(String r:result){

                         System.out.println(r);

                  }

           }

    }

    a) \ b) \\ c) \\\ d)\\\\ e)\\\\\

     

    3. What is the output of the following program? 

    public class Foo {

           public static void main(String[] args) {

                  char[] c = new char[] { '1' };

                  String s = new String(c);

                  System.out.println("abcd" + c);

                  System.out.println("abcd" + s);

           }

    }

    a) Compile error b)abcd1,abcd1 c) abcd49,abcd1 d) Program throws an exception e)none of above

     

    4. Which class is threading safe which one object can be used between multi-threads without extra synchronized? 

    a) Vector b) HashMap c) ArrayList d)StringBuilder e)HashSet

     

    5. What is the output of the following program? 

    public class Foo {

           public static void main(String[] args) throws IOException {

                  ByteArrayOutputStream baos = new ByteArrayOutputStream();

                  byte[] b = new byte[]{(byte)0x0,(byte)0x1,(byte)0x2};

                  baos.write(b);

                  baos.write(0x0102);

                  byte[] result = baos.toByteArray();

                  ByteArrayInputStream bais = new ByteArrayInputStream(result);

                  System.out.println(bais.available());

           }

    }

    a) 0 b) 1 c)4 d) 5 e) Program throws an exception

     

    6. What is return value of function “calc”?

    public class Foo {

           public static int calc() throws IOException{

                  int ret = 0;

                  try{

                         ++ret;

                         throw new IOException("try");

                  }

                  catch(IOException ioe){

                         --ret;

                         return ret;

                  }

                  finally{

                         ++ret;

                         return ret;

                  }

           }

    }

    a) 0 b) 1 c)2 d)3 e) throws an exception

     

    7. What is the output of the following program?

    public class Foo {

           public static class Value {

                  private int value;

                  public int get(){

                         return value;

                  }

                  public void set(int v){

                         value = v;

                  }

           }

           public static class Values implements Iterable<Value>{

                  public Values(int capacity){

                         this.capacity = capacity;

                  }

                 

                  int count =1 ;

                  int capacity;

                  Value v = new Value();

                  public Iterator<Value> iterator() {

                         return new Iterator<Value>(){

                                public boolean hasNext() {

                                       return count<=capacity;

                                }

     

                                public Value next() {

                                       v.set(count++);

                                       return v;

                                }

     

                                public void remove() {

                                       throw new UnsupportedOperationException();

                                }

                         };

                  }

           }

           public static void main(String[] args) {

                  Values vs = new Values(10);

                  Value result = null;

                  for(Value v:vs){

                         if(result ==  null){

                                result = v;

                         }

                         else{

                                result.set(result.get()+v.get());

                         }

                  }

                  System.out.println(result.get());

           }

    }

    a)       20 b)40 c)45 d)55 e)throws NullpointerException

     

    8. If add keyword “final” before a class member function, it means:

    a) The method can’t access the non-final member variable.

    b) The method can’t modify the member variable.

    c) The method can’t be override by subclass.

    d) The method is a thread-safe function.

    e) The method can’t be accessed by other non-final function.

     

    9. About java memory and garbage collector, which statement is correct?

    a) Moving variable from locale to class will make GC more effectively.

    b) When Full GC is executing, all the user threads will be paused.

    c) If object A contains a reference of object B and object B contains a reference of object A, the two objects can’t be reclaimed by GC.

    d) When a thread exits, all objects which created by that thread will be reclaimed

    e) It is recommended that calling “System.gc()” to control the memory usage.

     

    10. About java classpath and classloader, which statement is NOT correct?

    a) User can specify the classpath by using the option “-cp” in Java command line.

    b) If user doesn’t specify classpath, the JVM search the class from the current folder by default.

    c) A JVM can load two different versions of a library.

    d) To define customized class loader, it is possible to load class from internet at runtime.

     

     

    11. Which data structure has best performance when remove an element from it?

    a) Vector b)ArrayList c)LinkedList d)HashMap e)HashSet

     

    12. Which is the correct way to convert bytes from charset “gb2312” to “utf-8”?

    byte[] src , dst;

    a) dst = new String(src,”utf-8”).getBytes(“gb2312”);

    b) dst = new String(src,”gb2312”).getBytes(“utf-8”);

    c) dst = new String(src,”utf-16”).getBytes();

    d) dst = new String(src).getBytes();

    e) None of above.

     


    評論

    # re: 有點難度的java筆試題[未登錄]  回復  更多評論   

    2013-04-17 10:42 by Harry
    what is the correct answer of question 10? I choose 'e' - none of above.
    for (c), think about OSGi.

    if it said that a classloader can load two version of library, the answer would be (c) as a jvm has many classloaders, each of which could load the same library.

    # re: 有點難度的java筆試題  回復  更多評論   

    2013-04-18 09:32 by 小明
    @Harry

    The answer of question is b

    b) If user doesn’t specify classpath, the JVM search the class from the current folder by default.

    JVM doesn't search the class from the current folder by default.

    # re: 有點難度的java筆試題[未登錄]  回復  更多評論   

    2013-04-18 10:19 by Harry
    right. I forgot that part... in order to search current folder, we have to give it '-cp .'
    主站蜘蛛池模板: 欧美好看的免费电影在线观看| 亚洲国产综合精品中文第一区| 国产亚洲精品国看不卡| 亚洲欧洲∨国产一区二区三区| 亚洲精品视频在线免费| 日韩电影免费观看| 亚洲精品在线观看视频| 免费人成视频在线观看网站| 久久精品亚洲一区二区| 久久国产乱子免费精品| 亚洲国产综合自在线另类| 亚欧在线精品免费观看一区| 亚洲国产精品综合久久一线| 一边摸一边爽一边叫床免费视频| 97视频热人人精品免费| 亚洲一线产品二线产品| 国产又长又粗又爽免费视频 | 亚洲色图黄色小说| 99久久久精品免费观看国产| 亚洲中文字幕一二三四区苍井空| 两性色午夜视频免费播放| 亚洲福利视频一区| 午夜福利不卡片在线播放免费| 精品久久久久久亚洲| 亚洲第一se情网站| 国产片AV片永久免费观看| 在线综合亚洲欧洲综合网站| 99久久免费中文字幕精品| 亚洲一级免费毛片| 最近免费最新高清中文字幕韩国 | 特级毛片A级毛片100免费播放| 毛片免费视频播放| 狠狠热精品免费观看| 亚洲国产一区在线| 男女作爱在线播放免费网站| 亚洲人成电影青青在线播放| 性无码免费一区二区三区在线| 国产亚洲综合久久系列| 国产精品美女午夜爽爽爽免费| 亚洲一区二区三区四区视频| 精品成在人线AV无码免费看|