ºìÁªLinuxÃÅ»§
Linux°ïÖú

Java³£¼ûÎÊÌ⼯½õÀ´×Ô SunÖйú¹Ù·½Õ¾

·¢²¼Ê±¼ä:2006-08-11 00:06:00À´Ô´:ºìÁª×÷Õß:maya_human
ÎÊ: ÈçºÎÉèÖÃJava 2(JDK1.2)µÄ»·¾³±äÁ¿?
´ð:
??Java 2°²×°ºó,ÐèÒªÉèÖÃPATHºÍJAVA_HOME»·¾³±äÁ¿.ÓëJDK1.1²»Í¬µÄÊÇ:ÉèÖúÃJAVA_HOME»·¾³±äÁ¿ºó,JVM½«×Ô¶¯ËÑË÷ϵͳÀà¿âÒÔ¼°Óû§µÄµ±Ç°Â·¾¶.
??Java 2»·¾³±äÁ¿µÄÉèÖÃÈçÏÂÀýËùʾ:
??Solarisƽ̨: setenv JAVA_HOME Java2µÄ°²×°Â·¾¶
??setenv PATH $JAVA_HOME/bin:${PATH}
??Windowsƽ̨: set JAVA_HOME=Java2µÄ°²×°Â·¾¶
??set PATH=$JAVA_HOMEbin;%PATH%

ÎÊ: ÄÄЩJava¼¯³É¿ª·¢¹¤¾ßÖ§³ÖJava 2?
´ð:
??Ä¿Ç°Á÷ÐеÄJava¼¯³É¿ª·¢»·¾³,ÈçInpriseµÄJBuilder,SymantecµÄVisual Cafe, SybaseµÄPowerJ,¶¼Ö§³ÖJava 2.

ÎÊ: Èç¹ûÔÚNetscape»òIEä¯ÀÀÆ÷ÖÐÔËÐÐJava appletʱ³öÏÖÁË´íÎó,ÈçºÎÈ·¶¨´íÎó·¶Î§?
´ð:
??µ±java appletÔÚä¯ÀÀÆ÷ÖÐÔËÐÐʱ,ʹÓõÄÊÇä¯ÀÀÆ÷±¾ÉíµÄȱʡJVM.¶ø²»Í¬ä¯ÀÀÆ÷¶ÔJDKµÄÖ§³Ö³Ì¶ÈÒ²²»¾¡Ïàͬ. Òò´Ë,ÔÚNetscape»òIEä¯ÀÀÆ÷ÖÐÔËÐÐJava applet³öÏÖÁË´íÎó,½¨ÒéʹÓÃJDKÌṩµÄ¹¤¾ßappletviewer»òSun¹«Ë¾µÄHotjavaä¯ÀÀÆ÷À´²âÊÔ¸Ãapplet,ÒÔÈ·¶¨´íÎóµÄ²úÉúÊÇÓëä¯ÀÀÆ÷Ïà¹Ø.
??Èç¹ûappletÔÚappletviewer»òHotjavaÖÐÔËÐÐÒ»ÇÐÕý³£,Ôò´íÎóµÄ²úÉúÊÇÓÉÓÚä¯ÀÀ Æ÷²»ÍêÈ«¼æÈÝJDK¶øÒýÆðµÄ. ´Ëʱ,½â¾ö·½·¨¿ÉÒÔÊÇʹÓÃHotjavaä¯ÀÀÆ÷»òÕß°²×° Sun¹«Ë¾µÄJava Plugin.
??Èç¹ûappletÔÚHotjavaä¯ÀÀÆ÷»òappletviewerÖÐÔËÐм´·¢Éú´íÎó,ÔòÓ¦µ±¸ù¾Ý´íÎó Ìáʾ¼ì²éapplet³ÌÐò.

ÎÊ: µ±ÓÃJDBCÏòÊý¾Ý¿âÖвåÈëÊý¾Ý»ò´ÓÊý¾Ý¿âÖÐÌáÈ¡Êý¾Ýʱ,ΪºÎÓÐʱÖÐÎÄ×Ö·û»áÏÔʾΪÂÒÂë?
´ð:
?? Õâ¸öÎÊÌâµÄʵÏÖͨ³£Óë¸÷¸öJDBC driverµÄʵÏÖÓйØ. Ä¿Ç°´ó¶àÊýJDBC driver²ÉÓñ¾µØ±àÂë¸ñʽÀ´´«ÊäÖÐÎÄ×Ö·û,ÀýÈçÖÐÎÄ×Ö·û"0x4175"»á±»×ª³É"0x41"ºÍ"0x75"½øÐд«Êä. Òò´ËÎÒÃÇÐèÒª¶ÔJDBC driver·µ»ØµÄ×Ö·ûÒÔ¼°Òª·¢¸øJDBC driverµÄ×Ö·û½øÐÐת»».
??µ±ÓÃJDBC driverÏòÊý¾Ý¿âÖвåÈëÊý¾Ýʱ,ÐèÒªÏȽ«Unicodeת³Énative code; µ± JDBC driver´ÓÊý¾Ý¿âÖвéѯÊý¾Ýʱ,ÔòÐèÒª½«native codeת»»³ÉUnicode. ÏÂÃæ¸ø³öÁËÕâÁ½ÖÖת»»µÄʵÏÖ:

