Java Video Rental Store App - Part 1

One of the last computer engineering course works I had to do was to code a simple Java application. This application should use a database to store and retrieve its data. The discipline was Advanced Computing Topics. The teacher Luís Henrique Campos Braune sent the class an e-mail explaining what he wanted us to do. The following lines are a transcript of what he wanted us to do initially.

The basic idea was that we would study a sample java application1, a very simple one, and starting with it we would program another one. The work would be done in teams and the teacher orientation was that we should only use the allotted class time because we were also preparing our computer engineering final project and he didn't want us to spend time at home with course work related to his discipline. He thought that the time allotted to the classes would be sufficient for this task.

1 The sample Java application can be downloaded at the end of this post. The initial code and instructions were written in Portuguese. I translated all the code and instructions to the English language, so that it can reach a broader audience.

The Java Sample Application
The Java sample application is a functional and really rudimentary one and uses the Swing User Interface Toolkit.

We didn't use an Integrated Development Environment (IDE) to work with it. All the preliminary changes to the code was done using a simple text editor as the Windows Notepad. The purpose of this application was to introduce the students to the object oriented programming world based on windows and user events. We should compile and run it according to the following steps:

1st step - Download and decompress the .zip file provided by the teacher.

The sample application should be uncompressed in the root dir C:\ on the classroom computer to facilitate the work.

The following table shows the content of the .zip file:

.ZIP file content
File Description
MainMenu.java Class pertaining to the main menu
ClientRecord.java Class pertaining to Retrieve/Change/Save/Delete client
VideoRecord.java Class pertaining to Retrieve/Change/Save/Delete video
VideoRental.java Class pertaining to video rental
VideoDevolution.java Class pertaining to video devolution
DatabaseAccess.java Class pertaining to the database connection and functions
VideoRentalStore.mdb Microsoft Access database file
README.txt A read me file with instructions

2nd step - Compile the sample app To do this we should open a command prompt, navigate to the sample app directory and type: javac MainMenu.java

In case the above command didn't work for you, refer to the The Java Platform section bellow.

3rd step - Run the sample app After compiling the the Sample app it's necessary to run the same. To do this, again in the command prompt, type: java MainMenu

In both cases it's important to type observing UPPER and lower case letters. It's case sensitive.

The Java Platform
Evidently, to do the the last two steps we should have the Java Platform installed. The Java platform consists of several programs, each of which provides a distinct portion of its overall capabilities. The principal portions are: the Java compiler, the Java Virtual Machine (JVM), the Java Development Kit (JDK), the Java Runtime Environment (JRE), and the just-in-time (JIT) compiler.

If the 2nd step above didn't work, we have two possibilities:

- The JDK is installed but not configured

A simple tip to see if the JDK is already installed is to look for some version of the JDK in "C:\Program files\Java"; if there is a version but on trying to compile you get an error, then you need to configure it first. That's what we'll do in the Installing the Java Development Kit section bellow.

- The JDK isn't installed

There are different "editions" of the Java Platform, including:

  • Java ME (Micro Edition): Specifies several different sets of libraries (known as profiles) for devices which are sufficiently limited that supplying the full set of Java libraries would take up unacceptably large amounts of storage.
  • Java SE (Standard Edition): For general purpose use on desktop PCs, servers and similar devices.
  • Java EE (Enterprise Edition): Java SE plus various APIs useful for multi-tier client-server enterprise applications.

The one that would fit our necessity was the J2SE edition without the NetBeans IDE, that is usually offered with the Java Platform when you download it.

To download the J2SE go at http://java.sun.com/javase/downloads/index.jsp (select JDK 6 Update 5).

There are several flavors, each one suitable for a specific type of operating system. For this post I used the Windows offline installation file called jdk-6u2-windows-i586-p.exe (65.5 MB).

Installing the Java Development Kit
The following are the steps we used to install the JDK. It's really easy! You practically have to click on next, next and next.

Just pay attention to the fact that, after the installation of the JDK, the JRE will also be installed in case you don't have it.

The trick is to configure the Java Platform after the JDK has been installed. To do that, check where the installation was done. Usually it is in C:\Proram files\Java\jdk...

Now, right click on My computer, Properties, Advanced tab, Environment variables. Click on New variable. Can be in User variables or System variables. Create the two variables according to the following table:

Environment variables
Variable Name Value
1 CLASSPATH ;.;C:\Program files\Java\jdk1.6.0_02
2 PATH ;C:\Program files\Java\jdk1.6.0_02\bin

Notes: - A dot (.) is part of the CLASSPATH variable value. - The path here presented are for mere illustration. What really matter is the current path you have on your computer. - Each value has a semicolon in its beginning. - I used the value jdk1.6.0_02 because this is the JDK version I have on my machine. This explains why I used ... to point the JDK installation path. If you have a different version, make the appropriate change.

Save everything clicking OK.

To test if the Java Platform was installed/configured correctly, try to compile and run the sample application executing the 1st and 2nd steps of The Java Sample Application section above.

Configuring the database connection
It wasn't enough for our Java sample application. We then should configure the database, more precisely, the alias used to reference the Microsoft Access VideoRentalStore.mdb database file.

What we needed to do was to create an ODBC connection so that the database file would be referenced through the alias used within the DatabaseAccess.java source code file. To do this we should do the following:

Go to Control Panel, Administrative Tools, ODBC Data Sources, click on the Add connection and choose Microsoft Access driver; in data source name value we should type the alias "VideoRentalStore" used in the DatabaseAccess.java source code file and in Database we should select/point to the VideoRentalStore.mdb database file that is inside the uncompressed directory.

Doing so we should be able to Retrieve/Change/Save/Delete data using the sample application.

Any doubts should be reported to the teacher. That's what he's there for, right?!

OK that was the first class we had and so is the first post in this series.

Next post in this series
Come back to see a next post in which I'll start to drill down what I particularly did, that is, what path I followed to take advantage of and master my skills while developing the other version of such application.

Get the Java Video Rental Store sample application at:

http://leniel.googlepages.com/VideoRentalStoreSampleApp.zip