COSC 2011 N

General Course Material FAQ


Question:

Someone told me that JDK has a debugger "jdb", and how do you use it?

Answer:

The JDK does have a debugger (jdb).  The following link provides further documentation on how to use the debugger:

http://www.wiu.edu/users/mflll/CS412g/jdb3.html



Question:

If you define a method, for example, myMethod(), myMethod() neither throws exceptions or catches them.  If you run this method and there happens to be some exception, what will happen?

Answer:

If your method may throw an exception and you do not enclose the code which may actually throw the exception in a try/catch block or you do not explicitly specify your method throws the appropriate exception in the method signature, then your method will not compile.



Question:

What is the last day to enrol in the course?

Answer:

The last day to enrol in the course without permission from the instructor is Friday March 9.  Friday March 23 is the deadline to add a course with permission of the instructor.



Question:

Are Stack, Queue, Dequeue, and BinaryTree defined - as in do classes exist already such that we just need to import the correct package and we can declare these in our code instead of writing them. Not that I plan on as 1030 taught me how to write them - but I just wanted to know because then in case I ever need to write some code, say in a class that uses a Stack or Queue I can simply import them and use them instead of writing code for them.

 If they are - do they use an array based implementation or some linked representation ?   Or, are they declared as interfaces with certain set methods which we have to implement ourselves based on which representation we wish to use?

Answer:

The JDK does include a Stack class which provides the same functionality as we discussed in class. As far as Queue, Dequeue and
BinaryTree, I don't believe so.  In addition there is also a Vector, List, (Dictionary and HashTable - we haven't covered yet).  So yes, several of the data structures introduced in the lectures are available.  Notice how in order to use these classes available in the API you only need to know the methods, return types and argument types - e.g. the details have been abstracted away and you do not need to be concerned with the implementation or whether the implementation ever changes. Well in the COSC 2011 course, we take it a step further. We want to study both the API (e.g. interface) from both the user's point of view as well as the programmer's point of view.  So we are also studying implementation.  So keep in mind we are actually programmers and need to be concerned with the implementation.   In this course, we are generally not too concerned with writing a stack implementation for example since it was covered in COSC 1030 so unless otherwise stated, yes you can use the JDK versions.

As far as how these structures are actually implemented in the JDK, I am not sure.  However, that is the whole point of Object Oriented
programming - we don't have to know, we don't have to care and it doesn't matter!  Whether they are implemented with an array or a linked list, doesn't matter.  In addition, even if the implementation changes in the future or has changed, the API remains the same - you access the methods in the same way, same arguments, same return types.

 For the most part, implementations for structures used in the API are provided.  There may be some cases where this is not the case however usually an implementation is given.  Now, there may be the case where an interface is given (for example the List interface) however, the JDK also provides other classes which actually implement the interface (e.g. LinkedList implements the List interface).  Now of course you can also provide your own implementation for the List interface if you like.



Question:

What is an Iterator?

Answer:

 An iterator is simply a "way" to access all elements of your data structure, whether the data structure is a Stack, Queue, Vector etc. in a
linear order without having to worry about how they are ordered, arranged or obtained from the structure.  With an Iterator we can "walk through" and obtain all the elements of our data structure without worrying about how they are stored and how they must be obtained.



Question:

A question regarding Exceptions and Return Values:

You stated the following in your notes:  "Return a special value to indicate that an error occurred. This is the usual approach for C functions (which often return 0 or -1 to signal an  error). "

However:
   ----I don't understand the following sentence----

"It doesn't work if the function also returns a value on normal completion and all values are possible (i.e., there is no special value that can be used to signal an error)."

----It said if if the function also returns a value on normal completion and all values are possible, then doesn't that mean this function runs ok? If is ok, why we need to consider using special value to signal an error?

Answer:

If you want to return some value to indicate an error condition (for example, when a function is trying to open some file and
the file doesn't exist, the  function could return -1 to indicate to the caller that the file doesn't exist), you can only do this when the the
error code could never be the same as a valid return type of the function.

For example, consider a file which holds some float numbers which could be of any value.  Now also consider some function which will open the file, read one number and return the number read from the file.  Well lets suppose that the function returns -1 to indicate the file could not be opened.  Now further suppose that the file also contains -1.  Now even if the file is properly opened and the value -1 is read from the file and is returned, how can we distinguish between the error or correct value?



Question:  (Extendable Arrays)

When every time we extend the array double by its size, it takes O(n) to copy all the elements to the new array.  I know this operation is not efficient.  However, I don't understand when the textbook said the operation would eventually become efficient in a long term basic.

Answer:

Although the "growing" of the array may initially take O(N) time (since we have to copy the original elements into the new array), this will take place (usually) rarely. So once we actually increase the size of the array but now we have space for an additional n elements to add into the array before we have to increase the size again.  Usually, you will not need to grow the array very often (otherwise you should consider another structure such as a linked list) so the small price of moving all the elements is ok  when we consider the additional space we gain.



Question:

 I am not able to download the lecture slides, how is it possible to do so?

Answer:

What browser are you using to access the slides?  I have tried on both Unix, Mac and PC and have had no problems using Netscape.  Internet Explorer however wouldn't open the files so i had to actually save the file to disk and then open it.



Question:

Can you explain the detail what a container is?

Answer:

A container is a basically a data structure that stores and organizes a collection of objects and allows access to the objects (elements) through its abstract data type.  According to this definition, all the data structures we have examined in the lectures are all Containers. Now, each of the data structures however, although a container, is certainly more specialized.  For example, a Vector allows access to its elements using a rank while a List ADT allows access to its elements using Poisions.  However, the containers we are concerned with all have certain "common" methods (e.g. size(), isEmpty() etc.) So a Container itself can actually be an interface which each of the more specialized data structures implement. For further details, see pages 216-218 of the text book (first edition).