Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
TIJ swot_JAVA的初学者(五)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

1.7 Object landscapes and lifetimes

Well, mentioned something about C++

C++ takes the approach that control of efficiency is the most important issue, so it gives programmer the choice to determine the storage and lifetime while the program is being written, by placing the objects on the stack or in the staic storage area. (what the hell is that?) But this approach obviously sacrifices the flexibility.

In Java, objects are created dynamically in a pool of memory called the heap. In this approach, we dont know how many objects we need until the run-time. But because the storage is managed dynamically, at run-time, the amount of time required to allocate storage on the heap is significantly longer than the time to create storage on the stack.

Then , another issue, the lifetime. In a language like C++, it must be determined programmatically when to destroy the object, which can lead to memory leaks if you don't do it correctly. Java provides a feature called garbage collector that automatically discovers when an object is no longer in use and destroys it.

1.7.1 Collections and iterators

In OOP language, we have a set of containers to expand themselves whenever necessary to accomodate everything we place inside it. Such as, in C++ we have Standard Template Library(STL), Object Pascal has Visual Component Library(VCL). In Java, we we standard libraries, like vector, sets, queues, hash tables, trees, stacks, etc.

And, there comes iterator, which is an object as well. Its job is to select the elements within a container and present them to the user of the iterator.

The container, via iterator, is abstracted to be simply a sequence.

In vresion1.0 and 1.1, Java has standard iterator, called Enummeration. Java2 has added a much more complete library that contains an iterator called Iterator.

1.7.2 The singly rooted hierarchy

All classes in Java are inherited from class Object.

Hoop! What do I know?

Singly rooted hierarchy is good for OOP and easier to implement a garbage collctor. Come back later!

 

 

 




相关文章

相关软件