public class Example {
public static void main(String[] args) {
new Example().go();
}
public void go() {
System.out.println(subtract(add(7, 10), 3));
}
/**
* Computes the sum of two numbers.
* @param x The first addend.
* @param y The second addend.
* @return The sum.
*/
int add(int i, int j) {
return i + j;
}
/**
* Computes the difference of two numbers.
*/
int subtract(int x, int y) {
return x + y;
}
} |
import junit.framework.TestCase;
public class ExampleTest extends TestCase {
Example e;
public ExampleTest() {
super();
e = new Example();
}
protected void setUp() throws Exception {
}
public final void testAdd() {
assertEquals(9, e.add(6, 3));
}
public final void testSubtract() {
assertEquals(9, e.subtract(30, 21));
assertEquals(-3, e.subtract(-5, 2));
}
} |
All the IDEs (Integrated Development Environments) discussed here have the following features:
javac (java compiler) and java (program execution) javadoc (documentation generation) junit (unit testing) http://www.bluej.org/
The most recent stable
version is 2.1.3.
Additional features:
main method
required). Submitter (allows submission of projects
to specified address via email, ftp, http or file copy).Hint:
Clear Screen at Method Call and Unlimited Buffering http://drjava.sourceforge.net/
The most recent stable version is drjava-stable-20070130-2255. Supports Java
1.4, 1.5, and 6.
Additional features:
http://www.eclipse.org/downloads/
The most recent stable version is 3.2.2
Too many great features to list. Here is a sampling:
Downside: Intimidating.
I don't believe in teaching two complex things at once. So in the past I've started with BlueJ and later switched to Eclipse. This past year I started by teaching some Eclipse before starting to teach Java, and that's worked out we..
http://java.sun.com/javase/downloads/index.jsp (Download
along with Java)
The most recent stable version is 6.0 Preview (M9).
Additional features:
Disadvantages:
http://www.beanshell.org/
The most recent stable version is bsh-2.0b4.jar.
BeanShell isn't an IDE at all. It is "dynamically interpreted Java, plus a scripting language and flexible environment all rolled into one clean package." This is the most dynamic, hands-on way to experiment with Java.
BeanShell has a number of convenience features, like simplified printing and optional type declarations, that make it nice to use. However, these same features make it "almost but not quite Java," so in some sense its major advantages are the same as its major disadvantages. In my opinion, it's well worth a look.
Satisfice: "To accept a choice or judgment as one that is good
enough, one that satisfies. According to Herb Simon, who coined the term,
the tendency to satisfice shows up in many cognitive tasks such as playing
games, solving problems, and making financial decisions where people typically
do not or cannot search for the optimal solutions."
--The Penguin Dictionary of Philosophy
Energy barrier: The energy that must be put into a chemical reaction before
the reaction begins to produce energy.