text:
The Way of the Java/Debugging

Debugging
There are a few different kinds of errors that can occur in a program, and it is useful to distinguish between them in order to track them down more quickly.

itemize

Compile-time errors are produced by the compiler and usually indicate that there is something wrong with the syntax of the program. Example: omitting the semi-colon at the end of a statement.

Run-time errors are produced by the run-time system if something goes wrong while the program is running. Most run-time errors are Exceptions. Example: an infinite recursion eventually causes a StackOverflowException.

Semantic errors are problems with a program that compiles and runs, but doesn't do the right thing. Example: an expression may not be evaluated in the order you expect, yielding an unexpected result.

itemize

compile-time error run-time error semantic error error!compile-time error!run-time error!semantic exception

The first step in debugging is to figure out which kind of error you are dealing with. Although the following sections are organized by error type, there are some techniques that are applicable in more than one situation.

The compiler is spewing error messages.
error messages compiler

If the compiler reports 100 error messages, that doesn't mean there are 100 errors in your program. When the compiler encounters an error, it gets thrown off track for a while. It tries to recover and pick up again after the first error, but sometimes it fails, and it reports spurious errors.

In general, only the first error message is reliable. I suggest that you only fix one error at a time, and then recompile the program. You may find that one semi-colon ``fixes'' 100 errors. Of course, if you see several legitimate error messages, you might as well fix more than one bug per compilation attempt.

I'm getting a weird compiler message and it won't go away.
First of all, read the error message carefully. It is written in terse jargon, but often there is a kernel of information there that is carefully hidden.

If nothing else, the message will tell you where in the program the problem occurred. Actually, it tells you where the compiler was when it noticed a problem, which is not necessarily where the error is. Use the information the compiler gives you as a guideline, but if you don't see an error where the compiler is pointing, broaden the search.

Generally the error will be prior to the location of the error message, but there are cases where it will be somewhere else entirely. For example, if you get an error message at a method invocation, the actual error may be in the method definition.

If you are building the program incrementally, you should have a good idea about where the error is. It will be in the last line you added.

If you are copying code from a book, start by comparing your code to the book's code very carefully. Check every character. At the same time, remember that the book might be wrong, so if you see something that looks like a syntax error, it might be.

If you don't find the error quickly, take a breath and look more broadly at the entire program. Now is a good time to go through the whole program and make sure it is indented properly. I won't say that good indentation makes it easy to find syntax errors, but bad indentation sure makes it harder.

Now, start examining the code for the common syntax errors. syntax

enumerate

Check that all parentheses and brackets are balanced and properly nested. All method definitions should be nested within a class definition. All program statements should be within a method definition.

Remember that upper case letters are not the same as lower case letters.

Check for semi-colons at the end of statements (and no semi-colons after squiggly-braces).

Make sure that any strings in the code have matching quotation marks (and that you use double-quotes, not single).

For each assignment statement, make sure that the type on the left is the same as the type on the right.

For each method invocation, make sure that the arguments you provide are in the right order, and have right type, and that the object you are invoking the method on is the right type.

If you are invoking a fruitful method, make sure you are doing something with the result. If you are invoking a void method, make sure you are not trying to do something with the result.

If you are invoking an object method, make sure you are invoking it on an object with the right type. If you are invoking a class method from outside the class where it is defined, make sure you specify the class name.

Inside an object method you can refer to the instance variables without specifying an object. If you try that in a class method, you will get a confusing message like, ``Static reference to non-static variable.''

enumerate

If nothing works, move on to the next section...

I can't get my program to compile no matter what I do.
If the compiler says there is an error and you don't see it, that might be because you and the compiler are not looking at the same code. Check your development environment to make sure the program you are editing is the program the compiler is compiling. If you are not sure, try putting an obvious and deliberate syntax error right at the beginning of the program. Now compile again. If the compiler doesn't find the new error, there is probably something wrong with the way you set up the project.

Otherwise, if you have examined the code thoroughly, it is time for desperate measures. You should start over with a program that you can compile and then gradually add your code back.

itemize

Make a copy of the file you are working on. If you are working on Fred.java, make a copy called Fred.java.old.

Delete about half the code from Fred.java. Try compiling again.

itemize

If the program compiles now, then you know the error is in the other half. Bring back about half of the code you deleted and repeat.

If the program still doesn't compile, the error must be in this half. Delete about half of the code and repeat.

itemize

Once you have found and fixed the error, start bringing back the code you deleted, a little bit at a time.

itemize

This process is called ``debugging by bisection.'' As an alternative, you can comment out chunks of code instead of deleting them. For really sticky syntax problems, though, I think deleting is more reliable---you don't have to worry about the syntax of the comments, and by making the program smaller you make it more readable.

bisection!debugging by debugging by bisection

My program hangs.
infinite loop infinite recursion hanging

If a program stops and seems to be doing nothing, we say it is ``hanging.'' Often that means that it is caught in an infinite loop or an infinite recursion.

itemize

If there is a particular loop that you suspect is the problem, add a print statement immediately before the loop that says ``entering the loop'' and another immediately after that says ``exiting the loop.''

Run the program. If you get the first message and not the second, you've got an infinite loop. Go to the section titled ``Infinite loop.''

Most of the time an infinite recursion will cause the program to run for a while and then produce a StackOverflowException. If that happens, go to the section titled ``Infinite recursion.''

If you are not getting a StackOverflowException, but you suspect there is a problem with a recursive method, you can still use the techniques in the infinite recursion section.

If neither of those things works, start testing other loops and other recursive methods.

If none of those things works, then it is possible that you don't understand the flow of execution in your program. Go to the section titled ``Flow of execution.''

itemize

Infinite loop
If you think you have an infinite loop and think you know what loop is causing the problem, add a print statement at the end of the loop that prints the values of the variables in the condition, and the value of the condition.

For example,

verbatim while (x > 0 && y < 0) // do something to x       // do something to y

System.out.println ("x: " + x); System.out.println ("y: " + y); System.out.println ("condition: " + (x > 0 && y < 0)); verbatim

Now when you run the program you will see three lines of output for each time through the loop. The last time through the loop, the condition should be false. If the loops keeps going, you will be able to see the values of x and y and you might figure out why they are not being updated correctly.

Infinite recursion
Most of the time an infinite recursion will cause the program to run for a while and then produce a StackOverflowException.

If you suspect that method is causing an infinite recursion, start by checking to make sure that there is a base case. In other words, there should be some condition that will cause the method to return without making a recursive invocation. If not, then you need to rethink the algorithm and identify a base case.

If there is a base case, but the program doesn't seem to be reaching it, add a print statement at the beginning of the method that prints the parameters. Now when you run the program you will see a few lines of output every time the method is invoked, and you will see the parameters. If the parameters are not moving toward the base case, you will get some ideas about why not.

Flow of execution
flow of execution

If you are not sure how the flow of execution is moving through your program, add print statements to the beginning of each method with a message like ``entering method foo,'' where foo is the name of the method.

Now when you run the program it will print a trace of each method as it is invoked.

It is often useful to print the parameters each method receives when it is invoked. When you run the program, check whether the parameters are reasonable, and check for one of the classic errors---providing parameters in the wrong order.

When I run the program I get an Exception.
Exception

If something goes wrong during run time, the Java run-time system prints a message that includes the name of the exception, the line of the program where the problem occurred, and a stack trace.

The stack trace includes the method that is currently running, and then the method that invoked it, and then the method that invoked that, and so on. In other words, it traces the path of method invocations that got you to where you are.

The first step is to examine the place in the program where the error occurred and see if you can figure out what happened.

description

[NullPointerException:] You tried to access an instance variable or invoke a method on an object that is currently null. You should figure out what variable is null and then figure out how it got to be that way.

Remember that when you declare a variable with an object type, it is initially null, until you assign a value to it. For example, this code causes a NullPointerException:

verbatim Point blank; System.out.println (blank.x); verbatim

[ArrayIndexOutOfBoundsException:] The index you are using to access an array is either negative or greater than array.length-1. If you can find the site where the problem is, add a print statement immediately before it to print the value of the index and the length of the array. Is the array the right size? Is the index the right value?

Now work your way backwards through the program and see where the array and the index come from. Find the nearest assignment statement and see if it is doing the right thing.

If either one is a parameter, go to the place where the method is invoked and see where the values are coming from.

[StackOverFlowException:] See ``Infinite recursion.''

description

I added so many print statements I get inundated with output.
print statement statement!print

One of the problems with using print statements for debugging is that you can end up buried in output. There are two ways to proceed: either simplify the output or simplify the program.

To simplify the output, you can remove or comment out print statements that aren't helping, or combine them, or format the output so it is easier to understand.

To simplify the program, there are several things you can do. First, scale down the problem the program is working on. For example, if you are sorting an array, sort a small array. If the program takes input from the user, give it the simplest input that causes the error.

Second, clean up the program. Remove dead code and reorganize the program to make it as easy to read as possible. For example, if you suspect that the error is in a deeply-nested part of the program, try rewriting that part with simpler structure. If you suspect a large method, try splitting it into smaller methods and test them separately.

Often the process of finding the minimal test case leads you to the bug. For example, if you find that a program works when the array has an even number of elements, but not when it has an odd number, that gives you a clue about what is going on.

Similarly, rewriting a piece of code can help you find subtle bugs. If you make a change that you think doesn't affect the program, and it does, that can tip you off.

My program doesn't work.
In some ways semantic errors are the hardest, because the compiler and the run-time system provide no information about what is wrong. Only you know what the program was supposed to do, and only you know that it isn't doing it.

The first step is to make a connection between the program text and the behavior you are seeing. You need a hypothesis about what the program is actually doing. One of the things that makes this hard is that computers run so fast. You will often wish that you could slow the program down to human speed, but there is no straightforward way to do that, and even if there were, it is not really a good way to debug.

Here are some questions to ask yourself:

itemize

Is there something the program was supposed to do, but doesn't seem to be happening? Find the section of the code that performs that function and make sure it is executing when you think it should. Add a print statement to the beginning of the suspect methods.

Is something happening that shouldn't? Find code in your program that performs that function and see if it is executing when it shouldn't.

