计算机-外文翻译(共7页).doc





《计算机-外文翻译(共7页).doc》由会员分享,可在线阅读,更多相关《计算机-外文翻译(共7页).doc(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上Everything Is an Object “If we spoke a different language, we would perceive a somewhat 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
2、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 languages undesirable features, wh
3、ich 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 its already there). The benefit of this initial effort is the abi
4、lity to program in a language that is simpler to learn and to use than many other OOP languages. In this chapter youll 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 mean
5、s 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?
6、 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.1 You might imagine a television (the object) and a remote control (the reference). A
7、s long as youre holding this reference, you have a connection to the television, but when someone says, “Change the channel” or “Lower the volume,” what youre manipulating is the reference, which in turn modifies the object. If you want to move around 1 This can be a flashpoint. There are those who
8、say, “Clearly, its a pointer,” but this presumes an underlying implementation. Also, Java references are much more akin to C+ references than to pointers in their syntax. In the 1st edition of this book, I chose to invent a new term, “handle,” because C+ references and Java references have some impo
9、rtant differences. I was coming out of C+ and did not want to confuse the C+ programmers whom I assumed would be the largest audience for Java. In the 2nd edition, I decided that “reference” was the more commonly used term, and that anyone changing from C+ would have a lot more to cope with than the
10、 terminology of references, so they might as well jump in with both feet. However, there are people who disagree even with the term “reference.” I read in one book where it was “completely wrong to say that Java supports pass by reference,” because Java object identifiers (according to that author)
11、are actually “object references.” And (he goes on) everything is actually pass by value. So youre not passing by reference, youre “passing an object reference by value.” One could argue for the precision of such convoluted explanations, but I think my approach simplifies the understanding of the con
12、cept without hurting anything (well, the language lawyers may claim that Im lying to you, but Ill say that Im providing an appropriate abstraction). the room and still control the television, you take the remote/reference with you, not the television. Also, the remote control can stand on its own, w
13、ith no television. That is, just because you have a reference doesnt mean theres necessarily an object connected to it. So if you want to hold a word or sentence, you create a String reference: String s; But here youve created only the reference, not an object. If you decided to send a message to s
14、at this point, youll get an error because s isnt actually attached to anything (theres no television). A safer practice, then, is always to initialize a reference when you create it: String s = asdf; However, this uses a special Java feature: Strings can be initialized with quoted text. Normally, yo
15、u must use a more general type of initialization for objects.You must create all the objects When you create a reference, you want to connect it with a new object. You do so, in general, with the new operator. The keyword new says, “Make me a new one of these objects.” So in the preceding example, y
16、ou can say: String s = new String(asdf); Not only does this mean “Make me a new String,” but it also gives information about how to make the String by supplying an initial character string. Of course, Java comes with a plethora of ready-made types in addition to String. Whats more important is that
17、you can create your own types. In fact, creating new types is the fundamental activity in Java programming, and its what youll be learning about in the rest of this book. Where storage lives Its useful to visualize some aspects of how things are laid out while the program is running in particular ho
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 外文 翻译

限制150内