NetBeans and Java


Introduction

Most (if not all) professional programmers use Integrated Development Environment (IDE) software to develop code. An IDE is a software program that automates many aspects of programming, especially compilation (also called "build") steps. Automating compiliation is particularly important when you are developing code in the java language, where you must compile your code before you run it and there is no interactive interpreter. Being able to use an IDE effectively is a critical skill in bioinformatics programming, and so in this assignment you'll do some exercises designed to introduce you (gently) to a very useful and relatively easy-to-use IDE, which you will use for the rest of the semester for all your Java-based programming projects.

Two of the most popular IDEs for developing in java are NetBeans and Eclipse, both of which are free and available for most operating systems.

In this class you'll learn to use NetBeans to write programs in Java. You can also use NetBeans to write code in other languages, but in this class, we will mainly use it to write software in the Java programming language.

Most IDEs organize work into projects, which are sets of files and directories that include source code, documentation, testing code, and also project- or IDE-specific files that tell the IDE how to build your code and package it into executable files you can distribute to users or otherwise run independently from the IDE.

In this assignment, you'll learn how to set up a NetBeans Java project, check in parts of it to subversion, and write and run your own Java program from the Unix command line.

Let's get started....


Part One: Setting up NetBeans

minerva:dist admini$ pwd
/Users/admini/src/binf_prog/aloraine/netbeans_hw/HelloWorldApp/dist
minerva:dist admini$ java -jar HelloWorldApp.jar 
Hello World!

The "jar" file (stands for "java archive") contains compiled source code, which usually consists of multiple files with the extension .class. Large Java projects can often contain many hundreds of compiled .class files, which is why for convenience we typically bundle them into a single "jar" file and run them using the -jar option.


Part Two: Checking in the project files

Now use the terminal to view the contents of your new netbeans_hw directory. You will see a number of files and directories that NetBeans created when you set up your look inside the NetBeans project directory for netbeans_hw. You should see something like this:

minerva:HelloWorldApp admini$ pwd
/Users/admini/src/binf_prog/aloraine/netbeans_hw/HelloWorldApp
minerva:HelloWorldApp admini$ ls
build		dist		nbproject	test
build.xml	manifest.mf	src

Next, you'll check in a subset of directories and files to subversion so that you can easily re-create the project on your home (or other) computers. Before you do this, take a look at some of the files and directories so that you get familiar with how NetBeans projects work:

Files and directories made by NetBeans:

View the contents of the nbproject directory:
minerva:nbproject admini$ ls
build-impl.xml		private			project.xml
genfiles.properties	project.properties

Note that there's a subdirectory in here called private, which, as it name implies, contains files and settings that are private to the current computer where you are working. The private directory contains a file called private.properties. Use Unix command more to view the file contents. It should contain some system-specific details that only apply to one computer, the one you are using right now. For example:

minerva:nbproject admini$ more private/private.properties 
compile.on.save=true
jaxws.endorsed.dir=/Applications/NetBeans/NetBeans 6.7.app/Contents/Resources/Ne
tBeans/java2/modules/ext/jaxws21/api:/Applications/NetBeans/NetBeans 6.7.app/Con
tents/Resources/NetBeans/ide11/modules/ext/jaxb/api
user.properties.file=/Users/admini/.netbeans/6.7/build.properties

Note that the file contains path information for directories that exist on one computer. So when you check in your NetBeans project to subversion (or any version-control system) you should NOT check in the private directory or any file or directory that contains system-specific details. This is both for security's sake and also to ensure that you can use your NetBeans project on any of the computers you might use.

Checking in the NetBeans project files - just the ones you need!

svn add -N HelloWorldApp
svn add -N nbproject
svn add src
svn add build.xml
svn add manifest.mf
svn add project.xml
svn add genfiles.properties
svn add build-impl.xml
svn add project.properties

Don't add nbproject/private, build, or dist directories to the repository.

And finally, don't forget to check in all your changes in the usual way.

If you do all this correctly, then you will be able to check out and develop the HelloWorldApp project onto different computers. The key here is to check in the files that are not system-specific. This will make it possible for the instructor to run (and grade!) your projects and will also make it possible for you do develop your projects on different computers, using subversion to track your files.


Part Three: Test your knowledge - Interest App

Repeat the above process and create a new project inside the netbeans_hw directory named InterestApp. Copy and paste the Interest2 class from Eck's Chapter Two. Modify the program so that it accepts four additional parameters from the user and then computes the account's value, assuming no withdrawals are made:
  1. monthly addition -- amount of new savings added to the account on the first day of the month
  2. compound interest period -- number of times per year interest earned thus far is added to the principle (assume it's added at the beginning of the month)
  3. interest rate (annual)
  4. the investment period -- the number of years the account accrues interest.