码迷,mamicode.com
首页 > 其他好文 > 详细

helloworld的运行机制

时间:2016-05-28 17:13:23      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

public class helloworld{

  public static void main(String[] args){

   String s;

    s = "hello world!";

    System.out.println("输出:"+s); 

}

}

一个类中有且仅有一个主类,主类必须是static,然后是public,并且主类没有返回值。

java文件首先编译器编译为字节码文件,有几个方法编译几个字节码文件;然后由虚拟机执行,但单线程程序中,主方法是虚拟机的入口,

程序在运行时,方法区存放:首先由编译器编译一个类的字节码文件,四个类分别是:helloworld.class,String[].class,String.class,System.class;

堆中存放对象,里面包含:3方法:System.out,System.in,System.error

栈中包含变量,有args 数组,但是null数组串,还有s;

当虚拟机运行时,访问数组地址s,由于s指向“Helloworld”,调用String类中tostring方法,再有system类中的system.out输出。

 

个人理解不是很清楚,欢迎大家指出,

helloworld的运行机制

标签:

原文地址:http://www.cnblogs.com/lsl-918/p/5537860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!