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.