String native2Unicode(String s) {
if (s == null || s.length() == 0) {
return null;
}
byte[] buffer = new byte[s.length()];
for (int i = 0; i s.length(); i++) { if (s.charAt(i)>= 0x100) {
c = s.charAt(i);
byte []buf = (""+c).getBytes();
buffer[j++] = (char)buf[0];
buffer[j++] = (char)buf[1];
}
else {
buffer[j++] = s.charAt(i);
}
}
return new String(buffer, 0, j);
}
??³ýʹÓÃÒÔÉÏÁ½¸ö·½·¨Ö®Íâ,ÓÐЩJDBC driverÈç¹û¶Ôjdbc driver ManagerÉèÖÃÁËÕýÈ· µÄ×Ö·û¼¯ÊôÐÔ,ÒÔÉÏ2¸ö·½·¨¾Í²»ÐèÒªÁË.

ÎÊ:µ±ÓÃServletÀ´´¦ÀíhttpÇëÇó²¢²úÉú·µ»ØµÄHTMLÒ³Ãæʱ,ÈçºÎʹHTMLÒ³ÃæÖеÄÖÐÎÄ×Ö·ûÄܹ»Õý³£ÏÔʾ?
´ð:
??javax.servlet.http.HttpResponseÀàÓÃÓÚ²úÉú·µ»ØÒ³Ãæ.ͨ¹ýHttpResponse¶¨ÒåµÄ·½·¨getOutputStream()¿ÉÒÔ»ñµÃServletOutputStreamµÄʵÀý,ÕâÑùÓû§¾Í¿ÉÒÔÀûÓÃServletOutputStream.write·½·¨ÏòÊä³öÁ÷ÖÐдÈë·µ»ØÒ³ÃæµÄÄÚÈÝ. µ«ÊÇServletOutputStreamʹÓõÄÊÇȱʡµÄ±àÂ뷽ʽ,Èç¹ûҪʹ·µ»ØÒ³ÃæÖеÄÖÐÎÄ×Ö ·ûÄܹ»Õý³£ÏÔʾ,×îºÃÏÔʾµØÖ¸¶¨ËùÓõÄ×Ö·û±àÂ뷽ʽ. ͨ³£ÐèÒª¹¹ÔìÒ»¸ö OutputStreamWriter , Àý³ÌÈçÏÂ:

public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
OutputStreamWriter ow = new OutputStreamWriter(out,"GB2312");
ow.write("ÕâÊDzâÊÔ");
ow.flush();
ow.close();
}

ÎÊ:ÈçºÎÉèÖÃJava WebServerµÄCLASSPATH,ÒÔ°üº¬Óû§µÄclassÎļþ?
´ð:
??ÓÐÁ½ÖÖ·½·¨¿ÉÒÔÉèÖÃJava WebServerµÄCLASSPATH»·¾³±äÁ¿,ÒÔʹÓû§±àдµÄServletÄܹ»µ÷ÓÃÓû§µÄclassÎļþ.
??½«Óû§µÄclassÎļþ·Åµ½ JavaWebServer_Dir/classesĿ¼ÏÂ,ÔÚJava WebServer Æô¶¯Ê±,classesĿ¼±»×Ô¶¯¼ÓÈëµ½CLASSPATH»·¾³±äÁ¿ÖÐÁË.
??ÐÞ¸Ähttpd.nojreÎļþ,½«Óû§classÎļþËùÔڵķ¾¶Ãû¼Óµ½CLASSPATH»·¾³±äÁ¿ÖÐ.

