Notes Of Thinking In Java (1)
来源:互联网 发布:linux下搭建ftp服务器 编辑:程序博客网 时间:2024/04/28 03:29
As everyone knows, English is very important for a programmer, because most outstanding program books are written in English. Thus, when I read a program book, I select the English edition. Though I am not so skilled at English that read the English edition smoothly, it is significant to do that. Well, these days I am reading the Thinking In Java(Fourth Edition) and here are some notes of the previous six chapters.
Where storage lives
There are five different places to store data:
Registers;
The stack;
The heap;
Constant storage;
Non-RAM storage;
Special case: primitive types
the difference between using new and not using new:
using new:the variable created by new is placed on the heap
not using new:the variable created not using new holds the value directly, and it’s placed on the stack
Default values for primitive members
When a primitive data type is a member of a class, it is guaranteed to get a default value if you do not initialize it:
boolean false
char ‘/u0000’ (null)
byte (byte)0
short (short)0
int 0
long 0L
float 0.0f
double 0.0d
aliasing:
when you assign primitives, you copy the contents from one place to another;
Whenever you manipulate an object, what you’re manipulating is the reference, so when you assign “from one object to another,” you’re actually copying a reference from one place to another.
Cleanup: finalization and garbage collection
The garbage collector only knows how to release memory allocated with new.
Your objects might not get garbage collected.
Garbage collection is not destruction.
Garbage collection is only about memory.
When the garbage collector is ready to release the storage used for your object, it will first call finalize(), which Java provides, and only on the next garbage-collection pass will it reclaim the object’s memory.
Enumerated types
Although enums appear to be a new data type, the keyword only produces some compiler behavior while generating a class for the enum, so in many ways you can treat an enum as if it were any other class. In fact, enums are classes and have their own methods.
enums can be used inside switch statements.
package: the library unit
Each compilation unit must have a name ending in .java, and inside the compilation unit there can be a public class that must have the same name as the file (including capitalization, but excluding the .java file name extension). There can be only one public class in each compilation unit; otherwise, the compiler will complain. If there are additional classes in that compilation unit, they are hidden from the world outside that package because they’re not public, and they comprise “support” classes for the main public class.
conditional compilation
Since Java is intended to be automatically cross-platform,C’s conditional compilation is missing from java.
Java access specifiers
private
no one can access that member except the class that
contains that member, inside methods of that class .
Package access
all the other classes in the current package have access to that member, but to all the classes outside of this package, the member appears to be private.
protected
The derived classes and the classes in the current package have access to that member.
public
the member declaration that immediately follows public is available to everyone, in particular to the client programmer who uses the library.
The final keyword
final data
final makes the value a constant or makes the reference a constant. The confusable thing is once the reference is initialized to an object, it can never be changed to point to another object. However, the object itself can be modified; Java does not provide a way to make any arbitrary object a constant .
final methods
The first reason for final methods is to put a “lock” on the method to prevent any inheriting class from changing its meaning. The second is efficiency.
final classes
You cannot inherit from a final class.
- Notes Of Thinking In Java (1)
- thinking in java 3 notes
- thinking in java ch2 notes
- Thinking in Java --- Chapter 1 (Notes)
- [Notes] Thinking in JAVA 4th
- Note of 《thinking in java》1
- Thinking In C++ Notes(1) 方法论
- Thinking in java(1)
- Thinking in java-1
- Thinking in Java(1)
- Note of 《thinking in java》2
- Note of 《thinking in java》3
- Note of 《thinking in java》4
- Note of 《thinking in java》5
- Note of 《thinking in java》6
- Thinking In Java:Characteristics of Object-Oriented
- 处理教材:Operators of "Thinking in Java"
- thinking in java-chap 1
- javascript 嵌套的函数(作用域链)
- Silverlight 2.0 学习笔记——RIAs
- zai struct2 zhong shiyong json
- 用vb进行dll进程注入
- 胡子高级记事本VB版1.093源码
- Notes Of Thinking In Java (1)
- 关于VC/MFC中内存管理、堆、堆栈概念理解收集的几点说明
- 大裂变来了---- 读过的最好一段文章
- C#命名规则
- [转]Windows CE 5.0下16C2550串口芯片驱动硬件FIFO控制Bug分析以及修正方法
- OpenSolaris 2008.11 引导慢问题解决及build 106
- XP下命令及安全
- 中医是迷信和反科学的
- 介绍linux上两种rootkits检测工具: Rootkit Hunter和Chkrootkit