Is a section of code producing an effect that is not what you expected? Make sure that you understand the code in question, especially if it involves invocations to built-in Java methods. Read the documentation for the methods you invoke. Try out the methods by invoking the methods directly with simple test cases, and check the results.

itemize

In order to program, you need to have a mental model of how programs work. If your program that doesn't do what you expect, very often the problem is not in the program; it's in your mental model.

model!mental mental model

The best way to correct your mental model is to break the program into its components (usually the classes and methods) and test each component independently. Once you find the discrepancy between your model and reality, you can solve the problem.

Of course, you should be building and testing components as you develop the program. If you encounter a problem, there should be only a small amount of new code that is not known to be correct.

Here are some common semantic errors that you might want to check for:

itemize

If you use the assignment operator, =, instead of the equality operator, == , in the condition of an if, while or for statement, you might get an expression that is syntactically legal, but it doesn't do what you expect.

When you apply the equality operator, ==, to an object, it checks shallow equality. If you meant to check deep equality, you should use the equals method (or define one, for user-defined objects).

Some Java libraries expect user-defined objects to define methods like equals. If you don't define them yourself, you will inherit the default behavior from the parent class, which may not be what you want.

In general, inheritance can cause subtle semantic errors, because you may be executing inherited code without realizing it. Again, make sure you understand the flow of execution in your program.

itemize

I've got a big hairy expression and it doesn't do what I expect.
expression!big and hairy

Writing complex expressions is fine as long as they are readable, but they can be hard to debug. It is often a good idea to break a complex expression into a series of assignments to temporary variables.

For example:

verbatim rect.setLocation (rect.getLocation.translate                    (-rect.getWidth, -rect.getHeight)); verbatim

Can be rewritten as

verbatim int dx = -rect.getWidth; int dy = -rect.getHeight; Point location = rect.getLocation; Point newLocation = location.translate (dx, dy); rect.setLocation (newLocation); verbatim

The explicit version is easier to read, because the variable names provide additional documentation, and easier to debug, because we can check the types of the intermediate variables and display their values.

temporary variable variable!temporary order of evaluation precedence

Another problem that can occur with big expressions is that the order of evaluation may not be what you expect. For example, if you are translating the expression into Java, you might write

verbatim double y = x / 2 * Math.PI; verbatim

That is not correct, because multiplication and division have the same precedence, and are evaluated from left to right. So this expression computes.

A good way to debug expressions is to add parentheses to make the order of evaluation explicit.

verbatim double y = x / (2 * Math.PI); verbatim

Any time you are not sure of the order of evaluation, use parentheses. Not only will the program be correct (in the sense of doing what you intend); it will also be more readable for other people who haven't memorized the rules of precedence.

I've got a method that doesn't return what I expect.
return statement statement!return

If you have a return statement with a complex expression, you don't have a chance to print the return value before returning. Again, you can use a temporary variable. For example, instead of

verbatim public Rectangle intersection (Rectangle a, Rectangle b)     return new Rectangle (        Math.min (a.x, b.x),        Math.min (a.y, b.y),        Math.max (a.x+a.width, b.x+b.width)-Math.min (a.x, b.x)        Math.max (a.y+a.height, b.y+b.height)-Math.min (a.y, b.y) );

verbatim

You could write

verbatim public Rectangle intersection (Rectangle a, Rectangle b)     int x1 = Math.min (a.x, b.x); int y2 = Math.min (a.y, b.y); int x2 = Math.max (a.x+a.width, b.x+b.width); int y2 = Math.max (a.y+a.height, b.y+b.height); Rectangle rect = new Rectangle (x1, y1, x2-x1, y2-y1); return rect;

verbatim

Now you have the opportunity to display any of the intermediate variables before returning.

My print statement isn't doing anything
print statement statement!print

If your use the println method, the output gets displayed immediately, but if you use print (at least in some environments) the output gets stored without being displayed until the next newline character gets output. If the program terminates without producing a newline, you may never see the stored output.

If you suspect that this is happening to you, try changing all the print statements to println.

I'm really, really stuck and I need help
First of all, try getting away from the computer for a few minutes. Computers emit waves that affect the brain, causing the following symptoms:

itemize

Frustration and/or rage.

Superstitious beliefs (``the computer hates me'') and magical thinking (``the program only works when I wear my hat backwards'').

Random walk programming (the attempt to program by writing every possible program and choosing the one that does the right thing).

itemize

If you find yourself suffering from any of these symptoms, get up and go for a walk. When you are calm, think about the program. What is it doing? What are some possible causes of that behavior? When was the last time you had a working program, and what did you do next?

Sometimes it just takes time to find a bug. I often find bugs when I am away from the computer and I let my mind wander. Some of the best places to find bugs are trains, showers, and in bed, just before you fall asleep.

No, I really need help.
It happens. Even the best programmers occasionally get stuck. Sometimes you work on a program so long that you can't see the error. A fresh pair of eyes is just the thing.

Before you bring someone else in, make sure you have exhausted the techniques described here. You program should be as simple as possible, and you should be working on the smallest input that causes the error. You should have print statements in the appropriate places (and the output they produce should be comprehensible). You should understand the problem well enough to describe it concisely.

When you bring someone in to help, be sure to give them the information they need.

itemize

What kind of bug is it? Compile-time, run-time, or semantic?

If the bug occurs at compile-time or run-time, what is the error message, and what part of the program does it indicate?

What was the last thing you did before this error occurred? What were the last lines of code that you wrote, or what is the new test case that fails?

What have you tried so far, and what have you learned?

itemize

When you find the bug, take a second to think about what you could have done to find it faster. Next time you see something similar, you will be able to find the bug more quickly.

Remember, in this class the goal is not to make the program work. The goal is to learn how to make the program work. Program development plan

If you are spending a lot of time debugging, it is probably because you do not have an effective program development plan.

A typical, bad program development plan goes something like this:

enumerate

Write an entire method.

Write several more methods.

Try to compile the program.

Spend an hour finding syntax errors.

Spend an hour finding run time errors.

Spend three hours finding semantic errors.

enumerate

The problem, of course, is the first two steps. If you write more than one method, or even an entire method, before you start the debugging process, you are likely to write more code than you can debug.

If you find yourself in this situation, the only solution is to remove code until you have a working program again, and then gradually build the program back up. Beginning programmers are often unwilling to do this, because their carefully crafted code is precious to them. To debug effectively, you have to be ruthless!

Here is a better program development plan:

enumerate

Start with a working program that does something visible, like printing something.

Add a small number of lines of code at a time, and test the program after every change.

Repeat until the program does what it is supposed to do.

enumerate

After every change, the program should produce some visible effect that demonstrates the new code. This approach to programming can save a lot of time. Because you only add a few lines of code at a time, it is easy to find syntax errors. Also, because each version of the program produces a visible result, you are constantly testing your mental model of how the program works. If your mental model is erroneous, you will be confronted with the conflict (and have a chance to correct it) before you have written a lot of erroneous code.

One problem with this approach is that it is often difficult to figure out a path from the starting place to a complete and correct program.

I will demonstrate by developing a method called isIn that takes a String and a Vector, and that returns a boolean: true if the String appears in the list and false otherwise.

enumerate

The first step is to write the shortest possible method that will compile, run, and do something visible:

verbatim public static boolean isIn (String word, Vector v)    System.out.println ("isIn"); return false;

verbatim

Of course, to test the method we have to invoke it. In main, or somewhere else in a working program, we need to create a simple test case.

We'll start with a case where the String appears in the vector (so we expect the result to be true).

verbatim public static void main (String[] args) Vector v = new Vector ; v.add ("banana"); boolean test = isIn ("banana", v); System.out.println (test);

verbatim

If everything goes according to plan, this code will compile, run, and print the word isIn and the value false. Of course, the answer isn't correct, but at this point we know that the method is getting invoked and returning a value.

In my programming career, I have wasted way too much time debugging a method, only to discover that it was never getting invoked. If I had used this development plan, it never would have happened.

The next step is to check the parameters the method receives.

verbatim public static boolean isIn (String word, Vector v)    System.out.println ("isIn looking for " + word); System.out.println ("in the vector " + v); return false;

verbatim

The first print statement allows us to confirm that isIn is looking for the right word. The second statement prints a list of the elements in the vector.

To make things more interesting, we might add a few more elements to the vector:

verbatim public static void main (String[] args) Vector v = new Vector ; v.add ("apple"); v.add ("banana"); v.add ("grapefruit"); boolean test = isIn ("banana", v); System.out.println (test);

verbatim

Now the output looks like this:

verbatim isIn looking for banana in the vector [apple, banana, grapefruit] verbatim

Printing the parameters might seem silly, since we know what they are supposed to be. The point is to confirm that they are what we think they are.

To traverse the vector, we can take advantage of the code from Section vector. In general, it is a great idea to reuse code fragments rather than writing them from scratch.

verbatim public static boolean isIn (String word, Vector v)    System.out.println ("isIn looking for " + word); System.out.println ("in the vector " + v);

for (int i=0; i<v.size; i++) System.out.println (v.get(i)); return false;

verbatim

Now when we run the program it prints the elements of the vector one at a time. If all goes well, we can confirm that the loop examines all the elements of the vector.

So far we haven't given much thought to what this method is going to do. At this point we probably need to figure out an algorithm. The simplest algorithm is a linear search, which traverses the vector and compares each element to the target word.

Happily, we have already written the code that traverses the vector. As usual, we'll proceed by adding just a few lines at a time:

verbatim public static boolean isIn (String word, Vector v)    System.out.println ("isIn looking for " + word); System.out.println ("in the vector " + v);

for (int i=0; i<v.size; i++) System.out.println (v.get(i)); String s = (String) v.get(i); if (word.equals (s)) System.out.println ("found it"); return false;

verbatim

As always, we use the equals method to compare Strings, not the == operator!

Again, I added a print statement so that when the new code executes it produces a visible effect.

At this point we are pretty close to working code. The next change is to return from the method if we find what we are looking for:

verbatim public static boolean isIn (String word, Vector v)    System.out.println ("isIn looking for " + word); System.out.println ("in the vector " + v);