ÎÊ:ΪʲôÔÚWindowsƽ̨ÉÏÓÃNaming.lookupÀ´»ñÈ¡Ô¶³ÌRMI¶ÔÏóʱ»áºÜÂý?
´ð:
??»úÆ÷µÄÍøÂçÉèÖò»ÕýÈ·ºÜ¿ÉÄÜ»áÒýÆð¸ÃÎÊÌâµÄ·¢Éú.
??RMIʹÓÃÁËJavaÍøÂçÀà,ÌرðÊÇjava.net.InetAddressÀà,Ëü½«²éѯTCP/IPµÄÖ÷»úÃû, °üÀ¨IPµØÖ·µ½Ö÷»úÃûµÄÓ³ÉäºÍÖ÷»úÃûµ½IPµØÖ·µÄÓ³Éä.ÔÚWindowsƽ̨,ÕâÖÖ²éѯ¹¦ÄÜ ÊÇÓɱ¾µØµÄWindows Socket¿âÀ´ÊµÏÖµÄ. Òò´ËÑÓʱÊÇ·¢ÉúÔÚWindows¿âÖÐ,¶ø·ÇRMIÖÐ.
??Èç¹ûÄãµÄ»úÆ÷ÉèÖóÉʹÓÃDNS,ÎÊÌâͨ³£ÊÇDNS·þÎñÆ÷²é²»µ½Ö÷»úÃû,ÄãËù·¢ÏÖµÄÑÓʱ ÊÇDNS²éѯµÄÑÓʱ. Çë³¢ÊÔ½«RMIͨÐÅÖÐÉæ¼°µ½µÄËùÓÐÖ÷»úÃû/IPµØÖ·¼Óµ½±¾µØÎļþwinntsystem32driversetchosts»òwindowshostsÖÐ. ¸ñʽÈçÏÂ:

??IPµØÖ· Ö÷»úÃû

??Èç´ËÉèÖÃÓ¦µ±¿ÉÒÔÃ÷ÏԵؼõÉÙ²éѯËù»¨µÄʱ¼ä.

ÎÊ: ±àдJava applicationʱ,ÈçºÎÉèÖÃproxyµÄÐÅÏ¢,ÒÔ±ã·ÃÎÊÍⲿÍøÕ¾?
´ð:
??ÈôÔÚjava applicationÖзÃÎÊÍⲿÍøÕ¾,Ê×ÏÈÓ¦ÉèÖÃproxyÐÅÏ¢,ÑùÀý´úÂëÈçÏÂ:

import java.util.properties;

.....

Properties sys = System.getProperties();
sys.put("proxySet","true");
sys.put("proxyHost","myHTTP.proxyserver.com");
sys.put("proxyPort","80");
System.setProperties(sys);
u = new URL(website);
connect = (HttpURLConnection)u.openConnection();
.....


ÎÊ: Swing×é¼þJListµÄÁбíÊý¾ÝÐÞ¸ÄÁË,ÈçºÎ֪ͨJList¸Ä±äÏÔʾ?
´ð:
??JList×é¼þÓÐÒ»¸öµ¥¶ÀµÄÏÔʾģʽListModelÀ´±íʾJListµÄÏÔʾÊý¾Ý.
??JList´´½¨ÒÔºó,JListÊý¾ÝÔªËصÄÖµ¼°Êý¾ÝÔªËصÄÊýÁ¿¿ÉÒÔ¶¯Ì¬µØ¸Ä±ä.
??JListÔÚËüµÄÊý¾ÝģʽListModelÖй۲ìÊý¾ÝµÄ¸Ä±ä.Òò´Ë,Ò»¸öListModel µÄÕýȷʵÏÖÓ¦µ±ÔÚÿ´ÎÊý¾Ý·¢Éú¸Ä±äʱ,֪ͨʼþµÄ¼àÌýÕß.
??µ±Ê¹Óù¹Ô캯ÊýJList(Object[])´´½¨Ò»¸öJListµÄʵÀýʱ,ϵͳ½«×Ô¶¯ ´´½¨Ò»¸öDefaultListModelµÄʵÀýÀ´´æ´¢JListµÄÏÔʾÊý¾Ý, ¿ÉÒÔµ÷Óà DefaultListModelÖж¨ÒåµÄ¼ò±ã·½·¨À´¶¯Ì¬µØÐÞ¸ÄJListµÄÊý¾Ý,Èç removeElementAt(index),addElement(Object)µÈ. DefaultListModel ÔÚÐÞ¸ÄÊý¾ÝµÄͬʱ,½«Í¨ÖªJList¹ØÓÚÊý¾ÝµÄ¸Ä±ä.

ÎÊ:ÔÚJava appletÖÐÈçºÎʵÏÖÒ»¸öģʽ¶Ô»°¿ò?
´ð:
??ÔÚJava appletÖÐʵÏÖģʽ¶Ô»°¿òµÄ¹Ø¼ü¾ÍÊÇÔÚ´´½¨Ò»¸ö¶Ô»°¿òµÄʱºò ҪΪ¸Ã¶Ô»°¿òÖ¸¶¨Ò»¸öÕýÈ·µÄ¸¸´°¿Ú.ÒòΪAppletÊÇPanelÀàµÄ×ÓÀà,²» ¿ÉÒÔ×÷Ϊ¶Ô»°¿òµÄ¸¸´°¿Ú,ËùÒÔÊ×ÏÈÒª»ñµÃappletËùÔڵĴ°¿Ú,×÷Ϊģʽ ¶Ô»°¿òµÄ¸¸´°¿Ú. ÑùÀý´úÂëÈçÏÂ:
.....
Dialog d = new Dialog( getParentWindow(comp),title);
// compΪappletÉϵÄÈÎÒâÒ»¸ö×é¼þ
....
public void getParentWindow(Component compOnApplet,String title){
Container c = compOnApplet.getParent();
while (c != null) {
if (c instanceof Frame)
return (Frame) c;
c = c.getParent();
}
return null;
}

