TIJ swot_JAVA的初学者(五)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航