Java Web Programming (including HTML) – 2005 Course Report

This course was taught by me only once in 2005, if I recall correctly, for IInd M.Sc. (Maths) students in a deemed university in Andhra Pradesh, India. Unfortunately I have not been able to locate a record of the assignments given to the class. Therefore I decided to provide a course report using whatever data I have of the course and used my recollections as well as thoughts as I went through the course book and course book slides to add suggestions for assignments as well as a mini-project at the end of the course. [I clearly recall that students did do a mini-project at the end of the course which most, if not all, students found to be very useful in giving them confidence to do future small shopping-cart type web applications using Java servlets and JDBC+database.]

Pre-requisites for the course: It so happened that students of this course had studied C and C++ languages but without much exposure to exception handling in C++. Students also had studied a database theory course and an SQL lab. course. So C++ or other object oriented language, relational database theory and SQL are pre-requisites for this course.

Main Course Book: Core Web Programming, Second Edition by Marty Hall, Larry Brown. This book is now obsolete as can be noted from its website here: Pdf versions of the book may be available on the web. I must also state that the chapters of the book that are used in this course seem to me to be relevant even today. But as I have not taught Java Web programming after 2005 and not had any other reason to keep up with this area, I cannot be absolutely sure about it.

Course Notes

The HTML part (excluding HTML Forms) of the course is done first. Here is the related material.

Next we study those parts of core Java that are different from C++, note the important parts of core Java that are similar to C++, study HTML Forms, and study web server-side Java programming, using the main course book.

  • Chapter 6. Getting Started with Java. Slides in pdf format:
  • Chapter 7. Object-Oriented Programming in Java. Slides in pdf format are and As students already have gone through a C++ course this chapter can be browsed through quickly but with a focus on differences between Java and C++ and explanation of new and different constructs and programming techniques in Java. The latter include:
    • Object being topmost ancestor for all classes
    • Different main function and utility classes and methods like System.out.println()
    • all objects allocated on heap; garbage collection solving the grave memory leak problem; Java using reference instead of pointer
    • Interfaces in Java being a very different and very interesting concept
    • packages
    • JavaDoc and comments
  • Chapter 8. Basic Java Syntax. Slides in pdf format: This chapter can be browsed through but the following topics in it need proper study. [Please note that at the time I taught this course the students had not had much exposure to vector. list, map and exception in C++. So, if I recall correctly, I taught at least some of them in detail]:
    • Vector
    • Hashtable
    • Exposure to other collection classes of type sets, lists and maps.
    • Primitive data types being wrapped by corresponding wrapper class; parseXxx methods of such wrapper classes to convert string to underlying data type
    • Exceptions: try, catch, finally, throws, throw statements/keywords and exception class hierarchy.
  • Chapter 18 HTML Forms. Slides in pdf format: The following topics have to be studied:
    • Simple FORM with GET and POST methods and how it used on a browser; Action attribute of FORM specifying URL/CGI program that will receive FORM data; URL encoding
    • CGI (Common Gateway Interface) and examples of it were covered in the course but as it seems to have become obsolete I suggest that it be omitted
    • TEXT controls including password and textarea controls
    • Push buttons including Submit button
    • Check Boxes, Radio Buttons
    • Combo Boxes, List Boxes
    • Server Side Image Maps
    • Hidden Fields
    • File Upload Control
    • Grouping controls
  • Chapter 19: Server-side Java: Servlets. Slides in pdf format: This is a vital chapter for Java Web programming. The following topics have to be studied:
    • Servlets get data from FORMs and send output data (e.g. HTML) to client (e.g. browser); Servlets can send dynamically generated webpages to client; servlets run on server and so may have access to server data
    • Advantages of servlets over CGI
    • Free servlet engines (e.g. Apache Tomcat) [I think I used Apache Tomcat for this (student) class.]
    • Hello World servlet; compiling and invoking servlets
    • Servlet generating HTML
    • Servlet life cycle – init(), service(), doGet(), doPost() and destroy() methods
    • Debugging servlets
    • Reading form (query) data in servlets (also called request data); name-value pairs, HttpServletRequest class and its getParameter(), getParameterValues(), getParameterNames() methods; example servlet program echoing parameters back to client
    • Reading HTTP request headers; getHeaderNames(), getHeader(), getContentLength(), getContentType() methods of HttpServletRequest class; HTTP Request headers – Accept, Authorization, Connection, Cookie, Host, If-Modified-Since, Referer, User-Agent
    • Creating the HTTP response; HTTP status code, setStatus(), Common status codes: 200 – OK, 401 – Unauthorized, 404 – Not Found, setHeader(), setContentType(), setContentLength(), sendRedirect(), addCookie(), Servlet example (Prime Number generation)
    • Session Tracking: Stateless HTTP connection, sessions provide means of storing state associated with a client on the server using cookies or URL-rewriting, HTTPServletRequest class methods – getSession(), Hashtable-like mechanism to hold session data, setAttribute(), getAttribute(), isNew(), shopping cart and access count examples for session data
  • Chapter 22, JDBC. Slides in pdf format: This is a vital chapter from the point of view of database interaction with servlets (and JSP). The following topics have to be studied:
    • JDBC API – a standardized API to interact with (access) relational databases, JDBC Driver Manager, java.sql package
    • JDBC data types and their mapping to Java data types
    • Using JDBC: Loading JDBC driver, defining connection URL, establishing database connection – Connection class, creating a database statement – createStatement() method of Connection class returning object of Statement class, executing SELECT sql statements using executeQuery() method of Statement class which returns object of ResultSet class, executing INSERT, UPDATE and DELETE sql statements using executeUpdate() method of Statement class, Processing ResultSet (in short, details to be covered later), closing the database connection using close() method of Connection class, example code doing all these operations
    • ResultSet class: next() method to (attempt to) get next row, getXxx() method where Xxx is a Java type (int, double, string, short, long etc.) which takes in a column Name or column index and returns the associated value for the specified column in the current row in the ResultSet, MetaData methods like getColumnCount(), getColumnName();
    • PreparedStatement class for parametized SQL, CallableStatement class for database stored procedures
    • SQLExceptions
    • Transactions using JDBC
  • Chapter 20, Java Server Pages (JSP): Quick introduction to JSP (No time for detailed study). Slides in pdf format:


Class Assignments and Mini-Project

As students go through the various chapters of the book given above (and the HTML tutorial), students are expected to try out the examples given in these chapters (and HTML tutorial), make some small variations, demonstrate them to the teacher and provide a report of these activities. The assessment of this part of the course would be based on these demonstrations and reports.

The main hands-on work in this course should be a mini-project for which significant time, say around a quarter of the time period of the course, should be provided. The mini-project should involve teams of four or five students doing a mini-project together, but with each student providing a separate report detailing his/her contribution to the mini-project. The mini-project problem is left to the students but the scope is controlled by the teacher to make it doable in the time allotted for the mini-project.

One example of a suitable mini-project is a hostel food stall with database tables containing the details of various food items on offer, their availability, their rates etc. and table(s) to hold orders from students as well as track the status of the order. The web interface of the food stall must be attractive but driven by the underlying database data. Session tracking should be used to handle a shopping cart for students that place an order on the food stall and then track the order’s fulfillment status.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s