14 Jan
Java: Calculator Instructions
Author: RussellPreperation
Should you not have the Java Virtual Machine (JVM) you can find it at java.sun.com, this is used to run Java programs. There are several ways you can run the Calculator, the way I have been running it is to place both class files in a directory, compile them both and then run the Calculator class, I used cygwin but a DOS prompt or any other shell should also be ok.
You can use an Integration Development Environment (IDE) to run the Calculator, instead of the command line; however, if your not using an IDE you might find the following usefull.
Compiling and running using a shell
Once you have your shell/DOS prompt you will want to create a suitably named directory, and then place both class files in it. The following shows where you should be in the directory structure and what files you should see in there.
$ pwd /home/user/java/Calculator user@user ~/java/Calculator $ ls Calculation.java Calculator.java
Then from within the directory where the class files are, compile the class files using javac as follows.
$ javac Calculator.java user@user ~/java/Calculator $ javac Calculation.java
Once compiled you should see a few extra files, these will have a .class file extension, and they contain the bytecode which JVM will uses to execute, in this case resulting in the Calculator running and the user interface being displayed.
user@user ~/java/Calculator $ ls Calculation.class Calculator$1.class Calculator.java Calculation.java Calculator.class
Now you are ready to run the Calculator using the following command;
user@user ~/java/Calculator $ java -classpath . Calculator
Assuming you have done everything correctly you should see something similar to the following;

Filed under: Software Development