1 / 17

Java Programming Language

Java Programming Language. สาขาวิชาระบบสารสนเทศ คณะบริหารธุรกิจ มหาวิทยาลัยเทคโนโลยีราชมงคลกรุงเทพ. Class Outline. Class/Attention 10 point Midterm 35 point Final 35 point Work Class & H/W 20 poin. Topic. Class Object Method Control Exception String Class & Math Class

oshin
Télécharger la présentation

Java Programming Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Programming Language สาขาวิชาระบบสารสนเทศ คณะบริหารธุรกิจ มหาวิทยาลัยเทคโนโลยีราชมงคลกรุงเทพ

  2. Class Outline • Class/Attention10 point • Midterm 35 point • Final 35 point • Work Class & H/W 20 poin

  3. Topic • Class • Object • Method • Control • Exception • String Class & Math Class • Inheritance • Swing Set& JDBC

  4. การติดตั้งโปรแกรม • ดาวน์โหลดโปรแกรมภาษาจาวา jdk-1_5_0_03-windows-i586-p.exe ที่ www.java.sun.com เพื่อทำการติดตั้งโปรแกรม • ดาวน์โหลดคู่มือภาษาจาวาโปรแกรม jdk-1_5_0-doc.zip ที่ www.java.sun.com เพื่อติดตั้งคู่มือโปรแกรม • ติดตั้งโปรแกรมภาษาจาวา jdk-1_5_0_03 • ติดตั้งคู่มือโปรแกรมภาษาจาวา jdk-1_5_0_03-doc

  5. Config Path Program • กำหนด Pathเพื่อใช้งานโปรแกรม • กรณี win98ให้แก้ไขไฟล์ Autoexec.batดังนี้ set path = C:\Program Files\Java\jdk1.5.0_03 • กรณี winxp • คลิกขวา my computer > properties • แท็ป Advance > Environment Variable • ที่ System variablesแก้ไข pathเหมือน win98 path = C:\Program Files\Java\jdk1.5.0_03

  6. Test ProgramJava Application • เขียนโปรแกรมและบันทึกไฟล์ให้มีนามสกุล .java • ทำการคอมไพล์โปรแกรม c:\javac filename.java  จะได้ไฟล์ที่มีชื่อตามชื่อคลาส • ทำการรันโปรแกรม c:\java filename 

  7. animation Trace a Program Execution Enter main method //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

  8. animation Trace a Program Execution Execute statement //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

  9. animation Trace a Program Execution //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } print a message to the console

  10. NetBeans5.0 • Setup Program NetBeans5.0 • Test Program NetBeans5.0 show… System.out.println(“Hello World”); JOptionPane.showMessageDialog(null,”Hello World”);

  11. Displaying Text in a Message Dialog Box you can use the showMessageDialog method in the JOptionPane class. JOptionPane is one of the many predefined classes in the Java system, which can be reused rather than “reinventing the wheel.”

  12. The showMessageDialog Method JOptionPane.showMessageDialog(null, "Welcome to Java!", “Display Message", JOptionPane.INFORMATION_MESSAGE));

  13. Two Ways to Invoke the Method There are several ways to use the showMessageDialog method. For the time being, all you need to know are two ways to invoke it. One is to use a statement as shown in the example: JOptionPane.showMessageDialog(null, x, y, JOptionPane.INFORMATION_MESSAGE)); where x is a string for the text to be displayed, and y is a string for the title of the message dialog box. The other is to use a statement like this: JOptionPane.showMessageDialog(null, x); where x is a string for the text to be displayed.

  14. Anatomy of a Java Program • Comments • Package • Reserved words • Modifiers • Statements • Blocks • Classes • Methods • The main method

  15. Object Oriented Concept • OOPเป็นการเขียนโปรแกรมที่ประกอบไปด้วยกลุ่มของ Object • Objectสามารถสร้างได้จาก Class • รูปแบบ Classname Objectanme = new Constructorname(); • การเรียงใช้ Attributeหรือ Behaviorกระทำได้ผ่านชื่อ Object • Objectname.method หรือ Objectname.Variable • Classประกอบด้วย • คุณลักษณะ (Attribute) • พฤติกรรม (Behavior) • สามารถถ่ายทอดลักษณะ(Inheritance)ได้

  16. Example Class Car String name String type int Wheel String Color Engine (int cc)

  17. Create Class Program Java import java.lang.*; class TestCar{ public static void main(String args[]){ Car car1 = new Car(); car1.name=“Toyota”; car1.type=“F1” car1.wheel=4; car1.color=“red”; car1.engine(3000); } } import java.lang.*; class Car{ static String name; static String type; static int wheel; static String color; private int eng; Car(){ wheel = 0; color = null; eng = 0; } static void engine (int cc){ eng = cc; } }

More Related