Enterprise Applications with Java - March 2011


Notes and Assignments:

Week 1 - Wednesday, March 23rd, 2011
Welcome to the first day of class.
We'll do introductions, do a quiz to gauge current understanding, review some topics and cover the course topics of the day. Download the Course Presentations

Review Links:
Class
Control Statements
hello world program
if/then
input/output
Loops
switch

New Topic Links (for further understanding):
Java Programming Language
Java Servlets
Java Server Pages (JSP)
Java Certifications
Assigned reading for this week: P. 2-12, 16-63, 606-657, 658-670
Assigned reading to be done before next week: 64-227
Powerpoints for week 1
Week 2 - Wednesday, March 30th, 2011
Last week we had a quiz to get a feel for everyone's level of knowledge. We also assigned a lot of reading and some homework. This week, we'll start with a quiz and continue learning. We'll also work on our labs.

Links and Topics To Read/Understand:
Client/server applications
Java Server Pages (JSP)
Java Servlets
The Model View Controller (MVC)
Java Database Connectivity (JDBC)
JSP Standard Tag Library (JSTL)
Struts Framework
Spring Framework
Hibernate
Week 2 - Lab
1.      Hello world
2.      Output for loop 1 to 100 (e.g. Number followed by <br />)
3.      Output for loop 1 to 100 in table alternating row colors
4.      Forms with post – display input on 2nd page (get and post)
5.      Session – Page 1 post to Page 2 posts to page 3 which displays
inputs from page 1 AND 2
6.      Same as 5 but with cookies
Assigned reading: P. 229 - 299, due before next class.
Powerpoints for week 2

Week 3 - Wednesday, April 6th, 2011
Last week we worked on several topics and started to code. We focused on JSP, Servlets, Html posts, JSP sessions and writing to cookies. We will continue with these topics and add more to them.
As a reminder, homework should be email before the start of class and if you miss a class, it is your duty to get the homework information and copies of any handouts from fellow students (late work is not accepted). Lastly, if you miss a quiz, you miss the points for the quiz. Quizzes will "normally" be given at the beginning of class.
We'll start today by answering any questions people might have about the topics we've talked about so far. To further solidify our understanding, we'll follow the discussion with another quiz which will cover topics we've covered so far. Note that these quizes will count as part of your lab grade for the course.
Today we'll continue with our labs, cover new topics, cover some topics for fun and also talk the course project for the course.
Have you done your assigned reading? Have you reviewed the powerpoint slides?