for (int i=0; i<v.size; i++) System.out.println (v.get(i)); String s = (String) v.get(i); if (word.equals (s)) System.out.println ("found it"); return true; return false;

verbatim

If we find the target word, we return true. If we get all the way through the loop without finding it, then the correct return value is false.

If we run the program at this point, we should get

verbatim isIn looking for banana in the vector [apple, banana, grapefruit] apple banana found it true verbatim

The next step is to make sure that the other test cases work correctly. First, we should confirm that the method returns false if the word in not in the vector.

Then we should check some of the typical troublemakers, like an empty vector (one with size 0) and a vector with a single element. Also, we might try giving the method an empty String.

As always, this kind of testing can help find bugs if there are any, but it can't tell you if the method is correct.

The penultimate step is to remove or comment out the print statements.

verbatim public static boolean isIn (String word, Vector v)    for (int i=0; i<v.size; i++) System.out.println (v.get(i)); String s = (String) v.get(i); if (word.equals (s)) return true; return false;

verbatim

Commenting out the print statements is a good idea if you think you might have to revisit this method later. But if this is the final version of the method, and you are convinced that it is correct, you should remove them.

Removing the comments allows you to see the code most clearly, which can help you spot any remaining problems.

If there is anything about the code that is not obvious, you should add comments to explain it. Resist the temptation to translate the code line by line. For example, no one needs this:

verbatim // if word equals s, return true if (word.equals (s)) return true; verbatim

You should use comments to explain non-obvious code, to warn about conditions that could cause errors, and to document any assumptions that are built into the code. Also, before each method, it is a good idea to write an abstract description of what the method does.

The final step is to examine the code and see if you can convince yourself that it is correct.

At this point we know that the method is syntactically correct, because it compiles.

To check for run time errors, you should find every statement that can cause an error and figure out what conditions cause the error.

The statements in this method that can produce a run time error are:

tabularl l v.size         & if v is null. word.equals (s)  & if word is null. (String) v.get(i) & if v is null or i is out of                         bounds, & or the th element of v is not a String. tabular

Since we get v and word as parameters, there is no way to avoid the first two conditions. The best we can do is check for them.

verbatim public static boolean isIn (String word, Vector v)    if (v == null  word == null) return false; for (int i=0; i<v.size; i++) System.out.println (v.get(i)); String s = (String) v.get(i); if (word.equals (s)) return true; return false;

verbatim

In general, it is a good idea for methods to make sure their parameters are legal.

instanceof operator operator!instanceof

The structure of the for loop ensures that i is always between 0 and v.size-1. But there is no way to ensure that the elements of v are Strings. On the other hand, we can check them as we go along. The instanceof operator checks whether an object belongs to a class.

verbatim Object obj = v.get(i); if (obj instanceof String) String s = (String) v.get(i); verbatim

This code gets an object from the vector and checks whether it is a String. If it is, it performs the typecast and assigns the String to s.

As an exercise, modify isIn so that if it finds an element in the vector that is not a String, it skips to the next element.

If we handle all the problem conditions, we can prove that this method will not cause a run time error.

We haven't proven yet that the method is semantically correct, but by proceeding incrementally, we have avoided many possible errors. For example, we already know that the method is getting parameters correctly and that the loop traverses the entire vector. We also know that it is comparing Strings successfully, and returning true if it finds the target word. Finally, we know that if the loop exists, the target word cannot be in the vector.

Short of a formal proof, that is probably the best we can do.

title: The Way of the Java/Debugging


text:
The Way of the Java/Java IO

System objects
System is the name of the built-in class that contains methods and objects used to get input from the keyboard, print text on the screen, and do file input/output (I/0).

System.out is the name of the object we have used to print text. When you invoke print and println, you invoke them on the object named System.out.

Interestingly, you can print System.out:

verbatim System.out.println (System.out); verbatim

The output is:

verbatim java.io.PrintStream@80cc0e5 verbatim

As usual, when Java prints an object, it prints the type of the object, which is PrintStream, the package in which that type is defined, java.io, and a unique identifier for the object. On my machine the identifier is 80cc0e5, but if you run the same code, you will probably get something different.

There is also an object named System.in that has type BufferedInputStream. System.in makes it possible to get input from the keyboard. Unfortunately, it does not make it easy to get input from the keyboard.

Keyboard input
First, you have to use System.in to create a new InputStreamReader.

verbatim InputStreamReader in = new InputStreamReader ("System.in"); verbatim

Then you use in to create a new BufferedReader:

verbatim BufferedReader keyboard = new BufferedReader (in); verbatim

The point of all this manipulation is that there is a method you can invoke on a BufferedReader, called readLine, that gets input from the keyboard and converts it into a String. For example:

verbatim String s = keyboard.readLine ; System.out.println (s); verbatim

reads a line from the keyboard and prints the result.

There is only one problem. There are things that can go wrong when you invoke readLine, and they might cause an IOException. There is a rule in Java that if a method might cause an exception, it should say so. The syntax looks like this:

verbatim public static void main (String[] args) throws IOException verbatim

This indicates that main might ``throw'' an IOException. You can think of throwing an exception as similar to throwing a tantrum.

File input
Reading input from a file is equally stupid. Here is an example:

verbatim public static void main (String[] args) throws FileNotFoundException, IOException processFile ("/usr/dict/words");

public static void processFile (String filename) throws FileNotFoundException, IOException

FileReader fileReader = new FileReader (filename); BufferedReader in = new BufferedReader (fileReader);

while (true) String s = in.readLine; if (s == null) break; System.out.println (s); verbatim

This program reads each line of the named file (/usr/dict/words) into a String and then prints the line. Again, the declaration throws FileNotFoundException, IOException is required by the compiler. The object types FileReader and BufferedReader are part of the insanely complicated class hierarchy Java uses to do incredibly common, simple things. Other than that, you couldn't possibly care how this program works.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: The Way of the Java/Java IO


text:
The Way of the Java/Table

Arrays, Vectors and Tables
array Vector table

Arrays are a generally useful data structure, but they suffer from two important limitations:

itemize

The size of the array does not depend on the number of items in it. If the array is too big, it wastes space. If it is too small it might cause an error, or we might have to write code to resize it.

Although the array can contain any type of item, the indices of the array have to be integers. We cannot, for example, use a String to specify an element of an array.

itemize

In Section vector we saw how the built-in Vector class solves the first problem. As the user adds items it expands automatically. It is also possible to shrink a Vector so that the capacity is the same as the current size.

But Vectors don't help with the second problem. The indices are still integers.

That's where the Table ADT comes in. The Table is a generalization of the Vector that can use any type as an index. These generalized indices are called keys.

Just as you would use an index to access a value in an array, you use a key to access a value in a Table. So each key is associated with a value, which is why Tables are sometimes called associative arrays.

dictionary associative array key entry index

A common example of a table is a dictionary, which is a table that associates words (the keys) with their definitions (the values). Because of this example Tables are also sometimes called Dictionaries. Also, the association of a particular key with a particular value is called an entry.

The Table ADT
Table ADT ADT!Table

Like the other ADTs we have looked at, Tables are defined by the set of operations they support:

description

[constructor:] Make a new, empty table.

[put:] Create an entry that associates a value with a key.

[get:] For a given key, find the corresponding value.

[containsKey:] Return true if there is an entry in the Table with the given Key.

[keys]: Return a collection that contains all the keys in the Table.

description

The built-in Hashtable
Hashtable class!Hashtable

Java provides an implementation of the Table ADT called Hashtable. It is in the java.util package. Later in the chapter we'll see why it is called Hashtable.

To demonstrate the use of the Hashtable we'll write a short program that traverses a String and counts the number of times each word appears.

We'll create a new class called WordCount that will build the Table and then print its contents. Naturally, each WordCount object contains a Hashtable:

verbatim public class WordCount Hashtable ht;

public WordCount ht = new Hashtable ;

verbatim

The only public methods for WordCount are processLine, which takes a String and adds its words to the Table, and print, which prints the results at the end.

processLine breaks the String into words using a StringTokenizer and passes each word to processWord.

verbatim public void processLine (String s)        StringTokenizer st = new StringTokenizer (s, " ,."); while (st.hasMoreTokens) String word = st.nextToken; processWord (word.toLowerCase ); verbatim

The interesting work is in processWord.

verbatim public void processWord (String word) if (ht.containsKey (word)) Integer i = (Integer) ht.get (word); Integer j = new Integer (i.intValue + 1); ht.put (word, j); else ht.put (word, new Integer (1)); verbatim

If the word is already in the table, we get its counter, increment it, and put the new value. Otherwise, we just put a new entry in the table with the counter set to 1.

Enumeration class class!Enumeration traverse

To print the entries in the table, we need to be able to traverse the keys in the table. Fortunately, the Hashtable implementation provides a method, keys, that returns an Enumeration object we can use. Enumerations are very similar to the Iterators we saw in Section iterator. Both are abstract classes in the java.util package; you should review the documentation of both. Here's how to use keys to print the contents of the Hashtable:

verbatim public void print Enumeration enum = ht.keys ; while (enum.hasMoreElements ) String key = (String) enum.nextElement ; Integer value = (Integer) ht.get (key); System.out.println (" " + key + ", " + value + " "); verbatim

Each of the elements of the Enumeration is an Object, but since we know they are keys, we typecast them to be Strings. When we get the values from the Table, they are also Objects, but we know they are counters, so we typecast them to be Integers.

Finally, to count the words in a string:

verbatim WordCount wc = new WordCount ; wc.processLine ("da doo ron ron ron, da doo ron ron"); wc.print ; verbatim

The output is

verbatim ron, 5 doo, 2 da, 2 verbatim

The elements of the Enumeration are not in any particular order. The only guarantee is that all the keys in the table will appear.

A Vector implementation
implementation!Table table!vector implementation KeyValuePair

An easy way to implement the Table ADT is to use a Vector of entries, where each entry is an object that contains a key and a value. These objects are called key-value pairs.

A class definition for a KeyValuePair might look like this:

verbatim class KeyValuePair Object key, value;

public KeyValuePair (Object key, Object value) this.key = key; this.value = value;

public String toString return " " + key + ", " + value + " ";