ÎÊ: ÔÚJava appletÖÐÈçºÎÏÔʾÁíÍâÒ»¸öHTMLÒ³Ãæ?
´ð:
??ͨ¹ýjava.applet.Applet.getAppletContext()·½·¨¿ÉÒÔ»ñµÃÓë¸ÃappletÏà¹ØµÄAppletContext, AppletContext.showDocument(URL)·½·¨¾Í¿ÉÒÔʹappletËùÔÚµÄä¯ÀÀÆ÷ÏÔʾÁíÍâÒ»¸öÍøÒ³.

ÎÊ: ÓÃJDKʵÏÖµÄÇ©Ãûapplet,¿É·ñÔÚNetscape»òIEÖÐÔËÐÐ?
´ð:
??ÓÃJDKʵÏÖµÄÇ©Ãûapplet,²»¿ÉÒÔÔÚNetscape»òIEÖÐÔËÐÐ,µ«ÊÇ¿ÉÒÔÔÚHotjavaä¯ÀÀÆ÷ÖÐÔËÐÐ.
??²»Í¬µÄä¯ÀÀÆ÷ÌṩÁ˲»Í¬µÄÇ©Ãûapplet»úÖÆ,ÈçNetscapeÌṩÁËzigbert¹¤¾ßºÍ Capability API, ¶øIEÔòÐèҪʹÓÃCABÎļþ. µ«ÊÇ,ÎÞÂÛÊÇNetscape¹¤¾ß²úÉúµÄ Ç©Ãûapplet,»¹ÊÇÓÃIE²úÉúµÄÇ©Ãûapplet,¶¼²»¿ÉÒÔÔÚÆäËüµÄä¯ÀÀÆ÷ÖÐÔËÐÐ.
??Èç¹ûҪʹJDK²úÉúµÄÇ©ÃûappletÄܹ»ÔÚNetscape»òIEÖÐÔËÐÐ,½â¾ö·½·¨ÊÇÔÚ Netscape»òIEÖа²×°Java Plugin,ÔòÓÃJDKʵÏÖµÄÇ©Ãûapplet¾Í¿ÉÒÔÔÚÕâÁ½ÖÖ ä¯ÀÀÆ÷ÖÐÔËÐÐ.

ÎÊ: ÓÃJNI¼¼Êõ¿ÉÒÔ´ÓJavaÓ¦ÓÃÖе÷ÓÃC³ÌÐò¿â,µ«ÊÇÈçºÎʹ¸ÃC³ÌÐò¿â¿ÉÒÔµ÷ÓÃÁíÍâµÄC³ÌÐò¿â?
´ð:
??Èç¹ûÒ»¸ö±»Javaµ÷ÓõÄC³ÌÐò¿âC1ÈÔÐèÒªµ÷ÓÃÁíÍâÒ»¸öC³ÌÐò¿âC2,ÄÇôÔÚ±àÒëC1µÄʱºòÓ¦µ±Áª½Ó³ÌÐò¿âC2,²½ÖèÈçÏÂ(Solarisƽ̨):
??±àдµ÷ÓÃC¿âµÄJavaÎļþ,²¢±àÒë.
??javac javaÎļþÃû

??²úÉúC³ÌÐòÍ·Îļþ
??javah -jni javaÎļþÃû(²»´øºó׺.java)

??±àд±»Javaµ÷ÓõÄC³ÌÐòC1.c,ÒÔ¼°±»C1µ÷ÓõÄC2.c,²¢±àÒë.
??cc -G -Iinclude·¾¶Ãû C2.c -o libC2.so
??cc -G -Iinclude·¾¶Ãû -lC2 C1.c -o libC1.so

??ÉèÖû·¾³±äÁ¿
??setenv LD_LIBRARY_PATH libC1.so,libC2.soËùÔÚ·¾¶:${LD_LIBRARY_PATH}

??ÔËÐÐjavaÓ¦ÓÃ

