public class HelloWorld{
public static void main(String args[]){
System.out.print( "Java HelloWorld!" );
}
}
|
解釋:以上java小應(yīng)用程序代碼輸出結(jié)果為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" );
}
}
// 從內(nèi)部類集成
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);
}
}
|
用以下命令來調(diào)試代碼: javac HelloWorld.java java HelloWorld
HelloWorld.java
package mars;
public class HelloWorld {...}
javac -d . HelloWorld.java //加上-d .參數(shù)后,javac會(huì)自動(dòng)創(chuàng)建mars文件夾,并將HelloWorld.class放入該文件夾內(nèi)
mars.mf (注意最后面一行內(nèi)容后面必須有一個(gè)空行,否則最后一行將被丟棄。)
Main-Class: mars.HelloWorld
jar cvfm mars.jar mars.mf mars
java -jar mars.jar
// 內(nèi)部類:生成Parcel.class、Parcel$Destination.class、Parcel$Contents.class
// 如果內(nèi)部類是匿名的,那么編譯器會(huì)簡單地生成數(shù)字,把它們作為內(nèi)部類標(biāo)識(shí)符使用。若內(nèi)部類嵌套于其他內(nèi)部類中,則它們的名字簡單地追加在一個(gè)$以及外部類標(biāo)識(shí)符的后面。
![]() | ![]() .. 定價(jià):¥45 優(yōu)惠價(jià):¥42 更多書籍 |
![]() | ![]() .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書籍 |