亚洲精品tv久久久久久久久,亚洲一级毛片免费看,老司机亚洲精品影院无码http://m.tkk7.com/sandy/category/51017.htmlJust a software engineerzh-cnWed, 07 Nov 2012 11:46:50 GMTWed, 07 Nov 2012 11:46:50 GMT60有點(diǎn)難度的java筆試題http://m.tkk7.com/sandy/archive/2012/11/07/390916.html小明小明Wed, 07 Nov 2012 01:46:00 GMThttp://m.tkk7.com/sandy/archive/2012/11/07/390916.htmlhttp://m.tkk7.com/sandy/comments/390916.htmlhttp://m.tkk7.com/sandy/archive/2012/11/07/390916.html#Feedback0http://m.tkk7.com/sandy/comments/commentRss/390916.htmlhttp://m.tkk7.com/sandy/services/trackbacks/390916.html

---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.

 



小明 2012-11-07 09:46 發(fā)表評論
]]>
使用Amazon EC2 命令行工具http://m.tkk7.com/sandy/archive/2012/03/07/371409.html小明小明Wed, 07 Mar 2012 08:03:00 GMThttp://m.tkk7.com/sandy/archive/2012/03/07/371409.htmlhttp://m.tkk7.com/sandy/comments/371409.htmlhttp://m.tkk7.com/sandy/archive/2012/03/07/371409.html#Feedback0http://m.tkk7.com/sandy/comments/commentRss/371409.htmlhttp://m.tkk7.com/sandy/services/trackbacks/371409.html閱讀全文

小明 2012-03-07 16:03 發(fā)表評論
]]>
詭異的mysql latin1編碼http://m.tkk7.com/sandy/archive/2012/02/24/mysql_latin1.html小明小明Fri, 24 Feb 2012 06:54:00 GMThttp://m.tkk7.com/sandy/archive/2012/02/24/mysql_latin1.htmlhttp://m.tkk7.com/sandy/comments/370685.htmlhttp://m.tkk7.com/sandy/archive/2012/02/24/mysql_latin1.html#Feedback0http://m.tkk7.com/sandy/comments/commentRss/370685.htmlhttp://m.tkk7.com/sandy/services/trackbacks/370685.html

Mysql 的latin1 不等于標(biāo)準(zhǔn)的latin1(iso-8859-1) 和cp1252,比iso-8859-1多了0x80-0x9f字符,比cp1252多了0x81,0x8d,0x8f,0x90,0x9d 一共5個字符。

 

http://dev.mysql.com/doc/refman/5.0/en/charset-we-sets.html

latin1 is the default character set. MySQL's latin1 is the same as the Windows cp1252 character set. This means it is the same as the official ISO 8859-1 or IANA (Internet Assigned Numbers Authority) latin1, except that IANA latin1 treats the code points between 0x80 and 0x9f as “undefined,” whereas cp1252, and therefore MySQL's latin1, assign characters for those positions. For example, 0x80 is the Euro sign. For the “undefined” entries in cp1252, MySQL translates 0x81 to Unicode 0x0081, 0x8d to 0x008d, 0x8f to 0x008f, 0x90 to 0x0090, and 0x9d to 0x009d.
這樣在Java中,如果使用標(biāo)準(zhǔn)的iso-8859-1或者cp1252解碼可能出現(xiàn)亂碼。
s.getBytes("iso-8859-1") 或者 s.getBytes("cp1252");

寫了一段代碼來解決這個問題
private String convertCharset(String s){
        
if(s!=null){
            
try {
                
int length = s.length();
                
byte[] buffer = new byte[length];
                
//0x81 to Unicode 0x0081, 0x8d to 0x008d, 0x8f to 0x008f, 0x90 to 0x0090, and 0x9d to 0x009d.
                for(int i=0;i<length;++i){
                    
char c = s.charAt(i);
                    
if(c==0x0081){
                        buffer[i]
=(byte)0x81;
                    }
                    
else if(c==0x008d){
                        buffer[i]
=(byte)0x8d;
                    }
                    
else if(c==0x008f){
                        buffer[i]
=(byte)0x8f;
                    }
                    
else if(c==0x0090){
                        buffer[i]
=(byte)0x90;
                    }
                    
else if(c==0x009d){
                        buffer[i]
=(byte)0x9d;
                    }
                    
else{
                        buffer[i] 
= Character.toString(c).getBytes("cp1252")[0];
                    }
                }
                String result 
= new String(buffer,"utf-8");
                
return result;
            } 
catch (UnsupportedEncodingException e) {
                logger.error(
"charset convert error", e);
            }
        }
        
return null;
    }


小明 2012-02-24 14:54 發(fā)表評論
]]>
Snaker開發(fā)筆記(1)-實現(xiàn)插件http://m.tkk7.com/sandy/archive/2012/01/20/368643.html小明小明Fri, 20 Jan 2012 07:27:00 GMThttp://m.tkk7.com/sandy/archive/2012/01/20/368643.htmlhttp://m.tkk7.com/sandy/comments/368643.htmlhttp://m.tkk7.com/sandy/archive/2012/01/20/368643.html#Feedback2http://m.tkk7.com/sandy/comments/commentRss/368643.htmlhttp://m.tkk7.com/sandy/services/trackbacks/368643.html閱讀全文