ÎÊ: ÔÚJavaÓïÑÔÖÐ,ÈçºÎÁгöPC»úÎļþϵͳÖеÄËùÓÐÇý¶¯Æ÷Ãû?
´ð:
??ÔÚJava 2°æ±¾ÖÐ,java.io°üÖеÄFileÀàÐÂÔö¼ÓÁË·½·¨listRoots()¿ÉÒÔʵÏÖÕâÒ»¹¦ÄÜ.

ÎÊ: ΪʲôRuntime.exec("ls")ûÓÐÈκÎÊä³ö?
´ð:
??µ÷ÓÃRuntime.exec·½·¨½«²úÉúÒ»¸ö±¾µØµÄ½ø³Ì,²¢·µ»ØÒ»¸öProcess×ÓÀàµÄʵÀý,¸ÃʵÀý¿ÉÓÃÓÚ¿ØÖƽø³Ì»òÈ¡µÃ½ø³ÌµÄÏà¹ØÐÅÏ¢. ÓÉÓÚµ÷ÓÃRuntime.exec·½·¨Ëù´´½¨µÄ×Ó½ø³ÌûÓÐ×Ô¼ºµÄÖն˻ò¿ØÖÆ̨,Òò´Ë¸Ã×Ó½ø³ÌµÄ±ê×¼IO(Èçstdin,stdou,stderr)¶¼Í¨¹ýProcess.getOutputStream(),Process.getInputStream(), Process.getErrorStream()·½·¨Öض¨Ïò¸øËüµÄ¸¸½ø³ÌÁË.Óû§ÐèÒªÓÃÕâЩstreamÀ´Ïò ×Ó½ø³ÌÊäÈëÊý¾Ý»ò»ñÈ¡×Ó½ø³ÌµÄÊä³ö. ËùÒÔÕýÈ·Ö´ÐÐRuntime.exec("ls")µÄÀý³ÌÈçÏÂ:
try
{
process = Runtime.getRuntime().exec (command);
InputStreamReader ir=newInputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
String line;
while ((line = input.readLine ()) != null)
System.out.println(line);
}
catch (java.io.IOException e){
System.err.println ("IOException " + e.getMessage());
}

ÎÊ: ÈçºÎ²úÉúÇ©Ãûapplet,ÒÔʹappletÄܹ»·ÃÎʱ¾µØ×ÊÔ´?
´ð:
??ÔÚjdk1.1ÖÐ,¿ÉÒÔʹÓÃjavakeyÃüÁîÀ´²úÉú¹«Ô¿,˽Կ,Ö¤ÊéºÍÇ©ÃûµÄjarÎļþ,Ïêϸ×ÊÁÏ Çë²Î¿¼: http://java.sun.com/security/usingJavakey.html¶øjava 2¶ÔÇ©Ãû»úÖÆ×öÁ˱ȽϴóµÄ¸Ä½ø,ÔÊÐíÓû§¸üÁé»îµØÉèÖð²È«È¨ÏÞ.Java 2ÌṩÁËÈý¸ö¹¤¾ß:keytool,policytoolºÍjarsignerÀ´ÊµÏÖÇ©Ãûapplet.ÀýÈç,Joe±àдÁËÒ»¸öÇ©Ãûapplet:SignedApplet.java,ÄÇô²úÉúÒ»¸ö¼òµ¥µÄÇ©ÃûappletµÄ¹ý³ÌÈçÏÂ:

//²úÉúÃÜÔ¿,ÃÜÔ¿±ðÃûΪjoe,¿ÚÁîΪsign12,´æ·ÅÔÚÃÜÔ¿¿âjoestoreÖÐ
keytool -genkey -alias joe -keypass sign12 -keystore joestore
//½«SignedApplet.class¼°Ïà¹ØÎļþ´ò°ü³ÉjarÎļþ
jar cvf SignedAppletDemo.jar
//ÀûÓÃkeytoolÉú³ÉµÄ×ÔÇ©ÃûµÄÖ¤Êé²úÉúÇ©Ãûapplet(jarÎļþ)
jarsigner -keystore joestore -signedjar joe.jar SignedAppletDemo.jar joe
//½«×ÔÇ©ÃûÖ¤Êé´ÓkeystoreÖÐÊä³öµ½Îļþ
keytool -export -keystore joestore -alias joe -file joe.cer
¶ø¶ÔÓÚÇ©ÃûappletµÄ½ÓÊÜ·½Susan,ÐèҪͨ¹ýÈçϲ½ÖèÀ´°²È«µØÖ´ÐÐ
Joe±àдµÄÇ©Ãûapplet:
//µÃµ½JoeµÄÖ¤Êé²¢½«Ö®¶ÁÈëµ½ÃÜÔ¿¿âÖÐsusanstoreÖÐ
keytool -import -alias joe -file joe.cer -keystore susanstore
//ÔËÐÐpolicytool²úÉúÂú×ãSusanÒªÇóµÄpolicyÎļþ
policytool
//ÓÃappletviewerÔËÐÐÖ®,»òÔÚä¯ÀÀÆ÷Öа²×°java pluginÀ´ÔËÐÐÖ®.
¹ØÓÚÇ©ÃûappletÔÚJava PluginÖеIJ¿ÊðÇë²Î¿¼ÒÔÏÂÍøÒ³: http://java.sun.com/security/signExample12/

