Laboratory 8
Ant & Chapter 21: Generic Classes & Methods

Before the lab, do the Self-Review exercises in the chapter.

Put the Java source code of your solution to the exercise below on your private GitHub repository:

Feel free to talk to whomever you like about any aspect of the laboratory. Working in pairs may be helpful.

Ant

Please look at the course Resources page for information about Ant.

In this lab, you will create a Pair class in Java. Understand the Ant file below. It:


build.xml
<project name="MyProject" default="run" basedir=".">
    <description>simple example build file</description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} directory trees -->
    <delete dir="${build}"/>
  </target>
  
  <target name="init">
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}" includeantruntime="false"/>
  </target>
  
  <target name="run" description="run computer" depends="compile">
    <java classname="Main" fork="true">
        <classpath>
            <path location="${build}"/>
        </classpath>
    </java>
</target>

</project>

Modify the Ant file, so that its targets work for your laboratory assignment. Your build.xml, uploaded to your private GitHub repository, will be run to grade your work.

Chapter 21

Do exercise 21.8 (Generic Class Pair). In addition to the get & set methods, implement a main method that is used to construct & print 2 different Pair objects:

Again, your build.xml file will be used to compile your Pair class, & run its main method.


 cappello@cs.ucsb.edu © Copyright 2014 Peter Cappello                                           2014.05.20