11. B-Com : NCU 19/06/56
51-302 Computer Programming 2 11
ทดสอบหลังการติดตั1ง
• ไปที dos promt แล้วพิมพ์คําสัง java -version
OK
first program
/*
This is a first program.
*/
class Lab1 // ชือ class จะเป็นชือเดียวกันไฟล์
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
บันทึกให้ชือไฟล์เป็น d:j2sdk1.4.2_02codeLab1.java
12. B-Com : NCU 19/06/56
51-302 Computer Programming 2 12
comment
/*
This is a first program.
*/
class Lab1
{
// public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
comment
comment
• /*
comment มากกว่าหนึงบรรทัด
..............................................
......................................................................
......................................................................
*/
• // comment ทีละบรรทัด
// comment บรรทัดทีสอง
13. B-Com : NCU 19/06/56
51-302 Computer Programming 2 13
class
/*
This is a first program.
*/
class Lab1
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
class
class
• ในไฟล์หนึงไฟล์จะต้องมี class อย่างน้อย 1 class
• รายละเอียดใน class จะประกอบด้วย data member
และ method
รูปแบบ
class ชือ class
{
<class member declaration>
}
14. B-Com : NCU 19/06/56
51-302 Computer Programming 2 14
method
/*
This is a first program.
*/
class Lab1
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
method
method
public static void main(String[] args)
{
System.out.println("Hello World!");
}
modifier modifier return type method name parameter
method body
15. B-Com : NCU 19/06/56
51-302 Computer Programming 2 15
program template
class
{
}
method and attribute
class name
import statement
comment
ทดลองสร้างโปรแกรม
resume.java
ประกอบด้วย
code
name
major
address