Programmierung 2

Download Report

Transcript Programmierung 2

Exceptions
All Exception classes look like this!
Define your own exception class to distinguish your exceptions from any other kind.
public class AssertionException extends Exception {
AssertionException() { super(); }
AssertionException(String s) { super(s); }
}
The implementation consists of a default constructor, and a constructor that takes a
simple message string as an argument.
Both constructors call super() to ensure that the instance is properly initialized.
© O. Nierstrasz
— P2 —
1
Testing Assertions
It is easy to add an assertion-checker to a class:
private void assert(boolean assertion)
throws AssertionException {
if (!assertion) {
throw new AssertionException("Assertion failed in LinkStack");
}
}
What should an object do if an assertion does not hold?
 Throw an exception.
© O. Nierstrasz
— P2 —
2
Make
Make is a Unix and Windows-based tool for managing
dependencies between files.
You can specify in a “Makefile”:
• Which files various targets depend on
• Rules to generate each target
• Macros used in the dependencies and rules
• Generic rules based on filename suffixes
When files are modified, make will apply the minimum
set of rules to bring the targets up-to-date.
© O. Nierstrasz
— P2 —
3
A Typical Makefile
.SUFFIXES: .class .java
.java.class :
javac $<
# generic rule
CLASS = AbstractBoardGame.class AssertionException.class \
BoardGame.class GameDriver.class Gomoku.class Player.class \
Runner.class TestDriver.class TicTacToe.class
all : TicTacToe.jar Test.jar
TicTacToe.jar : manifest-run $(CLASS)
jar cmf manifest-run $@ $(CLASS)
# default target
# target and dependents
# generation rule
Test.jar : manifest-test $(CLASS)
jar cmf manifest-test $@ $(CLASS)
clean :
rm -f *.class *.jar
© O. Nierstrasz
— P2 —
4
Running make
% make
javac AbstractBoardGame.java
javac GameDriver.java
javac TestDriver.java
jar cmf manifest-run TicTacToe.jar AbstractBoardGame.class
AssertionException.class BoardGame.class GameDriver.class Gomoku.class
Player.class Runner.class TestDriver.class TicTacToe.class
jar cmf manifest-test Test.jar AbstractBoardGame.class AssertionException.class
BoardGame.class GameDriver.class Gomoku.class Player.class Runner.class
TestDriver.class TicTacToe.class
% touch Runner.java
% make Test.jar
javac Runner.java
jar cmf manifest-test Test.jar AbstractBoardGame.class AssertionException.class
BoardGame.class GameDriver.class Gomoku.class Player.class Runner.class
TestDriver.class TicTacToe.class
© O. Nierstrasz
— P2 —
5
RCS command overview
ci
Check in revisions
co
Check out revisions
rcs
Set up or change attributes of RCS files
ident
Extract keyword values from an RCS file
rlog
Display a summary of revisions
merge
Merge changes from two files into a third
rcsdiff
Report differences between revisions
rcsmerge
Merge changes from two RCS files into a third
rcsclean
Remove working files that have not been changed
rcsfreeze
Label the files that make up a configuration
© O. Nierstrasz
— P2 —
6
Using RCS
When file is checked in, an RCS file called file,v is created in the
RCS directory:
mkdir RCS
ci file
# create subdirectory for RCS files
# put file under control of RCS
Working copies must be checked out and checked in.
co -l file
ci file
co file
ci -u file
ci -l file
rcsdiff file
© O. Nierstrasz
# check out (and lock) file for editing
# check in a modified file
# check out a read-only copy
# check in file; leave a read-only copy
# check in file; leave a locked copy
# report changes between versions
— P2 —
7
Additional RCS Features
Keyword substitution
• Various keyword variables are maintained by RCS:
$Author$
$Date$
$Log$
who checked in revision (username)
date and time of check-in
description of revision (prompted during check-in)
Revision numbering:
• Usually each revision is numbered release.level
• Level is automatically incremented upon each check-in
• A new release is created explicitly:
ci -r2.0 file
© O. Nierstrasz
— P2 —
8
Other tools
Be familiar with the programming tools in your
environment!
• memory inspection tools: like ZoneRanger
help to detect other memory management
problems, such as “memory leaks”
• zip and jar: store and compress files and
directories into a single “zip file”
• awk, sed and perl: process text files
according to editing scripts/programs
© O. Nierstrasz
— P2 —
9
What you should know!
 How do make and Ant support system building?
 What functionality does a version control system
support?
 When should you use a debugger?
 What are breakpoints? Where should you set them?
 What should you do after you have fixed a bug?
 When should you use a profiler?
 What is an IDE?
© O. Nierstrasz
— P2 —
10
Can you answer these
questions?
 When should you use Ant rather than make?
 When should you use CVS rather than RCS?
 How often should you checkpoint a version of your
system?
 When should you specify a version of your project
as a new “release”?
 How can you tell when there is a bug in the compiler
(rather than in your program)?
 How can you tell if you have tested every part of
your system?
© O. Nierstrasz
— P2 —
11