代码分析系列 内存执行过程
2015-03-14 13:09
267 查看
1、内存执行过程:(六:01:32:08-->)
package primary;
public class Main {
public static void main(String args[]){
Main m= new Main();
int day = 15;
Birthday b1 = new Birthday(27,11,1988);
Birthday b2 = new Birthday(23,04,2013);
m.change1(day);
m.change2(b1);
m.change3(b2);
b1.Display();
b2.Display();
}
void change1(int num){
num = 123;
}
void change2(Birthday b){
b = new Birthday(04,01,1989);
}
void change3(Birthday b){
b.setDay(26);b.setMonth(01);b.setYear(2015);
}
}
class Birthday{
int day;int month;int year;
Birthday(int _day, int _month, int _year){
day = _day;month = _month;year = _year;
}
void Display(){
System.out.println("Birthday is:"+year+"-"+month+"-"+day);
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}
输出:
Birthday is:1988-11-27
Birthday is:2015-1-26
2、涉及知识:
栈内存和堆内存;引用传递和值传递;栈变量用完就释放,堆内存若干时间后会被GC回收。
package primary;
public class Main {
public static void main(String args[]){
Main m= new Main();
int day = 15;
Birthday b1 = new Birthday(27,11,1988);
Birthday b2 = new Birthday(23,04,2013);
m.change1(day);
m.change2(b1);
m.change3(b2);
b1.Display();
b2.Display();
}
void change1(int num){
num = 123;
}
void change2(Birthday b){
b = new Birthday(04,01,1989);
}
void change3(Birthday b){
b.setDay(26);b.setMonth(01);b.setYear(2015);
}
}
class Birthday{
int day;int month;int year;
Birthday(int _day, int _month, int _year){
day = _day;month = _month;year = _year;
}
void Display(){
System.out.println("Birthday is:"+year+"-"+month+"-"+day);
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}
输出:
Birthday is:1988-11-27
Birthday is:2015-1-26
2、涉及知识:
栈内存和堆内存;引用传递和值传递;栈变量用完就释放,堆内存若干时间后会被GC回收。
相关文章推荐
- OO中的继承分析,主要分析在编译和运行过程中子类父类的方法、字段和实例化时候在内存中分配和执行的先后,以及两个原则
- java 程序执行的 内存代码划分即 java执行过程中的内存管理
- 代码的编译、连接与执行过程分析
- Ansible系列(七):执行过程分析、异步模式和速度优化
- Linux内核初始化高端内存的过程(代码分析)
- JVM学习笔记(1、 基本结构;2、Java代码编译和执行的整个过程3、内存管理和垃圾回收 4、 内存调优 )
- java——程序执行过程的内存分析
- ATECC508A芯片开发笔记(五):Provision执行过程及代码分析
- hsqldb源码分析系列3 执行引擎分析 插入过程分析
- 面向对象编程(三)——程序执行过程中内存分析
- MDK __main()代码执行过程分析
- 程序执行过程的内存分析(简单篇)
- 反编译C程序为汇编代码,汇编代码执行过程的分析与思考
- hsqldb源码分析系列3 执行引擎分析 插入过程分析
- 反编译C程序为汇编代码,汇编代码执行过程的分析与思考
- java再复习——代码执行的大体流程与内存分析
- 《linux内核分析》作业一:反汇编一个C语言程序并分析汇编代码执行过程
- 分析MapReduce执行过程(包含代码)
- JVM学习笔记(1、 基本结构;2、Java代码编译和执行的整个过程3、内存管理和垃圾回收 4、 内存调优 )
- 计算机执行程序代码的过程分析