Monday, November 3, 2008

lecture 25

What Object Orientated principles did we use in the project?
Encapsulation -the way similar items were grouped together for example the domain, DAO and GUI

Overloading - you could view all the products or products by category
Overriding - the getAll() method was over-ridden with different objects such as Customer, Product.
Aggregation / Composition - an Order involves a Customer and 0-Many Order Items, an Order Item involves a Product and a Shopping Cart involves a Customer and 0-Many Order Items. However, Composition was not used.
Inheritance - the way the DAO's inherited the getAll(), and save methods from Abstract DAO
Design Patterns - in terms of singleton design only one instance of Entity manager was created, and facade design: the DAO classes are facades that provide access to a related set of objects that deal with their storage.

lecture 24

1.Discuss the differences between Waterfall model and Extreme Programming.
with the waterfall model, every phase of the the development is a "stand alone" process and require only the staff for the particular phase.Extreme Programming model is an "agile" model that has the ability to respond to change. it involves the whole team, regular testing, pair programming obtain a more powerful and stable system.

lecture 19

1.HTML and XML were designed for different purposes. Explain a scenario in which XML documents should be interchanged between applications.
suppose you want to transfer your primary school marks to your university application, but the format of the marks is not supported in the university application. you therefore encode the marks to XML document so that the university can understand. XML documents are text based and are easier to read and understand.With XML, data can be exchange between incompatible systems.

Sunday, November 2, 2008

lecture 18

Describe one scenario where Java Reflection can be useful.
a scenario would be that if you are marking a set of projects, the students have implemented their project using different class names, fieldnames, and method names with the same functionality.You cant use JUnit for this scenario as you need to have the classnames, fieldnames and method names to be the same.

lecture 17

Describe the request-response programming model of Servlets using an example.
the client sends a request to the request-response model in the form of a ServletRequest object. The response is send to the client in the form of a Servletresponse object.
For Example: if a client wanted the addtion of two numbers by entering in the browser, the server response with the answer.

2. Why do we need Java Servlets? Aren't static HTML stored in Web Servers good enough?
we need Java Servlets because web content these days keep changing all the time like weather forecasting, news, scores. therefore we need to dynamically update the web page to keep the response up to date.

lecture 13

What is design pattern and why is it useful?
design pattern offers advices, recommendations to developers to solve a problem.It is useful in the same way as a FAQ's page – providing access to problem solutions that someone has already come across.

lecture 12

1.explain the benefits of using Exception handling API in Java.
exception handling can provide the user with messages that indicate where the error occurred in the method and also provides error handling code that tells you what to do to stop the error from occurring again.

lecture 11

Explain the difference between an abstract class and an interface.
abstract classes for example can help you define some behaviors and forces the sub classes to provide others. the sub classes that inherit abstract classes must implement their methods.

Interfaces are used when some subclasses require certain methods, abstract classes require all subclasses to implement the abstract methods. You cannot instantiate an abstract class

Describe a scenario where you might prefer to use an abstract class over an interface.

Used for objects that all have certain states and behaviors in common. for example, shapes within a graphic application that have same colours and move in a specific way.

lecture 8

Explain the difference between black-box and white-box testing?
in black box testing, there is no prior knowledge of the system.The testers must first determine the scope of the system before starting their analysis. The behaviour of the system is examined from an external point of view.Advantages of black-box testing is the fact that the test cases can be created in parallel with the implementation activity.

in white-box testing, it focuses on the internal knowledge of the system before you start testing.

lecture 7

1.What are the benefits of inheritance?
a) you can reuse blocks of code,because the child class has access to the parent's fields and methods.

b) Parent constructors can be invoked from the child, and their private fields can be accessed using the superclass' public accessing methods.
c) The child class can declare fields and methods that are not in the parent.

d) Method over-riding can be used (the child method can over-ride the parent method).
e) Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass Example, then the application can be adapted to return any class that is descended from Examplethe benefits of inheritance is that you can reuse the code and maintainability (only need to change code in the parent, and it is reflected in the child class).

