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?