一切都是對象------計(jì)算機(jī)外文資料翻譯.doc
約18頁DOC格式手機(jī)打開展開
一切都是對象------計(jì)算機(jī)外文資料翻譯,“if we spoke a different language, we would perceive a some what different world.” ludwig wittgenstein (1889-1951)although it is based on c++, java is more of a...


內(nèi)容介紹
此文檔由會員 wanli1988go 發(fā)布
“If we spoke a different language, we would perceive a some what different world.” Ludwig Wittgenstein (1889-1951)Although it is based on C++, Java is more of a “pure” object-oriented language.
Both C++ and Java are hybrid languages, but in Java the designers felt that the hybridization was not as important as it was in C++. A hybrid language allows multiple programming styles; the reason C++ is hybrid is to support backward compatibility with the C language. Because C++ is a superset of the C language, it includes many of that language’s undesirable features, which can make some aspects of C++ overly complicated.
The Java language assumes that you want to do only object-oriented programming. This means that before you can begin you must shift your mindset into an object-oriented world (unless it’s already there). The benefit of this initial effort is the ability to program in a language that is simpler to learn and to use than many other OOP languages. In this chapter you’ll see the basic components of a Java program and learn that (almost) everything in Java is an object.
You manipulate objects with references
Each programming language has its own means of manipulating elements in memory. Sometimes the programmer must be constantly aware of what type of manipulation is going on. Are you manipulating the element directly, or are you dealing with some kind of indirect representation (a pointer in C or C++) that must be treated with a special syntax?
All this is simplified in Java. You treat everything as an object, using a single consistent syntax. Although you treat everything as an object, the identifier you manipulate is actually a “reference” to an object. You
“如果我們說另一種不同的語言,那么我們就會發(fā)覺一個有些不同的世界”。
—Ludwig Wittgenstein(1889-1951)
“盡管以C++為基礎(chǔ),但Java是一種更純粹的面向?qū)ο蟪绦蛟O(shè)計(jì)語言”。
無論C++還是Java都屬于雜合語言。但在Java中,設(shè)計(jì)者覺得這種雜合并不像在C++里那么重要。雜合語言允許采用多種編程風(fēng)格;之所以說C++是一種雜合語言,是因?yàn)樗С峙cC語言的向后兼容能力。由于C++是C的一個超集,所以包含的許多特性都是后者不具備的,這些特性使C++在某些地方顯得過于復(fù)雜。
Java語言首先便假定了我們只希望進(jìn)行面向?qū)ο蟮某绦蛟O(shè)計(jì)。也就是說,正式用它設(shè)計(jì)之前,必須先將自己的思想轉(zhuǎn)入一個面向?qū)ο蟮氖澜纾ǔ窃缫蚜?xí)慣了這個世界的思維方式)。只有做好這個準(zhǔn)備工作,與其他OOP語言相比,才能體會到Java的易學(xué)易用。在本章,我們將探討Java程序的基本組件,并體會為什么說Java乃至Java程序內(nèi)的一切都是對象。
1.1 用句柄操縱對象
每種編程語言都有自己的數(shù)據(jù)處理方式。有些時候,程序員必須時刻留意準(zhǔn)備處理的是什么類型。您曾利用一些特殊語法直接操作過對象,或處理過一些間接表示的對象嗎(C或C++里的指針)?
Both C++ and Java are hybrid languages, but in Java the designers felt that the hybridization was not as important as it was in C++. A hybrid language allows multiple programming styles; the reason C++ is hybrid is to support backward compatibility with the C language. Because C++ is a superset of the C language, it includes many of that language’s undesirable features, which can make some aspects of C++ overly complicated.
The Java language assumes that you want to do only object-oriented programming. This means that before you can begin you must shift your mindset into an object-oriented world (unless it’s already there). The benefit of this initial effort is the ability to program in a language that is simpler to learn and to use than many other OOP languages. In this chapter you’ll see the basic components of a Java program and learn that (almost) everything in Java is an object.
You manipulate objects with references
Each programming language has its own means of manipulating elements in memory. Sometimes the programmer must be constantly aware of what type of manipulation is going on. Are you manipulating the element directly, or are you dealing with some kind of indirect representation (a pointer in C or C++) that must be treated with a special syntax?
All this is simplified in Java. You treat everything as an object, using a single consistent syntax. Although you treat everything as an object, the identifier you manipulate is actually a “reference” to an object. You
“如果我們說另一種不同的語言,那么我們就會發(fā)覺一個有些不同的世界”。
—Ludwig Wittgenstein(1889-1951)
“盡管以C++為基礎(chǔ),但Java是一種更純粹的面向?qū)ο蟪绦蛟O(shè)計(jì)語言”。
無論C++還是Java都屬于雜合語言。但在Java中,設(shè)計(jì)者覺得這種雜合并不像在C++里那么重要。雜合語言允許采用多種編程風(fēng)格;之所以說C++是一種雜合語言,是因?yàn)樗С峙cC語言的向后兼容能力。由于C++是C的一個超集,所以包含的許多特性都是后者不具備的,這些特性使C++在某些地方顯得過于復(fù)雜。
Java語言首先便假定了我們只希望進(jìn)行面向?qū)ο蟮某绦蛟O(shè)計(jì)。也就是說,正式用它設(shè)計(jì)之前,必須先將自己的思想轉(zhuǎn)入一個面向?qū)ο蟮氖澜纾ǔ窃缫蚜?xí)慣了這個世界的思維方式)。只有做好這個準(zhǔn)備工作,與其他OOP語言相比,才能體會到Java的易學(xué)易用。在本章,我們將探討Java程序的基本組件,并體會為什么說Java乃至Java程序內(nèi)的一切都是對象。
1.1 用句柄操縱對象
每種編程語言都有自己的數(shù)據(jù)處理方式。有些時候,程序員必須時刻留意準(zhǔn)備處理的是什么類型。您曾利用一些特殊語法直接操作過對象,或處理過一些間接表示的對象嗎(C或C++里的指針)?