Explain each benefit in the context of an example.
class Animal {


String name;
double age;
double height;

Account() {
}

Account(String n, double b, double d) {
name = n;
age = b;
height = d;
}

void getAge() { **a
System.out.println("Age is : " +age);
}
}

public class Farm extends Animal{
double cattle; **c

Farm() {
}

Farm(String n, double b, double d, double o) {
super(n, b, d); **b
cattle = o;
}

public static void main(String args[]) {
Farm frm = new Farm(“cow”, 20, 5.5, 1000);
System.out.println(frm.Age()); **a
System.out.println("This animal is " + frm.name);

System.out.println (getAge());
}

void getAge() { **d
System.out.println("The age is" + cattle); }
}

2. Does Java support multiple inheritance? Justify your answer.
no it is not possible to do that. but with the use of interfaces and inheritance hierarchy (each subclass is linked to a superclass, which ultimately ends with Object at the root) multiple inheritance can be simulated.

3. It is recommended that you should “program to an interface". An example of programming to an interface is given below where an object of type ArrayList is assigned to a List interface reference. Explain the advantage of this approach.
List studentList = new ArrayList();

instead of tying relationships to classes, you can tie them to interfaces as this has the advantage of being able to change the implementation of a program, with minimal effort.

lecture 6

Assume that there is a large software company developing an application that retrieves data from five different database systems such as Oracle, and SQL Server. Each of these databases have their own API to store and retrieve data. Currently the application has five separate modules dealing with connections to these databases. This has resulted in maintenance problems (such as upgrading the connection code whenever a database API changed). You are a consultant who can offer a solution to this problem. What would you recommend? Justify your answer.

JDBC provides a standard API for programmers and makes it possible to write database applications using a pure java API.you can write a single program using the JDBC API, and the
program will be able to send SQL statements to any database system for which an appropriate JDBC driver has been written.

lecture 5

Why do we need collections API? (Application Programming Interface)
A collection class is a class that can store a collection of objects. . it manipulates groups of data as a single unit. there are few collection interfaces
The Set interface extends Collection but forbids duplicates.They have few properties such as
They contains only one instance of each item
They may be finite or infinite.
They can define abstract concepts

The List interface extends Collection, allows duplicates, and introduces positional indexing.

The Map interface extends neither Set nor Collection.
map is a special kind of set. It is a set of pairs, each pair representing a one-directional
mapping from one element to another (eg. student ID and name).

2. Take a look at the following code. Your intention was to store objects that belong to the Animal hierarchy to an ArrayList. A subclass that belongs to Animal hierarchy is a Dog class. There are other classes such as a Truck class and a Melon class. Assume that one object of each subclass type exists.


ArrayList arrayList = new ArrayList();
arrayList.add(dog);
arrayList.add(animal);
arrayList.add(truck);
arrayList.add(melon);

a. Has the code met the designer’s objective of storing objects of type Animal in an ArrayList?
no it hasn't it only stores the elements in the array list not the objects of type animal.

b. Write a piece of code to extract Animal objects out of the ArrayList.
for (Iterator iter = animals.iterator(); iter.hasNext();) {
Animal temp = iter.next();
System.out.println(temp.getName());
}

How can you ensure that only objects of type Animal be stored in the ArrayList?

public static void main(String args[]) {
ArrayList animals = new ArrayList();

animals.add(new Animal(“dog”, "bow"));
animals.add(new Animal(“cat”, "meow"));
animals.add(new Animal(“tiger”, "zimba"));
animals.add(new Animal(“elephant”, "Dumbo"));
}


public Animal (String species, String name) {
this.species = species;
this.name = name;
}

lecture 4

1. What do you understand by the term event driven programming? In particular explain what events are and how they are handled by the event handling mechanism in Java.

Event driven programming is a technique where the program "listens out" to actions made by the user to determine the sequence it will perform its methods . It then awaits further response from the use

In Java events could mean selecting a radio button or menu item, manipulating a scroll bar or clicking a button.

2. Assume that there are several buttons in a frame. Each button when clicked generates an event. In this case do we need to have a unique listener for each button? What is the benefit of the approach that you have chosen.