verbatim

Then the implementation of Table looks like this:

verbatim public class Table Vector v;

public Table v = new Vector ;

verbatim

To put a new entry in the table, we just add a new KeyValuePair to the Vector:

verbatim public void put (Object key, Object value) KeyValuePair pair = new KeyValuePair (key, value); v.add (pair); verbatim

Then to look up a key in the Table we have to traverse the Vector and find a KeyValuePair with a matching key:

verbatim public Object get (Object key) Iterator iterator = v.iterator ; while (iterator.hasNext ) KeyValuePair pair = (KeyValuePair) iterator.next ; if (key.equals (pair.key)) return pair.value; return null; verbatim

The idiom to traverse a Vector is the one we saw in Section iterator. When we compare keys, we use deep equality (the equals method) rather than shallow equality (the == operator). This allows the key class to specify the definition of equality. In our example, the keys are Strings, so it will use the built-in equals method in the String class.

traverse

For most of the built-in classes, the equals method implements deep equality. For some classes, though, it is not easy to define what that means. For example, see the documentation of equals for Doubles.

equals equality

Because equals is an object method, this implementation of get does not work if key is null. We could handle null as a special case, or we could do what the build-in Hashtable does---simply declare that null is not a legal key.

Speaking of the built-in Hashtable, it's implementation of put is a bit different from ours. If there is already an entry in the table with the given key, put updates it (give it a new value), and returns the old value (or null if there was none. Here is an implementation of their version:

verbatim public Object put (Object key, Object value) Object result = get (key); if (result == null) KeyValuePair pair = new KeyValuePair (key, value); v.add (pair); else update (key, value); return result; verbatim

The update method is not part of the Table ADT, so it is declared private. It traverses the vector until it finds the right KeyValuePair and then it updates the value field. Notice that we don't have to modify the Vector itself, just one of the objects it contains.

verbatim private void update (Object key, Object value) Iterator iterator = v.iterator ; while (iterator.hasNext ) KeyValuePair pair = (KeyValuePair) iterator.next ; if (key.equals (pair.key)) pair.value = value; break; verbatim

The only methods we haven't implemented are containsKey and keys. The containsKey method is almost identical to get except that it returns true or false instead of an object reference or null.

As an exercise, implement keys by building a Vector of keys and returning the elements of the vector. See the documentation of elements in the Vector class for more information.

The List abstract class
abstract class!List List abstract class

The java.util package defines an abstract class called List that specifies the set of operations a class has to implement in order to be considered (very abstractly) a list. This does not mean, of course, that every class that implements List has to be a linked list.

Not surprisingly, the built-in LinkedList class is a member of the List abstract class. Surprisingly, so is Vector.

The methods in the List definition include add, get and iterator. In fact, all the methods from the Vector class that we used to implement Table are defined in the List abstract class.

That means that instead of a Vector, we could have used any List class. In Table.java we can replace Vector with LinkedList, and the program still works!

This kind of type generality can be useful for tuning the performance of a program. You can write the program in terms of an abstract class like List and then test the program with several different implementations to see which yields the best performance.

Hash table implementation
implementation!Table implementation!hash table hash table!implementation table!hash table implementation

The reason that the built-in implementation of the Table ADT is called Hashtable is that it uses a particularly efficient implementation of a Table called a hashtable.

Of course, the whole point of defining an ADT is that it allows us to use an implementation without knowing the details. So it is probably a bad thing that the people who wrote the Java library named this class according to its implementation rather than its ADT, but I suppose of all the bad things they did, this one is pretty small.

Anyhoo, you might be wondering what a hashtable is, and why I say it is particularly efficient. We'll start by analyzing the performance of the List implementation we just did.

Looking at the implementation of put, we see that there are two cases. If the key is not already in the table, then we only have to create a new key-value pair and add it to the List. Both of these are constant-time operations.

In the other case, we have to traverse the List to find the existing key-value pair. That's a linear time operation. For the same reason, get and containsKey are also linear.

Although linear operations are often good enough, we can do better. It turns out that there is a way to implement the Table ADT so that both put and get are constant time operations!

The key is to realize that traversing a list takes time proportional to the length of the list. If we can put an upper bound on the length of the list, then we can put an upper bound on the traverse time, and anything with a fixed upper bound is considered constant time.

analysis!hashtable

But how can we limit the length of the lists without limiting the number of items in the table? By increasing the number of lists. Instead of one long list, we'll keep many short lists.

As long as we know which list to search, we can put a bound on the amount of searching.

Hash Functions
hash function mapping

And that's where hash functions come in. We need some way to look at a key and know, without searching, which list it will be in. We'll assume that the lists are in an array (or Vector) so we can refer to them by index.

The solution is to come up with some mapping---almost any mapping---between the key values and the indices of the lists. For every possible key there has to be a single index, but there might be many keys that map to the same index.

For example, imagine an array of 8 lists and a table made up of keys that are Integers and values that are Strings. It might be tempting to use the intValue of the Integers as indices, since they are the right type, but there are a whole lot of integers that do not fall between 0 and 7, which are the only legal indices.

modulus operator!modulus

The modulus operator provides a simple (in terms of code) and efficient (in terms of run time) way to map all the integers into the range. The expression

verbatim key.intValue verbatim

is guaranteed to produce a value in the range from -7 to 7 (including both). If you take its absolute value (using Math.abs) you will get a legal index.

For other types, we can play similar games. For example, to convert a Character to an integer, we can use the built-in method Character.getNumericValue and for Doubles there is intValue.

shifted sum

For Strings we could get the numeric value of each character and add them up, or instead we might use a shifted sum. To calculate a shifted sum, alternate between adding new values to the accumulator and shifting the accumulator to the left. By ``shift to the left I mean ``multiply by a constant.

To see how this works, take the list of numbers and compute their shifted sum as follows. First, initialize the accumulator to 0. Then,

enumerate

Multiply the accumulator by 10.

Add the next element of the list to the accumulator.

Repeat until the list is finished.

enumerate

As an exercise, write a method that calculates the shifted sum of the numeric values of the characters in a String using a multiplier of 32.

For each type, we can come up with a function that takes values of that type and generates a corresponding integer value. These functions are called hash functions, because they often involve making a hash of the components of the object. The integer value for each object is called its hash code.

There is one other way we might generate a hash code for Java objects. Every Java object provides a method called hashCode that returns an integer that corresponds to that object. For the built-in types, the hashCode method is implemented so that if two objects contain the same data, they will have the same hash code (as in deep equality). The documentation of these methods explains what the hash function is. You should check them out.

deep equality hash function hash code

For user-defined types, it is up to the implementor to provide an appropriate hash function. The default hash function, provided in the Object class, often uses the location of the object to generate a hash code, so its notion of ``sameness'' is shallow equality. Most often when we are searching a hash table for a key, shallow equality is not what we want.

Regardless of how the hash code is generated, the last step is to use modulus and absolute value to map the hash code into the range of legal indices.

Resizing a hash table
resizing hash table!resizing

Let's review. A Hash table consists of an array (or Vector) of Lists, where each List contains a small number of key-value pairs. To add a new entry to a table, we calculate the hash code of the new key and add the entry to the corresponding List.

To look up a key, we hash it again and search the corresponding list. If the lengths of the lists are bounded then the search time is bounded.

So how do we keep the lists short? Well, one goal is to keep them as balanced as possible, so that there are no very long lists at the same time that others are empty. This is not easy to do perfectly---it depends on how well we chose the hash function---but we can usually do a pretty good job.

Even with perfect balance, the average list length grows linearly with the number of entries, and we have to put a stop to that.

The solution is to keep track of the average number of entries per list, which is called the load factor; if the load factor gets too high, we have to resize the table.

load factor rehashing

To resize, we create a new table, usually twice as big as the original, take all the entries out of the old one, hash them again, and put them in the new table. Usually we can get away with using the same hash function; we just use a different value for the modulus operator.

Performance of resizing
analysis!Hashtable

How long does it take to resize the table? Clearly it is linear with the number of entries. That means that most of the time put takes constant time, but every once in a while ---when we resize---it takes linear time.

At first that sounds bad. Doesn't that undermine my claim that we can perform put in constant time? Well, frankly, yes. But with a little wheedling, I can fix it.

Since some put operations take longer than others, let's figure out the average time for a put operation. The average is going to be, the constant time for a simple put, plus an additional term of, the percentage of the time I have to resize, times , the cost of resizing.

equation t(n) = c + p kn equation

I don't know what and  are, but we can figure out what is. Imagine that we have just resized the hash table by doubling its size. If there are entries, then we can add an addition  entries before we have to resize again. So the percentage of the time we have to resize is.

Plugging into the equation, we get

equation t(n) = c + 1/n kn = c + k equation

In other words, is constant time!

Glossary
table entry key value dictionary associative array hash table hash function hash code shifted sum load factor

description

[table:] An ADT that defines operations on a collection of entries.

[entry:] An element in a table that contains a key-value pair.

[key:] An index, of any type, used to look up values in a table.

[value:] An element, of any type, stored in a table.

[dictionary:] Another name for a table.

[associative array:] Another name for a dictionary.

[hash table:] A particularly efficient implementation of a table.

[hash function:] A function that maps values of a certain type onto integers.

[hash code:] The integer value that corresponds to a given value.

[shifted sum:] A simple hash function often used for compounds objects like Strings.

[load factor:] The number of entries in a hashtable divided by the number of lists in the hashtable; i.e. the average number of entries per list.

description

title: The Way of the Java/Table


text:
The Way of the Java/Wrapper classes

Wrapper classes
For every primitive type in Java, there is a built-in object type called a wrapper class. For example, the wrapper class for int is called Integer; for double it is called Double.

Wrapper classes are useful for several reasons:

Each wrapper class contains special values (like the minimum and maximum values for the type) and methods that are useful for converting between types.

You can instantiate wrapper classes and create objects that contain primitive values. In other words, you can wrap a primitive value up in an object, which is useful if you want to invoke a method that requires an object type.

Creating wrapper objects
The most straightforward way to create a wrapper object is to use its constructor:

verbatim verbatim

