Tuesday, May 1, 2012

Exam 2

Just a reminder that exam 2 will be this Friday during class.  If you think you might be absent due to current illness, sick pet, etc., please email me.  Comments thread is open for discussing study groups, study topics, your favorite kinds of questions, etc.  Please don't post practice-exam answers here.

Practice Exam Spoilers

This thread is for discussing the answers to the practice exam.

Friday, April 27, 2012

Project:Sorter Discussion

Hi all,

Here's a place for any issues you may wish to discuss related to Project:Sorter.

Wednesday, April 4, 2012

Discussion for 4/4: Threads & Multiprocessing

Hi class.  Please post your thoughts or questions about threads & concurrency here.

Links to some helpful reading:
http://docs.oracle.com/javase/tutorial/essential/concurrency/
http://docs.oracle.com/javase/tutorial/uiswing/concurrency/

UPDATE: remember to check out the threads examples from the class repository.
https://svn.cs.unm.edu/common/edu/unm/cs/cs251spr12/hayes/lecture30_threads
Try to figure out the MysteryDemo example.
Also: What sort of changes to these code examples might lead to race conditions?

Tuesday, April 3, 2012

April 3rd Office Hour Cancellation

All,

My office hours from 3 - 6pm today April 3rd will be cancelled. Sorry for the short notice.

Joe

Friday, March 30, 2012

StereoVision Urgent

This thread is for more urgent questions or discussion, or topics which otherwise ought
to be brought to the attention of the whole class.  Try to use this thread sparingly.  I may
create additional posts if the volume of discussion warrants it.

StereoVision Discussion

Please post non-urgent questions and discussion of the StereoVision project here.
The project spec has been posted on the main course website.

Monday, March 19, 2012

Practice Midterm

Today in class we took a stab at last year's midterm as practice for this Friday's exam.
Since we didn't have time to do the answers to all questions, we'll discuss the remainder under this posting.  Feel free to post your answers if you want feedback about how they would be marked.

Saturday, February 25, 2012

Discussion for Feb 24

Hi all!  As promised in class, Quiz #1 is now online.  Head over to the "main" course website, and see the latest post under "Assignments."

Regarding today's class, I'd like to hear your thoughts about how the "undo" method should work, and what exactly the HistListOp subclasses should provide in terms of methods to cause the correct behavior for undoing add, get and set operations.  This will really test your understanding of what methods are for.

For a bit of related supplemental reading, go into the Java API, and check out the package javax.swing.undo.  The obvious question you should be asking as you read about this is, "Could we use this framework instead of 'rolling our own' for HistList?"  Can you answer it?

I await your posts on these topics or anything else related to recent class material.  Please, no spoilers related to the Quiz.

Wednesday, February 22, 2012

Feb 22 Discussion

OK, please post questions/comments related to today's class in the Comments.

I wanted to correct one thing I said in class about Interfaces.
When you assign to a variable whose type is an Interface name, you've got to make it refer to an actual object, and every object is an instance of an actual Class.  So, to initialize a List<String> variable, you can't write:
List<String> myList = new List<String> ( );
You'll get a compile time error, pointing out that there is no such constructor because List is an interface, not a class.  Instead, do something like:

List<String> myList = new ArrayList<String> ( );    // or
List<String> myList = new LinkedList<String> ( );

Again, when the type of a variable is an Interface, the variable (if non-null) will always refer to an instance of some implementing class.

Here's an exercise to think about:
Write a List class called SilentArrayList that acts like ArrayList except:
If the user tries to set or get a value that is out of range (>= this.size( )), instead of throwing an exception, it just silently fails, returning a null reference in the get case.

There are some technical issues involving the type of item to be stored, but try not to get too hung up about those for now, even though they need to be handled right if you want your solution to compile.

Monday, February 20, 2012

Discussion for Feb 20

Hi folks,

Please post some answers to the following questions, related to today's lecture.  You can either try to deduce the answers, or find out more online, or both.  If you find a webpage you think is useful, you may post the URL as well as (but not in place of) your answer.  Suppose class C extends class B extends class A, like in lecture.

We talked a bit today about how "any C is a B" and "any B is an A", which allows you to do assign objects of a subclass into a variable whose type is a superclass.  Why does this force subclasses to have all the methods of the superclass?  Why doesn't it force subclasses to have all the constructors of the
superclass?

On a related note, if I type this:
B myB = new C("Mr. C");
myB.printName( );
Will this execute the printName( ) method defined in B.java or C.java?
Why is this a related note?

What if I now pass myB as the argument to this method:
public int ageOf( A someA ) {
    someA.printName( );
    return someA.age;
}
Which printName( ) method gets called now?
Can the variable age, defined in A.java ever be "overridden" in any sense in B.java or C.java?  If so, explain how as clearly as you can.  If so, is there a way to access the values from the superclasses?

