Presentation is loading. Please wait.

Presentation is loading. Please wait.

April 20023CSG11 Electronic Commerce Java (1) John Wordsworth Department of Computer Science The University of Reading Room 129,

Similar presentations


Presentation on theme: "April 20023CSG11 Electronic Commerce Java (1) John Wordsworth Department of Computer Science The University of Reading Room 129,"— Presentation transcript:

1 April 20023CSG11 Electronic Commerce Java (1) John Wordsworth Department of Computer Science The University of Reading J.B.Wordsworth@rdg.ac.uk Room 129, Ext 6544

2 April 20023CSG12 Lecture objectives Outline the place of the Java language in E-commerce Revise the concepts of object-oriented programming Describe the structure of a Java class and its parts Describe the structure of a Java application, and the way it uses objects Explain how Java implements inheritance

3 April 20023CSG13 What is Java An object-oriented programming language invented by Sun Microsystems A collection of classes that model useful objects: windows, buttons, text areas, files, databases … A language for developing applications that can be executed on many platforms:  Write Java source code  Compile to Java bytecodes (javac)  Execute under the control of the Java Virtual Machine (java)

4 April 20023CSG14 Java in e-commerce Client programming with applets:  Classes for setting up and controlling the graphical user interface Server programming with servlets:  Classes for managing the interface with tier 1 (JSPs)  Classes for managing the interface with tier 3 (EJBs)

5 April 20023CSG15 An object-oriented language Object - an instance of a class: variables methods Message - executing a method: destination object (class) parameters Class - a blueprint for objects: class variable (static) and class method (static) instance variable and instance method constructor inheritance Interface - a collection of methods

6 April 20023CSG16 An interface for a simple bank account public interface AccountIf { void deposit (int amt); void withdraw (int amt); void showBal; }

7 April 20023CSG17 A class for a simple bank account public class Account implements AccountIf { private String sortcode, acctno; private int balance; Account (String sc, String an) { sortcode = new String (sc); acctno = new String (an);balance = 0;} public void deposit (int amt) { balance = balance + amt; } public void withdraw (int amt) { balance = balance – amt;} public void showBal { System.out.println ( “Sort code “+sortcode+” Acct number “+acctno=“ Balance “+balance); }

8 April 20023CSG18 A program to use a bank account public class AccountMain { public static void main (String [] args) { Account ac1 = new Account ("304050", "01234567"); ac1.showBal(); ac1.deposit(500); ac1.showBal(); ac1.withdraw(575); ac1.showBal(); }

9 April 20023CSG19 A bit of inheritance public class DAccount extends Account { DAccount (String sc, String an, int opening) { super (sc, an); balance = opening;} public void withdraw (int amt) { if (amt < balance) { balance = balance - amt; } else { System.out.println ( "Withdrawal not allowed"); } }

10 April 20023CSG110 A program to use a deposit account public class DAccountMain { public static void main (String [] args) { DAccount ac2 = new DAccount ("304050", "01234567“, 1000); ac1.showBal(); ac1.withdraw(500); ac1.showBal(); ac1.withdraw(500); ac1.showBal(); }

11 April 20023CSG111 Sample output Sort code 405060 Account number 98765432 Balance 1000 Sort code 405060 Account number 98765432 Balance 500 Withdrawal not allowed Sort code 405060 Account number 98765432 Balance 500

12 April 20023CSG112 Key points Java is an object-oriented language for writing portable applications. Java has classes that support the construction of programs to run in Tier 1 (applets) and Tier 2 (servlets) of an e-commerce system. Java classes have a regular structure that can be adapted to writing object-oriented applications, classes, and objects.


Download ppt "April 20023CSG11 Electronic Commerce Java (1) John Wordsworth Department of Computer Science The University of Reading Room 129,"

Similar presentations


Ads by Google