计算机专业毕业设计文献翻译--一切都是对象(编辑修改稿)内容摘要:
when someone says “change the channel” or “lower the volume,” what you‟re manipulating is the reference, which in turn modifies the object. If you want to move around the room and still control the television, you take the remote/reference with you, not the 第 8页 television. Also, the remote control can stand on its own, with no television. That is, just because you have a reference doesn‟t mean there‟s 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 you‟ve created only the reference, not an object. If you decided to send a message to s at this point, you‟ll get an error (at run time) because s isn‟t actually attached to anything (there‟s 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, you 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 keyword. The keyword new says, “Make me a new one of these objects.” So in the preceding example, you 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, String is not the only type that exists. Java es with a plethora of readymade types. What‟s more important is that you can create your own types. In fact, that‟s the fundamental activity in Java programming, and it‟s what you‟ll be learning about in the rest of this book. It‟s useful to visualize some aspects of how things are laid out while the program is running—in particular how memory is arranged. There are six different places to store data: Registers. This is the fastest storage because it exists in a place different from that of other storage: inside the processor. However, the number of registers is severely limited, so registers are allocated by the piler according to its needs. You don‟t have direct control, nor do you see any evidence in your programs that registers even exist. The stack. This lives in the general randomaccess memory (RAM) area, but has direct support from the processor via its stack pointer. The stack pointer is moved down to create 第 9页 new memory and moved up to release that memory. This is an extremely fast and efficient way to allocate storage, second only to registers. The Java piler must know, while it is creating the program, the exact size and lifetime of all the data that is stored on the stack, because it must generate the code to move the stack pointer up and down. This constraint places limits on the flexibility of your programs, so while some Java storage exists on the stack—in particular, object references—Java objects themselves are not placed on the stack. The heap. This is a generalpurpose pool of memory (also in the RAM area) where all Java objects live. The nice thing about the heap is that, unlike the stack, the piler doesn‟t need to know how much storage it needs to allocate from the heap or how long that storage must stay on the heap. Thus, there‟s a great deal of flexibility in using storage on the heap. Whenever you need to create an object, you simply write the code to create it by using new, and the storage is allocated on。计算机专业毕业设计文献翻译--一切都是对象(编辑修改稿)
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。