Saturday, February 18, 2012

Discussion for MacroSoft PowerDisplay

The Lab and pre-lab assignment for Feb. 22nd is now available. As usual, a physical copy of your prelab assignment is due at the start of your lab. This lab is not due until March 7th. The prelab will be collected February 29th.

http://www.cs.unm.edu/~tberge01/spring.2012/cs251/labs/feb22.php

Have a great weekend!

Saturday, February 11, 2012

Discussion for World of CarCraft

The Lab and pre-lab assignment for Feb. 15 are now available. As usual, a physical copy of your pre-lab assignment is due at the start of lab on February 15th. This lab has been extended and is due February 29th.


http://www.cs.unm.edu/~jmonter/CS251/S12/feb15.php


Please post your questions and comments here.

Have a great weekend!

Friday, February 10, 2012

Discussion for Feb 10

Okay, so today we *tried* to look over the code from lecture 10 some more. However, we were side tracked by 4 topics "svn uses", "emacs functionality", "inheritance", and "interfaces".

Homework:
Look over the code from lecture 10 and come up with improvements

Topics for Discussion (reply for participation credit):
What is the dictionaries definition of inherit? How does this relate to inheritance in Object Oriented Programming? Do you think inheritance was a good choice to describe this? Why or why not?

What keyword is used to describe inheritance in java? What is the syntax of this keyword?

Every Class in Java inherits from another Class. If left unspecified, what Class does it inherit from? What does it mean to inherit from this class?

We saw in class that in every Class Constructor you must invoke a Constructor from the class you inherit. How is this done? Knowing this, what does it mean if your class has no default constructor? What if your class only has private constructors?

Some languages have multiple inheritance. What does this term mean? Java does not allow for an class to have more than 1 super class. How does Java allow for the benefits of multiple inheritance?

What is an interface in Java? Why would you ever use an interface?

Have a good weekend!

Wednesday, February 8, 2012

Discussion for Feb. 8th

We talked about the new and improved GuessingGame.java and GGFrame.java. Make sure to look over these in the repository. There are some tricky bits in these so it is okay if you don't understand *everything* but do your best and post questions.

Topics for Discussion:
In class, we decided it was better to separate the GUI code from the GuessingGame code. Why is this a good idea? Name a few reasons and explain them in a one or two sentences.

You will notice that GuessingGame extends Object. What does this mean? What would change if we removed the extends Object portion of this declaration?

We saw a StringBuilder on line 65 of GuessingGame.java. We used this object to create a String. Why do we use this instead of concatenating Strings together using +=?

The term immutable came up in the discussion today. What does this term mean? Why is the String object immutable in Java? How do we get around String being immutable?

Look at the code here: http://pastebin.com/42arBK9j
It prints two booleans. Can you guess what they are? After guessing, compile and run. Were you correct? What is going on here?

Look at the GuessingGame files in the lecture10 package. What additional improvements can we make?

See you Friday!

Joe

Monday, February 6, 2012

Discussion for Feb. 6

Today we went over the GGFrame.java example. You should look over this code and see what improvements can be made. How can we make it more modular?

Discussion Topics (post for participation credit):
We saw many new things today. Two of these appeared on the class declaration line of GGFrame.java: extends and implements. What does it mean to extend a class? What does it mean to implement an interface?

This brings up another question, what is an interface? You should read about interfaces here: http://docs.oracle.com/javase/tutorial/java/concepts/interface.html Post your thoughts on interfaces. Define it, post 1 (or more) pro for using an interface, post 1 (or more) cons for using an interface.

We saw the basics for implementing the ActionListener interface today. Read about it here: http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html then post your thoughts. When do you need to implement this interface?

We are starting to see GUI components in class. You may not know it but, there is a very large number of components that the javax.swing library provides. Look through the javax.swing library in the Java 6 API and pick 1 or 2 classes that start with a J (such as JFrame or JPanel) and explain them. When would you use these components?

The term overload came up today. Java allows us to overload both methods and constructors. What does it mean to overload a method or constructor? Give a short example using pastebin.com links.

Another term came up today Override. Override is an annotation that has been available since java 5. What is its purpose? What is the difference between overloading a method an overriding a method?

Composition came up in the discussion today. You will be doing object composition for the lab this week as well. When we are talking about composition in object oriented programming, what does it mean? Give an example.

See you Wednesday!

Saturday, February 4, 2012

Discussion for Computer Composition Lab

The Lab and pre-lab assignment are now available. As usual, a physical copy of your pre-lab assignment is due at the start of lab on February 8th.


Please post your questions and comments here.

Have a great weekend!

Friday, February 3, 2012

Discussion for Feb. 3

Today we covered many topics while covering the JFrameDemo class (go look at it again).

