Week1 Participation topic

MobilePhoneTaxonomy.png

Homework1

Week2 Participation topic

  • Question

For this week, please consider a pair of concrete classes in the JDK in a parent-child relationship and discuss a few polymorphics and/or overloaded methods.

  • Answer

Polymorphism is a mechanism in object-oriented programming that enables to the programmer to send a message to objects but make them work differently as a function of each objects. The advantage of using polymorphism is that the programmer doesn't have to modify the caller method to change the program behaviors.

For example, if there are three classes named Shape, Rectangle, and Triangle, and Shape is the parent of other two classes, polymorphism is utilized. If you want to calculate the area of them, you can define a getArea method in Shape class as an abstract method. The function of this method is only to draw. Then, you can define another getArea methods, in which are implemented detailed functions, in Rectangle and Triangle class.

Method overloading is one of the most important functions to work polymorphism that is to define two or more methods of a same name with a different return value and number/type of arguments within the same class.

Project1

  • Class Diagram
LibraryTestClassDiagram.png

Week3 Participation topic

  • Question

For this week, please consider the taxonomy you defined in Week 1 and define an interface that could be used in your class hierarchy. Show the methods defined in the interface and describe how the interface fits in your design.

  • Answer

I created two interfaces for my MobilePhoneTaxonomy as below.

// MobilePhone.java
public interface MobilePhone {
	// make a call.
	void actionCall(String name);
	// send an email.
	void sendMail(String email, String subject, String text);
}
// Smartphone.java
public interface Smartphone extends MobilePhone {
	// get a touch event.
	void onTouchEvent();
	// get an accelerator sensor event.
	void accelSensor();
	// get a geolocation.
	void getGeoLocation();
}

MobilePhone.java is a super interface, and Smartphone.java is its sub interface. Here is a sample implementation of the interfaces below. All the methods defined in the interfaces are overridden in Android.java. An instance of Android object is created in InterfaceTest.java.

// Android.java
public class Android implements Smartphone {
	@Override
	public void actionCall(String name) {
		System.out.println("Calling " + name);
	}
	@Override
	public void sendMail(String email, String subject, String text) {
		System.out.println("Your message to " + email + " has been sent.");
	}
	@Override
	public void onTouchEvent() {
		System.out.println("Got your x and y coordinates.");
	}
	@Override
	public void accelSensor() {
		System.out.println("Got your x, y and z accelerations.");
	}
	@Override
	public void getGeoLocation() {
		System.out.println("Got your latitude and longitude.");
	}
}

Homework2

Week4 Participation topic

  • Question

For this week, please pick one of the programming examples at the end of Chapters 16 or 17 in Liang and describe the JDK AWT and Swing classes needed by the program specified by that exercise.

  • Answer

I choose exercise 17.6 which is a simple speed unit converter. It converts miles to kilometers and vice versa quickly. The program is needed the following JDK AWT and Swing classes.

JFrame is a subclass of Frame class which creates a window. It is a basic class for Swing GUIs.

JPanel is a subclass of Container class. It allows the user to set a layout of some components at once.

JLabel allows the user to set character strings or images, fonts, and sizes.

JTextField creates a single-row input box from the user.

GridLayout is a layout manager. Components are divided into uniformly sized areas in a grid by setting the number of rows and columns.

BorderLayout is a layout manager. Components are divided into left, right, top, bottom, and center.

Project2

  • Class Diagram
LibraryTestOfMap.png

Week5 Participation topic

  • Question

For this week, please describe in your own words what multithreading is and how can multiple threads run simultaneously on a single-processor system? You don't need to provide code examples, just try to describe the principles in your own words.

  • Answer

A thread is an independent execution unit through a program. Normally, only a single thread can run on a single-processor at the same time. Multithreading in Java is the process which two or more threads run concurrently by dividing the CPU processing time into multiple small parts and executing one after another. The concept is also known as time sharing.

Homework3

Week6 Participation topic

  • Question

For this week, please pick one of the statements on pg 110 of Goetz and use your own words to explain why the statement is important for programmers and not just Java programmers.

  • Answer

4. Encapsulation makes it practical to manage the complexity. Encapsulation is the concept in Object-object programming, which is hiding fields or methods intentionally. It allows the program to decrease dependency on other modules, and increase its independency. Therefore, programmers will be easy to maintain programs efficiently. Also, abstraction of classes or operations is one of the essential elements of encapsulation.

Project3

  • Class Diagram
LibraryTestOfJTableAndJTree.png

Week7 Participation topic

  • Question

For this week, please describe in your own words why some of the methods in the Thread class are deprecated.

  • Answer

Thread.stop, Thread.suspend, and Thread.resume are discouraged to use.

If you use Thread.stop, all the monitoring locks by the thread is released, so that the monitor objects become unable to preserve data consistency. Then, you lose thread safety, and that causes unexpected behavior of your application.

Thread.suspend and Thread.resume have the potential to cause deadlocks.

When you use Thread.suspend, and if the thread locks other monitors which have critical system resources, no other thread can access the resources until the thread resumes. If you try to release the suspended thread before you invoke Thread.resume, it causes a deadlock.

Homework4

Week8 Participation topic

  • Question

For this week, please respond to the following:

(a) Describe an application that can deadlock, or starve a thread.

(b) Describe a testing strategy that would detect such a problem efficiently.

  • Answer

A deadlock is multiple processes wait for releasing locks on resources each other, and finally stop their processing.

For avoiding deadlocks, it is important to conduct not only unit testing but also integration testing. Parallel testing, which several users access to application codes, modules, or database records concurrently, is also effective.

Final Project

  • Class Diagram
LibraryThreadManager.png

添付ファイル: fileCMSC335_FinalProject(LibraryThreadManager_java).pdf [詳細] fileCMSC335_Homework1.pdf [詳細] fileCMSC335_Project3(LibraryTestOfJTableAndJTree_java).pdf [詳細] fileCMSC335_Project2(LibraryTestOfMap_java).pdf [詳細] fileCMSC335_Project1(LibraryTest_java).pdf [詳細] fileCMSC335_Homework4.pdf [詳細] fileCMSC335_Homework3.pdf [詳細] fileCMSC335_Homework2.pdf [詳細] fileLibraryThreadManager.png [詳細] fileLibraryTestOfJTableAndJTree.png [詳細] fileLibraryTestOfMap.png [詳細] fileLibraryTestClassDiagram.png [詳細] fileMobilePhoneTaxonomy.png [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2015-09-22 (火) 15:38:57 (3132d)