小明 2012-01-20 15:27 發(fā)表評論
]]>
Java 控制臺中文問題(windows平臺)http://m.tkk7.com/sandy/archive/2012/01/19/368747.html小明小明Thu, 19 Jan 2012 08:18:00 GMThttp://m.tkk7.com/sandy/archive/2012/01/19/368747.htmlhttp://m.tkk7.com/sandy/comments/368747.htmlhttp://m.tkk7.com/sandy/archive/2012/01/19/368747.html#Feedback1http://m.tkk7.com/sandy/comments/commentRss/368747.htmlhttp://m.tkk7.com/sandy/services/trackbacks/368747.html閱讀全文

小明 2012-01-19 16:18 發(fā)表評論
]]>
java i18n kithttp://m.tkk7.com/sandy/archive/2005/12/19/24655.html小明小明Mon, 19 Dec 2005 09:26:00 GMThttp://m.tkk7.com/sandy/archive/2005/12/19/24655.htmlhttp://m.tkk7.com/sandy/comments/24655.htmlhttp://m.tkk7.com/sandy/archive/2005/12/19/24655.html#Feedback1http://m.tkk7.com/sandy/comments/commentRss/24655.htmlhttp://m.tkk7.com/sandy/services/trackbacks/24655.htmlHere is my some recommendations for java i18n .

1.  The correct way to handle text-based resource files for localization

 Use java.util.ResourceBoundle to read resource from file.

e.g.
 Local local = Local.CHINA;
 ResourceBundle rb = ResourceBundle.getBundle("test", local);
 String title = rb.getString("helloworld.title");
 System.out.println(title);

 //The program will read file: test_zh.properties
 # This locale is zh_CN
 # helloworld.title=中文1234
 and the file should use native2ascii program to convert (native2ascii.exe is in JDK)
 # This locale is zh_CN
 helloworld.title=\u4f60\u597d1234

 if you don't use native2ascii  to covert,you must covert it in the java program,like this:
 ResourceBundle rb = ResourceBundle.getBundle("test", Locale.CHINA);
     String title = rb.getString("helloworld.title");
    System.out.println(new String(title.getBytes("8859_1")));  //covert to os/jvm default charset

2.       Locale driven date and time display
 
 Use java.text.DateFormat to format date string
e.g.
 DateFormat df = DateFormat.getDateInstance(DateFormat.FULL,Locale.CHINA);
 String date = df.format(new Date());
    System.out.println(date);

 DateFormat df2 = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.DEFAULT,Locale.CHINA);
 String datetime = df2.format(new Date());
    System.out.println(datetime);

3.       JSP localization method.

1) native method:
 use "Local local = request.getLocale();" to get the page accessor's local info
 then use ResourceBoundle to read local resource
 and page should use utf-8 charset
 
e.g.
<%@ page contentType="text/html; charset=utf-8" %>
<%
Local local = request.getLocale();
ResourceBundle rb = ResourceBundle.getBundle("test", local);
String title = rb.getString("helloworld.title");
%>
<html>
<head>
<title>test</title>
</head>
<body bgcolor="#ffffff">
<h1><%=title%></h1>
</body>
</html>
notice:put the  test_zh.properties into directionary WEB_INF/classes

2)use jsp taglib to simplify the page

 the Jakarta i18n taglib is a good choice. http://jakarta.apache.org/taglibs/doc/i18n-doc/index.html
e.g.
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="<i18n:bundle baseName="test" id="test" localeRef="userLocale"
             scope="request"
             changeResponseLocale="false"/>
<html>
<head>
<title>test</title>
</head>
<body bgcolor="#ffffff">
<h1><i18n:message key="helloworld.title" /></h1>
</body>
</html>

3)use j2ee web framework(Struts) to simplify

 the Struts web framework supply i18n support
 Please refer:
http://www.allapplabs.com/struts/struts_internationalization.htm



小明 2005-12-19 17:26 發(fā)表評論
]]>
主站蜘蛛池模板: 免费黄色网址入口| 巨波霸乳在线永久免费视频| 好吊妞788免费视频播放| 亚洲精品美女视频| 91麻豆国产免费观看| 久久久久亚洲AV片无码下载蜜桃| 在线成人精品国产区免费| 亚洲第一AAAAA片| 久艹视频在线免费观看| 亚洲国产综合精品中文第一区| 国产一级淫片a免费播放口| 国产精品亚洲A∨天堂不卡 | 好看的亚洲黄色经典| 中文成人久久久久影院免费观看| 亚洲另类激情综合偷自拍图| 国产啪精品视频网站免费尤物| 久久青青成人亚洲精品| 日韩电影免费观看| 亚洲日韩乱码久久久久久| 在线视频观看免费视频18| 狼人大香伊蕉国产WWW亚洲| 亚洲女人被黑人巨大进入| 国产一二三四区乱码免费| 久久精品国产亚洲AV嫖农村妇女| 亚洲一区二区三区免费观看| 亚洲日本va一区二区三区 | 成人性生交视频免费观看| 亚洲国产成人精品无码区花野真一| 国产在线播放免费| 一级特黄录像免费播放肥| 亚洲AV日韩AV永久无码绿巨人| 久久国产免费福利永久| 亚洲第一成年免费网站| 亚洲综合熟女久久久30p| 亚洲国产精品免费在线观看| 亚洲精品久久久久无码AV片软件| 亚洲国产精品国产自在在线| 最刺激黄a大片免费网站| 欧洲亚洲综合一区二区三区| 亚洲gv猛男gv无码男同短文| 免费无码又爽又刺激聊天APP|