Everything Is an Object
来源:互联网 发布:知秋歌曲 编辑:程序博客网 时间:2024/05/22 12:48
Where Storage Lives
Register
- Exists different from other storage (inside the processor).
- In java you don't have a direct control, nor do you see any evidence in your programs that registers even exist. While in C an C++, you will be allowed to suggest register allocation to the compiler.
Stack
- lives in random access memory (RAM), has direct support from the processor via its stack pointer.
- Fast and efficient way, second only to registers. Instead of Java object, Java object references are placed on the stack.
- 声明的引用放在stack里。
The heap
- Also in RAM area, general-purpose pool of memory where all Java objects live.
- Unlike stack, compiler doesn't need to know hong long that storage must stay on the heap.
- It take more time to allocate and clean up heap storage than stack storage.
- 创建的对象放在heap里。
Constant storage
- Constant values are often placed directly in the program code, which is sage since they never change.
- Sometimes constants are cordoned off by themselves so that they can be optionally placed in read-only memory (ROM), in embedded system.
Non-RAM storage
data lives completely outside a program, it can exist while the program is not running.
Primitive Types
The reason for primitive types in Java is that to create an object with new operator (especially a small, simple variable) isn't very efficient, because new places objects on the heap.
For primitive types, Java (falls back on C and C++) variable of primitive type will not hold a reference, it holds the value directly.
Arrays in Java
A Java array is guaranteed to be initialized and cannot be accessed outside of its range. The range checking comes at the price of having a small amount of memory overhead on each array as well as verifying index at run time.
While using arrays in C and C++ is perilous, because arrays are only blocks of memory. If a program access the array outside of its memory block or uses the memory before initialization, there will be unpredictable results.
Scope of Objects
{ String string = new String("a string");} // end of scope
The reference vanishes at the end of the scope while the String object that s pointing to is still occupying memory (but there is no way to access the object after the end of the scope).
Java has a garbage collector, which looks at the objects that were created with new and figures out which ones are not being referenced anymore.
While in C++ you must make sure that the objects stay around for as long as you need them, you must also destroy the objects when you are done with them.
The Static Keyword
When create a class you re describing how objects of that class look like and how they will behave. You don't actually get an object until you create one using new keyword, at that point storage is allocated and methods become available. While there are two situation where this approach is not sufficient.
- One is you want to have only a single piece of storage for a particular field, regardless of how many objects of that class are created, or even if no objects are created.
- The other is if you need a method that isn't associated with any particular object of this class.
Using the static keyword means that particular field or method is not tied to any particular object instance of that class. There are two way to refer to a static member.
- name it via an object reference.
- name it via a class name.
- Everything Is an Object
- Everything Is an Object
- Scala Everything is an object
- Chapter 2:Everything is an object
- 第二章: Everything is an Object
- 2.Everything is an Object
- Java Note - Everything is an object
- 处理教材:Everything is an object of "Thinking in Java"
- [Thinking_in_Java] 一切都是对象 —— Everything is an object
- Scala 学习笔记(二)— Everything is an object
- Thinking in java-11 Everything is an object
- Everything is a object
- everything is object
- 第二章万事万物皆物件(Everything is an Object)
- 《JAVA编程思想》学习备忘(第61页:Everything Is an Object--1)
- 《JAVA编程思想》学习备忘(第61页:Everything Is an Object--2)
- 《JAVA编程思想》学习备忘(p61:Everything Is an Object--3)
- 处理教材:Everything is an object of "Thinking in Java"
- eclipse中配置tomcat 启动正常 访问报404
- java学习杂记
- Unable to load configuration. - bean - jar:file:/C:/Program%20Files/Apache%20Sof
- FusionCharts V3.4今日发布,主要改进抢先看
- hdu 1715 大菲波数(高精度加法)
- Everything Is an Object
- Swift开发iOS项目实战视频教程(八)---一站到底4(手写代码加控件)
- (十四)重载与类型转换
- 人类顶尖高手vs最强多人对战俄罗斯方块AI视频
- c/c++数据类型转换整理
- 如何修改cloud标准产品的元数据。
- 静态库和共享库 库的定位搜索路径
- Yii AR事务处理
- ubuntu下安装Apache+PHP+Mysql