5.3. Setting up for Activity

In the remaining sections of this chapter, we will give you an opportunity to practice with a hands-on example on Odin. Those sections also dive deeper into some of the details we omitted in this section to help you gain a deeper understanding of the inner workings of interfaces.

Be sure and work through those sections and take the opportunities to compile, modify, and run the code. As always, do your best and let us know if you have any questions while working through the examples.

Learn by Experimenting!

For each of the remaining sections in this chapter, be sure to login to Odin and type out the commands given in each part, taking notes as needed. When you are done, you will have a step-by-step outline for creating and using interfaces in Java. Your notes and will be very useful on upcoming homework assignments and projects.

As you work through this example, you will write code to properly utilize an interface called Styleable that allows you to seamlessly change the way text is printed to the screen. This section is all about getting that environment setup on Odin.

On Odin, complete each of the following steps:

  1. Use the following command to download the starter code for this chapter and places it into a subdirectory called cs1302-interfaces:

    sh -c "$(curl -fsSl https://cs1302uga.github.io/cs1302-book/_bundle/cs1302-interfaces.sh)"
    
    - downloading cs1302-interfaces bundle...
    - verifying integrity of downloaded files using sha256sum...
    - extracting downloaded archive...
    - removing intermediate files...
    subdirectory cs1302-interfaces successfully created
    
  2. Change into the cs1302-interfaces directory that was just created and look around. Then, change into the styleable subdirectory. There should be multiple Java files contained in the src directory. To see a listing of all of the files in src, use the tree command.

    You should see output similar to the following:

    Listing 5.7 The current directory structure
    .
    └── src
        └── cs1302
            └── interfaces
                ├── StyleDriver.java
                ├── contract
                │   └── Styleable.java
                └── impl
                    ├── Fancy.java
                    └── SuperFancy.java
    
    Starter Code - Output of the tree command

    Each subdirectory within cs1302-interfaces plays a role in the example. Here is a breakdown of the different subdirectories and their roles:

    • src is the default (no-name) package directory for our source code (default package for source code);

    • cs1302 stores the main driver program (with the main method).

    • interfaces stores our Styleable interface code.

    • impl stores two different implementing classes. Each one implements the Styleable interface in a different way.