3. โครงสร้างภาษาจาวา (ต่อ)
▪ ตัวอย่างโปรแกรมภาษาจาวา
▪ ไฟล์ Example.java
▪ class Example
▪ {
▪ public static void main(String[] args)
▪ {
▪ String dataname = “Java Language“;
▪ System.out.println(“My name is OAK“);
▪ System.out.println(“OAK is a “ + dataname +“. “);
▪ }
▪ }
4. โครงสร้างภาษาจาวา (ต่อ)
▪ หมายเหตุ
▪ Compile : javac Example.java จะได้ไฟล์ Example.class
▪ Run : java Example
▪ Output : My name is OAK
▪ OAK is a Java Language
▪ คาอธิบาย
▪ – method main( ) จะเป็น method หลักที่ใช้ในการ run program ดังนั้นการกระทาต่าง
ๆ ที่ต้องการให้เกิดขึ้น ในการ run program จะต้องทาการเขียนคาสั่งไว้ใน method นี้
▪ – การแสดงผลทางจอภาพ (Console Output) ใช้ method ชื่อ “println” ซึ่งอยู่ใน
System.out คาสั่งนี้จะรับข้อมูลที่เป็น String เพื่อนามาแสดงผลทางจอภาพ