java·¶ÐÍѧϰ
javaµÄ·¶ÐÍ»úÖÆ¿´ÆðÀ´ÓеãÏñC++µÄÄ£°æ£¬µ«Ïà±È½ÏC++µÄÄ£°æÀ࣬javaÖеķ¶ÐÍûÓйؼü×Ötemplate£¬²¢ÇÒÓÐ×Ų»Í¬µÄʵÏÖ»úÖÆ£¨±¾ÖÊÇø±ð£©¡£
·¶ÐÍÀà
ÏÈ¿´Ò»¸ö·¶ÐÍÀàµÄÀý×Ó£º
public class Demo1<T> {
private T value;
public Demo1(T value) {
this.value= value;
}
public void setFirst(T value){this.value= value;}
public T getFirst(){return value;}
}
ÀàÐͱäÁ¿T£¬ÓÃ<>À¨Æ𣬷ÅÔÚÀàÃûµÄºóÃæ¡£µ±ÎÒÃÇÐèÒªÕâ¸öÀàÊÇ£¬Ö»ÐèÒªÈç϶¨Ò壺
String string = "yangsq";
Demo1<String> demo1 = new Demo1<String>(string);
ÕâÑùÉùÃ÷µÄÒ»¸öDemo1ÀàÏ൱ÓÚ°ÑÉÏÃ涨ÒåµÄDemo1ÀàÖÐT¶¼»»×÷StringÁË¡£
·¶ÐÍÀà¿ÉÒÔÓжà¸öÀàÐÍ£¬ÀýÈçÏñÉÏÃæµÄDemo1À࣬ÎÒÃÇ¿ÉÒÔ¸Ä×÷ÈçÏ£º
public class Demo2<T,U> {
private T tValue;
private U uValue;
public Demo2(T tValue, U uValue) {
this.tValue= tValue;
this.uValue = uValue;
}
... ...
}
2. ·¶ÐÍ·½·¨
Èç¹ûÎÒÃDz»ÐèÒª·¶ÐÍÀ࣬Ҳ¿ÉÒÔÖ»¶¨ÒåÎÒÃÇÐèÒªµÄ·¶ÐÍ·½·¨¡£·¶ÐÍ·½·¨¿ÉÒÔÔÚÆÕͨÀàÀﶨÒå¡£
public class Demo3 {
public <T> T getMiddle(T[] array) {
return array[array.length/2];
}
}
ÕâÀïÐèҪעÒâµÄÊÇÀàÐÍÐÞÊηûºÅ£¨ºìÌå±ê³öµÄ<T>£©£¬ËüÒª·ÅÔÚpublic£¨static/final£©ºóºÍ·µ»ØÀàÐÍÇ°¡£ÔÚÎÒÃÇÐèҪʹÓÃÕâ¸ö·½·¨Ê±£¬¿ÉÒÔÈçϵ÷Óãº
Demo3 demo3 = new Demo3();
String[] strings = {"abc", "def", "wxy"};
String middle = demo3.<String>getMiddle(strings);
ʵ¼ÊÉÏ£¬ºìÌå±ê³öµÄ<String>ÍêÈ«¿ÉÒÔÊ¡ÂÔ¡£ÒòΪ¿ÉÒÔ¸ù¾ÝstringsµÄString[]ÀàÐÍÍƳö¡£
ÎÒÃÇ»¹¿ÉÒÔ¶Ô·¶ÐͼÓÒÔÔ¼Êø£¬ÀýÈçÎÒÃÇ¿ÉÄÜÏ£ÍûTµÄÀàÐÍÄÜÓ¦ÓÃcomparaTo·½·¨£¬¼´Tµ
Ïà¹ØÎĵµ£º
ȺÄÚһλÅàѵÀÏʦ·¢³öÀ´Ò»¸öÎÊÌâ:
int[][] a = new int[10][10];
ÕâÖÖ¶àάÊý×é»áÔÚÕ»ÉÏÉú³É¼¸¸ö¶ÔÏó?
Õâ¸öÎÊÌâÐÂÏÊ,ûÈËÎʹý.
·¢³öÀ´ºó ´ó¼Ò¶¼ÈÏΪÓм¸¸öÔªËØ ¾Í»áÉú³É¼¸¸ö¶ÔÏó.
ÎÒ¿ªÊ¼Ò²
ÕâôÈÏΪ.
ÓÚÊÇд¸öÁ˳ÌÐòÊÔÁËÏÂ.·¢ÏÖûÓÐÄÇô¼òµ¥
public static void main(String[] args) {
int[][] a = new int[10][10 ......
ÕâÊÇÒ»¸öwebËÑË÷µÄ»ù±¾³ÌÐò£¬´ÓÃüÁîÐÐÊäÈëËÑË÷Ìõ¼þ£¨ÆðʼµÄURL¡¢´¦ÀíurlµÄ×î´óÊý¡¢ÒªËÑË÷µÄ×Ö·û´®),
Ëü¾Í»áÖð¸ö¶ÔInternetÉϵÄURL½øÐÐʵʱËÑË÷,²éÕÒ²¢Êä³öÆ¥ÅäËÑË÷Ìõ¼þµÄÒ³Ãæ¡£ Õâ¸ö³ÌÐòµÄÔÐÍÀ´×Ô¡¶java±à³ÌÒÕÊõ¡·£¬
ΪÁ˸üºÃµÄ·ÖÎö£¬Õ¾³¤È¥µôÁËÆäÖеÄGUI²¿·Ö£¬²¢ÉÔ×÷ÐÞ¸ÄÒÔÊÊÓÃjdk1.5¡£ÒÔÕâ¸ö³ÌÐòΪ»ù´¡£¬¿ÉÒÔд³öÔÚ» ......
keytoolÉú³ÉÖ¤Êé
ÑéÖ¤ÊÇ·ñÒÑ´´½¨¹ýͬÃûµÄÖ¤Êé
keytool -list -v -alias tomcat -keystore "%JAVA_HOME%/JRE/LIB/SECURITY/CACERTS" -storepass changeit
ɾ³ýÒÑ´´½¨µÄÖ¤Êé
keytool -delete -alias tomcat -keystore "%JAVA_HOME%/JRE/LIB/SECURITY/CACERTS" -storepass changeit
´´½¨Ö¤Êé
1.·þÎñ ......
Problem: email thread is hanging at socket read
Today we found a email problem in production, all of the mail threads (3 threads) are hanging/sitting/blocking at same point
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
......
1.String str = new String("abc"); ÇëÎʶ¨ÒåÁ˼¸¸ö¶ÔÏ󡣶¨ÒåÁËÁ½¸ö¶ÔÏó£¬Ò»¸ö"abc", Ò»¸öÊÇnew String().<String s = "abc";Ê×Ïȵ½¶ÑÖвéÕÒֵΪ"abc"µÄ¶ÔÏó£¬Ã»ÓоÍн¨Ò»¸ö¶ÔÏó£¬"abc"±¾Éí¾ÍÊÇÒ»¸ö¶ÔÏó¡£>
2.ÃæÏò¶ÔÏóµÄ¶«Î÷£ºabstract & interfaceµÄ¸÷×ÔµÄ×÷Óã¬Çø±ð¡£
3.ÃæÏò¶ÔÏóµÄÌØÕ÷£¬ÒÔ¼°ÔõôʵÏֵġ£1 ......