Links and Topics To Read/Understand:
Big O - Link from Jeremiah
Big O Notation. Read about both Big O and Big Omega
Data Structures to Read About
Sorting Network
Lab exercises:
7.      1-3 w/ Servlets
8.      JSP w/ class output var values in class
9.      JSP class that outputs hello World (method)
10.     JSP/Servlet that outputs “n” prime numbers. N is speficed by user
through a form.
11.     JSP and Servlet that outputs button w/ javascript attached for
“hello world” alert.
12.     Time/Calc between two button clicks.
13.     Read and play with http response headers
Projects 1 – 3 due 20th April (week 5). Best programs will be used for the open house. Bonus points if your project is selected to present.
Project 1 Summary: Interactive Sorter. User enters a list of strings that are separated by commas. These strings will then be sorted using different sorting algorithms such as bubble sort, selection sort, and insertion sort. Your program should show the steps of each algorithm as it sorts the steps. Bonus: Quicksort and Randomized Quicksort, plus any others you can find and implement.
Project 2 Summary: Game - I'm thinking of a number between 1 and n. User inputs n, then has to guess the number the computer is thinking of. Results will show how many guesses the user took and what the worst case would of been with binary search.
Project 3 Summary: Write JSP to display info about user's computer such as browswer, IP, etc. If you can make do "whois"  then bonus. e.g. Give me a list of all domains 5 chars long that are not yet registered.
Summary of topics:
casting
loops
control structs
records and classes
methods
jsp
servlets
jsp with servlets
cookies
sessions
local vars
database
javascript
http response headers
date/time
string manipulation
Gold Star Challenge: 9 to 9 to 9:
Here is some example code if you need help getting started (note: this is a premitive way of doing it and not as efficient as the way we talked about in class. You'll also want to save the final output to a file, and might consider ways to save computation as you do it, incase you make a mistake and have to reimport some of those previous calculations):
            BigInteger answer = BigInteger.valueOf(3);
            BigInteger powerOf3 = BigInteger.valueOf(3);
            for(int i=1;i<3;i++){
                powerOf3 = powerOf3.multiply(BigInteger.valueOf(3));
            }
            for(BigInteger i = BigInteger.valueOf(1); i.compareTo(powerOf3) <= 0; i = i.add(BigInteger.valueOf(1))){
                answer = answer.multiply(BigInteger.valueOf(3));
//                out.println("answer so far: <BR>");
//                out.println("i: " + i + "<BR>");
//                out.println("powerOf3: " + powerOf3 + "<BR>");
//                out.println("i.compareTo(powerOf3): " + i.compareTo(powerOf3) + "<BR>");
//                out.println("answer: " + answer + "<BR>");
//                out.println("<BR><BR>");
            }
            out.println("answer: " + answer + "<BR>");

Assigned reading: P. 229 - 299, 303-396
Powerpoints for week 3, week 4

Week 4 - Wednesday, April 13th, 2011
All homework and labs are do before class starts. I will pass out a status of where everyone currently sits in the class. We'll start today with a quiz.

Extra Links for Further Clarification:
Google Code Jam - Link from Jeremiah
Permutation
Fractal
Series
Sequence
JSP Tutorial
Servlet Tutorial
SCWCD
Oracle Certification Program - Oracle certified Professional Java EE 5 Web Component Developer
Ant
WAR file format (Sun)
XML
XML tutorial
SQL tutorial
MySQL
WhoIs command
WhoIs w/ java.net
Sum of Squares
The following is to help jumpstart you with Project 3, if you are a bit stumped. You'll have to convert the following either into a servlet or to be used with a servlet. Using the code from the "WhoIs w/ java.net" link above you can have code similar to:
package com.jamesoravec;

import java.net.*;
import java.io.*;

public class whois {

  public final static int port = 43;
  public final static String hostname = "whois.internic.net";

  public whois(String input) {
    Socket theSocket;
    DataInputStream theWhoisStream;
    PrintStream ps;

    try {
      theSocket = new Socket(hostname, port, true);
      ps = new PrintStream(theSocket.getOutputStream());
      ps.print(input + " ");
      ps.print("\r\n");
      theWhoisStream = new DataInputStream(theSocket.getInputStream());
      String s;
      while ((s = theWhoisStream.readLine()) != null) {
        System.out.println(s);
      }
    }
    catch (IOException e) {
      System.err.println(e);
    }
  }

  public static void main(String[] args) {
    Socket theSocket;
    DataInputStream theWhoisStream;
    PrintStream ps;

    try {
      theSocket = new Socket(hostname, port, true);
      ps = new PrintStream(theSocket.getOutputStream());
      for (int i = 0; i < args.length; i++) ps.print(args[i] + " ");
      ps.print("\r\n");
      theWhoisStream = new DataInputStream(theSocket.getInputStream());
      String s;
      while ((s = theWhoisStream.readLine()) != null) {
        System.out.println(s);
      }
    }
    catch (IOException e) {
      System.err.println(e);
    }
  }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;
import com.jamesoravec.*;

/**
 *
 * @author joravec
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        whois myWhoIs = new whois("jamesoravec.com");
    }

}

Lab exercises:
14. Permutations of letters (e.g. abc, acb, bac, bca, cab, cba)
15. Code a sorting network, using permuations to verify correctness of sorting network, for all possible inputs.
16. Create visual sorting network output for a 3 sorting netework. 
17. Create a sorting network that will sort 6 items and verify it for all 6 input (a,b,c,d,e,f) permuations. (Hint: 6 inputs means 6! possible input strings, or 6*5*4*3*2*1 = 720 possible input strings).
18. Java power example. Write a simple program that has a jsp request calculations from a servlet which in turns requests inforamtion from a normal java class. Display the output to the web broswer.
*19. For advanced students. Can you write a program that will make sorting networks, test them for correctness, and log the results?  

*20. For advanced students. Write a program that gives a visual of fractals.
*21. For advanced students. Write a jsp page that which connects to a db, and perform a simple XSS on the db using javascript alert(). Make a copy of the jsp page and rewrite it to protect against the XSS attack.
*22. For advanced students. Write a program that will take a URL, and traverse its links 3 deep and return a list of all emails it comes across. On your webpages, what can you do to make it more difficult, for people who write such programs, to get your email address?

Extra Credit: Challenge yourself with some ACM programming problems. Program the answers in java, submit them to the site and then redo them as jsp or as a servlet. Submit your both your java code and jsp/servlet code to me once the website approves your answer.
When on the website you'll want to click on "browse problems" on the left, then "problem set volumes." You'll have to create an account, submit your code and verify that it is correct through their system. Once you have successfully coded problem(s), send me an email with the code which references the website description and problem number and have your class name and your name documented in the code as well. Some problems are easier than others, which can be judged by me on the solving percent shown by the UVA system. The harder the problem, the more extra credit you'll receive. If you kmnow Java then you can submit the answers to the website that way.


Week 5 - Wednesday, April 20th, 2011
Prior to class you should have finished the assigned reading for week 5, as well as the powerpoints for week 5.
We'll start with a quiz today. We'll then cover some topics you'll need to understand in order to work on the labs. The labs assigned today will count for both this week's lab as well as next week's lab.
Eclipse and Java for Total Beginners - Install and Watch and follow along with all of the videos.
Java Stock Prices
Ant

Lab exercises - these labs will :
23. Write a servlet/jsp program which will send emails.
24. Write a servlet/jsp program that can process an xml file.
25. Write a jsps that use includes.
26. Write a servlet/jsp program that can scrap information from another page.
27. Write a java/servlet/jsp program that can get stock prices from yahoo.
* 28. For the advanced students who wrote the program that allows users to upload images and store them as blobs in a db. Expand your program in three ways:




Week 6 - Wednesday, April 27th, 2011
Prior to class you should have finished the assigned reading for week 6, as well as the powerpoints for week 6.
No new material will be covered this week. There will be no quiz today, however there will be a quiz next week. Today will be used as a catch up day to complete all work assigned from last week.

Week 7 - Wednesday, May 4th, 2011
Prior to class you should have finished the assigned reading for week 7, as well as the powerpoints.
We will start with a quiz.
Topics/Links/Related Topics:

Project 2:
Description: You are to create a website using jsp/servlets that will interact with a user. The website will store information into a database and will demonstrate some basics about the MVC design. You will turn in your source code, as well as a dump of your database, so that the database can be recreated and tested on my side. Please label the dump file as Project2Dump.sql. If you can, try to encapsulate some of your data in javabeans.
* Create MySQL Db to stor table info.
* Create login page. 2 users (customer and admin)
* Have different views for the customers.
** Customer can view items in the database
** Customer can review their previous orders
** Admin can review all orders
** Admin can view items in the database

Items

OrderItem

Order

Customer

Week 8 - Wednesday, May 11th, 2011
Prior to class you should have finished the assigned reading for week 8, as well as the powerpoints.

Topics/Links/Related Topics:

Lab exercises:
29. Create a javabean for a person and a jsp page that works with that bean and uses the useBean tag.
30. Write JSP pages that post to each other information that uses JSTL c:set and c:out to set and output values of variables passed between pages.
31. Write JSP pages that post to each other and demonstrate the use of conditional logic using JSTL (choose).
32. Write JSP pages that post to each other and demonstrate the use looping using JSTL (foreach).
33. Write JSP pages that post to each other and make use of the c:url to create a link to a url passed in from a different page.
33. Write JSP pages that uses c:redirect to redirect to another page.
34. Create a custom JSTL tag for "today" which will return today's date and use it in code.

Assignment Wk8: In your own words, write at least two paragraphs (4 to 8 well written sentences each) to define and describe the following topics and how they can be useful to you, or how you might need to know about them, in your career as a programmer:
  1. JSP
  2. JSP scriplets
  3. JSP expressions
  4. Servlet
  5. Java Bean
  6. EJB
  7. MVC Pattern
  8. JDBC
  9. MySQL
  10. Oracle
  11. ODBC
  12. Java Package
  13. Java Interface
  14. DNS
  15. JSTL
  16. Tomcat





Week 9 - Wednesday, May 18th, 2011
Prior to class you should have finished the assigned reading for week 9, as well as the powerpoints.
Assignment Wk8 and Project 2 are due at the beginning of class.
Due to the length of today's assignment, I cancelled today's quiz, so you can have more time to work on the assignment.

For today's lab, we will try something slightly different. We will use the tutorial references provided in earlier weeks. The lab itself will be more of a "free form" in the sense that you'll be able to work on any tutorials you are interested in learning. The purpose will be to allow you to play with the technology that interests you the most, or the technology that is the most challenging to you. You are to write a summary of what tutorials you went through, what you learned and provide copies of the tutorial code you produced. What you turn in needs to be enough to justify at least 4 hours worth of work.

Assignment Wk9:
Please provide brief, yet complete answers/descritions to the following items:
  1. Are JSP pages compile or interpreted?
  2. What kind of code runs on the server?
  3. What kind of code runs on the client?
  4. Are cookies server or client based? Is the data stored in a persistent way?
  5. Are sessions server or client based? Is the data stored in a persistent way?
  6. When creating a new project in Tomcat what directories are made for you and what should go in each of them?
  7. Which port is the default port for Tomcat?
  8. Where can you change Tomcat's default port?
  9. In order to create a servlet, your servlet class needs to extend what?
  10. Are servlets compiled or intrepreted? 2nd part, when does it happen?
  11. What is a request line?
  12. What is a request header and how is it used?
  13. How can you test if Tomcat is running properly?
  14. Write a small snippet of code that will redirect your current page to a different url.
  15. Write a small snippet of code that will refresh your page.
  16. Explain how headers can be used in your programming.
  17. Explain the difference between permanent and persistent data.
  18. What kind of information is stored in a database?
  19. What is the purpose of a Web Server?
  20. What, if any, are the differences between an Web Server different and an Application Server?
  21. Can you change the path in which cookies are saved?
  22. What is URL rewriting?
  23. How do you do comments in Html?
  24. How do you do comments in JSP?
  25. How do you do a JSP declaration?
  26. How do you do a JSP scriplet?
  27. How do you do output in JSP?
  28. How do you do output in a servlet?
  29. What is a JVM?
  30. How is the JVM used with JSP and Servlets?
  31. What role does a web browser play with JSP and servlets?
  32. Does the web browser, web server, or both need to be able to support JSP/servlets to view the page?
  33. Can java code be embedded in JSP?
  34. Can html be embedded in JSP?
  35. Can java code be embedded in Servlets?
  36. Can html be embedded in Servlets?
  37. Can you have classes in JSP?
  38. Does a client's computer need java installed in order to view a jsp page?
  39. Can you do imports with JSP?
  40. Can you do imports with Servlets?
  41. Can you do includes with JSP?
  42. Can you do includes with Servlets?
  43. What is a taglib?
  44. What is a buffer and how might you use it with JSP and servlets?
  45. What does the term Thread Safe mean and why is it important?
  46. In your JSP applications where should your source code exist?
  47. In your JSP applications where should your java classes exist?
  48. In your JSP applications where should your jar files exist?
  49. In your JSP applications where should your war files exist?
  50. How do you get and set values with beans? Is there a difference between booleans and other variables?
  51. How do you connect to a database using java?
  52. What is xml and what are some of the uses with JSP and Servlets?
  53. When working with a database, how do you do perform a select statement?
  54. When working with a database, how do you do perform an update statement?
  55. What is meta data? Why do we care about it and how do we use it?
  56. What is a ResultSet and how do we use it?
  57. What is JDBC used for?
  58. What is the MVC pattern?
  59. What part of MVC are jsp pages?
  60. What part of MVC are servlets?
  61. What part of MVC is the database?
  62. How are Tag Library Descriptor (TLD) files used?
  63. Write a code snippet that shows how to use tag conditional statement?
  64. Write a code snippet that shows how to use tag loop?
  65. How do we use Struts and what is the importance or usefulness of it?
  66. How do we use Hibernate and what is the importance or usefulness of it?


Week 10 - Wednesday, May 25th, 2011
Prior to class you should have finished the assigned reading for week 10, as well as the powerpoints.
We will use today as a review of the course and try to address any questions that you might have about what we've learned during this course.
Assignment Wk9 is due at the beginning of class.

Week 11 - Wednesday, June 1st, 2011
Final Exam Today.