Fall Semester 2009


Lecture 11/03: Running Java Programs. Getting ready for Homework One. .
One of the books I recommended is:
Java All-In-One Desk Reference For Dummies, 2nd Edition
by Doug Lowe and Barry Burd
The book is available from the on-line resource:
http://www.libraries.iub.edu/scripts/countResources.php?resourceId=59555
Here's some help with what you can learn from this book.

Please compile and run all these programs today.

For each program describe in a few sentences what the program does (and how it accomplishes that).

You can use the book of course.

What I need from you:

  1. an e-mail at the end of the class today with what you managed to do in class today
  2. an e-mail later in the week when you're done running all these programs below
Book One: Java Basics
  1. Welcome to Java

    "In Java even the simplest program is a class..."

  2. Installing and Using Java Tools

    We went here:

    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
    This chapter indicates (as we did in class) that we have:

    a) the option to compile and run from the command line
    b) the option to use an IDE (BlueJ, DrJava, Eclipse...)

  3. Working with TextPad

    One could use TextPad instead of Notepad or pico etc.

  4. Using Eclipse

    Learning Eclipse has a very steep curve. BlueJ or DrJava are easier to start with.

So that's the end of the first book. Useful info, mostly reference.

Book 2: Programming Basics
  1. Java Programming Basics

    Keywords, types, values, operators, expressions, variables, assignment statements etc.

    Object-oriented programming: a class is a container. It contains:

    a) static members
    b) a blueprint
    Classes don't need to be public all the time. If they are the file must bear their name.

    Let's take a look at HelloApp2.java and Greeter.java.

    You compile: javac HelloApp2.java which automatically compiles the other file.

    Then run the class with the main: java HelloApp2

    Now rewrite Greeter.java as follows. Then re-compile and run HelloApp2 again.

    Similar, but quite different, right? (But definitely similar. Except distinctly different, as well).

  2. Working with Variables and Data Types

    Describe how this program works when compiled and run.

    Same question here.

    Example of using a Scanner.

    Getting input from a GUI element.

  3. Working with Numbers and Expressions

    Compile and run this program. What does it do? How (does it work)?

    Same question for this program.

    Can you come up with a similar, useful variant of this program?

    What's the purpose of this program? What is there to learn from it?

    Same questions for this program, and for this one as well.

    This is not the easiest way of formatting, but it's the most powerful.

  4. Making Choices

    Lots of useful things, no full program developed.

  5. Loops

    This already uses material from the previous chapter, but on a higher level.

    Programs to look at, in order: EvenCounter, Duodecaphobia, CountForever.

    New version of Duodecaphobia, followed NumberPhobia, NumberPhobia2, Duodecaphobia2.

    Now start with EvenCounter2, then look at GetABet, GetABet2 and GetABet3.

    Next we look at CountToTen, CountToTenError, CountToTenErrorFixed and ForEvenCounter.

    New group includes: CountDown, LaunchControl, TerseCoder, CountBothWays and ExpressionGanging.

    We end with ForDuodecaphobia, ForDuodecaphobia2, NestedLoop, and the GuessingGame.

  6. Using the Switch Statement

    Here's VoterApp, and its variant VoterApp2.

    Here's CarWashApp with the variant CarWashApp2.

  7. Methods

    Simple example: HelloWorldMethod. Have we seen this before?

    When we say "function" we usually mean return type: example.

    Now here's a rewrite of an earlier program. And another. Can you explain the difference?

    Two more examples: ParameterScope and ChangeParameters. And then: another rewrite.

    Conclusions.

  8. Handling Exceptions

    Read the chapter for all the details (though we need just a basic idea).

    Programs: DivideByZero, GetInteger, GetInteger2 introduce the topic.

    Also: CrazyWithZeros, FileException2 and MyException.

Book 3: Object-Oriented Programming
  1. Understanding Object-Oriented Programming

    A lot of the things we discussed in class are being described here.

  2. Making Your Own Classes: basic template.

    Basic example: what's the benefit? Why does this not compile?

    Why doesn't this compile? How can you fix it?

    Does this change anything? What else is to say about it?

    How does this work? Does it compile? Discuss, fix, etc.

    How about this? How can you demonstrate what it does and how?

    Why is this wrong? How is this different?

  3. Working with Statics

    Have we seen this before? What is the Singleton pattern?

    What is this? How can you illustrate what it does in an example?

  4. Using Subclasses and Inheritance

    What's new in this? Does this show constructor chaining? How about this? (Older review.)

    What's this for? What makes this better? What's the use of this?

  5. Using Abstract Classes and Interfaces

    What does this program illustrate? What's the difference between an abstract class and an interface?

  6. Using the Object and Class Classes

    Skip this chapter. But what do we know about this example?

    Likewise, what does this tell us? Does something like this occur in sorting objects?

  7. Using Inner Classes

    Skip this chapter. Although it would be good to see why inner classes were invented.

    Inner classes can even be anonymous.

  8. Packaging and Documenting Your Classes

    Skip this chapter. Although you could learn how to create a .jar file etc.

Book Four: Strings, Arrays, and Collections
  1. Working with Strings

    What does this program illustrate. Same question for this. And again for this.

  2. Using Arrays

    Describe how this program works.

    A fun but complicated example. What does it show, how does it work?

    There are utilities we need to know about. Explain what and why.

  3. Using the ArrayList Class

    Small fragments of code explaining how to use it.

    Read it, remember our Game/Player/Deck/Card example.

    The Deck was a subclass of ArrayList<Card> in that one.

  4. Using the LinkedList Class You can skip this chapter.

  5. Creating Generic Collection Classes

    You can skip this chapter, too. But final question:

    How do you sort an ArrayList of Circles, Rectangles and Triangles (by area)?
Book Five: Programming Techniques

  1. Programming Threads

    You can skip this chapter.

  2. Network Programming

    You can skip this chapter.

    Here's an old network programming tutorial for A202:

    http://www.cs.indiana.edu/classes/a202-dger/sum99/lectures/lecture14.html
    I have other easy tutorials on various networking approaches in Java. Won't be discussing them here though.

  3. Using Regular Expressions

    I'd say: skip this chapter. But it's worth looking at some of the programs.

  4. Using Recursion

    Skip this chapter. But take a look at this program. Interesting, right?


Updated by Adrian German for A202/A598, A290/A590 and A348/A548