javaºÍC++µÄÓï·¨Çø±ð—1
C++ÓëJavaµÄÓï·¨Çø±ð
Ê×ÏÈ£¬Á½¸ö´óµÄ²»Í¬ÊÇÖ÷º¯ÊýºÍÔõÑù±àÒëµÄ²»Í¬£¬½ÓÏÂÀ´ÊÇÐí¶àСµÄÇø±ð¡£
main º¯Êý
C++
//×ÔÓɸ¡¶¯µÄº¯Êý
int main( int argc, char* argv[])
{
printf( "Hello, world" );
}
Java
// ÿ¸öº¯Êý¶¼±ØÐëÊÇÒ»¸öÀàµÄÒ»²¿·Ö;µ±java <class>ÔËÐÐÊÇÒ»¸öÌض¨ÀàµÄÖ÷º¯Êý»á±»µ÷ÓÃ
// (Òò´ËÄã¿ÉÒÔÈÃÿ¸öÀ඼ÓÐÒ»¸ömainº¯Êý£¬ÕâÔÚдµ¥Ôª²âÊÔÊǺÜÓÐÓÃ)
class HelloWorld
{
public static void main(String args[])
{
System.out.println( "Hello, World" );
}
}
ÀàµÄÉùÃ÷
³ýÁË Java ²»ÒªÇóÓ÷ֺÅÍ⼸ºõÊÇÏàͬµÄ¡£
C++
class Bar {};
Java
class Bar {}
·½·¨ÉùÃ÷
¶¼ÏàͬµÄ, ³ýÁËÔÚJava,·½·¨±ØÐë×ÜÊÇij¸öÀàµÄÒ»²¿·Ö²¢ÇÒ¿ÉÄÜpublic/private/protected ×÷ΪÐÞÊÎ
¹¹Ô캯ÊýºÍÎö¹¹º¯Êý
¹¹Ô캯Êý¶¼ÊÇÏàͬµÄ (¼´ÀàµÄÃû×Ö), JavaûÓÐ׼ȷÒâÒåÉϵĵÄÎö¹¹º¯Êý
¾²Ì¬³ÉÔ±º¯ÊýºÍ±äÁ¿
·½·¨ÉùÃ÷ÊÇÏàͬµÄ, µ« Java Ìṩ¾²Ì¬³õʼ»¯¿éÀ´À´³õʼ»¯¾²Ì¬±äÁ¿ (²»ÐèÒªÔÚÔ´ÎļþÖÐÉùÃ÷):
class Foo
{
static private int x;
// ¾²Ì¬³õʼ»¯¿é
{ x = 5; }
}
¶ÔÏóµÄÉùÃ÷
C++
// ÔÚÕ»ÖÐ
myClass x;
//»òÕßÔÚ¶ÑÖÐ
myClass *x = new myClass;
Java
// ×ÜÊÇÔÚ¶Ô¶ÑÖÐÉùÃ÷
myClass x = new myClass();
¼Ì ³Ð
C++
class Foo : public Bar
{ ... };
Java
class Foo extends Bar
{ ... }
·ÃÎʼ¶±ð (abstraction barriers)
C++
public:
void foo();
void bar();
Java
public void foo();
public void bar();
Ð麯Êý
C++
 
Ïà¹ØÎĵµ£º
Javaѧϰ´ÓÈëÃŵ½¾«Í¨
Ò»¡¢ JDK (Java Development Kit)
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJ ......
1. ÄãÐèÒª¾«Í¨ÃæÏò¶ÔÏó·ÖÎöÓëÉè¼Æ£¨OOAOOD£©¡¢É漰ģʽ£¨GOF£¬J2EEDP£©ÒÔ¼°×ÛºÏģʽ¡£ÄãÓ¦¸ÃÁ˽âUML£¬ÓÈÆäÊÇclass¡¢object¡¢interactionÒÔ¼°statediagrams. ¡¡¡¡2. ÄãÐèҪѧϰJavaÓïÑԵĻù´¡ÖªÊ¶ÒÔ¼°ËüµÄºËÐÄÀà¿â£¨collections¡¢serialization¡¢streams¡¢networking¡¢multithreading¡¢reflection¡¢event¡¢handling¡¢N ......
/*µ±Ö´ÐÐSQLʱ·¢ÏÖ²»ÄÜÁ¬½ÓÊý¾Ý¿â£¬ÏÈÖØÁ¬Ò»´Î*/
import java.io.FileInputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
......
±¾ÎÄ·ÖÁ½²¿·Ö£ºFLASH±à³Ì ºÍ Java±à³Ì£¬´ËÎļǼµÄ½ö½öÊÇÎÒÔÚ̽Ë÷ÖеÄһЩÊÕ»ñ£¬ÆäÖÐÓÃÁ˺ܶà¸öÈË»¯µÄÃèÊöÓïÑÔ£¬²¢²»ÊÇÒµ½ç±ê×¼µÄÓÃÓï¡£ £º£©
̽Ë÷±Ê¼Ç£º
Ä¿Ç°¹úÄÚFlashÓ¦Óô󲿷ֻ¹ÊÇÔÚÖÆ×÷¾«ÃÀµÄ¶¯»·½Ã棬µ«¾ÝÎÒÁ˽âÔçÔÚFlash4 µÄʱ´ú£¬¹úÍâһЩÈ˾ÍÒѾ¿ªÊ¼½«flash¼¼ÊõÔËÓÃÓÚ¿ª·¢¶¯Ì¬ÍøÕ¾£¨ºÍphp¡ ......
finalize·½·¨
ËüÊÇjava.lang.ObjectÀàÖеķ½·¨. ÊÇprotectedµÄ.
ȱʡʱÕâ¸ö·½·¨ÊÇ¿ÕµÄ. JavaÔËÐÐϵͳÔÚÀ¬»ø»ØÊÕʱÔÚ¶ÔÏó±»³·Ïú֮ǰµ÷ÓÃÕâ¸ö·½·¨. µ«ÓÉÓÚÀ¬»øµ¥Ôª
»ØÊÕµÄʱ¼äÊDz»È·¶¨µÄ.ËùÒÔ²»Äܹý·ÖÒÀÀµËü(ÕâºÍc++µÄÎö¹¹º¯Êý²»Í¬).
¶øÖ»ÄÜÊÇ"ÔÚ¶ÔÏó±»³·Ïú֮ǰ"×öһЩ´¦Àí.ÀýÈç¿ÉÒÔÔÚÕâÀï¹Ø±Õ¹¹Ôì·½·¨Öдò¿ ......