×¢:ÒÔÉϵÄÀý×ÓΪ¼òµ¥Æð¼û,ʹÓÃÁËkeytool²úÉúµÄ×ÔÇ©ÃûÖ¤Êé.Æäʵ,Óû§Ò²¿ÉÒÔʹÓÃkeytool -certreqÏòÉÌÒµCAÖÐÐÄÉêÇëµç×ÓÖ¤Êé.

ÎÊ:Èôͨ¹ýObjectOutputStreamÏòÒ»¸öÎļþÖжà´ÎÒÔ×·¼Ó·½Ê½Ð´Èëobject,ΪʲôÓÃObjectInputStream¶ÁÈ¡ÕâЩobjectʱ»á²úÉúStreamCorruptedException?
´ð:
??ʹÓÃȱʡµÄserializetionµÄʵÏÖʱ,Ò»¸öObjectOutputStreamµÄ¹¹ÔìºÍÒ»¸öObjectInputStreamµÄ¹¹Ôì±ØÐëÒ»Ò»¶ÔÓ¦.ObjectOutputStreamµÄ¹¹Ô캯Êý»áÏòÊä³öÁ÷ÖÐдÈëÒ»¸ö±êʶͷ,¶øObjectInputStream»áÊ×ÏȶÁÈëÕâ¸ö±êʶͷ.Òò´Ë,¶à´ÎÒÔ×·¼Ó·½Ê½ÏòÒ»¸öÎļþÖÐдÈëobjectʱ,¸ÃÎļþ½«»á°üº¬¶à¸ö±êʶͷ.ËùÒÔÓÃObjectInputStreamÀ´deserializeÕâ¸öObjectOutputStreamʱ,½«²úÉúStreamCorruptedException.Ò»ÖÖ½â¾ö·½·¨ÊÇ¿ÉÒÔ¹¹ÔìÒ»¸öObjectOutputStreamµÄ×ÓÀà,²¢¸²¸ÇwriteStreamHeader()·½·¨.±»¸²¸ÇºóµÄwriteStreamHeader()·½·¨Ó¦ÅжÏÊÇ·ñΪÊ×´ÎÏòÎļþÖÐдÈëobject,ôÊ?Ôòµ÷ÓÃsuper.writeStreamHeader();Èô·ñ,¼´ÒÔ×·¼Ó·½Ê½Ð´Èëobjectʱ,ÔòÓ¦µ÷ÓÃObjectOutputStream.reset()·½·¨.

ÎÊ: ¶ÔÏóµÄÐòÁл¯(serialization)ÀàÊÇÃæÏòÁ÷µÄ,Ó¦ÈçºÎ½«¶ÔÏóдÈëµ½Ëæ»ú´æÈ¡ÎļþÖÐ?
´ð:
??Ä¿Ç°,ûÓÐÖ±½ÓµÄ·½·¨¿ÉÒÔ½«¶ÔÏóдÈëµ½Ëæ»ú´æÈ¡ÎļþÖУ¬µ«ÊÇ¿ÉÒÔʹÓÃByteArrayÊäÈë/Êä³öÁ÷×÷ΪÖнé,À´ÏòËæ»ú´æÈ¡ÎļþÖÐдÈë»ò´ÓËæ»ú´æÈ¡ÎļþÖжÁ³ö×Ö½Ú,²¢ÇÒ¿ÉÒÔÀûÓÃ×Ö½ÚÁ÷À´´´½¨¶ÔÏóÊäÈë/Êä³öÁ÷,ÒÔÓÃÓÚ¶Áд¶ÔÏó.ÐèҪעÒâµÄÊÇÔÚ×Ö½ÚÁ÷ÖÐÒª°üº¬Ò»¸öÍêÕûµÄ¶ÔÏó,·ñÔò¶Áд¶ÔÏóʱ½«·¢Éú´íÎó. ÀýÈç,java.io.ByteArrayOutputStream¿ÉÓÃÓÚ»ñÈ¡ObjectOutputStreamµÄ×Ö½ÚÁ÷,´ÓÖпɵõ½byteÊý×é²¢¿É½«Ö®Ð´Èëµ½Ëæ»ú´æÈ¡ÎļþÖÐ.Ïà·´,ÎÒÃÇ¿ÉÒÔ´ÓËæ»ú´æÈ¡ÎļþÖжÁ³ö×Ö½ÚÊý×é,ÀûÓÃËü¿É¹¹ÔìByteArrayInputStream,½ø¶ø¹¹Ôì³öObjectInputStream,ÒÔ¶ÁÈ¡¶ÔÏó.