Topics for Discussion (reply for participation credit):
The new keyword was mentioned today. What is its purpose?

Another word that came up was null. What is null? What does it mean for something to be null? When might you get a NullPointerException?

We mentioned the 8 primitive types in Java. What are they?

Through out today's class the word reference popped up quite a bit. What is a reference? Why can't primitive types contain references?

In Java, we don't have to worry about managing our own memory. There is a special feature that walks around in the background like your mother cleaning up your messes. What is the name of this thing? When does it clean up your memory? How do you know an Object is ready to be cleaned up?

Pass by value and Pass by reference were also mentioned. What does it mean to be pass by value? What does it mean to be pass by reference?

Look at the following code Incrementor.java: http://pastebin.com/TPN5XDbF
Don't compile and run it. First write down what you think it will print out. Explain your answer.
Now compile and run it. Did it run the way you thought? Explain what is going on here.

Preparing for Monday
Review JFrameDemo.java and understand what it is doing. Read through some GUI tutorials in Java. A good place to start is here: http://docs.oracle.com/javase/tutorial/ui/index.html

Have a great weekend!

Wednesday, February 1, 2012

Discussion for Feb. 1

Today we touched on a large variety of topics. Let's see how much we know and can learn about them.

Discussion Topics (respond for participation credit):
We briefly talked about two related classes, InputStreamReader and BufferedReader. Google around a bit, look at the Java API and then describe what these classes do. What can they be used for? Are there other Reader classes?

Another word that came up today was Exception. Can you explain what an exception is? Why do these exist? How are they used? Why are these used?

At the end of the GuessingGame class we called the main method. There is a term for a method that calls itself, what is it? We said that when we do this "The Stack" grows. What does that mean? What is this magic "stack"? Read about it on wikipedia http://en.wikipedia.org/wiki/Call_stack. Then describe what it is doing in your own words.

We talked a little bit about how to efficiently solve the GuessingGame. The term Binary Search was mention. What is a Binary Search? What are its applications?

The keyword "final" was also mentioned today. What does final mean? Write a little example in java and share it via pastebin.com links.

Using methods to logically break up your code into manageable chunks is important. How do you know when you should break up your code? Why is this important?

Visibility and scope have also been tossed around quite a bit. What do these mean? What are we referring to when we say visibility? What are we referring to when we say scope?


Tuesday, January 31, 2012

Note-taker needed

Hi class,

I need someone who is responsible and takes good notes to go sign up with the Accessibility Resource Center to provide them for a student who could use help with this.  In fact, ARC will pay you for your trouble.  Please let me know via email when the position is filled, and I will post a follow-up here.  Thanks!

Monday, January 30, 2012

Discussion for Jan. 30th

Today we talked about access control, package hierarchy, and class path.

Discussion Starters (respond for participation credit):
Pick one or more of the following to answer. If you're unsure about a question, google it, post your response, and cite your source. If possible, give examples via pastebin.com links.


What access levels does Java provide?
What does each mean?
For member variables, when would you want to mark them private?
Is there a good reason to mark them public? Explain your reasoning.

What does the package declaration mean?
Why do packages exist in Java?
Which package(s) are loaded by default in java?
How do you include an entire package in a class you write?
How do you include just a single class from a package in a class you write?
In a unix shell, how do you check your class path? How do you change your class path?
In the Java API there are two List classes*, java.awt.List and java.util.List. If you want to use both of these in the same class, how would you do it?

See you Wednesday!

Joe

P.S. 
Don't forget to do your pre-lab for the February 1st lab.

Sunday, January 29, 2012

Discussion for Celestial Bodies Lab

Feel free to post questions and comments regarding the Celestial Bodies lab assignment here.

Common Problem from Pre-lab
After grading the pre-lab assignments, I think a little clarification is needed.

1. static variables belong to the Class, you do not need an instance of that class to access it.

2. private access only allows visibility of a method or member variable within the declared class. All nested classes have visibility because they are inside the class. However, you do not have access within the entire file.

3. private member variables have no visibility outside the class. To access it you must write a method that is non-private that accesses it. This provides an interface to allow someone to use and manipulate what is inside your class.