Technically String is not a wrapper class, because there is no corresponding primitive type, but the syntax for creating a String object is the same:

verbatim verbatim

On the other hand, no one ever uses the constructor for String objects, because you can get the same effect with a simple String value:

verbatim verbatim

In my development environment, the Boolean wrapper class has not been implemented correctly. There is supposed to be a constructor that takes a primitive boolean as an argument, but the following code

verbatim verbatim

generates an error.

Creating more wrapper objects
Some of the wrapper classes have a second constructor that takes a String as an argument and tries to convert to the appropriate type. For example:

verbatim verbatim

There is supposed to be a Boolean constructor that takes a String argument, but it has not been implemented in my development environment. There is no such constructor for Characters.

The type conversion process is not very robust. For example, if the Strings are not in the right format, they will cause a NumberFormatException. Any non-numeric character in the String, including a space, will cause the conversion to fail.

verbatim verbatim

It is usually a good idea to check the format of the String before you try to convert it.

Creating even more wrapper objects
Annoyingly, there is yet another way to create wrapper objects, using class methods in the wrapper classes.

verbatim verbatim

These methods use the same conversion methods as the constructors (parseInt and parseDouble), so they are no more robust.

When there are two ways to do the same thing, it is probably best to choose one and stick to it consistently. In this case, I think using the constructors is much better than using valueOf, because it makes it much clearer that you are creating new wrapper objects. The name valueOf is poorly chosen; given the name, it is not at all clear what it does.

Getting the values out
Java knows how to print wrapper objects, so the easiest way to extract a value is just to print the object:

verbatim verbatim

Alternatively, you can use the toString method to convert the contents of the wrapper object to a String

verbatim verbatim

Finally, if you just want to extract the primitive value from the object, there is an object method in each wrapper class that does the job:

verbatim verbatim

There are also methods for converting wrapper classes into different primitive types.

Useful methods in the wrapper classes
As I mentioned, the wrapper classes contain useful methods that pertain to each type. For example, Integer contains methods for interpreting and printing integers in different bases. If you have a String that contains a number in base 6, you can convert to base 10 using parseInt.

verbatim verbatim

Since parseInt is a class method, you invoke it by naming the class and the method in dot notation.

Base 6 might not be all that useful, but hexadecimal (base 16) and octal (base 8) are common for computer science related things.

In the Character class, there are lots of methods for converting characters to upper and lower case, and for checking whether a character is a number, letter, or symbol.

title: The Way of the Java/Wrapper classes


text:
Wikijunior:Solar System/Uranus/Miranda

Miranda is a moon of the planet Uranus. It is the smallest and innermost of Uranus's five major moons. It is sometimes called "Uranus V".

The first pictures of this moon from a spacecraft were taken on January 24, 1986, when Voyager 2 passed by the planet. Only the southern half of Miranda has been viewed in detail, and the rest of the moon has yet to be seen.

How big is Miranda?
This moon has a diameter of only 472 km. This is slightly smaller than the asteroid Vesta, which is the second biggest object in the asteroid belt. Miranda would easily fit within the borders of the state of Arizona.

What is its surface like?
The surface of Miranda seems to be made almost entirely of ice. There are huge, deep canyons, some reaching over 19 km (12 mi) deep, and a lot of rugged ground, with some large, strange parallel grooves in parts the surface. There are also some craters on Miranda. This moon does not have any atmosphere and it is bitterly cold.

How long is a day on Miranda?
This moon takes the same time to orbit Uranus as it does to rotate around its axis. This means that it has become tidally locked. The gravity from Uranus has caused it to gradually slow its rotation until now it always keeps the same face toward the planet. The length of one orbit, and the length of a day on Miranda, is 1.41 days, or about 1 day and just under 10 hours.

What is it made of?
This moon is made of frozen stuff such as water ice, and it has a core of rock on the interior.

How much would Miranda's gravity pull on me?
Newtons describe how hard gravity is pulling you down. On Earth, if you weigh 51 kilograms or 112 pounds, your weight is 500 newtons. We only use newtons for some special purposes, when we are really interested in how hard we push down on something because gravity is pulling us.

Your weight in newtons would be less on Miranda, only about 1/124 of what it is on Earth. To find your weight in newtons as you stand on Miranda, just take your weight on Earth, and if that weight is in kilograms, multiply it by 0.079. Iff that weight is in pounds, divide it by 28 to get newtons. But then you'll have to add in the weight of your spacesuit as well, because that is pressing down on the surface just like you are.

Who is it named after?
The English bard William Shakespeare wrote a play called "The Tempest". In this play there is a sorcerer named Prospero who has a daughter called Miranda. Both the sorcerer and his daughter were stranded on an island for twelve years in the Adriatic sea.

The name of Shakespeare's character Miranda comes from the Latin root "mira", which means "to wonder". In the play the daughter is often called "a wonder".

How was it discovered?
This moon was discovered by the astronomer Gerard Kuiper, who was born and educated in Holland, but later came to the United States. He found this moon on February 16, 1948. He also found Neptune's moon Neried just over a year later.

Wikijunior Sonnensystem/ Uranus/ Miranda

title: Wikijunior:Solar System/Uranus/Miranda


text: Origami/Paper Fundamentals

title: Origami/Paper Fundamentals


text:
Statistics/Different Types of Data

Data are assignments of values onto observations of events and objects. They can be classified by their coding properties and the characteristics of their domains and their ranges.

Identifying data type
When a given data set is numerical in nature, it is necessary to carefully distinguish the actual nature of the variable being quantified. Statistical tests are generally specific for the kind of data being handled.

Data on a nominal (or categorical) scale
Identifying the true nature of numerals applied to attributes that are not "measures" is usually straightforward and apparent. Examples in everyday use include road, car, house, book and telephone numbers. A simple test would be to ask if re-assigning the numbers among the set would alter the nature of the collection. If the plates on a car are changed, for example, it still remains the same car in reality.

Data on an Ordinal Scale
An ordinal scale is a scale with ranks. Those ranks only have sense in that they are ordered, that is what makes it ordinal scale. The distance [rank n] minus [rank n-1] is not guaranteed to be equal to [rank n-1] minus [rank n-2], but [rank n] will be greater than [rank n-1] in the same way [rank n-1] is greater than [rank n-2] for all n where [rank n], [rank n-1], and [rank n-2] exist. Ranks of an ordinal scale may be represented by a system with numbers or names and an agreed order.

We can illustrate this with a common example: the Likert scale. Consider five possible responses to a question, perhaps Our president is a great man, with answers on this scale

Here the answers are a ranked scale reflected in the choice of numeric code. There is however no sense in which the distance between Strongly agree and Agree is the same as between Strongly disagree and Disagree.

Numerical ranked data should be distinguished from measurement data.

Measurement data
Numerical measurements exist in two forms, Meristic and continuous, and may present themselves in three kinds of scale: interval, ratio and circular.

Meristic or discrete variables are generally counts and can take on only discrete values. Normally they are represented by natural numbers. The number of plants found in a botanist's quadrant would be an example. (Note that if the edge of the quadrant falls partially over one or more plants, the investigator may choose to include these as halves, but the data will still be meristic as doubling the total will remove any fraction).

Continuous variables are those whose measurement precision is limited only by the investigator and his equipment. The length of a leaf measured by a botanist with a ruler will be less precise than the same measurement taken by micrometer. (Notionally, at least, the leaf could be measured even more precisely using a microscope with a graticule.)

Interval Scale Variables measured on an interval scale have values in which differences are uniform and meaningful but ratios will not be so. An oft quoted example is that of the Celsius scale of temperature. A difference between 5° and 10° is equivalent to a difference between 10° and 15°, but the ratio between 15° and 5° does not imply that the former is three times as warm as the latter.

Ratio Scale Variables on a ratio scale have a meaningful zero point. In keeping with the above example one might cite the Kelvin temperature scale. Because there is an absolute zero, it is true to say that 400°K is twice as warm as 200°K, though one should do so with tongue in cheek. A better day-to-day example would be to say that a 180 kg Sumo wrestler is three times heavier than his 60 kg wife.

Circular Scale When one measures annual dates, clock times and a few other forms of data, a circular scale is in use. It can happen that neither differences nor ratios of such variables are sensible derivatives, and special methods have to be employed for such data.

title: Statistics/Different Types of Data


text:
User:Neonumbers

I don't contribute to this project as such, I just use it occasionally and use this account to make minor edits. I'm not familiar with any conventions that might differ here from Wikipedia, so if I make a mistake, just drop a word. Thanks.

I contribute mostly to the English Wikipedia.

See my user page at w:User:Neonumbers

title: User:Neonumbers


text:
Talk:Swedish/The sje and tje sounds

referensen till "ich" är inte perfekt. Den funkar olika bra beroende på vilken tysk dialekt som menas - i vissa sägs ch nästan som i bach!
 * När man skriver "German ich-Laut" betyder det lämpligen "ich" så som det förekommer i rikshögtyska, där det är ett annat och ljusare ljud än ach-Laut i bach. --Salleman 09:59, 20 August 2005 (UTC)

title: Talk:Swedish/The sje and tje sounds


text:
Biotechnology

This book is meant for students and professionals who are looking for reference on different areas in this field, to bring a new student or new hire up to speed.

A scientific revolution less than 20 years old that has already changing the foods we eat and react to the environment.

''' To bring out the best in nature. '''

What is Biotech?
Farmers and bakers were the pioneers of the biotech. Remember Grandma's freshly baked bread? How Grandpa kept the seeds of those really big pepper or tomatoes? Your grandparents were practicing biotechnology. Maybe you still do the same, that is the basis of biotechnology.

Defining "Biotechnology"

The application of the principles of engineering and the use of technology in the field of life sciences-bioengineering.

 * 1) The use of living things to make products.
 * 2) The study, application and control of a biological processes.
 * 3) The application of any of the above or derivatives thereof, to make or modify products or processes for specifically defined uses.

The use of microorganisms (such as bacteria or yeasts) or biological substances (such as enzymes) to perform specific industrial or manufacturing processes. Applications include the production of certain drugs, synthetic hormones, and bulk foodstuffs, as well as the bioconversion of organic waste and the cleanup of oil spills.

