java毕业设计外文文献原文及译文.doc

上传人:韩长文 文档编号:5175597 上传时间:2020-02-15 格式:DOC 页数:7 大小:42.50KB
返回 下载 相关 举报
java毕业设计外文文献原文及译文.doc_第1页
第1页 / 共7页
java毕业设计外文文献原文及译文.doc_第2页
第2页 / 共7页
java毕业设计外文文献原文及译文.doc_第3页
第3页 / 共7页
java毕业设计外文文献原文及译文.doc_第4页
第4页 / 共7页
java毕业设计外文文献原文及译文.doc_第5页
第5页 / 共7页
亲,该文档总共7页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《java毕业设计外文文献原文及译文.doc》由会员分享,可在线阅读,更多相关《java毕业设计外文文献原文及译文.doc(7页珍藏版)》请在三一文库上搜索。

1、毕业设计说明书英文文献及中文翻译 学 号: 学 号: 软件学院学生姓名: 软件工程学 院: 专 业: 指导教师: 2014 年 6 月 Thinking in JavaAlthough 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 hybri

2、d 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, which can make some aspects of C+ overly complicated. The Java languag

3、e 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 ability to program in a language that is simpler to learn and to use th

4、an many other OOP languages. In this chapter well see the basic components of a Java program and well learn that everything in Java is an object, even a Java program.Each programming language has its own means of manipulating data. Sometimes the programmer must be constantly aware of what type of ma

5、nipulation is going on. Are you manipulating the object 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. Altho

6、ugh you treat everything as an object, the identifier you manipulate is actually a “reference” to an object. You might imagine this scene as a television (the object) with your remote control (the reference). As long as youre holding this reference, you have a connection to the television, but when

7、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 the room and still control the television, you take the remote/reference with you, not the television. Also, the remote control can stand o

8、n its own, with 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: But here youve created only the reference, not an object. If you decided to send a message to

9、s at this point, youll get an error (at run time) because s isnt actually attached to anything (theres no television). A safer practice, then, is always to initialize a reference when you create it.However, this uses a special Java feature: strings can be initialized with quoted text. Normally, you

10、must use a more general type of initialization for objectsWhen 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: Not only does this mean

11、“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 comes with a plethora of ready-made types. Whats more important is that you can create your own types. In fact, thats

12、the fundamental activity in Java programming, and its what youll be learning about in the rest of this bookIts useful to visualize some aspects of how things are laid out while the program is runningin particular how memory is arranged. There are six different places to store data: Registers. This i

13、s 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 compiler according to its needs. You dont have direct control, nor do you see any evidence in your pr

14、ograms that registers even exist. The stack. This lives in the general random-access memory (RAM) area, but has direct support from the processor via its stack pointer. The stack pointer is moved down to create new memory and moved up to release that memory. This is an extremely fast and efficient w

15、ay to allocate storage, second only to registers. The Java compiler 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 flex

16、ibility of your programs, so while some Java storage exists on the stackin particular, object referencesJava objects themselves are not placed on the stack. The heap. This is a general-purpose pool of memory (also in the RAM area) where all Java objects live. The nice thing about the heap is that, u

17、nlike the stack, the compiler doesnt need to know how much storage it needs to allocate from the heap or how long that storage must stay on the heap. Thus, theres 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 b

18、y using new, and the storage is allocated on the heap when that code is executed. Of course theres a price you pay for this flexibility. It takes more time to allocate heap storage than it does to allocate stack storage (if you even could create objects on the stack in Java, as you can in C+). Stati

19、c storage. “Static” is used here in the sense of “in a fixed location” (although its also in RAM). Static storage contains data that is available for the entire time a program is running. You can use the static keyword to specify that a particular element of an object is static, but Java objects the

20、mselves are never placed in static storage. Constant storage. Constant values are often placed directly in the program code, which is safe since they can never change. Sometimes constants are cordoned off by themselves so that they can be optionally placed in read-only memory (ROM), in embedded syst