ÎÊ: ÔËÐÐRMIÓ¦ÓÃʱ,¿É²»¿ÉÒÔ²»ÊÖ¹¤Æô¶¯Ãû×Ö·þÎñrmiregistry,¶øÊÇ´Ó³ÌÐòÖÐÆô¶¯Ö®?
´ð:
??¿ÉÒÔ. java.rmi°üÖÐÌṩÁËÀàjava.rmi.registry.LocateRegistry,ÓÃÓÚ»ñÈ¡Ãû×Ö·þÎñ»ò´´½¨Ãû×Ö·þÎñ.µ÷ÓÃLocateRegistry.createRegistry(int port)·½·¨¿ÉÒÔÔÚijһÌض¨¶Ë¿Ú´´½¨Ãû×Ö·þÎñ,´Ó¶øÓû§ÎÞÐèÔÙÊÖ¹¤Æô¶¯rmiregistry.´ËÍâ,LocateRegistry.getRegistry(String host,int port)·½·¨¿ÉÓÃÓÚ»ñÈ¡Ãû×Ö·þÎñ.

ÎÊ: ʹÓÃÀàPrintJob½øÐдòÓ¡²Ù×÷ʱ,Ó¦ÈçºÎÉèÖôòÓ¡»úÃûµÈ´òÓ¡ÊôÐÔ?
´ð:
??ʹÓÃÈçÏ·½·¨¿ÉÒÔ»ñµÃPrintJobµÄʵÀýÓÃÓÚ¿ØÖÆ´òÓ¡²Ù×÷:
??Toolkit.getPrintJob(Frame f, String jobtitle, Properties prop)
??ÄÇô¶ÔÓÚ´òÓ¡ÊôÐÔµÄÉèÖÿÉÒÔͨ¹ý¶ÔpropµÄÊôÐÔÉèÖÃÀ´ÊµÏÖ,´òÓ¡ÊôÐÔ°üÀ¨:
??awt.print.destination: ¿ÉÒÔÊÇ"printer"»ò"file"
??awt.print.printer: ´òÓ¡»úÃû
??awt.print.fileName: ´òÓ¡ÎļþÃû
??awt.print.numCopies: ´òÓ¡·ÝÊý
??awt.print.options: ´òÓ¡ÃüÁîµÄ´òÓ¡Ñ¡Ïî
??awt.print.orientation: ´òÓ¡·½Ïò,¿ÉÒÔÊÇ"portrait"»ò"landscape"
??awt.print.paperSize: Ö½ÕÅ´óС,¿ÉÒÔÊÇ"letter","legal","executive"»ò"a4"

ÎÊ:ÔÚJDK1.1ÖÐThreadÀඨÒåÁËsuspend()ºÍresume()·½·¨,µ«ÊÇÔÚJDK1.2ÖÐÒѾ­¹ýʱ,ӦʹÓÃʲô·½·¨À´Ìæ´úÖ®?
´ð:
??Thread.suspend±¾ÉíÒ×ÓÚ²úÉúËÀËø.Èç¹ûÒ»¸öÄ¿±êÏ̶߳Ôijһ¹Ø¼üϵͳ×ÊÔ´½øÐÐÁ˼ÓËø²Ù×÷,È»ºó¸ÃÏ̱߳»suspend,ÄÇô³ý·Ç¸ÃÏ̱߳»resume,·ñÔòÆäËüÏ̶߳¼½«ÎÞ·¨·ÃÎʸÃϵͳ×ÊÔ´.Èç¹ûÁíÍâÒ»¸öÏ߳̽«µ÷ÓÃresume,ʹ¸ÃÏ̼߳ÌÐøÔËÐÐ,¶øÔÚ´Ë֮ǰ,ËüÒ²ÐèÒª·ÃÎÊÕâһϵͳ×ÊÔ´,Ôò½«²úÉúËÀËø.
??Òò´Ë,ÔÚJava 2ÖÐ,±È½ÏÁ÷Ðеķ½Ê½ÊǶ¨ÒåÏ̵߳Ä״̬±äÁ¿,²¢Ê¹Ä¿±êÏß³ÌÂÖѯ¸Ã״̬±äÁ¿,µ±×´Ì¬ÎªÐü¹Ò״̬ʱ,¿ÉÒÔʹÓÃwait()·½·¨Ê¹Ö®´¦Óڵȴý״̬.Ò»µ©ÐèÒª¸ÃÏ̼߳ÌÐøÔËÐÐ,ÆäËüÏ̻߳áµ÷ÓÃnotify()·½·¨À´Í¨ÖªËü.

