Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Faq

Homework

Labs

Lecture Notes

Links

Schedule

Since You Asked

Staff

Syllabus

Online Submission Utility

Java API reference

Class Forum

Grades Online (GRIT)

 

CSCI1902 Home

Announcements RSS Feed

 
 

Printer-friendly version

 

Since You Asked

This page will be used to publish, from time to time, answers to questions we receive.

Miscellaneous things you might be wondering

  • What to call me?

    Up to you — Professor Terveen or "Loren", if you're comfortable with that

  • I will call on groups at random to come up to present their results
  • Prereqs for sucess
    • You don't have to know Java in advance... but it does make your job easier.
  • Java
    • syntax/details - how will you learn them?
      • I'll present examples of basic programs and constructs in class, starting today
      • I'll call out new details and syntax
      • And you must read, too
    • How much Java?
      • Basics/Core
        • You will be able to "program Java" by the end of the semester - remember the learning objective:

          Solve moderately complex real-world problems using the Java language. You will be able to use basic control structures and data types. You will be able to construct models of data using fundamental object-oriented concepts such as classes and objects, methods, encapsulation, inheritance, and polymorphism.

      • Much we won't cover, including (alas) UIs, web programming
  • Programming assignments
    • You choose your partner to work with on assignments 1, 3, and 5.
    • You must do assignments 2 and 4 alone.
    • Highly recommended that you actually work together. Trying to divide the task, work alone, then integrate the results is much more likely to fail and certainly reduces the learning benefit. Read about pair programming: http://en.wikipedia.org/wiki/Pair_programming
    • Can do assignments on whatever computers you want: ITLabs, your home machine, laptop, etc. However, we'll run them on ITLabs machines.
    • You don't have to use Eclipse, but I strongly recommend it
    • You can submit remotely
    • Assignments will be time-consuming, esp. after the first one
    • The last assignment will be the hardest (note that you've got 4 weeks for that one)
  • Tests and Grading
    • Quizzes are in class: the last 25 minutes of the session
    • Format of quizzes: number, difficult of questions
      • Will provide samples by Wednesday Feb 6
      • Will spend some time in class on Feb 6 discussing types of questions to expect (and that you should write)
    • Grade distributions
      • Intention: With sufficient work, it should be relatively easy to get a B. Getting an A should be a real achievement. Previous offerings:
        A and A- About 25%
        B+, B, B- About 40%
        C+, C, C- About 22%
        Less than C- About 13%
  • Labs
    • No grades, no extra credit: you just have to complete (the required parts of) 10 out of 14
  • Lecture notes are available on the course web site

Readings - Appendix A and online references as indicated in the notes

January 28

Your Profile

Have you taken 1901?

Yes 92
No 4
Didn't answer 2

Do you know Java?

Yes 18
No 60
Some/Minimal 18
Didn't answer 2

Succeeding in this course

  • Tutoring?
  • "I have no absolutely no prior knowledge of Java, I'm scared"
    • Don't be... most of your fellow students don't either. You can learn the Java you need through paying attention in class, working in the lab, doing the readings, and working on the homework assignments. Come to see any of the course staff if you're having trouble.
  • How do I study successfully for this class?
    • Come to class. Engage in the activities.
    • Do the readings
    • PROGRAM: Doing the lab and homework assignments is a minimum. The book is a good source of questions and exercises which you can use as self-tests.
    • Work through the review material I prepare for each quiz. Be sure you understand the topics and can do all the sample problems.

Programming assignments

  • How do I find partners for the homework assignments?
    • Talk to people in your lab session and in class. It's absolutely fine to have a partner who's in a different lab session.
  • How long will the programming assignments take? (if I want to get an A).
    • It's hard to answer precisely: I'd guess 5-10 hours for the first assignment and 10-20 hours for the rest.
  • What aren't we doing any "big projects"?
    • Big projects: high reward, high risk... For the same reason, we have four quizzes (and you can drop the lowest score) instead of two mid-terms

Quizzes/exams

  • When is the final?
    • Good question: I'll have an answer by next week.
  • Where can I find practice problems?
    • I will post sample problems/questions for each quiz. The book is a good source, too.
  • Are there unannounced quizzes?
    • No
  • Are exams "open book open notes"?
    • All the exams are closed-book; however, you may bring one letter-size piece of paper, two-sided, of handwritten notes.
  • What is the format of quizzes?
    • I will post lots of sample questions. However, in general, you will have to write some code fragments and answer written questions to show your understanding of concepts
  • Studying for quizzes
    • I will post topics that will be covered and sample questions
    • I will go over in class briefly, ask for your questions
    • There may be outside class review sessions, but there is no guarantee of this

Labs

  • Must finish by the end of class - they're designed that way
  • Not graded. Just complete the (required) activity for credit ("check mark")
  • What if you didn't get a check mark in the first lab?
    • Check with your TA

Grading

  • "Will there be a curve?"
    • Only if necessary
  • Extra credit?
    • Often the assignments have a little extra credit. Sometimes the quizzes do, too.

Content questions

Note: Many of these will be covered in detail later in the semester

  • How do you measure efficiency of algorithms?
    • Find the right units to count (like "comparisons")
    • Count how "long" (in terms of these units) the program will take to run in the worst case
    • Express "how long" as a function of the "size of the input"

Questions about Java

  • This class uses only Java, not other programming languages It covers only the fundamental aspects of Java. Java is a huge language (with many class libraries), and we will not cover most of them. Things we will not cover include:
    • applets, web programming
    • graphical user interfaces
  • What are advantages of Java?
    • write once, run anywhere
    • industry standard language
    • security model: Web applets
    • networked
    • object-oriented: a better way to build software
    • huge set of libraries
  • Is Java used for more than just internet-based programs?
    • Yes
  • History of Java?
  • How long do programming languages last?
    • Some last a long time:
      • Fortran, Cobol, Lisp, ...
  • Why are we using Java 5, not Java 6?
    • Java 5 introduced several key features to the core language that are relevant and useful to the type of program you'll write in this course, notably generics and autoboxing. (I will cover these topics later). You may use Java 6, but your programs must compile in Java 5, since that's what we're using.
  • How different would this class be if you were using another language or programming environment?
    • It would probably be about 20-30% different. You'd learn that language instead of Java, obviously. The core of the class would stay the same, however: you'd still learn the same data structures, algorithms, and analytic techniques.
  • Many questions about Java specifics that will be answered over the next few weeks
  • What is "object-oriented programming"?

Eclipse

Eclipse is open source, freely available. Works for all platforms. You can download it to your computer (if you have one) and do all your work there. However, you must ensure that your program runs on ITLabs machines and create a file to submit. See the instructions for Assignment 1 and the FAQ.

February 13

Java

Abstract Classes

- Why would you want to declare abstract methods in an abstract

superclass?

  • They are a sort of "contract" or even "documentation in code". That is, at the level of the abstract class, one can say that this behavior exists, but cannot implement it. However, any subclass of the abstract class must implement the abstract method (or, if it does not, the subclass will be abstract too). - What are abstract classes used for?
  • Where "there is common functionality that you'd like to implement in a superclass, and (b) some behavior is unique to specific classes and cannot be factored into the superclass." Case (a) gives rise to methods that you actually implement in the abstract class. Case (b) gives rise to abstract methods. - Must an abstract class have a subclass?
  • Yes. Since you can't make an instance of an abstract class, if you don't define subclasses of the class, it will be of no use.

The equals() method

When we define the equals method for our class, are we overriding or overloading?

CLARIFICATION: The example I gave last time was "wrong"... I was overloading, not overriding as I intended. The reason is that the parameter of equals must be of type Object in order to override the method inherited from object. Technically, the signature must be exactly the same as the signature of the inherited method.

The tricky thing is that this problem may manifest itself right away: if you invoke equals directly, the results will be as you expect. However, the equals method is called automatically by lots of methods that are used frequently for Lists, such as indexOf and contains. Theese methods (indexOf, contains, etc.) call the equals method with the signature:

public boolean (Object o)

so if you wrote an equals method whose parameter is not of type Object, it will not be invoked in these cases. Instead, the default equals method from the Object class will be used. THIS WILL NOT BE WHAT YOU WANT.

Overriding vs. Overloading

"I still don't understand overriding vs. overloading" clearly.

  • Overloading — see p. 25-26 in the text.

    "A method in a class overloads another method in the same class when both methods have the same name but differ in the number of types of parameters."

    Terminology: "A method's signature" consists of its name and parameters. Thus, overloaded methods have the same name but different signatures."

  • Overriding (and overloading) — see pp. 52-57 in the text.

    "A method in a derived class overrides a method in the base clase when both methods have the same name, the same number and type of parameters, and the same return type... [in other words] when both methods have the same signature and return type."

  • More on overriding vs. overloading (overloading is still unclear to me)
    • See the text, page ...

Can you make a class private?

No, at least not "top level" classes (i.e., classes that are not defined within another class). There are only two options for a top level class:

  • public
  • package-private. If you DO NOT specify the public access modifier for a class, this is the default. This means that only classes within the same package as this class can access it.

Soon we'll see that you can define a class within another class. These so-called "inner classes" may be private or protected. They can be public, too, but often you don't want them to be public.

How much of Java will we learn?

  • How "in depth" will we go into Java?
  • Will we learn anything about creating applets?
  • Are we going to learn anything about the newest version of Java? If not, can you point out the major differences?

We are learning only enough to work through the data structures and algorithms that are the focus of the course. We've learned most of what we will need. Things we're still going to cover (most of them right now):

  • Interfaces
  • Generics
  • Enums
  • autoboxing
  • Iterators
  • Exceptions
  • Logging
  • Some built-in interfaces and classes, such as List, ArrayList, LinkedList.

We will not cover applets. We are not going to use features of the latest version of Java (6) because they are not necessary for the type of code we'll be writing. However, you should be aware that we will make heavy use of features introduced in Java 5 (generics, enums, autoboxing) because they are extremely useful for the type of code we'll be writing.

I still don't understand the difference between private and public clearly

See the text (p. 10) or http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html

"Any classes can use a public method, but a private method can be used only by the class that defines it."

"Still not clear about 'this'"

See pages 12, 22, and 50 in the text

Within the body of a method "this" refers to the object that invoked the method. Therefore, this.someVariable is a way to refer to the someVariable instance variable of the object a method was invoked on. And this.someMethod(...) is a way to invoke another method on the object.

You can invoke one constructor from another constructor. That's where the this(...) syntax comes in. See p. 22-23 in the text.

Enumeration / enums

See pp. 26-27, and 872-873 in the text.

What are all the Java keywords?

Look on the inside front cover of the textbook.

Why is the Object class ever used?

It isn't used much anymore (in part due to the introduction of generics in Java 5). One place you're still likely to use it is in equals methods that you write.

Structure of a large Java application

"does everything need to be contained with a larger class?"

No. Public classes (and their public methods) can be used from "anywhere".

What does the "new" operator do?

It creates an instance of the specified class, for example:

Customer c = new Customer("Fred", 12345);

creates a new Customer object.

How similiar are Java and C++?

Hard to answer simply. From "far enough away", extremely similar. Once you get closer, there are significant differences in the details. But if you know Java, learning C++ will be pretty easy. If you want to get an overview of the similarities and differences, see http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B. Or do a google search "Comparing Java and C++". You'll see lots of web articles that do just that.

Grading, Assignments, and Homework

Assignment 1

You'll get your grades and feedback today

Labs

  • What happens if you don't get 10 lab check marks?

    You don't pass the class. However, THIS HAS NEVER HAPPENED! So if you are falling behind in the labs, please see me at once!

  • If you don't finish the lab on time, please talk to your TA to see what you can do to receive credit
  • Can you use classes/methods in your homework that we haven't gone over in class?

    It depends. Often you're instructed specifically to use certain classes and methods because that's a big part of the assignment. If that isn't the case, however, typically you can use whatever classes/methods you want. Please ask me if you're not sure.

  • Can test cases be posted earlier?

    We'll always post some right away, but we want to give you time to think through the assignment on your own. Think of the test data and test cases that are posted a day before the assignment is due as a "rescue" opportunity helping you notice any incorrect assumptions you made in your solution before it's too late.

General Requests, Suggestions, and Questions

  • "I wish we would go over more actual writing code"

    We will do so... I'll give you more exercises to write code, and I'll go over more and more code in Eclipse during class

  • Use more diagrams when explaining

    More diagrams will be forthcoming.

  • "Can you post the Java code you go over in class?"

    Yes, I always do. Typically the lecture notes and code are posted by the next day

  • Please post the lab Monday night, not Tuesday at 9 am

    If it's ready by then, we will

  • Will we be concentrating more on data structures or algorithms?

    Both pretty equally

  • How can I get a private tutor?
  • "When will the pace of the class pick up?"

    Now!

  • "Will we catch back up to where we're supposed to be?"

    Probably not, but we will not get any further behind.

  • "If I have a hard time following in class, does the book provide enough info to understand everything necessary for the course?"
    • Probably yes
    • BUT, if you don't follow in class, I'd urge you to come talk to me in office hours, so I can try to help understand why you don't, and enable you to do so.
  • Resources for studying other than the textbook
  • What's the difference between object-oriented and functional programming?

    A good source: The Wikipedia articles on each topic

February 27

Java

If you want to really understand Lists and other "collections" in Java, you should check out [http://java.sun.com/docs/books/tutorial/collections/index.html]. This will also help you understand the use of generic types better

See also: http://java.sun.com/docs/books/tutorial/collections/interfaces/list.html

Comparing the pros and cons of ArrayList and LinkedList

  • We will get to this soon

Since Java already has provided impelementations of the List interface, when would it be useful to develop your own implementation?

  • In most cases, you will not do so. The major reason that we do it in class is so you can understand how it's done.

What's the difference between the length of an array and the size of a List?

  • Conceptually, the difference is that the length of an array tells you how many memory locations have been allocated for that array. Put another way, it tells you the MAXIMUM number of elements the array could hold. The size of a list tells you how many elements actually are in the list.

How can you 'swap' the positions of 2 items in an ArrayList?

  • The old "temp" trick
temp = al.get(i);
al.set(i, al.get(j));
al.set(j, temp);

Note that the same logic would be used for an array

Generic types

  • "The E[] syntax"???
  • See pp. 43-45 and much of chapters 4 and 5 in the text
  • See also http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
  • Why should you declare a variable to be of type List<E> rather than ArrayList<E>?
    • Whenever possible, avoid implementation commitments: for example, if you write a method that takes a List as a parameter, then it will work whether the List is implemented as an ArrayList, LinkedList, or Vector (or other possibilities).
  • Will you learn about input?
    • A little bit
  • How to write data to a file?

Access modifiers: private vs. public

  • See pages 10-12 of the text
  • When should you use private methods?
    • For the same reason as you declare private instance variables: when the method is conceptually "internal" to a class. Earlier, we had only discussed methods that needed to be public because they constituted the external "application programmer interface" for a class, i.e., the functionality that a class wanted to make available to the outside world (other classes). However, as we saw when implementing a List, sometimes it is convenient for a class to define methods that are only called by other methods within the class. For an array-based implementation of a List, for example, the doubleArray() method doesn't need to be externally visible. Even more strongly, since it would "give away" something about the internal implementation of the list, one would not want to make it public.
  • What "kind of thing" is an array?
    • See the extensive index entry on arrays in the textbook. Start with pp. 890-897.
  • The use of type casting in the .equals method
    • See the text, pp. 59-61
    • The parameter of the .equals method is of type Object. However, you really want to check the equality of two objects of a more specific type of data (Customer or Card or Album or...). Typecasting is a way of telling Java, "Look, this object that (so far) you only think of as an Object actually is a Card!".

Enums

  • How do you increment an enum?
    • You don't increment an enum, exactly. However, the values() method will give you an array of all the values in an enum. You then can iterate through the array (typically using a for-each loop).
  • How do you use the parameters of objects in enums?
    • See the getShape and getColor methods in Suit.java (Assignment 2)

Can you rename a class after it's been created?

  • Not while your program is running. Of course, you can always change the name of any object in your code, as long as you change it consistently.

Implementing PI (or other irrational numbers) in Java

How do you refer to objects you create?

  • They must either be stored on a variable (i.e., that you can access by name) or be stored as part of a data structure (e.g., an array or List) that is stored on a variable.

How to use random number generators

  • See the documentation for the class Random() or the method Math.random()

Programming Issues

  • How important is it for your programs to be efficient?
    • For the purposes of the assignment, time efficiency typically is not an issue (unless that's part of the point of the assignment). However:
      • A key tool for a software engineer is understanding efficiency, so he or she can select the most efficient (and, more generally the most appropriate) algorithm for a given problem.
      • Further, "good design" — e.g., following Java conventions, structuring modules that make sense and are of a reasonable size, using interfaces and abstract classes appropriately, etc. etc. — is crucial. We will note this — and grade accordingly — whenever we have the opportunity.
  • Is our array-based implementation of the List interface efficient?
    • Yes. In its essentials, it's quite similar to java's ArrayList implementation.
  • "Why should you every use arrays? Lists seem better".
    • You're right: Lists usually are better. However, there are circumstances when you want to use arrays and reasons for knowing how to use arrays, which I believe I've addressed in class. To summarize:
      • If efficiency really matters and/or the collection of data you're storing is of a predictable and relatively fixed size, use arrays.
      • Second, we take two perspectives on abstract data types in this class: user and implementer. When you use Java's List interfaces and supplied classes (e.g., ArrayList), you're taking the user perspective. However, it also is important for you to know how to define ADTs: so far, we've done that with our array-based implementations of List.
  • Why should we use exceptions? Why not just print out an error message?

Course Issues

Pace of class

  • We're now going about as fast as we should be. If the pace feels too fast for you:
    • Read the book, paying attention to the questions and problems
    • Form a study group
    • Come to office hours

Will there be extra credit?

  • Yes, typically the homework assignments will have extra credit. The quizzes and final may, but there is no set pattern here

Can I post sample problems online to solve?

  • I will try, but I can't guarantee it.
  • Am I available outside my office hours?
    • Send me email, and I will try to find time. However, I cannot make any guarantees that I will be able to do so.
 
The University of Minnesota is an equal opportunity educator and employer.
Structure of Computer Programming II