21、ems. Non-RAM storage. If data lives completely outside a program, it can exist while the program is not running, outside the control of the program. The two primary examples of this are streamed objects, in which objects are turned into streams of bytes, generally to be sent to another machine, and

22、persistent objects, in which the objects are placed on disk so they will hold their state even when the program is terminated. The trick with these types of storage is turning the objects into something that can exist on the other medium, and yet can be resurrected into a regular RAM-based object wh

23、en necessary. Java provides support for lightweight persistence, and future versions of Java might provide more complete solutions for persistenceOne group of types, which youll use quite often in your programming, gets special treatment. You can think of these as “primitive” types. The reason for t

24、he special treatment is that to create an object with newespecially a small, simple variableisnt very efficient, because new places objects on the heap. For these types Java falls back on the approach taken by C and C+. That is, instead of creating the variable by using new, an “automatic” variable

25、is created that is not a reference. The variable holds the value, and its placed on the stack, so its much more efficient. Java determines the size of each primitive type. These sizes dont change from one machine architecture to another as they do in most languages. This size invariance is one reaso

26、n Java programs are portableJava编程思想 “尽管以C+为基础,但Java是一种更纯粹的面向对象程序设计语言”。无论C+还是Java都属于杂合语言。但在Java中,设计者觉得这种杂合并不象在C+里那么重要。杂合语言允许采用多种编程风格;之所以说C+是一种杂合语言,是因为它支持与C语言的向后兼容能力。由于C+是C的一个超集,所以包含的许多特性都是后者不具备的,这些特性使C+在某些地方显得过于复杂。 Java语言首先便假定了我们只希望进行面向对象的程序设计。也就是说,正式用它设计之前,必须先将自己的思想转入一个面向对象的世界(除非早已习惯了这个世界的思维方式)。只有做

27、好这个准备工作,与其他OOP语言相比,才能体会到Java的易学易用。在本章,我们将探讨Java程序的基本组件,并体会为什么说Java乃至Java程序内的一切都是对象。 每种编程语言都有自己的数据处理方式。有些时候,程序员必须时刻留意准备处理的是什么类型。您曾利用一些特殊语法直接操作过对象,或处理过一些间接表示的对象吗(C或C+里的指针)? 所有这些在Java里都得到了简化,任何东西都可看作对象。因此,我们可采用一种统一的语法,任何地方均可照搬不误。但要注意,尽管将一切都“看作”对象,但操纵的标识符实际是指向一个对象的“句柄”(Handle)。在其他Java参考书里,还可看到有的人将其称作一个“

28、引用”,甚至一个“指针”。可将这一情形想象成用遥控板(句柄)操纵电视机(对象)。只要握住这个遥控板,就相当于掌握了与电视机连接的通道。但一旦需要“换频道”或者“关小声音”,我们实际操纵的是遥控板(句柄),再由遥控板自己操纵电视机(对象)。如果要在房间里四处走走,并想保持对电视机的控制,那么手上拿着的是遥控板,而非电视机。 此外,即使没有电视机,遥控板亦可独立存在。也就是说,只是由于拥有一个句柄,并不表示必须有一个对象同它连接。所以如果想容纳一个词或句子,可创建一个String句柄: 但这里创建的只是句柄,并不是对象。若此时向s发送一条消息,就会获得一个错误(运行期)。这是由于s实际并未与任何东

29、西连接(即“没有电视机”)。因此,一种更安全的做法是:创建一个句柄时,记住无论如何都进行初始化:;然而,这里采用的是一种特殊类型:字串可用加引号的文字初始化。通常,必须为对象使用一种更通用的初始化类型。 创建句柄时,我们希望它同一个新对象连接。通常用new关键字达到这一目的。new的意思是:“把我变成这些对象的一种新类型”。所以在上面的例子中,可以说:String s = new String(asdf); 它不仅指出“将我变成一个新字串”,也通过提供一个初始字串,指出了“如何生成这个新字串”。 当然,字串(String)并非唯一的类型。Java配套提供了数量众多的现成类型。对我们来讲,最重要

