300130 Internet Programming

300130 Internet Programming

300130 Internet Programming Dr Zhuhan Jiang Penrith Campus 1 1 Contact Details Name: Zhuhan Jiang Office: ECG-64, Parramatta campus Telephone: 9685 9336 Email: [email protected] Unit Homepage: http://www.cit.uws.edu.au/~zhuhan/ip 2 Time Table Lectures 10am-12pm Thursday, UG13 Practical (workshops) 2pm-4pm Thursday, Y241 4pm-6pm Thursday, Y241 (repeat, not available) Consultation 11am-1pm Tuesdays, ECG-64, Parramatta nd First workshop starts on the 2 week 3 Prerequisites/Exclusions Prerequisites Introduction to Analysis and Design (or equivalent) Object Oriented Programming (or equivalent programming experience) Exclusions Objected Oriented/Internet Programming Internet Computing 4 Assessment 3 Random Workshops 5% each 1 Individual Assignment 15% 1 Group Assignment 25% 3-4 people per group Self-organised or assigned Final Exam 45% All submissions (other than group assignment) are electronic. 5 Text/Reference Books Real code for real Core Web Programming programmers nd Hall M & Brown L, 2 ed, Sun Microsystems, Prentice-Hall, 2001 Java, How to Program th Deitel H M & Deitel P J, 4 ed, Prentice-Hall, 2000 (3rd ed also ok) The Java Tutorial Continues: The Rest of JDK (free on web) Campione M et al, Addison-Wesley, 1998 (free on web) 6 Main objectives Master principles & techniques of OOP Master for the Internet curve Web pages with forms and CGI/PERL diary Java applet with GUI and multithreads ufo Multimedia and Internet games explorer Java networking and security server Distributed computing with RMI chatlite Java Server Pages, JDBC, Beans, XML etc 7 Hardware and Software Windows 2000, Linux, Unix platforms Web, CGI, PERL or others Java 2 (ver 1.4), Eclipse IDE J2RE plug-in for IE and Netscape Tomcat for servlets and JSP MS Access for JDBC Java BeanBox 8 What is Java? Prominent in OOP Portable at bytecode level Less time for application development Connection with C/C++ Other keywords Interpreted, distributed, robust, secure, multithreaded Main executables javac, java, appletviewer, javadoc 9 Internet and Browsers Internet World’s largest IP based network Talk to each other using IP protocol Connected world wide, owned distributively Mainstream browsers typically support Java, CSS, Javascript etc Netscape Navigator Internet Explorer HotJava, Mosaic etc 10 Java Program Execution /* filename: SimpleJava.java */ public class SimpleJava { public static void main(String[] args) { System.out.println("Hello world!"); } } Naming for code and class files Compile: javac SimpleJava.java Execute: java SimpleJava 11 HTML Documents normal text interspersed with markup tags <tag P1=V1 …>affected text </tag> may contain Javascript, Java applets, server- side includes etc javadoc - generates class docs in HTML <HTML><HEAD> tags <TITLE>document title</TITLE></HEAD> <BODY>document content</BODY> </HTML> 12 Access Attributes Web server often run as user nobody All html etc files to be accessed by a remote browser must have “readable to others” attributes chmod a+r index.html *.gif CGI needs “executable to others” Not needed if running cgiwrap, see later CGI in script needs “readable” All webpath subdirectories must be “executable” 13 Forms http://localhost/ip/webquiz/submit.pl Collect data from user of web browser This data may be used locally on the HTML page, or sent to CGI for processing web search engine guest book, registration, logon online shopping, online quiz feedback form 14 General Format <form name="formname" method="method" action="action" target=...> <input type= ......> </form> "formname" is any string and is used to identify a particular form if more than one is used in a page 15 Method & Action "method" is either "POST" or "GET" In the "GET" method, the form data is appended to the URL of the action In the "POST" method the form data is sent as part of the HTTP header information "action" is usually the URL of a CGI program on the server that will process the form data 16 CGI Work Flow HTML Form Data from B Form Input r Form o Web Processing w User Server program s Data from (CGI) E Form HTML r Output Document HTML Document 17 Form Example with CGI <FORM METHOD="POST" ACTION= "http://www.cit.uws.edu.edu.au/cgi-bin/ cgiwrap/~zhuhan/listall.cgi" > Input Name:<INPUT TYPE="TEXT" NAME="FullName"> Input Age: <INPUT TYPE="TEXT" NAME="Age"> <INPUT TYPE="SUBMIT" VALUE="Post"></FORM> “POST” reads paras from STDIN “GET” from env QUERY_STRING Or directly, e.g. http://…/listall.cgi?FullName=…&Age=… 18 CGI Languages UNIX shell script PERL (Practical Extraction and Reporting Language) C/C++ ASP - Active Server Pages Virtually any language that understands stdin/stdout and environment variables 19 CGI URL Popular/standard format http://localhost/~zhuhan/listall.cgi (Apache) http://localhost/ip/listall.asp (IIS) CIT’s format (on the Unix machine) http://www.cit.uws.edu.au/cgi- Where to keep bin/cgiwrap/~zhuhan/listall.cgi CGI programs username CGI program listall.cgi resides in /~zhuhan/Homepage/cgi-bin (“~” represents $HOME) at the CIT site cgiwrap more secure: server assumes the status of the program’s owner 20 Simple CGI Program #!/bin/sh # file: listenv.cgi read message_by_post echo content-type: text/plain echo if ! [ -z "$message_by_post" ] ; then echo POST_STDIN=$message_by_post fi env CGI in any script or in compiled form Must be preceded by a header 21 CGI Header MIME: Multipart Internet Mail Extensions output of CGI must have a MIME header to indicate what type of output is to expect Content-type: type/subtype Other-settings-if-any: values header terminated by an empty line e.g. text/plain, text/html, image/gif, image/jpeg 22 Associative array PERL useful $paras{'name'}=value but not examinable object Another Example use CGI; # filename: paras.pl $cgi=new CGI; A field of the object %paras=$cgi->Vars; print "content-type: text/html\n\n"; print "<B>ALL FORM PARAMETERS ARE:<hr>"; foreach $i (keys %paras) { print "<br><i>$i=</i>",$paras{$i}; } http://localhost/ip/sale.htm 23 Java Basics What are classes? Blueprint or prototype defining variables and methods common to all objects of a certain kind What is an object? A software bundle of variables and related methods An instance of a class Every Java program is a class def. 24 Class Definition Modifier class ClassName { public class Demo { variable declarations/initiation; private int i; method declaration/definition; public void set(int x) { more of such declarations i=x; } } int get() { return i; } } Modifiers: public, protected, private, abstract 25 Simple Class Example Fields va ria public class Group { bl public long id; es public String name; public Group stem; public Group root; public static long nextID = 1; } public Group(){}; Default constructor 26 Primitives & Type Casting Primitive types are of fixed size Class variables defaulted, method variables must be initialised Auto type cast from smaller to larger byte<short<int<long<float<double char<int Larger to smaller: explicit casting Boolean not for casting: No if((boolean) i) … (wrong) pointers 27 Arithmetic, Logic & Control All operands first promoted to richest type To int if smaller than int All primitive but boolean, char, void are signed Array: int [ ] x= { 1, 2, 3 }; Integer [ ][ ] y; Logical operators and values true, false, ==, !=, >, <, >=, <=, &&, ||, ! Obj instanceof ClassName No goto, limited use of label new op Better structured 28 "static" "final" Keywords static storage contains data available for entire time a program is runs Located in a “fixed location” static variables/methods can be accessed without via an object Math.PI, Math.random() in class Math Constants defined by final No pre- E.g. public static final int VALUE=10; processor No #define 29 Static Membership class Dumb { Class members referred int i; by “.” static String x; ObjName.MethodName( int f() { return 0; } arg1,…,argN) } Dumb.x - static member referred to without a=new an object (“fixed location”) Dumb(); if a is an object of Dumb then a.i, a.x, a.f() are legal reference to the members 30 Memory Management All memory allocation made via keyword new Memory de-allocation done via automatic garbage collection Order and time unpredictable May explicitly request via System.gc() finalize() of an object called before being garbage collected No malloc(), free(), compared with C 31 Library Packages Auto-linked library package java.lang Object, Math, String, System, Thread Standard output System.out.println(TextString); Online API Package java.util, document Class System belongs to java.lang Random, Date, Arrays, Vector 32 Objects Create an object: Use new operator Dumb d1 = new Dumb(); d1 is an object leaf Java Runtime will create enough space to store the fields or new throws OutofMemoryError Root Trunk 33 Constructor A constructor - normally for initialization has the same name as the class has no return type is called when an object is created A default constructor is called if there is no constructor given default constructor, if needed, must be declared if constructor is defined for other input parameters 34 public class RandomNumbers { /* make 10 random chars */ /** just a constant below */ public static final int LENGTH=10; static Store [ ] array=new Store[ LENGTH ]; Entry point /** entry point to the class */ from OS public static void main(String[ ] args) { for( int i=0; i<LENGTH; i++ ) { array[i]=new Store( (char) (Math.random()* 26 + 'A') ); System.out.print( array[ i ].get( ) ); 2 classes

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    44 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us