`
shinepengwei
  • 浏览: 45792 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Everything Is an Object(Thinking In Java读书笔记)

阅读更多

 

  •   我们操作的是对象/类的引用(reference)。
  
  •   存储数据data的五个地方:
  1. Registers
This is 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 as they are needed. You don’t have direct control, nor do you see any evidence in your programs that registers even exist (C & C++, on the other hand, allow you to suggest register allocation to the compiler).
寄存器,数量较少,java中对程序员透明。(cc++可以suggest
  1. 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 way to allocate storage, second only to registers. The Java system must know, while it is creating the program, the exact lifetime of all the items that are stored on the stack. This constraint places limits on the flexibility of your programs, so while some Java storage exists on the stack—in particular, object references—Java objects themselves are not placed on the stack. 
堆栈stack虽然很快,但其存储的变量要求知道生命周期,降低了其灵活性。因此,java的对象没有存储在堆栈。
  
  1. 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, unlike the stack, the compiler doesn’t need to know how long that storage must stay on the heap. Thus, there’s a great deal of flexibility in using storage on the heap. Whenever you need an object, you simply write the code to create it by using new, and the storage is allocated on the heap when that code is executed. Of course there’s a price you pay for this flexibility: It may take more time to allocate and clean up heap storage than stack storage (if you even could create objects on the stack in Java, as you can in C++).
堆栈具有更高的灵活性。
  1. 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 systems.
存放常量,可以放在ROM中。
  
  1. 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 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 when necessary. Java provides support for lightweight persistence, and mechanisms such as JDBC and Hibernate provide more sophisticated support for storing and retrieving object information in databases.
持久层,将类以一定的格式存入硬盘等永久存储。

  • java中的原始类型保存在stack中,效率更高。
          Wrapper 可以使用一个类来表示一个基本类型(存储在heap中).
          eg:
              char c = ‘x’;
          Character ch = new Character(c); 

Primitive type
Size
Minimum
Maximum
Wrapper type
boolean
Boolean
char
16 bits
Unicode 0
Unicode 216- 1
Character
byte
8 bits
-128
+127
Byte
short
16 bits
-215
+215 -1
Short
int
32 bits
-231
+231 -1
Integer
long
64 bits
-263
+263 -1
Long
float
32 bits
IEEE754
IEEE754
Float
double
64 bits
IEEE754
IEEE754
Double
void
Void

          高精度Wrapper类BigInteger and BigDecimal. 对应int和float。精度高,效率低。


  • 垃圾收集器garbage collector

     

    looks at all the objects that were created with new and figures out which ones are not being referenced anymore. 

  • 类中feild的基本变量会自动初始化,但是对于普通的基本变量声明不会初始化,而是给他一个随机的值。报错。
  • 函数参数的传递其实是传递的reference。
  • 两种情况使用static:
    • One is if 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. That is, you need a method that you can call even if no objects are created. 
  • 包java.lang.*自动import
  • 可以通过注释生成javadoc,效果很不错。
    • 所有生成javadoc的注释以/**开始(普通的以/*开始)
    • 只显示public和protect的域和函数。
    • 可以通过嵌入HTML标签来格式化javadoc

更多内容欢迎访问围观IT





  

 



  
分享到:
评论
2 楼 shinepengwei 2012-11-28  
1 楼 qiemengdao 2012-02-10  
java书籍推荐《java深度历险》,《深入java虚拟机》,《practical java》

相关推荐

    thinking in Java guide solution

    "Everything is an Object"章节是Java语言的核心理念之一,强调面向对象编程的思想。在这个章节,读者会了解到如何创建、使用和理解Java中的类、对象以及它们之间的关系。练习1至11分别覆盖了不同的面向对象编程概念...

    thinking in Java guide solutio

    Everything is an Object (一切皆对象) - **基本概念**:这一章介绍了面向对象编程的基本概念,如类、对象、封装等。 - **实例变量与静态变量的区别**: - 实例变量:每个对象都有一份独立的副本,存储在堆内存中...

    java学习笔记.doc

    * 对象: everything is an object(万物皆对象),对象有两个方面:属性(what)和方法(can do). * 面向对象编程的优点:符合人类看待事物的一般规律,高内聚、低耦合,易于拼装成为一个系统。 2. 类和对象: ...

    Java学习笔记(必看经典)

    Java学习笔记(必看经典) 什么是对象:EVERYTHING IS OBJECT(万物皆对象)

    Killer Game Programming in Java

    Recent updates to Java make it faster and easier to create powerful gaming applications-particularly Java 3D-is fueling an explosive growth in Java games. Java games like Puzzle Pirates, Chrome, Star...

    java版everything+纯java不用任何包读取office中word文件

    这个项目可能是一个自研的解决方案,其目标是创建一个Java版的"Everything"工具,这是一个快速的文件搜索工具,但目前可能还处于未完成状态。 首先,让我们深入理解“不使用任何jar包读取docx文件”。docx文件本质...

    Thinking in LINQ

    LINQ is an API that provides several operators to express your intent. Although that is super powerful, it comes with a price. If you don’t know how these operators work internally, you might end up ...

    Packt.Object-Oriented.JavaScript.3rd.Edition

    and make them your own Understand objects in Google Chrome developer tools and how to use Them Use a mix of prototypal inheritance and ...techniques while coding in JavaScript In Detail JavaScript is an object...

    Java编程基础

    realize that everything in this world is an object. Every concept of object-oriented design is fi rst illustrated through real-life analogy. Corresponding Java language constructs are introduced in ...

    java学习笔记(经典)

    "EVERYTHING IS OBJECT",意味着我们可以将任何复杂的问题或实体抽象成对象。 使用面向对象编程的主要原因有两点。首先,它更符合人类理解和解决问题的思维方式,我们习惯于将事物看作具有特定特性和行为的独立实体...

    类everything java源码

    java实现的类everything源码,当前未支持文件添加,删除操作的更新,有一些日志方便开发使用,当然代码有一些冗余,当前支持,多字符串搜索,支持正则表达式搜索,用于学习,来自于: ...

    Genetic Algorithms in Java Basics(Apress,2015)

    Genetic Algorithms in Java Basics is a brief introduction to solving problems using genetic algorithms, with working projects and solutions written in the Java programming language. This brief book ...

    达内java学习笔记-总最全

    "EVERYTHING IS OBJECT"这一原则表明,Java设计者认为一切都可以被看作是对象。 在面向对象编程中,类是创建对象的蓝图。类定义了对象的属性和方法,而对象是类的实例。例如,`class Student`定义了一个学生类,...

    java学习笔记大全

    在Java中,一切皆为对象,这是"EVERYTHING IS OBJECT"概念的体现。对象包含了属性(也称为成员变量或字段)和方法,前者描述了对象的状态,后者定义了对象的行为。对象是类的实例,类是对具有共同属性和行为的对象的...

    Java学习笔记 必看经典

    在面向对象的世界里,一切皆为对象(EVERYTHING IS OBJECT)。对象拥有两个基本特征:属性和方法。属性描述对象的状态,而方法则定义了对象的行为。一个对象的属性可以是另一个对象,这使得对象间的关系更加丰富和...

Global site tag (gtag.js) - Google Analytics