|
|
- Java Development Environment Setup
- Set up Java in local machine
- Try to run Sample Java programs in Environment
- Debugging Basics
- Learn some simple but efficient tricks for debugging Java programs
- Eclipse Tutorial
- Get familiar with Eclipse IDE
- Java development in Eclipse
- Assessment
- Try to fix all the bugs in few demo programs
|
|
Set up Java development environment in local machine
- Download and install Java Development Kit (JDK) on your local machine. Helpful video for installation
- The bin folder contains all the java tools like compilation (javac), execution (java/javaw), applet viewer (appletviewer) and so on. To use the command
javacto compile Java source code, you need to set the system environment variable:PATHandCLASSPATH, so that the system knows where to find the command and the class (libraries).- In Windows 95/98/ME, add the following lines at the end of
c:\autoexec.bat
set PATH=C:\Program Files\Java\jdk1.7.0_18\bin;%PATH%set CLASSPATH=.;C:\Program Files\Java\jdk1.7.0_18\jre\lib;%CLASSPATH%set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_18- In Windows 2000/XP professional:
- Click Control Panel > System > Advanced > Environment Variables.
- Double click
PATH,CLASSPATHandJAVA_HOME, to edit the values; or click "New..." to add a new variable.- Windows 7:
- Select Computer from the Start menu
- Choose System Properties from the context menu
- Click Advanced system settings > Advanced tab
- Click on Environment Variables, under System Variables, find PATH, and click on it.
- In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value. Reopen Command prompt window, and run your java code.
- Helpful Site to set or change the PATH system variable (Windows)
- In Unix, edit
~/.cshrc_user
setenv PATH /usr/local/packages/java/bin:${PATH}setenv CLASSPATH .:/usr/local/packages/java/jre/libsetenv JAVA_HOME /usr/local/packages/java- Helpful Site to Set JAVA_HOME / PATH variables Under Linux Bash Profile
- Mac OSX 10.5 or later,
$ vim .bash_profileexport JAVA_HOME=$(/usr/libexec/java_home)$ source .bash_profile$ echo $JAVA_HOME /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home- Helpful Site to Set $JAVA_HOME environment variable on Mac OS X
Try two toy Java programs
- Download HelloWorld.java Program
- Open a command prompt by clicking: start > run > type in "
cmd" > OK- To compile HelloWorld.java, type: (.java is needed)
javacHelloWorld.java- To execute it, type: (.class CANNOT be specified)
java HelloWorld- To compile and run StdIOTest.java:
javac StdIOTest.javajava StdIOTest > StdIOTest.html- To end std input, use ctrl+Z in Windows, or ctrl+D in Linux.
|
|
- Here we introduce some simple tricks for debugging Java programs. For more sophisticated debugging techniques, refer to Eclipse tutorial
- An efficient way for tracking Java programs is to print or log the values of the variables with code like this:
System.out.println("x=" + x);mylogger.info("x=" + x);after creating a Logger named "mylogger" usingLogger mylogger = Logger.getLogger("mylogger");- We can set the level to which the messages will be logged:
mylogger.setLevel(Level.ALL);mylogger.setLevel(Level.OFF); // turns off the logger- Here is an example, FactorialLog.java, which uses
Loggerto track the computation of factorials.- Instead of the default
Logger, we can use customized loggers for advanced features. An example is given in HelloWorldLog.java.
- Download the Eclipse tutorial
- Follow the steps in the tutorial.
- Click here to download Eclipse tutorial
|
|
- Could you try to fix all the bugs in the simple programs using Eclipse?
- Click here to download Lab1 Assignments