Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaÖÐequalºÍ==µÄ±È½Ï[zz]

×î½ü¿´µ½Ò»¸öÍøÓѹØÓÚ==ºÍequals ×öµÄ×ܽᣬ·ÖÏíÒ»ÏÂ
javaÖÐequals·½·¨ºÍ“==”µÄÇø±ð£º
equals ·½·¨ÊÇ java.lang.Object ÀàµÄ·½·¨¡£
ÓÐÁ½ÖÖÓ÷¨ËµÃ÷£º
£¨1£©¶ÔÓÚ×Ö·û´®±äÁ¿À´Ëµ£¬Ê¹ÓÓ==”ºÍ“equals()”·½·¨±È½Ï×Ö·û´®Ê±£¬Æä±È½Ï·½·¨²»Í¬¡£
“==”±È½ÏÁ½¸ö±äÁ¿±¾ÉíµÄÖµ£¬¼´Á½¸ö¶ÔÏóÔÚÄÚ´æÖеÄÊ×µØÖ·¡£
“equals()”±È½Ï×Ö·û´®ÖÐËù°üº¬µÄÄÚÈÝÊÇ·ñÏàͬ¡£
±ÈÈ磺
String s1,s2,s3 = "abc", s4 ="abc" ;
s1 = new String("abc");
s2 = new String("abc");
ÄÇô£º
s1==s2 ÊÇ false //Á½¸ö±äÁ¿µÄÄÚ´æµØÖ·²»Ò»Ñù£¬Ò²¾ÍÊÇ˵ËüÃÇÖ¸ÏòµÄ¶ÔÏó²» Ò»Ñù£¬
¹Ê²»ÏàµÈ¡£
s1.equals(s2) ÊÇ true //Á½¸ö±äÁ¿µÄËù°üº¬µÄÄÚÈÝÊÇabc£¬¹ÊÏàµÈ¡£
×¢Ò⣨1£©£º
Èç¹û£º StringBuffer s1 = new StringBuffer("a");
StringBuffer s2 = new StringBuffer("a");
½á¹û£º s1.equals(s2) //ÊÇfalse
½âÊÍ£ºStringBufferÀàÖÐûÓÐÖØж¨ÒåequalsÕâ¸ö·½·¨£¬Òò´ËÕâ¸ö·½·¨¾ÍÀ´×ÔObjectÀ࣬
¶øObjectÀàÖеÄequals·½·¨ÊÇÓÃÀ´±È½Ï“µØÖ·”µÄ£¬ËùÒÔµÈÓÚfalse.
×¢Ò⣨2£©£º
¶ÔÓÚs3ºÍs4À´Ëµ£¬ÓÐÒ»µã²»Ò»ÑùÒªÒýÆð×¢Ò⣬ÓÉÓÚs3ºÍs4ÊÇÁ½¸ö×Ö·û
´®³£Á¿ËùÉú³ÉµÄ±äÁ¿£¬ÆäÖÐËù´æ·ÅµÄÄÚ´æµØÖ·ÊÇÏàµÈµÄ£¬
ËùÒÔs3==s4ÊÇtrue£¨¼´Ê¹Ã»ÓÐs3=s4ÕâÑùÒ»¸ö¸³ÖµÓï¾ä£©
£¨2£©¶ÔÓÚ·Ç×Ö·û´®±äÁ¿À´Ëµ£¬"=="ºÍ"equals"·½·¨µÄ×÷ÓÃÊÇÏàͬµÄ¶¼ÊÇÓÃÀ´±È½ÏÆä
¶ÔÏóÔÚ¶ÑÄÚ´æµÄÊ×µØÖ·£¬¼´ÓÃÀ´±È½ÏÁ½¸öÒýÓñäÁ¿ÊÇ·ñÖ¸Ïòͬһ¸ö¶ÔÏó¡£
±ÈÈ磺
class A
{
A obj1 = new A();
A obj2 = new A();
}
ÄÇô£ºobj1==obj2ÊÇfalse
obj1.equals(obj2)ÊÇfalse
µ«ÊÇÈç¼ÓÉÏÕâÑùÒ»¾ä£ºobj1=obj2;
ÄÇô obj1==obj2 ÊÇtrue
obj1.equals(obj2) ÊÇtrue
×ÜÖ®£ºequals·½·¨¶ÔÓÚ×Ö·û´®À´ËµÊDZȽÏÄÚÈݵģ¬¶ø¶ÔÓÚ·Ç×Ö·û´®À´ËµÊDZȽÏ
ÆäÖ¸ÏòµÄ¶ÔÏóÊÇ·ñÏàͬµÄ¡£
== ±È½Ï·ûÒ²ÊDZȽÏÖ¸ÏòµÄ¶ÔÏóÊÇ·ñÏàͬµÄÒ²¾ÍÊǶÔÏóÔÚ¶ÔÄÚ´æÖеĵÄÊ×µØÖ·¡£
StringÀàÖÐÖØж¨ÒåÁËequalsÕâ¸ö·½·¨£¬¶øÇұȽϵÄÊÇÖµ£¬¶ø²»ÊǵØÖ·¡£ËùÒÔÊÇtrue¡£
¹ØÓÚequalsÓë==µÄÇø±ð´ÓÒÔϼ¸¸ö·½ÃæÀ´Ëµ£º
£¨1£©Èç¹ûÊÇ»ù±¾ÀàÐͱȽϣ¬ÄÇôֻÄÜÓÃ==À´±È½Ï£¬²»ÄÜÓÃequals
±ÈÈ磺
public class TestEquals {
public static void main(String[] args)
{
int a = 3;
int b = 4;
int c = 3;
System.out.println(a == b);//½á¹ûÊÇfalse
System.out.println(a == c);//½á¹ûÊÇtrue
System.out.pr


Ïà¹ØÎĵµ£º

javaÖеÄclon()ºÍcloneable½Ó¿ÚdzÎö

 The clone( ) method generates a duplicate copy of the object on which it is called. Only classes that implement the Cloneable interface can be cloned.
 
...clone()²úÉúÁËÒ»¸öµ÷ÓÃËüµÄ¶ÔÏóµÄ¸´ÖÆ;Ö»ÓÐʵÏÖÁËCloneable½Ó¿ÚµÄÀà²Å¿ÉÒÔ±»¸´ÖÆ¡£
 
 
The Cloneable interface defines no ......

ѧϰJavaÀàµÄÊôÐÔ

ѧϰJavaÀàµÄÊôÐÔ-Î人±±´óÇàÄñ
¡¡¡¡Public¡¢private¡¢protectedÏÔʾÁËÈýÖÖÀàÖеÄÊôÐԺͷþÎñµÄÀàÐÍ£¬publicÊÇ¿ÉÒÔËæÒâ·ÃÎʵġ¢privateÊÇÍâ½ç²»ÄÜ·ÃÎʵÄ(ÏÔʾÁËÊý¾ÝµÄ·â×°ÐÔ)¡¢protected˵Ã÷Êý¾ÝÊÇÊܱ£»¤µÄ¡£ÏÂÃæ¾ÍÀ´Ïêϸ½²ÊöÒ»ÏÂÕâÈý¸ö¾¿¾¹ÓÐʲôÇø±ð¡£
¡¡¡¡Ê×ÏÈÒªÁ˽âһϰüµÄ¸ÅÄî¡£ÓÐÈô¸É¸öÀ࣬ËüÃÇÏ໥֮¼äÓÐÒ»¶¨µÄ¹ØÏ ......

JavaÉè¼Æģʽ֮State(״̬ģʽ)

¶¨Ò壺
GOF¡¶Éè¼Æģʽ¡·Öиø״̬ģʽϵĶ¨ÒåΪ£ºÔÊÐíÒ»¸ö¶ÔÏóÔÚÆäÄÚ²¿×´Ì¬¸Ä±äʱ¸Ä±äËüµÄÐÐΪ¡£
ÏÈ¿´Ò»¸öÀý×Ó£º
package com.state;
public class KissingPrincess {
// ±ê־룬±êÖ¾ÊÇÇàÍÜ»¹ÊÇÍõ×Ó¡£
private boolean isFrog = true;
// ¸ù¾ÝisFrog½øÐв»Í¬µÄ²Ù×÷¡£
public void greet() {
if (isFrog)
......

Javaµ÷Óô洢¹ý³Ì(MySqlÊý¾Ý¿â)

Ò»¡¢½¨±í
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `ID` int(11) NOT NULL auto_increment,
  `NAME` varchar(16) NOT NULL default '',
  `REMARK` varchar(16) NOT NULL default '',
  PRIMARY KEY  (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8;
&nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