TIJ swot_JAVA的初学者(五)

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!

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值