30、的就是记住能自行创建类型。事实上,这应是Java程序设计的一项基本操作,是继续本书后余部分学习的基础。程序运行时,我们最好对数据保存到什么地方做到心中有数。特别要注意的是内存的分配。有六个地方都可以保存数据:(1) 寄存器。这是最快的保存区域,因为它位于和其他所有保存方式不同的地方:处理器内部。然而,寄存器的数量十分有限,所以寄存器是根据需要由编译器分配。我们对此没有直接的控制权,也不可能在自己的程序里找到寄存器存在的任何踪迹。(2) 堆栈。驻留于常规RAM(随机访问存储器)区域,但可通过它的“堆栈指针”获得处理的直接支持。堆栈指针若向下移,会创建新的内存;若向上移,则会释放那些内存。这是一种

31、特别快、特别有效的数据保存方式,仅次于寄存器。创建程序时,Java编译器必须准确地知道堆栈内保存的所有数据的“长度”以及“存在时间”。这是由于它必须生成相应的代码,以便向上和向下移动指针。这一限制无疑影响了程序的灵活性,所以尽管有些Java数据要保存在堆栈里特别是对象句柄,但Java对象并不放到其中。(3) 堆。一种常规用途的内存池(也在RAM区域),其中保存了Java对象。和堆栈不同,“内存堆”或“堆”(Heap)最吸引人的地方在于编译器不必知道要从堆里分配多少存储空间,也不必知道存储的数据要在堆里停留多长的时间。因此,用堆保存数据时会得到更大的灵活性。要求创建一个对象时,只需用new命令编

32、制相关的代码即可。执行这些代码时,会在堆里自动进行数据的保存。当然,为达到这种灵活性,必然会付出一的代价:在堆里分配存储空间时会花掉更长的时间!(4) 静态存储。这儿的“静态”(Static)是指“位于固定位置”(尽管也在RAM里)。程序运行期间,静态存储的数据将随时等候调用。可用static关键字指出一个对象的特定元素是静态的。但Java对象本身永远都不会置入静态存储空间。(5) 常数存储。常数值通常直接置于程序代码内部。这样做是安全的,因为它们永远都不会改变。有的常数需要严格地保护,所以可考虑将它们置入只读存储器(ROM)。(6) 非RAM存储。若数据完全独立于一个程序之外,则程序不运行时

33、仍可存在,并在程序的控制范围之外。其中两个最主要的例子便是“流式对象”和“固定对象”。对于流式对象,对象会变成字节流,通常会发给另一台机器。而对于固定对象,对象保存在磁盘中。即使程序中止运行,它们仍可保持自己的状态不变。对于这些类型的数据存储,一个特别有用的技巧就是它们能存在于其他媒体中。一旦需要,甚至能将它们恢复成普通的、基于RAM的对象。Java 1.1提供了对Lightweight persistence的支持。未来的版本甚至可能提供更完整的方案。 有一系列类需特别对待;可将它们想象成“基本”、“主要”或者“主”(Primitive)类型,进行程序设计时要频繁用到它们。之所以要特别对待,是由于用new创建对象(特别是小的、简单的变量)并不是非常有效,因为new将对象置于“堆”里。对于这些类型,Java采纳了与C和C+相同的方法。也就是说,不是用new创建变量,而是创建一个并非句柄的“自动”变量。这个变量容纳了具体的值,并置于堆栈中,能够更高效地存取。 Java决定了每种主要类型的大小。就象在大多数语言里那样,这些大小并不随着机器结构的变化而变化。这种大小的不可更改正是Java程序具有很强移植能力的原因之一。第 7 页 共 7 页

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 项目管理


经营许可证编号:宁ICP备18001539号-1