ÎÊ: ʹÓÃJDBC±à³Ì,Ó¦ÈçºÎ¿ØÖƽá¹û¼¯ResultSetµÄÖ¸Õë,ʹ֮Äܹ»ÉÏÏÂÒƶ¯,ÒÔ¼°Òƶ¯µ½½á¹û¼¯µÄµÚÒ»ÐкÍ×îºóÒ»ÐÐ?
´ð:
??ÔÚJDK1.1ÖÐ,ResultSetÀàÖÐÖ»¶¨ÒåÁËnext()·½·¨Ö§³ÖÊý¾ÝÖ¸ÕëµÄÏÂÒÆ.µ«ÔÚJava 2ÖÐ,ResultSetÀàÔö¼ÓÁËÈçÏ·½·¨Ö§³ÖÊý¾ÝÖ¸ÕëµÄÒƶ¯,°üÀ¨:

??ResultSet.first():½«Êý¾ÝÖ¸ÕëÒƵ½½á¹û¼¯µÄµÚÒ»ÐÐ
??ResultSet.last(): ½«Êý¾ÝÖ¸ÕëÒƵ½½á¹û¼¯µÄ×îºóÒ»ÐÐ
??ResultSet.previous(): ½«Êý¾ÝÖ¸ÕëÉÏÒÆÒ»ÐÐ

??ÒÔÉϵķ½·¨¶¨ÒåÔÚJDBC2.0µÄ¹æ·¶ÖÐ,ËùÓÐÖ§³ÖJDBC 2.0µÄJDBCÇý¶¯³ÌÐò¶¼¿ÉÒÔÖ§³ÖÉÏÊö·½·¨.Ä¿Ç°IntersolvºÍOpenLinkµÈJDBCÇý¶¯³ÌÐò³§É̾ùÓвúÆ·Ö§³ÖJDBC 2.0 .

ÎÊ: Äļ¸ÖÖWeb ServerÖ§³ÖServlet?ÈçºÎʹIISÖ§³ÖServlet?
´ð:
??Ä¿Ç°,Ö§³ÖServletµÄ·þÎñÆ÷¶Ë²úÆ·Ö÷ÒªÓÐ: Sun¹«Ë¾µÄJava WebServer,Lotus DominoGo WebServer,BEA weblogic Tengah Server,Jigsaw,NetForge,AcmeServerºÍMot Bays JettyµÈ.
??´ËÍâ,һЩµÚÈý·½³§ÉÌÒ²¿ª·¢ÁËServlet engine,ÒÔʹÆäËüWebServer(ÈçNetscape Web Server,IISµÈ)Äܹ»ÔËÐÐServlet,ÈçLiveSoftwareµÄJrun(http://www.livesoftware.com/ products/jrun/)µÈ.

ÎÊ: ÈçºÎÔÚJavaÓ¦ÓÃÖн«Í¼Ïñ´æ´¢µ½Í¼ÏñÎļþÖÐ?
´ð:
??Java Advanced Imaging API(°üº¬ÔÚJava Media APIÖÐ)ÔÊÐíÔÚJavaÓ¦ÓÃÖÐÖ´Ðи´ÔÓµÄ,¸ßÐÔÄܵÄͼÏñ´¦Àí.JAI APIÌṩÁ˴洢ͼÏñµÄÄÜÁ¦.Ä¿Ç°,JAI APIÖ§³ÖÒÔϼ¸ÖÖͼÏñÎļþ¸ñʽ:BMP,JEPG,PNG,PNM,TIFF.ÏÂÃæ¸ø³öÁ˽«Í¼Ïñ´æ´¢µ½BMPÎļþµÄÒ»¶Î´úÂë:
OutputStream os = new FileOutputStream(fileToWriteTo);
BMPEncodeParam param = new BMPEncodeParam();
ImageEncoder enc = ImageCodec.createImageEncoder("BMP", os, param);
enc.encode(img);
os.close();
Óйش洢ͼÏñÎļþµÄ±à³ÌÖ¸ÄÏÇë²Î¿¼ÒÔÏÂÍøÒ³:
http://java.sun.com/products/java-media/jai/forDevelopers/jai-guide/

ÎÊ: ÈçºÎÓÃJavaÓïÑÔÏò´®¿Ú¶ÁдÊý¾Ý£¿
´ð:
??Sun¹«Ë¾µÄJava Communication API2.0¿ÉÓÃÓÚ¶Áд´®¿Ú,ËüÖ§³ÖRS232´®¿ÚºÍIEEE 1284 ²¢¿Ú,ÌṩÁËÒ»ÖÖÓëƽ̨Î޹صĴ®/²¢¿ÚͨÐÅ»úÖÆ.
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