我的java学习之路疑点小结
2015-04-23 12:31
239 查看
疑点1:编写一个java文件的时候,
疑点2:一个程序中有很多的类,运行的时候(例如在tomcat上),是否加载所有的类?如果那样的话当程序太大的时候会不会内存溢出?
解答:
疑点2:一个程序中有很多的类,运行的时候(例如在tomcat上),是否加载所有的类?如果那样的话当程序太大的时候会不会内存溢出?
解答:
package ClassLoad; public class Test { public static void main(String[] args) { System.out.println("------------------begin--------------------"); new Gum(); try{ Class.forName("ClassLoad.Cookie"); }catch(Exception e) { throw new RuntimeException(e); } System.out.println("After Class.forName('Cookie')"); new SweetShop(); System.out.println("------------------end--------------------"); } } class Gum{ static{ System.out.println("Gum.enclosing_method()"); } } class Cookie{ static{ System.out.println("Cookie.enclosing_method()"); } } class SweetShop{ static{ System.out.println("SweetShop.enclosing_method()"); } }经过验证,可知,所有的类都是在第一次使用是动态加载到JVM中的,java程序在在它运行之前并非被完全加载,也就不存在因为加载过多不必要的类而导致系统内存溢出。(回收机制也会回收哪些长时间不使用的类)
相关文章推荐
- 黑马程序员 【】java学习之路——枚举小结
- 黑马程序员 【】java学习之路——代理小结
- 小结一年半的java学习之路
- java中继承关系学习小结
- netty框架学习之路(一)—— Java网络IO模型
- [置顶] JAVA学习之路--与JVM的亲密接触
- 我的JAVA学习之路
- Java学习之路[0]:配置JDK9及其主流IDE安装(Win10与Linux(Deepin))
- java基础学习_常用类小结
- Java学习小结
- Java学习之路[目录]
- java学习之路——第一天
- 演绎人生之JAVA学习之路起航
- java学习之路——第二天
- Java学习之路[2]:JavaFX 前瞻&资料收集__正在更新__
- Java学习之路(书籍推荐)
- 我的学习之路_第二章java入门_接口/多态
- C++到Java的学习之路--初识java(一)变量初始化
- java IO学习小结
- Java 学习之路 之 成员变量和局部变量