ÓйØjavaÖеÄString£¬StringBuffer£¬StringBuild
String ×Ö·û´®³£Á¿
StringBuffer ×Ö·û´®±äÁ¿£¨Ḭ̈߳²È«£©
StringBuilder ×Ö·û´®±äÁ¿£¨·ÇḬ̈߳²È«£©
¼òÒªµÄ˵£¬ String ÀàÐÍºÍ StringBuffer ÀàÐ͵ÄÖ÷ÒªÐÔÄÜÇø±ðÆäʵÔÚÓÚ String ÊDz»¿É±äµÄ¶ÔÏó, Òò´ËÔÚÿ´Î¶Ô String ÀàÐͽøÐиıäµÄʱºòÆäʵ¶¼µÈͬÓÚÉú³ÉÁËÒ»¸öÐ嵀 String ¶ÔÏó£¬È»ºó½«Ö¸ÕëÖ¸ÏòÐ嵀 String ¶ÔÏó£¬ËùÒÔ¾³£¸Ä±äÄÚÈݵÄ×Ö·û´®×îºÃ²»ÒªÓà String £¬ÒòΪÿ´ÎÉú³É¶ÔÏ󶼻á¶ÔϵͳÐÔÄܲúÉúÓ°Ï죬Ìرðµ±ÄÚ´æÖÐÎÞÒýÓöÔÏó¶àÁËÒÔºó£¬ JVM µÄ GC ¾Í»á¿ªÊ¼¹¤×÷£¬ÄÇËÙ¶ÈÊÇÒ»¶¨»áÏ൱ÂýµÄ¡£
¶øÈç¹ûÊÇʹÓà StringBuffer ÀàÔò½á¹û¾Í²»Ò»ÑùÁË£¬Ã¿´Î½á¹û¶¼»á¶Ô StringBuffer ¶ÔÏó±¾Éí½øÐвÙ×÷£¬¶ø²»ÊÇÉú³ÉеĶÔÏó£¬Ôٸıä¶ÔÏóÒýÓá£ËùÒÔÔÚÒ»°ãÇé¿öÏÂÎÒÃÇÍƼöʹÓà StringBuffer £¬ÌرðÊÇ×Ö·û´®¶ÔÏó¾³£¸Ä±äµÄÇé¿öÏ¡£¶øÔÚijЩÌرðÇé¿öÏ£¬ String ¶ÔÏóµÄ×Ö·û´®Æ´½ÓÆäʵÊDZ» JVM ½âÊͳÉÁË StringBuffer ¶ÔÏóµÄÆ´½Ó£¬ËùÒÔÕâЩʱºò String ¶ÔÏóµÄËٶȲ¢²»»á±È StringBuffer ¶ÔÏóÂý£¬¶øÌرðÊÇÒÔϵÄ×Ö·û´®¶ÔÏóÉú³ÉÖУ¬ String ЧÂÊÊÇÔ¶Òª±È StringBuffer ¿ìµÄ£º
String S1 = “This is only a” + “ simple” + “ test”;
StringBuffer Sb = new StringBuilder(“This is only a”).append(“ simple”).append(“ test”);
Äã»áºÜ¾ªÑȵķ¢ÏÖ£¬Éú³É String S1 ¶ÔÏóµÄËٶȼòֱ̫¿ìÁË£¬¶øÕâ¸öʱºò StringBuffer ¾ÓÈ»ËÙ¶ÈÉϸù±¾Ò»µã¶¼²»Õ¼ÓÅÊÆ¡£ÆäʵÕâÊÇ JVM µÄÒ»¸ö°ÑÏ·£¬ÔÚ JVM ÑÛÀÕâ¸ö
String S1 = “This is only a” + “ simple” + “test”; Æäʵ¾ÍÊÇ£º
String S1 = “This is only a simple test”; ËùÒÔµ±È»²»ÐèҪ̫¶àµÄʱ¼äÁË¡£µ«´ó¼ÒÕâÀïҪעÒâµÄÊÇ£¬Èç¹ûÄãµÄ×Ö·û´®ÊÇÀ´×ÔÁíÍâµÄ String ¶ÔÏóµÄ»°£¬ËٶȾÍûÄÇô¿ìÁË£¬Æ©È磺
String S2 = “This is only a”;
String S3 = “ simple”;
String S4 = “ test”;
String S1 = S2 +S3 + S4;
Õâʱºò JVM »á¹æ¹æ¾Ø¾ØµÄ°´ÕÕÔÀ´µÄ·½Ê½È¥×ö
Ôڴ󲿷ÖÇé¿öÏ StringBuffer > String
StringBuffer
Java.lang.StringBufferḬ̈߳²È«µÄ¿É±ä×Ö·ûÐòÁС£Ò»¸öÀàËÆÓÚ String µÄ×Ö·û´®»º³åÇø£¬µ«²»ÄÜÐ޸ġ£ËäÈ»ÔÚÈÎÒâʱ¼äµãÉÏËü¶¼°üº¬Ä³ÖÖÌض¨µÄ×Ö·ûÐòÁУ¬µ«Í¨¹ýijЩ·½·¨µ÷ÓÿÉÒԸıä¸ÃÐòÁеij¤¶ÈºÍÄÚÈÝ¡£
¿É½«×Ö·û´®»º³åÇø°²È«µØÓÃÓÚ¶à¸öÏ̡߳£¿ÉÒÔÔÚ±Ø
Ïà¹ØÎĵµ£º
Ê×ÏÈÎÒÃÇÒªÏÈдһ¸ö±¸·ÝÀà
BackupDb.java
´úÂëÈçÏ£º
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class BackupDb {
public BackupDb() {
}
public String back ......
ÎÒÃÇÖªµÀ£¬ÔÚJavaÖÐÉèÖñäÁ¿ÖµµÄ²Ù×÷£¬³ýÁËlongºÍdoubleÀàÐ͵ıäÁ¿ÍⶼÊÇÔ×Ó²Ù×÷£¬Ò²¾ÍÊÇ˵£¬¶ÔÓÚ±äÁ¿ÖµµÄ¼òµ¥¶Áд²Ù×÷ûÓбØÒª½øÐÐͬ²½¡£
ÕâÔÚJVM 1.2֮ǰ£¬JavaµÄÄÚ´æÄ£ÐÍʵÏÖ×ÜÊÇ´ÓÖ÷´æ¶ÁÈ¡±äÁ¿£¬ÊDz»ÐèÒª½øÐÐÌرðµÄ×¢ÒâµÄ¡£¶øËæ×ÅJVMµÄ³ÉÊìºÍÓÅ»¯£¬ÏÖÔÚÔÚ¶àÏ̻߳·¾³ÏÂvolatile¹Ø¼ü×ÖµÄʹÓñäµÃ·Ç³£ÖØÒª¡£
ÔÚµ±Ç° ......
1. SerialBean
SerialBeanÊDZ¾Àà¿âÓëÆäËûÓ¦ÓóÌÐòµÄ½Ó¿Ú¡£¸ÃÀà¿âÖж¨ÒåÁËSerialBeanµÄ¹¹Ôì·½·¨ÒÔ¼°³õʼ»¯´®¿Ú£¬´Ó´®¿Ú¶ÁÈ¡Êý¾Ý£¬Íù´®¿ÚдÈëÊý¾ÝÒÔ¼°¹Ø±Õ´®¿ÚµÄº¯Êý¡£¾ßÌå½éÉÜÈçÏ£º
public SerialBean(int PortID)
±¾º¯Êý¹¹ÔìÒ»¸öÖ¸ÏòÌض¨´®¿ÚµÄSerialBean£¬¸Ã´®¿ÚÓɲÎÊýPortIDËùÖ¸¶¨¡£PortID = 1 ±íʾCOM1£¬PortID = 2 ......
1.¾²Ì¬µ¼È룺
¾²Ì¬µ¼ÈëÊÇJDK1.5ºóмӵŦÄÜ£¬Ò»°ã²»Ôõô³£Ó㬺ܼòµ¥¸øÄã¾Ù¸öÀý×ÓÄã¾ÍÄÜÃ÷°×ÁË£¬¿´Õâ¶Î´úÂ룺
import static java.lang.System.out;//µ¼Èëjava.lang°üϵÄSystemÀàµÄ¾²Ì¬·½·¨out;
public class HelloWorld{
public static void main(String[] args){
out.print("Hello World!");//¼ÈÊÇÔÚÕ ......
JAVAµÄ¿çƽ̨µÄÌØÐÔÉîÊÜjava³ÌÐòÔ±ÃǵÄϲ°®,µ«ÕýÊÇÓÉÓÚËüΪÁËʵÏÖ¿çƽ̨µÄÄ¿µÄ,ʹµÃËüºÍ±¾µØ»úÆ÷µÄ¸÷ÖÖÄÚ²¿ÁªÏµ±äµÃºÜÉÙ,´ó´óÔ¼ÊøÁËËüµÄ¹¦ÄÜ,±ÈÈçÓëһЩӲ¼þÉ豸ͨÐÅ,ÍùÍùÒª»¨·ÑºÜ´óµÄ¾«Á¦È¥Éè¼ÆÁ÷³Ì±àд´úÂëÈ¥¹ÜÀíÉ豸¶Ë¿Ú,¶øÇÒÓÐһЩÉ豸³§ÉÌÌṩµÄÓ²¼þ½Ó¿ÚÒѾ¾¹ýÒ»¶¨µÄ·â×°ºÍ´¦Àí,²»ÄÜÖ±½ÓʹÓÃjava³ÌÐòͨ¹ý¶Ë¿ÚºÍÉè± ......