首页 > 编程语言 > 详细

[Java Basics] Stack, Heap, Constructor

时间:2014-08-08 23:59:46      阅读:606      评论:0      收藏:0      [点我收藏+]

Good about Java:

friendly syntax, memory management[GC can collect unreferenced memory resources], object-oriented features, portability.

Stack

Stores method invocations, local variables(include object reference, but the object itself is still stored in heap).

If you look at the stack trace, the top method is the one being called, and once it is finished, it will be removed out of the stack.

Heap

Stores all objects(include instance variables in the class).

.hashcode() returns the memory address of the object, so no same hashcode for two objects.

But when the Class is value object, you could override .hashcode() and .equals().

Constructor

Default parameterless constructor: only generated by compiler when there is no your constructor.

Parent constructor: if parent class has default constructor, compiler will automatically call it without .super(). But if not, or you want to call the parent constructor with parameters, you need to call .super() explicitly.

Overloaded constructor: use .this(...) at the first line. 

File I/O

There are two streams: Character stream & Binary stream

Character stream: 

to read/write human readable files, like .txt .xml .html

Class: FileReader/Writer, more advanced: BufferedReader/Writer

Binary stream: 

to read/write machine readable files, like .exe .class .obj

Class: FileInput/OutputStream, more advanced for Object: ObjectInput/OutpoutStream(.writeObject() method).

Immutable Class

Instance could not be modified.

How to: private final fields, final class, no setter methods, ensure exlusive access to mutable components.

 

[Java Basics] Stack, Heap, Constructor,布布扣,bubuko.com

[Java Basics] Stack, Heap, Constructor

原文:http://www.cnblogs.com/chayu3/p/3900243.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!