Thứ Sáu, 14 tháng 11, 2008

Make run a Java program with command

// class NewClass => file NewClass.java
package test;

public class NewClass {
int i;
public NewClass(int index) {
// TODO Auto-generated constructor stub
i = index;
}
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
}

// class Test contains main function => file Test.java
package test;

public class Test {
public static void main(String[] args)
{
NewClass newClass = new NewClass(10);
System.out.println(newClass.getI());
}

}

Lâu rồi ko viết Java, trước có note lại cách make run để ghi nhớ. Ghi nhớ này chưa hoàn chỉnh và hệ thống lắm nhưng giờ chưa có điều kiện để viết, lúc nào rảnh thì viết sau. Để make run một Java program, ta dùng lệnh sau :
/* command to execute the program, with file.class (not yet jar)
* . : current directory.
* test.Test : test is package name, and Test is the main Class (do not go into the test directory).
*/

java -classpath . test.Test

Không có nhận xét nào:

Đăng nhận xét