Due Monday, Feb. 8, on Gradescope. Read Gradescope
info for how to prepare a pdf for submission, and details on
submission. Be sure to get a Linux account as soon as possible, to
list your username for the needed Oracle and mysql accounts, and access
to our Linux server pe07.cs.umb.edu.
1. Basic HTML and URLs, intro to web apps.
--Learn about absolute and relative URLs, say by looking at this tutorial on URLs and looking at the examples in
Murach, pg. 101.
--Read Murach, Chap. 1, through pg. 17 for an intro to web apps.
--Read Murach, Chap. 4 through pg. 105. We will go on to CSS and
HTML forms in the next homework.
2. Review SQL. Read Murach pp. 364-373. Go to sqlzoo.net, Pull down the Tutorials menu, and select the following tutorials:
3. Review Java OO principles,
specifically the idea that all Java classes are subclasses of the
Object class, and thus must have all the methods of the Object
class. You can see the Object class API (and any other standard class)
by following the link "JDK API" on the class web page under Resources,
or at the Piazza site. Choose “Object” in the pane titled All Classes,
and the API will be displayed on the right.
a. What are the three most important Object methods? (Hint: their
names start with e, h, and t). Because all objects have these methods,
we can use HashSet to contain any set of objects (we'll stick to sets of
same-type objects in our work).
b. Show equals in use by writing one if (…) that checks whether s String
s is equal to a String t, character by character. Explain what
this comparison is doing if s = “abc” and t = “abx”. Compare this
to what happens in if (s == t).
c. Find the hashCode and toString values for String s =
“abc”. Also for the Integer of value 6.
4. Java Beans. a. Write a small Java class Box1.java that has
private int fields x, y for the dimensions of the (2-dimensional) box in
mm. Give it getters and setters for x and y, and a simple constructor
that takes x and y values, but no other methods. This is a simple “Java
Bean”. For Box1 objects b and c, separately created but both
describing 10x12 boxes, what is b.equals(c)? What is being compared
here?
b. For Java class Box2.java, start from the Box1.java code and add an
equals method that compares the x’s and y’s of the two Box2 objects to
see if they are both the same or not. Make sure your equals method
overrides Object.equals by using the annotation @Override (it’s easy to
go wrong here). For an example, see
http://www.geeksforgeeks.org/overriding-equals-method-in-java/.Write
a hashCode method that is consistent with your equals method.
Consistent here means satisfying the second bulleted requirement under
the Object.hashCode documentation, namely “If two objects are equal
according to the equals(Object) method, then calling
the hashCode method on each of the two objects must produce
the same integer result.”
c. Finally, write a toString method that returns “10x12” for a 10 by 12
box. For Box2 objects b and c, separately created but both
describing 10x12 boxes, what is b.equals(c)?
5. Review Java Collection classes.
Look at the
Collection Framework home page at Oracle, and from there the
Collections Framework Overview and Collections Tutorial, for
Java 8. .
a. What are the two most important concrete classes that are
available for the Set interface? the Map interface?
b. Explain how you can find all the elements of a given Set
object. Does your answer also apply to Lists? other things?
what class of objects?
c. Explain how you can find all the keys of a given Map.
d. Write a Java fragment that creates a Map from String to
Integer. Add the association "x" -> 6, that is, key "x" maps to
Integer 6.
9. Mysql.
User ronghui, for example, will have an account on mysql on pe07 with
username ronghui, password ronghui, and a database named
ronghuidb. To access it, login to pe07.cs.umb.edu and use the
command:
mysql –u ronghui –D ronghuidb –p
and enter ronghui at the password prompt. Another way is shown on pg. 351 of Murach:
mysql –u ronghui –p
ronghui
use ronghuidb
Similarly run JdbcCheckup on your mysql account. You can log in on pe07 and use the mysql command to look at the database. Also try out h2, the embedded DB (see header comment on JdbcCheckup.java for directions). Record your success or problems.
10.a. Try out the Data Source Explorer view in eclipse. Click on the
"New Connection Profile" icon (it has a little plus on it) in the Data
Source Explorer view, and add a new Connection to localhost (and have
the tunnel working), with driver MySQL (with driver jar from the jdbc
directory), Database xxxxdb, URL jdbc:mysql://localhost/xxxxdb, and User
name xxxx, where xxxx is your username. See your welcome table
there. Record your success or problems.
b. Similarly set up an eclipse Connection to Oracle and view your
welcome table there, and similarly for h2