If there are several buttons in a frame,you can create an anonymous inner class for each button which is one-to-one mapping.the benefit of this is that it does not slow down the run-time.

lecture 3

Assume that you are planning to build a website similar to Amazon (www.amazon.com) website which is primarily used for ordering books for the US from any location in the world through Internet. Say, a user would like to buy four items in one transaction using the concept of shopping cart. Explain how you would incorporate the following principles while designing the user interface of your system. You can invent details as required.

Aesthtics:in terms of colour used, used matching colors and dont use colours that are hard on the eyes. Use clear fonts,nothing too small.Align buttons and text consistently (but don't over-crowd) to improve visibility and overall aesthetics.Make sure animations don't detract from the main site, take too long to download.

Consistency: is very important in a user interface.Keep placement, formatting, wording and actions uniform: for example, the Close button is always red and at top-right.
You have to set user interface design standards, cause the user already has a basic idea of how to use the site.

Forgiveness: warn users when something irreversible is about to happen. one way of doing that is to ask the user if they are sure they want to delete a file, displaying a low battery warning or a creating a restore point.

Appropriate user feedback:a good way to give feedback would be to advise the user of what is currently happening (eg. a status bar or pop-up window stating that a download is 10% complete.

Use of metaphors:Borrow “themes” from existing familiar systems. For example: Title Menu or Next Chapter on a DVD is similar to a book's terminology.

lecture 2

1.Explain the concepts of Encapsulation, Inheritance and Polymorphism. In the context of an example explain the benefits of the above mentioned concepts. Note that you do not have to write any code.

Encapsulation: objects have attributes and methods combined into one unit. Instead of accessing values directly, encapsulation protects the values of the variables by only allowing values to change using method calls.

Inheritance:one class takes on characteristics of another class and extends it. the parent class acts like a template to the child class. the child class can access any methods and variables and can also define its own variables and methods. this helps in making the design a simpler process as you keep reusing the code.

Polymorphism:means the object can have multiple forms. different classes can have the same method name but they have different parameters.That methods behaviour will differ depending on the object type it is dealing with.

2.Create an inheritance hierarchy of Vehicle: Bicycle, Car, and Truck. In the base class (Vehicle class), provide one method that are common to all Vehicle classes (say, getNoOfWheels method – assume that Trucks have more than 6 wheels), and override this in the derived classes to return different number of wheels based on the specific type of Vehicle. In the main() method of a class named Assignment2, create an array of Vehicle, fill it with different specific types of Vehicles, and call your base-class methods to see what happens.

public class Vehicle ( ) {
public int getNoOfWheels ( ) {
return 0;
}
}

public class Bicycle extends Vehicle ( ) {
public int getNoOfWheels ( ) {
return 2;
}
}

public class Car extends Vehicle ( ) {
public int getNoOfWheels ( ) {
return 4;
}
}

public class Truck extends Vehicle ( ) {
public int getNoOfWheels ( );
return 12;
}
}

public class Assignment2 ( ) {

public static void main (String [ ] args) {

Vehicle veh [ ] = new Vehicle [3];
Bicycle bike = new Bicycle ( );
Car car = new Car ( );
Truck tr = new Truck ( );

veh[0] = bike;
veh[1] = car;
veh[2] = tr;

for (int i = 0; i <>
System.out.println (veh[i].getNoOfWheels( ));

}
}

Lecture 1

Imagine you are hired to improve the current situation in a software firm that develops word processing type applications. The software firm is using the code and fix approach and they have lawsuits for producing low quality software that was delivered late. What would your advice be in the context of software lifecycle methodology?

i would recommend using the spiral method.
a. Explain the advantage of the methodology that you are suggesting over the current one.
you get earlier feedback from customers so that you can improve on your system
Testing starts earlier in the development life cycle, helps maintaining good stable system instead of creating just one complete system that does not meet the requirements.

b. Give more details about how the word processing application should be managed according to the methodology you have chosen.
you can assign different members to work on each iteration. for example ,one member working on save and delete option, and the other working on the print option etc. doing this results in simultaneous progression at each phase.