4. a static method is accessed through the class (i.e Math.pow()). Again, no instance is required. A non-static method is accessed through an instance of the class. (i.e. Object j = new Object; System.out.println(j.toString()).

Best of luck!

Joe

Friday, January 27, 2012

Discussion from Class Jan. 27th

Today we covered various topics. Here are some things I want you to have taken away from lecture today.

Be curious
Don't just use emacs like a text editor. Google things like "autocomplete emacs java" and "compile emacs java". If there is something you wish emacs did, it probably does! Go and find it!

What is a Class?
A class is a definition of an Object in java. It contains information on how instances of that class should exist in java land.

What does it mean to be public vs. private?
When something is public it can be accessed by ANY other class. When something is private it may only be accessed within the class it is declared. How does this help us maintain the state of our Objects in java?

What is a Constructor?
For our purposes, you can think of a constructor as a "special" method that must return a new instance of the class that is being created. Note: If a constructor is not explicitly defined in a class, by default it will have a public constructor that takes no parameters.

Something to discuss (respond for participation credit):
What does it mean to have a private constructor? Can you do this? Would you ever do this? When and why?


What is the purpose of having a private member variable? What are the pros? Are there any cons?

Write up some coding examples to support your arguments and share them via pastebin.com links.

Have a great weekend!

Joe

P.S.
In class we were unable to get our class files to run when they were in a package. We almost had it. We were trying to run it by using the following command "java -cp /path/to/files/ GalacticDriver". However, this was not quite correct. Since GalacticDriver.java had the package declaration "edu.unm.jcollard.jan27" I needed to specify exactly which package it was in. To get the file to run from the command line you must use the following argument "java -cp /path/to/files/ edu.unm.jcollard.jan27.GalacticDriver". This tells the java virtual machine where the class file exists. This allows us to have multiple classes named GalacticDriver that exist in different packages. However, I would try to avoid this ;)


Wednesday, January 25, 2012

Lab Assignment - Integer Calculator

Post any thoughts or questions you have about the Integer Calculator lab assignment here.

Questions and Answers from Pre-lab Assignment:
I have tried to encapsulate all of the questions asked on the pre lab assignment that were relevant to this lab. If your question was not answered, please post it in the comments.


Q: If the user inputs bad data, do you want us to exit or show error messages and restart the program?
A: The answer to this is in the write up specification under the Requirements section: "If the user enters too few or too many arguments or an invalid argument the program prints the usage." Also, because you are receiving input from the command line it does not make sense to restart the program this would result in the same input.

Q: What does isOp() return?
A: Because it is not specified in the write up specification it may return anything you want. However, it is good practice to have methods starting with isX and hasX to return booleans.

Q: Once the program prints usage does it end or restart the program?
A: Your program should exit if invalid input is given to it. It does not make sense to restart the program because you are receiving the input from the command line.

Q: Are we only calculating ints?
A: Yes.

Q: Should we print a statement for each error?
A: This is not specified in the write up. It is generally good practice to do this so the user knows what they did wrong. However, you will not be docked points for not doing this.

Q: What if the user adds spaces in between the arguments of the String?
A: Because we are taking input from the command line you *should* receive 3 Strings if the input is correct. Each of these Strings should not contain any spaces. If they do, that would be invalid input.

Q: What is parsing?
A: To interpret something. In our case, we are parsing Strings to ints using the Integer.parseInt() method. Also, we must parse a String to see if it contains a valid operation

Q: What is op?
A: This is just an abbreviation for operation.

Q: What does it mean to be a static method?
A: A static method is associated with the class rather than the instance of the class. For the purposes of the Integer Calculator assignment just assume all methods need this.

Tuesday, January 24, 2012

When your SVN gets F'd.

So far, two students have screwed up. Shame on you!*

Time to play detective. How did I figure this out? Who screwed up and how? What should they have done differently? How did I repair the repository?

Please discuss in the comments section.

Here are two links to add to your reading. They are the first hits when you google "svn resolve conflict".
http://ariejan.net/2007/07/04/how-to-resolve-subversion-conflicts
http://www.logicaltrinkets.com/wordpress/?p=178


*just kidding. Mistakes are learning experiences.

Friday, January 20, 2012

Getting used to SVN

To ensure that you all get some practice with SVN as soon as possible, I want everyone in the class to do the following.
Checkout everything from my pub-svn directory, using this command from within your CS account:

svn checkout file:///nfs/faculty/hayes/pub-svn working

cd into the directory named "working" (the above line created it if it didn't exist already), and add one line of text to the file roster.txt, containing your username.

svn status should now print:
M roster.txt indicating that you have modified that file from its checked out version.

svn commit -m "added my name" commits the new version of roster.txt back into the repository.

svn log will show the record of all past changes to the repository.

If you are unlucky, someone else may have committed a new version in between your checkout and commit steps above, in which case the commit will fail. In this case you can type "svn update" to bring your version up-to-date.

I'll be checking the log files, so please impress me by doing this exercise promptly.

Questions? Post a comment below.

Wednesday, January 18, 2012

Getting Started

Forum for questions/answers about getting started with your CS account, java compiler, subversion, etc. (discuss in Comments section).

Tuesday, January 17, 2012

Discussion Topics

Hi class,

Welcome to CS 251. I will make new blog posts periodically, so that class discussion can take place in the comments section. Just let me know if you ever want me to start a new discussion thread on some topic, and I will generally do so fairly quickly.