`
shinepengwei
  • 浏览: 44078 次
  • 性别: 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 4th Edition.pdf

    Everything Is an Object 41  Operators 63  Controlling Execution 93  Initialization & Cleanup 107  Access Control 145  Reusing Classes 165  Polymorphism 193  Interfaces 219  Inner Classes 243 ...

    Thinking in JAVA 4th英文版

    Everything Is an Object 41 You manipulate objects with references ..................... 41 You must create all the objects ....................... 42 Where storage lives ...................... 42 ...

    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...

    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学习笔记

    java学习笔记必看经典,JAVA的面向对象编程--------课堂笔记,什么是对象:EVERYTHING IS 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的面向对象编程Java学习笔记(必看经典).doc

    什么是对象:EVERYTHING IS OBJECT(万物皆对象) 所有的事物都有两个方面: 有什么(属性):用来描述对象。 能够做什么(方法):告诉外界对象有那些功能。 后者以前者为基础。 大的对象的属性也可以是一个对象。...

    达内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 ...

    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 ...

    Java in a Nutshell

    <p><em>Java in a Nutshell</em> is a complete quick-reference guide to Java, the hot new programming language from Sun Microsystems. This comprehensive volume contains descriptions of all of the ...

    Object Oriented JavaScript(PACKT,3ed,2017)

    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...

    Electrical Engineering 101 Everything You Should Have Learned in School

    Electrical Engineering 101 Everything You Should Have Learned in School but Probably Didnt, 2nd

    Computer Graphics Programming in OpenGL with Java

    It is appropriate both for computer science undergraduate graphics programming courses in degree programs that emphasize Java, and for professionals interested in mastering 3D graphics skills who ...

    Genetic.Algorithms.in.Java.Basics.1484203291

    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 ...

    java7帮助文档

    JDK 7 is a superset of JRE 7, and contains everything that is in JRE 7, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE 7 provides the libraries, ...

Global site tag (gtag.js) - Google Analytics