考试首页 | 考试用书 | 培训课程 | 模拟考场 | 考试论坛  
全国  |             |          |          |          |          |         
  当前位置:计算机等级 > 二级考试 > Java语言程序设计 > 考试辅导 > 文章内容
  

全国计算机二级考试Java语言程序设计知识点(4)

中华IT学院   【 】  [ 2016年4月27日 ]

public class HelloWorld{

public static void main(String args[]){

System.out.print("Java HelloWorld!");

}

}

解释:以上java小应用程序代码输出结果为Java HelloWorld!。

HelloWorld.java

import java.util.*;

 

public class HelloWorld {

public static void main(String[] args){

System.out.println(new Date());

Properties p = System.getProperties();

p.list(System.out);

 

try{

Thread.currentThread().sleep(5 1000);

}catch(InterruptedException e){}

}

}

public class Parcel{

 class Contents{

 private int i = 11;

 public int value(){return i;}

 }

 

 class Destination{

 private String label;

 Destination(String what){label = what;}

 String readLabel(){return label;}

 }

 

 public static void main(String[] args)

 {

 Parcel p = new Parcel();

 Parcel.Contents c = p.new Contents();

 Parcel.Destination d = p.new Destination("Tanzania");

 }

}

// 从内部类集成

class Outer{

 class Inner{}

}

 

public class InheritInner extends Outer.Inner{

 //InheritInner() {} //Won't compile,need outer class'instance handle

 InheritInner(Outer outer){

 outer.super();

 }

 

 public static void main(String[] args){

 Outer outer = new Outer();

 InheritInner ii = new InheritInner(outer);

 }

}

    用以下命令来调试代码: javac HelloWorld.java java HelloWorld

    HelloWorld.java

    package mars;

    public class HelloWorld {...}

    javac -d . HelloWorld.java //加上-d .参数后,javac会自动创建mars文件夹,并将HelloWorld.class放入该文件夹内

    mars.mf (注意最后面一行内容后面必须有一个空行,否则最后一行将被丢弃。)

    Main-Class: mars.HelloWorld

    jar cvfm mars.jar mars.mf mars

    java -jar mars.jar

    // 内部类:生成Parcel.class、Parcel$Destination.class、Parcel$Contents.class

    // 如果内部类是匿名的,那么编译器会简单地生成数字,把它们作为内部类标识符使用。若内部类嵌套于其他内部类中,则它们的名字简单地追加在一个$以及外部类标识符的后面。

分享到:
本文纠错】【告诉好友】【打印此文】【返回顶部
将考试网添加到收藏夹 | 每次上网自动访问考试网 | 复制本页地址,传给QQ/MSN上的好友 | 申请链接 | 意见留言 TOP
关于本站  网站声明  广告服务  联系方式  站内导航  考试论坛
Copyright © 2007-2013 中华考试网(Examw.com) All Rights Reserved