Cloning, genetic manipulation, cell fusion, and mutation.

Modifying the genetic material of organisms directly and with increasing precision, has enabled the transfer of genes between extremely diverse organisms, in combinations unlikely to occur by non-technological means, allowing speedier and more specific results.

Essentially, doing "more and faster" building on what we have known and done for centuries and going beyond.

Life- Defined as:
 * Movement
 * (Though some living organisms many organisms remain non-motile or some may show negligible movement from their position throughout their lives even when they are alive)

 * Growth
 * (increase in size in terms of mass, volume, and/or number of cells in case of multicellular organisms till peak growth is attained.)

 * Eating
 * (though autotrophic organisms can produce their own food e.g. most plants (except carnivorous plants) are able to make their own food via photosynthesis in chloroplasts in presence of light)

 * Reproduction
 * Response to stimuli
 * Presence of metabolism
 * (ability to carry out metabolic biochemical reactions essential for survival e.g., glycolysis)

 * Presence of genetic material
 * (e.g. DNA in eukaryotes)

 * Interaction with abiotic and biotic components of environment
 * Homeostasis

Products
Products

Traditional

 * 1) Beer / Wine          (See Fermentation)
 * 2) Yeast
 * 3) Ethanol
 * 4) Cheese
 * 5) Idli

Protein Therapeutics

 * 1) Herceptin
 * 2) Neupogen
 * 3) Insulin - 1982 U.S. pharmaceutical manufacturer Eli Lilly the first to market genetically-engineered human insulin
 * 4) Somatostatin
 * 5) Growth hormone

Agriculture

 * 1) Bacillus thuringiensis (Bt) Crops Bt crops
 * 2) Herbicide tolerance
 * 3) Disease resistance
 * 4) Pest resistance

Industrial / Environmental

 * 1) Hazardous Waste
 * 2) Wastewater Treatment
 * 3) Bioremediation

Other

 * 1) Plastics
 * 2) Biopulping
 * 3) GMO (Genetically modified organism)

21 CFR 58
Good laboratory practice for nonclinical laboratory studies:

http://www.access.gpo.gov/nara/cfr/waisidx_02/21cfr58_02.html

21 CFR 11
Title 21 Code of Federal Regulations (21 CFR Part 11) Electronic Records; Electronic Signatures

http://www.fda.gov/ora/compliance_ref/part11/

21 Code of Federal Regulations Parts 210 and 211
Part 210 - current good manufacturing practice in manufacturing, processing, packing, or holding of drugs; general

Part 211 - current good manufacturing practice for finished pharmaceuticals

http://www.fda.gov/cder/dmpq/cgmpregs.htm

SOPs
SOP's (Standard Operating Procedures)

 * 1) Approved by management
 * 2) You don't put data in a SOP
 * 3) Written at 6th grade level
 * 4) Clear, current, complete
 * 5) Simple, Concise, Accurate
 * 6) Archived Where?

Notebooks
Notebook
 * 1) If it is not written, it is not done.
 * 2) pages signed
 * 3) Can you read it?
 * 4) Black or blue ink
 * 5) pages numbered
 * 6) Leave some pages in the front for TOC
 * 7) Required by GLP / GMP regs
 * 8) Signed by witness
 * 9) Traceability

Documentation for Integrity and traceability
 * 1) What you did
 * 2) Why you did it
 * 3) Results
 * 4) Reference earlier work?
 * 5) Also for Quality

Keys to Successful Biotech products
Keys to Successful Biotech products

 * 1) Availability of labor force
 * 2) Skilled labor force
 * 3) Power
 * 4) Good Universities nearby:
 * 5) For retraining
 * 6) For new ideas

 * 1) National and international labor pool
 * 2) Raw materials
 * 3) Marketing
 * 4) Clear trend and need

 * 1)  FDA approval

Record Keeping
 * 1) Inventory control logs
 * 2) Process Steps
 * SOP
 * 1) et cetera
 * 2) If it's not written it's not done
 * 3) Love it
 * 4) Live it
 * 5) Clinical trials
 * 6) GMP apply to:
 * 7) Manufacture
 * 8) Processing
 * 9) Packing
 * 10) Storage
 * 11) Validation of each process
 * 12) PAT (Process Analytical Technology)
 * 13) Quality should be built in and by design

 * 1) Environmental Concerns
 * 2) Use of energy
 * 3) Use of water
 * 4) Environmental Laws
 * 5) Waste streams

 * 1)  Do we have the technology?

Requirements
 * 1) Safety
 * 2) Identity and Strength
 * 3) Quality and purity
 * 4) The plant:
 * 5) Can we Measure
 * pH
 * 1) Aeration
 * 2) Baffiling
 * 3) impellers
 * 4) medium
 * 5) Seed train
 * 6) Are we Better than our competition?
 * 7) why?

Processes
Development / Upstream / Downstream processes

Development

 * 1) Need / market analysis
 * 2) Select a solution
 * 3) Process Development
 * 4) Understand the growth requirements
 * 5) Calculate yields of biomass
 * 6) Run small scale test

 * Fermentation

Chemical

Yeast
 * 1) High biomass yields
 * 2) Will secrete the protein

 * Picha Pastoris
 * Fungi
 * Mammalian Cells

Upstream
Fermentation?
 * 1) Media prep

Find best conditions
Expensive Labor intensive Open Ended Time Consuming

Constraints
Raw Materials Batch to Batch variations Transportation costs Storage

 * 1) Seed Prep

Find cell line
Composition Growth kinetics Yield Seed Bank Original Stored Cells Used in actual fermentation
 * Master Seed Bank MSB
 * Working Seed Bank WSB

Downstream

 * 1) Slurry Handling
 * 2) Excreted product
 * 3) Contamination
 * 4) Product purification
 * 5) Separation / purification / sterilization

Plugs up easily Usually not used for bulk filtration
 * How?
 * Plate and frame
 * Bulk filtration
 * Spiral wound

 * 1) Storage

Technician: Skills Needed
The Biotech Technician must be a person possessing skills with ability to solve problems and meet the customer in such a way that the translations of what is possible can be made clear. They have to maintain a notebook, one that can be read by someone else. Present results in a clear manner, and work with others to meet objectives.

Laboratory Skills
A technician must use the tools of the trade not unlike any other trade, we are farmers but our herd is tiny tiny wildlife. To take care of our herd we must measure certain aspects of their environment.

Solute,solvent, and solution

 * Solute = Dry Material
 * Solvent = What you mix with
 * Solution = Solute + Solvent

Measurement
most accurate more expensive piece of equipment Store in buffer Check for clogging very coarse measurement of pH
 * 1) Probe and meter
 * 1) Litmus paper
 * 1) Field kit

The letters pH stand for "power of hydrogen"

The most abundant element in the universe is hydrogen, which makes up about 3/4 of all matter!

Stronger acids give up more protons, H+ (hydrogen ions); stronger bases give up more OH- (hydroxide ions). Neutral substances have an even balance of H+ and OH-, E.g. Pure (distilled) water.

>7 base -- 7 Neutral  -- <7 Acid

Depending on your definition, an acid is a hydrogen ion or proton donator and a base is a hydrogen ion acceptor, hydroxide ion donator, or electron acceptor.

Acids produce H+ ions in aqueous solutions, whereas bases produce OH- ions in aqueous solutions

pH electrode compared to a battery

Store in buffer not H2O

Mercury tube Good for metals and biologicals and up to 80 degrees C

The common Silver-Silver Chloride reference electrode used with most combination pH electrodes has a Potassium Chloride salt-bridge which is saturated with Silver Chloride.

Works well in most samples, but not in biological samples containing proteins or related materials

Calibration
Span error Difference b/w perfect and actual pH Electrode at 25C produces 59.12 mV/pH unit

Offset error signal @ pH 7.0 @ 25 C is 0 mV
 * Difference from Perfect reading from actual reading is the offset error

Three point calibration
 * pH's 4, 7 and 10

Calibrate W/I range you going to use

Buffer and reagent Prep
Chemist use buffers to moderate the pH of a reaction. Buffers stabilize a solution at a specific pH value. Resist pH change when small amounts of acid or alkali are added.

KPO4

KPO4 buffer is highly recommended for most P450 assays (microsomal or recombinant enzymes) with the exception of CYP 2C9 and 2A6 where a Tris buffer system is more appropriate. TRIS buffer

TRIS buffers are used by biochemists to control pH in the physiological range (about 7 to 8 pH) because phosphates cause undesirable side reactions with the biological substances in their test samples.

"Good" buffers

These buffers were well received by the research community because "Good" buffers are nontoxic, easy to purify and their pKa is typically between 6.0 and 8.0, the range at which most biological reactions occur.

The "Good" buffers also feature minimal penetration of membranes, minimal absorbance in the 240-700 nm range and minimal effects due to salt, concentration or temperature.

pKa = dissociation constant

In chemistry and biochemistry, a dissociation constant or an ionization constant is a specific type of equilibrium constant used for dissociation (ionization) reactions. Dissociation in chemistry and biochemistry is a general process in which complexes, molecules, or salts separate or split into smaller molecules, ions, or radicals, usually in a reversible manner. Dissociation is the opposite of association and recombination.

Problems

 * 1) Ionic Strength
 * 2) Temperature
 * 3) Counter ion

What is Agar?
A gelatinous material derived from certain marine algae.

 * 1) Growth Media
 * 2) Carbon Sources
 * 3) Carbohydrates
 * 4) Proteins
 * 5) Nitrogen Sources

Two types:
 * Simple
 * Complex

Components required for preparing a minimal agar
 * 1) minerals
 * H2O
 * 1) vitamins
 * 2) Precursors
 * 3) Compounds that may lead to your product - inducers
 * 4) Compounds added to induce gene expression

LB (Luria-Bertani) Media

Blood
contains blood cells from an animal (e.g. a sheep). Most bacteria will grow on this medium

Chocolate
This contains lysed blood cells, and is used for growing fastidious (fussy) respiratory bacteria.

Mannitol Salt
Purpose Mannitol salt agar is both a selective and differential growth medium.

Brilliant Green
Inhibits Gram+ MacConkey

