Presentation is loading. Please wait.

Presentation is loading. Please wait.

Electronic Commerce Java (1)

Similar presentations


Presentation on theme: "Electronic Commerce Java (1)"— Presentation transcript:

1 Electronic Commerce Java (1)
John Wordsworth Department of Computer Science The University of Reading Room 129, Ext 6544 April 2002 3CSG1

2 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 April 2002 3CSG1

3 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) April 2002 3CSG1

4 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) April 2002 3CSG1

5 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 April 2002 3CSG1

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

7 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); } April 2002 3CSG1

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

9 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"); } } April 2002 3CSG1

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

11 Sample output Sort code 405060 Account number 98765432 Balance 1000
Withdrawal not allowed April 2002 3CSG1

12 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. April 2002 3CSG1


Download ppt "Electronic Commerce Java (1)"

Similar presentations


Ads by Google