Notes From Class
Week 1: January 26, 28 and 30, 2009
-
If you do not have a Glue computer account, please get one.
See the FAQ's for step-by-step instructions.
-
I will soon be putting your picture on the
meet the class page.
If you have any objections (e.g., the mug shot isn't up to
your usual GQ/Vogue standards), please let me know.
-
The National Education Association has created a little 6 minute video called
Shift Happens.
Week 2: February 2, 4 and 6, 2009
-
The class reader is now available at the Engineering Copy Center.
Cost is $40.00.
-
Reading
Please read chapters 1 and 2 of Austin/Chancogne.
Although some of the numbers are now six-seven years old,
the underlying story remains the same.
The "problem solving with computers" handout in your light green "class reader"
will one-day be a replacement for Chapters 1 and 2.
Week 3: February 9, 11 and 13, 2009
-
The campus dialup services are now deceased (June 30, 2007).
If you want remote access your account at school,
then you'll need a high-speed internet connection.
-
You can test the speed of your internet connection with
http://www.dslreports.com/stest .
-
OIT has created a new service
SSH Gateway on the Web .
Note. Students from past semesters tell me that it works,
but it can be very slow!
-
If your machine is running MS Windows then
you are probably better off downloading putty.
-
If you machine is an Apple running Mac OS X,
then you can simply use the Terminal program.
Look under /Applications/Utilities.
-
Here is a link to the
Putty telnet and ssh client program.
Note. It seems that Putty cannot traverse firewalls.
So you make need to add "Putty" as an exemption to your list of
programs that can bypass the firewall on your computer. On Windows XP,
see the security folder inside the control panel.
-
At home I use TurboFTP to transfer files/directories to/from school.
TurboFTP has a very friendly graphical user interface
that shows both the windows and unix files systems.
You can download a trial version
from http://www.tucows.com .
You will need to adjust the program settings so that the
connection to school is secure -- use sftp and socket 22 (not socket 21).
-
If you have downloaded an FTP program to your PC/laptop at home,
then you'll need the IP addresses for computers on the glue system, i.e.,
Site IP addresses
--------------------------------------------------
glue.umd.edu 128.8.10.68
128.8.10.71
--------------------------------------------------
Insert them into the (ftp program) site manager.
Week 4: February 16, 18 and 20, 2009
-
On a Apple Mac (and possibly also a linux box) you can
use the secure copy (scp) command to copy files back and forth
between your laptop and the glue systems.
The syntax for copying a file from your laptop to your home
directory on the glue system is as follows:
scp name-of-file glue.umd.edu:
Conversely, you can copy a file from your home directory to your
laptop with:
scp glue.umd.edu:name-of-file .
The dot at the end of this command means put the file in
the present working directory.
For more command options, see the online manual, i.e.,
man scp
-
Prelude to Homework 1 ....
Make sure that you know how to log in to your glue.
Read the instructions for creating a personal home page (pg. 23 of the light green
class reader). Then start to read the "A Beginners Guide to HTML" tutorial.
Use a text editor (vi or pico) to type in the minimal html document
on pages 27-28 of the class reader.
Then go to the "meet the class page" and make sure that the link from your
entry to your home page works.
-
Here are a few basic UNIX commands:
Unix Commands
--------------------------------------------------------------------------------
1. cd <-- change to home directory
2. cd file1 <-- change to directory file1
3. ls and ls -ls and ls -tl <-- list contents of a directory
4. mkdir file1 <-- make a directory called file1
5. rmdir file1 <-- remove directory file1
6. cp file1 file2 <-- copy file1 to file2
7. mv file1 file2 <-- move file1 to file2
--------------------------------------------------------------------------------
Note. Directories cannot be removed unless they are empty.
Let's suppose that you have created a file and now you want to remove it. Try:
8. rm file1 <-- remove/delete file1
Text editor commands
--------------------------------------------------------------------------------
1. vi filename <-- use vi editor to change contents of filename.
For example, the command sequence:
prompt >> cd ../pub
prompt >> vi Welcome.html
prompt >> vi resume.html
prompt >> vi ce-systems.html
moves your shell to the public directory and then systemantically creates the
HTML files for your home page, resume page, and a write-up on ce-systems.
Notice that each file name has the "html" extension -- web browsers need this information.
The class reader contains a list of basic editor commands.
--------------------------------------------------------------------------------
-
A more extensive description of the UNIX directory structure,
file handling, and operating system commands can be found in
Appendix 1 of Austin/Chancogne (pg's 621-628).
Week 5: February 23, 25 and 27, 2009
-
Homework 1 is available.
Due date is 9am, March 4, 2009.
Week 7: March 9, 11, and 13, 2009
-
Midterm 1. March 11, 9am.
The midterm will cover Chapters 1 and 2 of the class text,
the tutorials at the beginning of the "light green" lecture notes,
introduction to object-oriented programming concepts and Java,
and anything that was written on the
board during the first six weeks of class.
-
Homework 2 is available.
Due date is 9am, April 1, 2009.
Week 9: March 23, 25, and 27, 2009
-
To do ...
To see how basic data types can be declared and printed in various formats,
download ,
compile and run the files GettingStarted.java and DemoFormat.java.
Week 10: March 30, April 1 and 3, 2009
-
Homework 3 is available.
Due date is 9am, April 10, 2009.
Week 11: April 6, 8 and 10, 2009
-
We are covering one- and two-dimensional arrays in class.
Make sure that you are familiar with the
demonstration programs on the Java examples web page.
For a gentle introduction to arrays, see Section 18.10 of Austin/Chancogne.
-
There is a small typo in Question 26. The mass matrix
declaration should read:
double daMass [] = { 1.0, 1.0, ..... };
and not
double daMass [][] = { 1.0, 1.0, ..... };
Sorry about that!
Week 12: April 13, 15 and 17, 2009
-
We are now covering "classes and objects" ... on Monday I
introduced visual notations for describing various kinds
of relationships among classes (e.g., association, inheritance).
If you couldn't come to class,
please get a copy of the notes from someone else in the class.
-
Wednesday April 15. We will cover the Circle.java program.
-
No class on April 17.
Week 13: April 20, 22 and 24, 2009
-
Midterm 2 (35%): April 22. Open book and open notes.
This exam will cover the basics of programming in Java (e.e., data and variables,
branching constructs, looping constructs, one- and two-dimensional arrays, strings).
Week 14: April 27 and 29. May 1, 2009
-
Homework 4 is available ( pdf ).
Due date is 9am, May 8, 2009. No extensions!
-
For problem 40 in the java exercises, download, compile, and run the Complex.java file.
Notice how code the main() method systematically exercises the
operations for complex number arithmetic.
Then, write a file GeometricSeries.java that prompts a user for the
appropriate input and then computes the series
summations by calling methods in Complex.java.
To help you get started, here is a skeleton of code
for GeometricSeries.java .
A sample script of program i/o is:
Script started on Wed April 29 08:37:43 2009
prompt >>
prompt >> java GeometricSeries
Welcome to the Geometriic Series Computer
-----------------------------------------
Please enter complex number "a"
Coefficent a : Real : 1.0
Coefficent a : Imaginary : 2.0
Please enter number of terms in series "a"
No of terms in series : 3
The complex no you have entered is :s = 1.0+2.0i
No of terms in series is = 3
Summation with basic for-loop
=======================================
Summation 1 = -13.0+4.0i
Summation using Horner's formula
=======================================
Summation 2 = -13.0+4.0i
Summation with geometric-series formula
=======================================
Summation 3 = -13.0+4.0i
prompt >>
prompt >> java GeometricSeries
Welcome to the Geometriic Series Computer
-----------------------------------------
Please enter complex number "a"
Coefficent a : Real : -1.0
Coefficent a : Imaginary : 3.0
Please enter number of terms in series "a"
No of terms in series : 12
The complex no you have entered is :s = -1.0+3.0i
No of terms in series is = 12
Summation with basic for-loop
=======================================
Summation 1 = -788535.0-383985.0i
Summation using Horner's formula
=======================================
Summation 2 = -788535.0-383985.0i
Summation with geometric-series formula
=======================================
Summation 3 = -788535.0-383985.0i
prompt >>
prompt >> exit
script started on Wed April 29 08:37:50 2009
Notice that because we are working with complex number arithmetic here,
"1" needs to represeted as "1 + 0i"....
-
The (abbreviated) output that I get for Problem 3 is as follows:
prompt >> java EngineeringProperties
.... details of output omitted ....
Total Area = 5.86
---------------------------------
Moments of Inertia (about coordinate axes)
I_xx = 51.840
I_yy = 51.840
I_xy = 47.867
Centroid(X) = 2.84
Centroid(Y) = 2.84
Moments of Inertia (about centroid)
I_xx = 4.380
I_yy = 4.380
I_xy = 0.408
Orientation of Principal Axes
Angle = 0.785 radians
Angle = 45.000 degrees
prompt >>
Week 15: May 4, 6 and 8, 2009
-
Java Collections
Now that we know how to create objects,
the next thing to think about is their organization.
How, for example, do you organize (or aggregate) large numbers of
objects so that things are easy to find and modify?
A
collection
is an object that groups multiple elements into a single unit.
Collections are used to store, retrieve, manipulate, and communicate aggregate data.
Typically, they represent data items that form a natural group:
-
A poker hand (a collection of cards),
-
A mail folder (a collection of letters), or a
-
Telephone directory (a mapping of names to phone numbers).
A collections framework is a unified architecture for representing and
manipulating collections. This framework provides the following benefits:
-
Reduces programming effort
-
Increases programming speed and quality
-
Provides a standard way of accessing collections
-
Allows for effective reuse of code.
All collections frameworks contain the following:
-
Interfaces:
These are abstract data types that represent collections.
Interfaces allow collections to be manipulated independently of the details
of their representation.
-
Implementations:
These are the concrete implementations of the collection interfaces.
In essence, they are reusable data structures.
-
Algorithms:
These are the methods that perform useful computations,
such as searching and sorting, on objects that implement collection interfaces.
In the Java Collecctions Framework the interfaces are organized as follows:
Figure 1. Hierarchy of interfaces in the Java Collections Framework.
Units include:
-
Sets.
A set is a collection that cannot contain duplicate elements.
-
Lists.
An ordered collection (sometimes called a sequence).
Lists can contain duplicate elements.
The user of a List generally has precise control over
where in the list each element is inserted and can
access elements by their integer index (position).
-
Queues.
Queues typically order elements in a FIFO (first-in-first-out) manner.
-
Maps.
An object that maps keys to values.
A Map cannot contain duplicate keys.
Each key can map to at most one value.
-
SortedSet
A Set that maintains its elements in ascending order.
Several additional operations are provided to take
advantage of the ordering.
Sorted sets are used for naturally ordered sets,
such as word lists and membership rolls.
-
SortedMap
A Map that maintains its mappings in ascending key order.
This is the Map analog of SortedSet.
Sorted maps are used for naturally ordered collections of key/value pairs,
such as dictionaries and telephone directories.
Collections are used to store, retrieve, manipulate, and communicate aggregate data.
Typically, they represent data items that form a natural group.
General Purpose Implementations
A simplified view of the relationship between containers and
the Set, List and Map interfaces is as follows:
Interfaces |
Hash Table |
Resizeable Array |
Balanced Tree |
Linked List |
Set |
HashSet |
|
TreeSet |
|
List |
|
ArrayList |
|
LinkedList |
Map |
HashMap |
|
TreeMap |
|
In practice, an implementation will follow:
Figure 2. Taxonomy of interfaces, abstract classes, and concrete classes
in the Java Collections Framework.
Points to note:
-
There are only three container components -- Map, List and Set,
and as shown above only 2 or 3 implementations of each one.
-
The dotted boxes represent interfaces, the dashed boxes represent abstract classes,
and the solid boxes are regular (concrete) classes.
-
The dotted-line arrows indicate that a particular class is implementing an
interface (or in the case of an abstract class, partially implementing that interface).
The solid arrows show that a class can produce objects of the class the arrow is pointing to.
For example, any Collection can produce an Iterator and a List can produce a
ListIterator (as well as an ordinary Iterator, since List is inherited from Collection).
Bottom Line/Review
Containers provided in the standard Java library (Adapted from Eckel, Edition 3):
-
An array associates numerical indices to objects.
It holds objects of a known type so that you don't have to
cast the result when you are looking up an object.
It can be multidimensional, and it can hold primitives.
However, its size cannot be changed once you create it.
-
A Collection holds single elements, and a Map holds associated pairs.
-
Like an array, a List also associates numerical indices to
objects. You can think of arrays and Lists as ordered containers.
The List automatically resizes itself as you add more elements.
But a List can hold only Object references,
so it won't hold primitives, and you must always cast the
result when you pull an Object reference out of a container.
-
Use an ArrayList if you are doing a lot of random accesses,
but a LinkedList if you will be doing a lot of
insertions and removals in the middle of the list.
-
The behavior of queues, deques, and stacks is provided via the LinkedList.
-
A Map is a way to associate not numbers,
but objects with other objects.
The design of a HashMap is focused on rapid access,
whereas a TreeMap keeps its keys in sorted order,
and thus is not as fast as a HashMap.
A LinkedHashMap keeps its elements in insertion order.
-
A Set only accepts one of each type of object.
HashSets provide maximally fast lookups,
whereas TreeSets keep the elements in sorted order.
LinkedHashSets keep elements in insertion order.
-
There is no need to use the legacy classes Vector, Hashtable, and Stack in new code. Feedback
-
Problem 3: You will need to add concrete implementations
of the methods getX() and getY() to all classes that extend Shape.java.
Here is a sample of what I have -- in Circle.java, Rectangle.java and
Triangle.java, simply write:
public double getX() {
return c.dX;
}
-
Problem 4:
In this problem we will use an arraylist to store the collection of shape objects.
The script of code:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class EngineeringProperties2 {
public static void main ( String args[] ) {
// Create and initialize a grid of ten shapes
List shapes = new ArrayList();
Shape s0 = new Rectangle( 0.25, 0.25, 0.0, 2.0 );
shapes.add ( s0 );
.... etc ....
imports the appropriate packages and initializes an arraylist with the
first item. To compute the engineering properties we walk along
the array, retrieve the items and make the appropriate calculation, e.g.,
double dArea = 0.0;
for (int ii = 1; ii <= shapes.size(); ii = ii + 1) {
Shape s = (Shape) shapes.get(ii-1);
dArea = dArea + s.area();
}
Week 16: May 11, 2009
Week 17: .....
-
Final Exam
May 18, 8-10 am in our regular classroom.
The exam will be open book and open notes and will be a lot like midterm 2.
Developed in January 2009 by Mark Austin
Copyright © 2009, Department of Civil and Environmental Engineering,
University of Maryland