This type of agar is used since it is one of the most forgiving media available - it is hard to contaminate, and E. coli usually grow up as red colonies.

(Almost all spore forming bacteria are Gram-positive, but these cannot grow on MacConkey agar because of the detergent in it (bile salts), and very few Gram-negative bacteria can tolerate either the initial dryness of the plates, or the boiling temperatures needed to make the MacConkey agar. Also, while fungal spores can tolerate the dryness, they cannot tolerate the boiling.)

This is an agar upon which only Gram-negative bacteria can grow

Starch

An agar plate is a sterile Petri dish that contains agar plus nutrients, and is used to culture bacteria or fungi.

Neomycin agar
contains the antibiotic neomycin.

Sabouraud agar
Used for fungi. It contains gentamicin and has a low pH that will kill most bacteria.

LB
+ Complex + pH 7.2

UV/VIS Spectroscopy
Common UV/ VIS spectrophotometers Following is a list of commonly used spectrophotometers: GeneSys 20    HP8452A Diode Array Spectronic 20

Ultraviolet-Visible spectroscopy or Ultraviolet-Visible spectrophotometry (UV/ VIS) involves the spectroscopy of photons (spectrophotometry). It uses light in the visible and adjacent near ultraviolet (UV) and near infrared (NIR) ranges. In this region of energy space molecules undergo electronic transitions.

A=elc
 * 1) A=Absorbance
 * 2) e=Molar Absorbtivity
 * 3) l=Path length (cm)
 * 4) c=Concentration (M)

Laboratory calculations

 * 1) + - Prep of Sterile solid and Liquid media

Sterilization Methods
There are different types of Sterilization techniques. Some of them are 1. Physical sterilization 2. Chemical sterilization

Under Physical sterilization a) Heat b) Filtration c) Ionising Radiation etc., In Heat sterilization i. Temperature above 100 C ii. Temperature at 100 C iii. Temperature below 100 C.

i. Temperature above 100 C There are two methods involved in it a. Moisture heat sterilization b. Dry heat sterilization

Pipetting

 * 1) Growing concerns regarding repetitive strain injuries (RSIs)
 * 2) Adopting good pipetting techniques is critical for the accuracy of your analysis and your health.
 * 3) Contamination Prevention
 * 4) Care of

Measuring / Mixing
Using a balance Calibration / documentation

UV/VIS spectroscopy
* http://www.scienceofspectroscopy.info/ * Use correct Reagent * Use correct Wavelength

Gel Electrophoresis
Gel electrophoresis is a method that separates macromolecules-either nucleic acids or proteins-on the basis of size, electric charge, and other physical properties. Researchers can typically control the charge at the top and bottom of the gel. DNA is negatively charged so to run it through the gel, the top would have to be set to - and the bottom to +.

materials

 * Two basic types: agarose and polyacrylamide

agarose

Agarose is a natural colloid extracted from sea weed It is very fragile and easily destroyed by handling Agarose gels have very large "pore" size and are used primarily to separate very large molecules with a molecular mass greater than 200 kDaltons Agarose gels can be processed faster than polyacrylamide gels, but their resolution is inferior.

Agarose is a linear polysaccharide (average molecular mas about 12,000) made up of the basic repeat unit agarobiose, which comprises alternating units of galactose and 3,6-anhydrogalactose. Agarose is usually used at concentrations between 1% and 3%. Agarose is a chain of sugar molecules, and is extracted from seaweed.

Perhaps you have seen the terms TBE or TAE.

These are names of two commonly used buffers in electrophoresis.

The "T" stands for Tris, a chemical which helps maintain a consistent pH of the solution.

The "E" stands for EDTA, which itself is another anacronym. EDTA chelates (gobbles up) divalent cations like magnesium. This is important because most nucleases require divalent cations for activity, and you certainly wouldn't want any stray nucleases degrading your sample while it's running through the gel, would you?

Finally, the "B" or "A" stand for Boric acid or Acetic acid, which provide the proper ion concentration for the buffer.

polyacrylamide

The polyacrylamide gel electrophoresis (PAGE) technique was introduced by Raymond and Weintraub (1959).

Polyacrylamide is the same material that is used for skin electrodes and in soft contact lenses.

provide a wide variety of electrophoretic conditions:

By controlling the percentage (from 3% to 30%), precise pore sizes can be obtained, usually from 5 to 2,000 kdal. Polyacrylamide gels can be cast in a single percentage or with varying gradients Polyacrylamide gels offer greater flexibility and more sharply defined banding than agarose gels.

Spectrophotometer

 * Absorbance
 * Transmission
 * Colormetric
 * 400 to 700 nm
 * Pertaining to measurement of concentration of a solution based on its absorption or transmission of light, or on the intensity of color in a liquid.

Centrifugation

 * Speed
 * Distance from Center of rotation
 * RCF= relative Centrifugal Force

factors
o Higher RCF the faster the sedimentation o viscosity o size of particle o difference b/w particle and medium

Application
o Separation o + - Safety + Never exceed Max speed of rotor + Never use a cracked tube or bottle o + - Maintenance + Clean with mild detergent + air dry rotor + Check rotor O-rings

Types
+ - low speed + rpm<10k + g<8000

+ - High Speed + rpm<30k + g<100k + refrigeration used

+ - ultracentrifuge + rpm<120k + g<700k + refrigeration used + vacuum

+ - microfuge + tabletop + rpm<15k + g<21k + 1-2ml volumes

parts
+ + - rotors # horizontal # + - fixed angle * b/w 15 & 40 degrees # vertical

tubes / bottles
# glass # stainless steel # polycarbonate # + - Teflon * expensive # + - polypropylene * What most people use

Aseptic techniques
Aseptic techniques is defined as a method that keeps undesirable microbes from contaminating a pure culture.

Only a single species of an organism is what one should work with in a microorganismal laboratory all materials that will be used for transfer, growth, and experimentation of the microbe must be sterilized media and glassware most often is sterilized by using an autoclave.

Lab bench needs to be clean with a disinfectant before and after working.

Hands should be washed upon entering and leaving the laboratory.

Inoculation tools and the tops of tubes need to be sterilized over an flame

Inoculating Loop - held like a pencil

Computer Skills

 * 1) Popular OS'es and file management
 * 2) Excel
 * 3) PowerPoint
 * 4) Word
 * 5) Linux

People Skills
Energy and interest

WHAT CAN I DO FOR YOU?

How you are qualified

Brainpower:
In today's world, it's "be sharp or die."

Because we are status quo creatures. We like things just the way they are, thank you. Change unsettles us. If it works (or appears to work, actually), don't fix it.

Basic Microbiology
Basic Microbiology

Cell Identification
Enterotube

cell growth
Log Phase

Cryopreservation
http://nalgenelab.nalgenunc.com/techdata/technical/manual.asp

 * The protection of biological molecules during freezing and freeze-drying( lyophilization) is a subject of considerable practical importance, particularly in the pharmaceutical industry.

wide variety of compounds as cryoprotectants
 * Saccharides are often used in this capacity
 * They have been found to protect proteins during freezing and drying stresses.
 * They have also been shown to prevent damage to cells during freezing and drying.

Basic Molecular Biology
Basic Molecular Biology

Genetic engineering
"Geneticist and science writer Steve Jones argues that humanity does not, and will never have the technology that proponents of transhumanism seek. He once joked that the letters of the genetic code, A, C, G and T should be replaced with the letters H, Y, P and E. Jones claims that technologies like genetic engineering will never be as powerful as is popularly believed."

-http://en.wikipedia.org/wiki/Transhumanism

E. Coli The workhorse of molecular biology
Theodor Escherich isolates a microbe from the colon that is later given the name Escherichia coli in his honor.

 * 1) Ecoli
 * 2) HB101
 * 3) Fairly safe
 * 4) Needs
 * 5) 37 C
 * 6) Food
 * 7) H2O
 * 8) Vitamins

Escherichia coli, a subgroup of fecal coliform bacteria that is present in the intestinal tracts and feces of warm-blooded animals.

It is used as an indicator of the potential presence of pathogens. There are many different strains of E. coli that are classified into more than 170 serogroups.

Although most strains of E. coli are harmless and live in the intestines of healthy humans and animals, the E. coli O157:H7 strain produces a powerful toxin and can cause severe illness.

Its presence in groundwater is a common indicator of fecal contamination.

("Enteric" is the adjective that describes organisms that live in the intestines. "Fecal" is the adjective for organisms that live in feces, so it is often a synonym for "enteric.") The name comes from its discoverer, Theodor Escherich.

Basic Protein Separation
Basic Protein Separation

 * 1) Protein Separation
 * 2) Protein Analysis

Basic Tissue Culture
Basic Tissue Culture

 * 1) Cultures
 * 2) Cell line
 * 3) Culture methods
 * 4) Animal handling

Basic Chromatography
Basic Chromatography

 * 1) HPLC Systems

High Performance Liquid Chromatography (HPLC):

HPLC is a popular method of analysis because it is easy to learn and use and is not limited by the volatility or stability of the sample compound

Modern HPLC has many applications including separation, identification, purification, and quantification of various compounds

Textbook on High Performance Liquid Chromatography (HPLC) http://hplc.chem.shu.edu/NEW/HPLC_Book/

GC-MS

Biotech HOT SPOTS in the US

 * 1) RTP - Research Triangle Park, created in 1959, located between Duke University in Durham, North Carolina, the State University in Raleigh, and the University of North Carolina at Chapel Hill.
 * 2) Boston
 * 3) Albany
 * 4) South San Francisco

Acronyms / definitions
Acronyms / definitions

GLP
GLP Good Laboratory Practices

GMP
Good Manufacturing Practice http://www.fda.gov/cder/dmpq/cgmpregs.htm

Biocidol
Kills cells Disinfectant

Biostat
Chemical that stops cell growth - does not kill.

Supernatants
Liquid removed from a tank once the solids have settled. Usually a clear liquid left after material (like cells) has been precipitated or centrifuged.

The material remaining above the pellet after centrifugation of a suspension.

Authors of this Wikibook

 * Tom Maioli tmaioli

Biotecnologie

title: Biotechnology


