Java Applications using CodeWarrior

There are many ways to create Java programs using CodeWarrior but this page describes the default (i.e., simplest) way to create a program. Once you've spent a few weeks in the course, you can learn how to vary from this default process.

Creating a new Code Warrior project (from scratch)
When you want to create a new Java program using CodeWarrior, you first ask CW to create a new project. At a basic level, CodeWarrior associates projects with folders. In 15-100, we'll always associate a program with a folder and assume that everything needed for a program will exist inside that basic folder. Although CodeWarrior also creates additional subfolders within the program folder, you don't need to worry about them.
 

Using an existing Code Warrior project
When you've worked on a CW project in an earlier session (or if you've copied a previous project folder to start a new project), less work is needed.
 

Renaming your program files
By default, your program will be called "Trivial Application" -- of course, you don't want this name for every program. Unfortunately, it is not completely trivial to make this change in CW.


At this point, I'll assume that you've already started the Metrowerks CodeWarrior IDE (integrated development environment).

Creating a CW Project (i.e., program) from scratch


Using an existing CW project:

In the folder that CW creates, there will always be a file that stores the information corresponding to the MCP window (see the preceding graphic).  The mcp file's basic name will be the same as the project folder's name.

It is possible to have multiple files (of different varieties) with the same name and it will often be the case that the mcp file name is the same as a Java code file name. Windows always uses extensions (suffixes) to make the distinction; however, Macs sometimes use more sophisticated distinctions.
In either environment, when you display your folder using icons, the mcp file looks like it has a diagram, while the Java code file looks like it has written text.
For example, suppose the project (folder) is called  Attempt1 - in either environment the basic name of the mcp file will also be Attempt1. But if the project was created
  • in a Windows environment, the full file name is Attempt1.mcp
  • on a Mac, the full file name is Attempt1
  • Windows users who start projects on a Mac before transferring the project to a Windows environment should add the .mcp extension to the file name before trying to use the project with Windows.


    Starting an existing CW project also differs between the two environments.

    In Windows, when you double click on an mcp file, you start CodeWarrior (if necessary) and activate the project associated with the mcp file.
    On a Mac, when you first start, you can double click on an mcp file to automatically invoke CodeWarrior. However, once the CW program is running, this "trick" no longer works.  This occurs because the Mac's CW keeps track of your usage over your entire programming session. Instead, these are your options:

    Renaming in CW-based Projects:

    There are two reasons to change the names involved with projects. First, your Java program will be called Trivial_Application by default, and, of course, you don't want to use this name for major programs. Second, if you want to use an existing program you've created as a starting point for a new project, you'll also need to change names.

    To address the latter issue, you first need to change the name of the folder and the name of the mcp file. Then, you'll need to change the names of at least some of  the Java files.

    Each Java file should have its own unique name.  The Java file's name is supposed to match the internal "class" name of the Java file. Neither is hard to do in a low-level (basic) Java environment but it is more complicated when using CodeWarrior.

    Although the process described below involves more work than with a basic environment, CW avoids different issues which would become important in a basic Java environment. For example, CW's mcp is a graphical replacement for "basic" makefiles which you would otherwise have to learn.  If you choose to take additional CS courses, you will probably learn the basic environment (at least in 211).


    Renaming the components of a project.

    For our example, let's suppose we want to change the name of the program "TrivialApplication" to "Demo1".



    This footnote is a warning for students who have more than the just the one Generic option when creating a new Java project.
    I know of two reasons why this can happen. Either

    a) you're using a older computer which was previously used for Java programming or
    b) you're using an older version of CodeWarrior.
    Neither should be a problem as long as you are careful to select the correct (most current) version of Java which is Java 1.4 (or soon, 1.5).  If you ignore this step, it is possible that your programs may be using a much older version of Java which may not work properly (particularly regarding doubles (real numbers)).