text: Template:High School Mathematics Extensions/Primes/TOC


text: High School Mathematics Extensions/Primes/Modular Arithmetic


text:
Template talk:The Unicyclopedia/TOC1

A great many thanks to whoever created this TOC. I used it in High school mathematics extensions. This is great. Xiaodai 02:07, 20 August 2005 (UTC)

title: Template talk:The Unicyclopedia/TOC1


text:
High School Mathematics Extensions/Primes/Problem Set

Problem Set
1. Is there a rule to determine whether a 3-digit number is divisible by 11? If so, derive that rule.

2. Show that p, p + 2 and p + 4 cannot all be primes if p is an integer greater than 3.

3. Find x

\begin{matrix} x \equiv 1^7 + 2^7 + 3^7 + 4^7 + 5^7 + 6^7 + 7^7 \ \pmod{7}\\ \end{matrix} $$

4. Show that there are no integers x and y such that
 * $$x^2 - 5y^2 = 3 \!$$

5. In modular arithmetic, if
 * $$x^2 \equiv y \pmod{m} \!$$

for some m, then we can write
 * $$x \equiv \sqrt{y} \pmod{m}$$

we say, x is the square root of y mod m.

Note that if x satisfies x2 ≡ y, then m - x ≡ -x when squared is also equivalent to y. We consider both x and -x to be square roots of y.

Let p be a prime number. Show that

(a)

(p-1)! \equiv -1\ \mbox{(mod p)} $$ where

n! = 1 \cdot 2 \cdot 3 \cdots (n-1) \cdot n $$ E.g. 3! = 1*2*3 = 6

(b)

Hence, show that
 * $$\sqrt{-1} \equiv \frac{p - 1}{2}! \pmod{p}$$

for p ≡ 1 (mod 4), i.e., show that the above when squared gives one.


text:
High School Mathematics Extensions/Primes/Project/The Square Root of -1

Project -- The Square Root of -1
Notation: In modular arithmetic, if
 * $$x^2 \equiv y \pmod{m} \!$$

for some m, then we can write
 * $$x \equiv \sqrt{y} \pmod{m}$$

we say, x is the square root of y mod m.

Note that if x satisfies x2 ≡ y, then m - x ≡ -x when squared is also equivalent to y. We consider both x and -x to be square roots of y.

1. Question 5 of the Problem Set showed that
 * $$x \equiv \sqrt{-1} \equiv \sqrt{p-1} \pmod{p}$$

exists for p ≡ 1 (mod 4) prime. Explain why no square root of -1 exist if p ≡ 3 (mod 4) prime.

2. Show that for p ≡ 1 (mod 4) prime, there are exactly 2 solutions to
 * $$x \equiv \sqrt{-1} \pmod{p}$$

3. Suppose m and n are integers with gcd(n,m) = 1. Show that for each of the numbers 0, 1, 2, 3, .... , nm - 1 there is a unique pair of numbers a and b such that the smallest number x that satisfies:
 * x ≡ a (mod m)
 * x ≡ b (mod n)

is that number. E.g. Suppose m = 2, n = 3, then 4 is uniquely represented by
 * x ≡ 0 (mod 2)
 * x ≡ 1 (mod 3)

as the smallest x that satisfies the above two congruencies is 4. In this case the unique pair of numbers are 0 and 1.

4. If p ≡ 1 (mod 4) prime and q ≡ 3 (mod 4) prime. Does
 * $$x \equiv \sqrt{-1} \pmod{pq}$$

have a solution? Why?

5. If p ≡ 1 (mod 4) prime and q ≡ 1 (mod 4) prime and p ≠ q. Show that
 * $$x \equiv \sqrt{-1} \pmod{pq}$$

has 4 solutions.

6. Find the 4 solutions to
 * $$x \equiv \sqrt{-1} \pmod{493} $$

note that 493 = 17 × 29.

7. Take an integer n with more than 2 prime factors. Consider:
 * $$x \equiv \sqrt{-1} \pmod{n}$$

Under what condition is there a solution? Explain thoroughly.


text:
Template:High School Mathematics Extensions/TOC

 High School Mathematics Extensions Supplementary Chapters — Primes and Modular Arithmetic — Logic

Mathematical Proofs — Set Theory and Infinite Processes — Counting and Generating Functions — Discrete Probability

Matrices — Further Modular Arithmetic — Mathematical Programming — Markov Chains


text:
User:Tmaioli

Working with Biotechnology,Optics, and Computers.

I am interested in putting together guides on and learning more about:
 * Biotechnology
 * Technical_Analysis of stocks and markets in general.
 * Nanotech
 * Information Technology
 * Cognitive Science
 * Artificial Intelligence

title: User:Tmaioli


text:
Release Management

Release Management refers to management of the release cycle within a software project, which itself is when the software engineers provide a uniquely identified set of files for others to use. The others may be their department at work, their classmates at university, or The World. The set of files (perhaps a single file) constitute the software release. Managing the release means the software release manager knows:

 * What went into it
 * Where it went
 * Why it went there
 * How to deal with it when bugs are reported

Building software is the generic term applied to the compilation or aggregation of sources into a usable utility or application. Sources needn't be compiled (built) in the classic sense, which relies upon a compiler linking files together; modern systems may consist entirely of interpreted source files (such as those for Perl or PHP). Still, putting everything together in a usable format may be considered "building".

The larger and more complex the software project becomes, the greater the need for an extremely well-managed Build and Release function.

Several features are characteristic of the Build and Release process. The most common are use of overnight builds, normalized build numbering, high degrees of automation, scheduling and reuse, use of notification, metadata capture and storage, and implementation of a project portal or viewer.

Overnight builds
This is a basic function that accomplishes two primary objectives:

 * 1) It establishes the code-wise integration of the project.
 * 2) It immediately alerts you to code-wise disintegration.

These may sound like the same thing, but they aren't. The software engineer expects to see code-wise integration as the project matures; the overnight build confirms he/she has it. He/she does not expect to see code-wise disintegration (the "it built yesterday, but not today" problem), and thus wants to know immediately when it is encountered. Engineers should be the only ones who see legitimate code-wise disintegration. They should catch it during their unit tests and fix it prior to committing to the project. By running overnight builds, the engineer has no more than 24 hours of source code changes to review and/or back out if the build breaks.

Overnight builds also give the QA department something against which to execute test cases and to target for specific bug regressions. Overnight builds help the software project team stay on schedule by reducing the amount of time required to resolve real code integration issues.

Competent Build Numbering
When the team builds the project every night (or continuously), the need exists for a build numbering scheme along with rules for build publication. Build publication rules refer to what builds get published for QA consumption and the target for that publication. A special directory structure on a specific machine is sufficient for this purpose. Project team members determine this up front, start using it, and do not change it over the course of the project. Throughout the entire project cycle, any interested party can quickly look at any build. The numbering scheme must be flexible enough to provide specific, built-in meaning in the number itself. For example:

foobar20110

This build "number" allows for visible identification of its contents. Anyone on the project may look at this number and know the build contains:

 * Foobar
 * Version 2 source
 * Internal build # 110

The release manager and the build engineer must establish a numbering scheme that is easily incremented via automated build scripts.

Automation
Human error is an acceptable risk on trivial, performed-once operations such as writing an email message. Human error is not an acceptable risk when building and releasing your software. If the steps for the procedure may be entered into the keyboard, the procedure can probably be automated. Well designed automation modules may be reused elsewhere in the project, as well as in other separate projects.

Auto-generated Build Numbers
Embedding build numbers in the source code is common. This allows a user of the software application to open an "About" or "Version" screen and receive information about the application's version and build number. This is useful in support and upgrade situations. The user sees something like "Version 12.3 Build 1234". Those strings came from the source code, often from hand-editing prior to that build. That process - the generation of the build number and its insertion into the source code - may be automated. The release engineer must develop a script or other piece of automation code that reads the master build number file, increments and caches it, opens the source file with the build and version string in it, greps or searches for the string in the file, does a replace, closes the file, commits it, and tags it. The build number is now in the source code prior to build process.

Scheduling
Well run release management is similar to other aspects of the software development project in that it is highly dependent upon the completion of scheduled tasks. Builds are the single most important scheduled task that produces artifacts for the release management process. The release manager must ensure that the build schedule is predictable and maintained. One mechanism for achieving is through use of job schedulers like cron or at. This allows the release manager to establish a schedule for builds, publications and deployments that is automatically enforced.

Reuse
Reuse of automation modules allows the release manager to compress more activity into available time, increasing productivity without a corresponding increase in hands-on work. Examples of automation modules that may be reused within and across projects include those for email notification, source code checkout and checkin, file copying, and deployment.

Notification
It is advantageous for the release engineer to be notified of the success or failure of any given release or build procedure. Automatic notification from within the release process provides this. At the conclusion of a build, a simple "Build OK" message may be sent to the project team. The message may include a hyper-link to a log file with details and the team benefits from quickly receiving status. Similarly, when the build is broken, the notification immediately alerts the team with a "Build Broken" message that can be investigated.

Project Portal
Web servers can be easily deployed and have come into popular use as a presentation manager for build and release metadata. Projects members and other interested parties may obtain project status, with the proper level of detail for their purposes, by viewing a page in their web browser. Several well developed tools exist for this purpose, including Anthill, CruiseControl, and BuildMaster.

Database storage
Building and releasing software produces significant metadata, both in volume and importance. The release manager is interested in Examples of build metadata include:
 * build and release trends, which provide insight into improving future release cycles
 * audit logs which provide historical records on the migration of specific software changes.

 * Build number
 * Build date
 * Build version
 * Source code label or tag used
 * Overnight build (Y/N)
 * QA tested (Y/N)
 * QA test results (Pass/Fail)
 * Location of full logs

The release manager may use any RDBMS; several are freely available and can be quickly set up on a low-cost computer running any of the free operating systems. Existing build logs may be imported for historical data housing. Build metadata may vary from project to project, and it is generally accepted that there is a practical limit to the amount of metadata to be stored. For example, even though the release manager may capture and store data like "Number of binary files included in the build", it must be considered whether the data is meaningful. Simply because a piece of data is available, it doesn't automatically become information.

title: Release Management