APPENDIX A

image

Installing a Java Application on a PC

In this Appendix, we will show you how to install an application onto a Windows PC from the RAD environment. The means explaining system environment variables and the software required to run a Java application on a PC. We will also explore PC batch (.bat) files and show how they make applications easier to use. Finally, we’ll demonstrate how to import files into the RAD environment. The example assumes Chapters 1 and 2 have been completed.

Tutorial: Exporting an Application from RAD

Programmers use RAD to develop applications. Users do not have RAD. Therefore applications have to be installed onto user’s computers. To install an application, the application’s .class files must be moved from RAD onto the computer where they will be run. This is called exporting. In the process of installing a Java application, exporting is a relatively simple step. The more complicated steps involve installing a JRE and configuring Windows to enable Java applications.

In the example, the Employee application in myFirstPackage will be moved to a flash memory stick identified as the F: drive. We are putting the application on a memory stick so that it can be easily transported between computers. (If you don’t have a memory stick, any storage media that has at least 150 megabytes of space is OK. For example, a zip disk can provide the needed space and portability. At worst, sacrifice portability and use the C: drive.)

  • 1.  In the Package Explorer, select MyFirstProject.
  • 2.  Click File, then Export.

The Export window will be displayed (see Figure A-1). Files can be exported in several different formats. For instance, there are ZIP and JAR format options for Java applications, as well as, WAR (Web Archive File) and EAR (Enterprise Archive File) options for exporting server-based applications. (In later chapters, the text will cover server-based applications and how to install them.) All of these formats compress the files. Usually these compressed formats are used when exporting and installing (rather than exporting the .class files directly) because of storage and transfer time efficiencies.

The application can also be exported in several different “ways.” For instance, the FTP (File Transfer Protocol) option allows files to be sent to any computer that has a Web address (thereby helping with a remote application install). We are simply moving the application to a different location on the PC (i.e., from the RAD work space to the F: drive), so we will choose the File system option.

  • 3.  On the Export window expand the General item, click File System, then click the Next button.

The Export window will be displayed (see Figure A-2). Because we selected MyFirstProject for export, RAD assumes every folder and file will be exported. Because we are only going to run the application (not edit the source code) the .java files do not need to be exported.

  • 4.  Click the Filter Types. . . button.

The Select Types window will be displayed (see Figure A-3). As this window’s name implies, files for export can be specified by their type (i.e., file extension). As an application gets more complex, it may be comprised of hundreds if not thousands of class files. Rather than specifically selecting each class, this enables you to specify all of them for export.

  • 5.  Click the .class option and the OK button.

On the Export window, notice that the check mark next to MyFirstProject has changed to a solid blue square. This means that the project folder is not selected for export but something in the project is selected. Expanding MyFirstProject shows that a subfolder called bin has something selected.

Are you wondering where bin came from? Each perspective has a unique view of an application’s resources. The Java perspective does not display the class files or the folders and subfolders that hold them. Continuing to expand the subfolders would show that inside of myFirstPackage the two class files have been selected for export.

When files in a package are exported, they must be installed in a PC folder with the same name as the package. The easiest way to do this is to export the package also.

  • 6.  On the Export Window, expand MyFirstProject/bin and click the myFirstPackage checkbox twice to select the package and its content for export.
  • 7.  Specify F: (or whichever drive letter you are using) in the “To directory” field and make sure that the “Create only selected directories” radio button is selected.
  • 8.  Click the Finish button.
  • 9.  Verify that the files were copied by clicking on My Computer, then double-clicking the drive (e.g., the F: drive) and then the myFirstPackage folder.

The two class files will be displayed as in Figure A-4.

Tutorial: Downloading a JRE

The application class files have been successfully exported. Unfortunately, there is no JRE to translate the bytecode (in the class files) into machine language. We need to download and install a JRE before we can run the application.

There are many sources for a JRE. We will go to the Oracle website. (Be aware that there are frequent updates to the Oracle website and often the procedure for downloading and installing will change.)

The download page will be displayed (see Figure A-5).

Oracle puts out new releases of the JRE quite frequently, so the download Web site address and page (as well as the documentation Web site) may change with different Java releases. In addition, the currently available JRE release you will download will probably be newer than JRE 6.23 shown in these figures.

  • 2.  Click on the JRE Download link (indicated with the arrow in Figure A-5).

The license agreement page will be displayed (see Figure A-6).

As mentioned earlier, there are many different JRE versions. Do you remember why?

Because the JRE must work with a specific operating system, there are different JRE versions for each operating system. (This is the same reason applications—like games, word processors, etc.—come in Windows and Apple versions.)

  • 3.  Click the “Accept License Agreement” checkbox.

This activates the download links at the bottom of the page.

  • 4.  If you are using Windows 7, you can click the Windows Offline Installation file link (as indicated by the arrow in Figure A-6).

The File Download window will be displayed.

  • 5.  Click the Save button.

The Save As window will be displayed. The name of the file (jre-6u25-windows-i586-p.exe) will already be specified. (The name of the file will change with different releases, so do not worry if it is not exactly the same.) Make sure the correct drive is specified (i.e., F :).

  • 6.  Click the Save button.

The file will be downloaded to the specified drive (i.e., F:).

  • 7.  Click on My Computer and then double-click the F: drive icon to display the contents.

The newly downloaded Setup Launcher file and myFirstPackage folder will be displayed (see Figure A-7).

Tutorial: Installing a JRE

  • 1.  Double-click the Setup Launcher file (jre-6u25-windows-i586-p.exe) to run the install program.

The Java Setup – Welcome window will be displayed. The Typical setup puts the JRE on the computers default drive. Because we want to install to the F: drive, we will need to customize the setup option.

  • 2.  Click the “Change destination folder” checkbox and accept the license agreement by clicking the Install button (see Figure A-8).

The “Java Setup – Destination Folder” window will be displayed (see Figure A-9).

  • 3.  Click on the Change. . . button.
  • 4.  Click on the F: drive and click the Make New Folder button (see Figure A-10).
  • 5.  Type jre over the default name, New folder, and press the Enter key.

The folder will be renamed (see Figure A-11).

  • 6.  Click the OK button.

The “Java Setup – Destination Folder” window will be redisplayed with F:jre specified as the destination.

  • 7.  Click the Next button.

A progress window is displayed as the installation is performed. This may take a while, depending on the speed of the computer and the media chosen for the install. In addition, if there are open browser sessions, you will be required to close them to continue the install. (There are other applications that you may also be prompted to close.)

Eventually, the “Java Setup - Complete” window will be displayed.

If the installation was successful, a folder named jre containing the JRE will be on the F: drive.

  • 8.  Verify that the JRE has been installed by double-clicking on My Computer, then double-clicking the F: drive icon to display the contents of the F: drive.

There should be a new folder called jre.

  • 9.  Double-click the F:jre folder to display the contents.

The window should look like Figure A-12. (The contents of the folder may also change with new releases.) Most of the files contain general and legal information. The README file does contain a list of subfolders and files that are not essential for running Java applications. However, the entire jre folder is approximately 90 MB, so space should not be a problem.

More important are the bin and lib subfolders. The lib folder contains the JAR files that hold the core classes (e.g., String). For example, if you display the contents of lib, the rt.jar file can be seen. This file contains many of the core classes.

The bin folder holds many JRE functions. For instance, the file named java.exe in bin contains a program that allows you to run a Java application in the JRE. However, before that can happen Windows must be configured to find the Java support functions and core classes.

Tutorial: Environment Variables

There are many different Windows’ environment variables, each with a unique name. Environment variables can be defined as system variables—meaning that they are universal for all applications on the PC. (It is like saying that a red traffic light is a national “driving environment variable” meaning stop. Regardless of where you are driving in the nation, a red traffic light means stop.) Environment variables can also be defined as user variables. User variables are only valid for a particular user of the computer. In addition, environment variables can be changed dynamically. This means that a user or an application can change them temporarily. When changed dynamically, the new values are only in effect for as long as that user or application continues processing. If another application or the same user starts up, the variables original values are used.

One way to change environment variables values is through the Control Panel.

  • 1.  Click the Start button and on the right side of the Start menu select Control Panel

The “All Control Panel Items” window will be displayed (see Figure A-13).

  • 2.  Click System to display the “System” window (see Figure A-14).
  • 3.  On the “System” window, click the “Advanced System Settings” button to display the “System Properties” window (see Figure A-15).
  • 4.  On the “System Properties” window, click the “Environment Variables” button to display the “Environment Variables” window (see Figure A-16).

Notice that the environment variables are broken up in User and System variables. System variables are universal for all users on a computer. User variables are only valid for the particular user currently signed on to the computer. If there is a System and User variable with the same name, the User variable value will override the System variable value.

To understand the importance of Environment variables to Java we have to explain a little about how Windows (and many operating systems) “work”. When a user clicks an icon or a menu item, they are telling Windows to do “something” (i.e., specifying a function/command) against “something” (i.e., a file). So clicking on the “Internet Explorer” icon or menu item means the user is specifying run (i.e., the command) the iexplore.exe file stored in C:Program FilesInternet Explorer. This information was all specified when Internet Explorer was installed on the computer. Thank you, Microsoft!

Notice that Windows had to be told every little detail—like the exact location of the file to be run. This exact location and file name (C:Program FilesInternet Exploreriexplore.exe) is called a fully qualified file name. If a fully qualified name is not specified, Windows does not search the entire system to find the file. Instead Windows reads the environment variable PATH. PATH can hold many locations (separated by semicolons) and tells Windows where to search whenever an executable file (i.e., a command) is specified. The CLASSPATH variable tells Windows where to search whenever a Java class file is specified. As with the PATH variables, multiple path names (folders and subfolders) can be defined for the CLASSPATH variable. The “Environment Variables” window allows users to define a variable or edit an already existing variable.

In Chapter 2, you learned that Java source code has to be compiled (converted to bytecode) and interpreted (converted to machine language and run). Both of these functions are not standard Windows commands. If you tried to run a bytecode file, Windows would search the location in the PATH variable and not find the “run” command. In other words, Windows does not know anything about Java. Therefore, for a Java application to be executed, the PATH and CLASSPATH variables have to be edited to include the java command files location (i.e., in the JRE) and the location of the .class files.

If we modify the variables using the Environment Variables window, our application will only work for this computer. For example, if we took the memory stick (in the F: drive) to another computer, we would have to set that computer’s environment variables to look for our class files and the JRE on the F: drive. This would have to be done for every computer we want to run the application on. To get around this problem, we are going to write a small batch program (and store it on the F: drive) that will set the PATH and CLASSPATH variables dynamically on whatever computer we want to run the application on.

If you have not programmed on a PC before this may come as a surprise, but all the functions performed from the Windows GUI (graphical user interface) can be performed with commands. For instance, the dir (directory) command lets a user display the contents of a folder or drive (the same function that the My Computer icon provides). In addition, there are path and Set classpath commands that can control the two environment variables we need to define. Our batch program will use these commands to configure the environment variables. In addition, we will include a JRE command to run our Java application.

Tutorial: Creating a Batch File

Windows commands can be stored in a file with an extension of “bat” (indicating that the file is a batch file). When a bat file is specified at the command prompt (or its icon is double-clicked), Windows will execute the commands contained in the file in sequential order. We will use the Windows Notepad utility to enter, and save the commands in a batch file called Employee_Application.bat.

Notepad will create an unnamed file and display a blank window indicating that the file is empty. Commands are entered by positioning the cursor and typing. The first command we want to enter is the path command.

This will set the path to the bin folder that contains the JRE commands. The java command is needed to run the employee application in the JRE and is stored in the bin subfolder. (If you need proof, use My Computer to display the contents of the bin folder. You will see an “application” file called java. This program is run when the java command is issued.)

  • 3.  Press Enter to add a new line.
  • 4.  On the new line, type Set classpath=f:

This statement defines the classpath variable, which, essentially, tells Windows where to find our application classes (i.e., the package folders myFirstPackage). There must be at least one space between Set and classpath, and there are no other spaces in the command. Be careful: this must be coded exactly as shown. Common mistakes include using forward slashes instead of the back slashes, using colons for semicolons (and vice versa), and having an extra space at the end of a line.

  • 5.  Press Enter to add a new line.
  • 6.  On the new line, type java myFirstPackage/EmployeeApp

There must be at least one space after the java command and no spaces thereafter. When this command is encountered, Windows finds the java program (because of the path statement) and passes the name of our application (myFirstPackage/EmployeeApp) to the java program. Notice that when identifying the application both the package and class file names are needed and are separated by a forward slash. The java program then passes the bytecode (i.e., the class file) to the Java interpreter (i.e., the JVM) for translation into machine language and execution. The final code should look like Figure A-18.

  • 7.  In the Notepad window, click File, then Save As.

Notice that the default file save type is a text document (i.e., an extension of .txt). However, this file needs to be saved as a batch file (i.e., a file extension of .bat).

  • 8.  Click the “Save as type” drop down menu button and click on All Files.

The “Save as type” will change to All Files.

  • 9.  In the File name field, enter Employee_Application.bat
  • 10.  Change the location to F: and click the Save button.
  • 11.  In the Notepad window, click File, and then Print.
  • 12.  At the Print window, click the Print button.

A hard copy of the file contents will be printed.

  • 13.  Verify that the file was saved by selecting My Computer and display the contents of the F: drive.

The window will display the Employee_Application.bat file (see Figure A-19).

Tutorial: Running a Java Application on the PC

Let’s run an application:

  • 1.  Click Start, All Programs, Accessories, and then Command Prompt.

If the Command Prompt option is not listing in the Accessories menu, you can click the Start button, and then in the “Search programs and files” text field, specify cmd and press Enter.

The “Command Prompt” window will be displayed with the computer’s default directory (in this case, C:Windowssystem32 as in Figure A-20). The default directory can be changed, therefore it can be different for every PC, and so don’t worry if yours doesn’t match Figure A-20.

The “Command Prompt” window allows users to issue Windows commands interactively. The cursor (the blinking underscore) indicates where the commands will appear when typed. To the left of the cursor, the default directory followed by a > is displayed. To execute a command, type the command and simply hit Enter. As mentioned earlier, everything you can do in Windows can be done with commands. We’ll use the dir command an example.

  • 2.  In the Command Prompt window, type dir, and press the Enter key.

Whoa, that was a lot of information!

The directory command (dir) displays the contents of a drive or directory (folder). In this case, we did not specify what directory to display so the default directory was used. Figure A-21 shows that all the files and subfolders contained in C:Windowssystem32 (the default directory), as well as, some information about each (date and time, size, etc) and totals information for the directory. Notice that this is similar to double-clicking on a folder icon in the My Computer window and displaying its contents (well, maybe not as pretty).

To run the Employee_Application batch file all you need to do is identify the file and press the Enter key. To identify a file specify where the file is located (the file’s path) and the file name.

  • 3.  Type f:Employee_Application and press Enter.

Because Employee_Application is a batch file, Windows knows to execute the commands contained within. Notice that the Command Prompt window (in Figure A-22) shows each of the three batch file commands and the result of the Java application.

This may seem like a lot of work (for very little result). However, most of the work was one time, setup tasks. To rerun the application you only have to execute the java command again. No environment variables have to be reset, nor do you have to export the application again. However, if the application were modified, the classes would have to be reexported.

Tutorial: Breaking the Code

The batch file is very important to the successful installation of a Java application. Unfortunately, batch file mistakes are not easily diagnosed. We will create some of the most common mistakes and show their effects on running the application.

  • 1.  Start a Command Prompt session.
  • 2.  Start Notepad and open Employee_Application.bat.
  • 3.  On the first line change path=f:jrein to path=f:jreBin (i.e., change the b to upper case).
  • 4.  Save the source code.
  • 5.  At the command prompt, type f:Employee_Application and press Enter.

The application worked! You are probably saying, “Hey, you said Java was case sensitive!” That’s still true. However, Windows is not case-sensitive. If you reference files called Employee, employee, or EMPLOYEE, Windows will find the same file.

  • 6.  On the second line change the f to c (i.e., change the classpath).
  • 7.  Save the source code, go to the command prompt, type f:Employee_Application and press Enter.

You will get the following (always frustrating) error message:

Exception in thread “main” java.lang.NoClassDefFoundError: myFirstPackage/EmployeeApp

The error was caused by an incorrect classpath. Let’s walk through what is happening. The java command tells the JVM to execute myFirstPackage/EmployeeApp. The JVM searches through all the folders in the classpath (C:) looking for the folder called myFirstPackage. Unfortunately, myFirstPackage is on the F: not the C:. (Note, the set classpath command was executed, Windows not only did not check to see C: had the class file, it doesn’t even check to see if the C: is a valid drive.) Because the application cannot be found, the JVM throws up its hands and issues the “No class found” message. This is a frustrating error to fix because the message does not provide any clues as to where the problem is. For example, this message is also generated if the application name is specified incorrectly in the java command. Let’s prove it.

  • 8.  On the second line change C: back to F:.
  • 9.  On the third line, delete the last p (i.e., change EmployeeApp to EmployeeAp).
  • 10.  Save the source code.
  • 11.  At the command prompt, type f:Employee_Application and press Enter.

Notice that the same error is generated, but the message says it cannot find EmployeeAp. Whenever you get the “No class found” message, try to remember that the JVM usually cannot find the class specified in the java command because of a simple typo in either the classpath or the application name.

  • 12.  On the third line, change EmployeeAp back to EmployeeApp.
  • 13.  On the first line, delete the e in jre (i.e., change path=f:jrein to path=f:jrin).
  • 14.  Save the source code, go to the command prompt, type f:Employee_Application and press Enter.

You will get the following annoying error message:

‘java’ is not recognized as an internal or external command, operable program or batch file.

(If you do not get this error, the System32 folder contains the java.exe file. Go to the folder, rename the file, and do step 14 again. Don’t forget to change the file name back to java after you are done with step 19.) This time the problem is with the path environment variable. Whenever you enter text at the command prompt, Window searches the directories in the path looking for a batch file, executable program file, or operating system command file with the same name as the text specified. In this case we specified an incorrect folder name (jr instead of jre) when we defined the path. Windows looked for the executable file called java (which contains the java command program) in the folders specified in the path. The file was not in any of those folders, so Windows could not find the java command (stored in the f:jre bin folder).

If you had specified jave instead of java in the third line, you would have gotten the same error but this time identifying jave as the unrecognized command.

  • 15.  In Notepad, click File, Print, and then the Print button to generate a hardcopy of the source code in the batch file.
  • 16.  On the first line, insert the e, and save the source code.

Just to emphasize how careful you need to be (or how picky computers are), we will create one last mistake.

  • 17.  On the first line, add two blank spaces to the end of the statement (i.e., change “path= f:jreBin” to “path=f:jreBin ”) and save the source code.
  • 18.  At the command prompt, type f:Employee_Application and press Enter.

You will get the “java command not recognized” error message again. Why? Because spaces are valid characters in a folder name, therefore a folder specified as “bin ” is not the same as a folder specified as “bin.” Yikes-a-hootie!! Isn’t programming fun?

  • 19.  Delete the two spaces, save the source code, close Notepad, and close the command prompt session.

Tutorial: Stopping a Runaway Application in Windows

There will be occasions where you will write and/or run an application that never ends or “freezes up” (does not respond to the keyboard or mouse). On these occasions, you will want to end the application. The Windows Task Manager allows you to do this. (The Task Manager also displays performance information about the computer hardware, as well as, all active applications and processes.)

There are several ways to display the Task Manager. For instance, you can start the command prompt, type taskmgr, and press Enter. Alternatively, you can press the Ctrl, Alt, Delete keys simultaneously, and display the Windows Security window. The Windows Security window has a Task Manager option. Ctrl-Alt-Delete is used to regain control when the entire computer or all the applications are not responding.

However, it’s easiest to simply right-click in an empty area of the task bar. The task bar is (usually) at the bottom of the screen and shows buttons for all of the applications that are currently running. You have probably clicked the task bar buttons to move between applications. However, right-clicking in an empty area anywhere to the right of the Start button, displays a shortcut menu and one of the options is the Start Task Manager.

  • 1.  Right-click in the far right of the Task bar.
  • 2.  Click the Start Task Manager option.

The Windows Task Manager frame will be display as in Figure A-23. In this example, there are twelve active applications and their names appear in the Applications view. (The applications would also appear in the task bar’s application tray. Within each task bar icon would be individual items that are displayed in the task manager in Figure A-23.)

Java applications are identified with the “steaming cup of coffee” icon. In Figure A-23, the application My First Frame is a Java application. To end an application, first select the application by clicking its name and then click the End Task button.

Then “End Program – My First Frame” dialogue box will be displayed with a message saying that the application is not responding (Figure A-24). Of course, you would click the End Now button.

If you go back to the Task Managers Application list, you will see that the application name has been removed as in Figure A-25. (Sometimes this may take a second or two.)

As the applications you write become more complex, you will run into unexpected results and problems (such as endless loops) that prevent the application from responding or stopping. Try to remember to use the Task Manager; it is your escape hatch from such problems.

Importing into RAD

Importing allows programmers to bring files from outside of the RAD workspace into a project. Java source code files can be imported, as well as, many other types of files (image, database, web page, etc.). To import, RAD simply requires that a project already exists. If an application were exported, how and what was exported has implications for importing. For example, earlier only myFirstPackage and the .class files were exported (i.e., the project, bin, and src folders and were not exported). If myFirstPackage and the .class files were imported, the application could not be run because RAD’s Java perspective does not provide access to the .class files. To import and access an application in the Java perspective the source files have to be imported. This means the source code has to be exported if you want to import.

An entire project can be exported and imported very easily. However, this makes running the application more complicated because the entire folder structure will be exported. Figure A-26 shows the folder structure for the .java and .class files if the whole project is exported. In addition, this takes up a lot of space.

In the real world, Java applications are usually exported and transported as JAR files. However, the project structure is not preserved and if the whole JAR file is imported, the source code is not put in the correct location within the project. To avoid this problem we need to specify that only myFirstPackage be created in NewProject/src when importing.

Let’s prove it.

Tutorial: Importing into RAD

Now let’s import into RAD:

  • 1.  Export all of MyFirstProject to the F: by selecting it in the Package Explorer then click File and Export.
  • 2.  At the Export window, expand Java, select JAR file, then click the Next button.
  • 3.  At the JAR Export window, click MyFirstProject’s checkbox twice to select the project and all its subfolders.

If you expand the tree and drill down into src/myFirstPackage, the .java files will appear checked in the right-hand pane. Even though all the folders, subfolders and java files are selected, the source code will not be exported. Exporting the source code must be explicitly specified.

  • 4.  At the JAR Export window, click the Export Java source files and resources checkbox (see Figure A-27).
  • 5.  In the JAR file text field, specify F:MyFirstProjectJAR and click the Finish button. (If you get a JAR export warnings window, just ignore it by clicking the OK button.)
  • 6.  Using My Computer verify that the jar file is on the F:.

Well that’s great that we have a jar file but how can you tell what is in it? How about importing it into a new project?

  • 7.  In RAD, create a Java project called NewProject.
  • 8.  In the Package Explorer, expand NewProject and click on the src folder.
  • 9.  Click File then Import and at the Import Window expand General and select Archive File.
  • 10.  Click Next and in the From archive file text field specify F:MyFirstProjectJAR.jar.
  • 11.  Expand the tree diagram, unselect everything except myFirstPackage (see Figure A-28), then click the Finish button

If you expand the src folder in the Package Explorer, myFirstPackage should appear and within myFirstPackage should be the two .java files Employee and EmployeeApp.

That seemed like a lot work. Let’s show how easy it is to import if the entire project is simply exported to the file system.

  • 12.  Delete NewProject and all of its content.
  • 13.  Create a Java project called NewProject.
  • 14.  In the Package Explorer, click on MyFirstProject, then File and Export.
  • 15.  Expand the General item, select File System and click the Next button.
  • 16.  At the Export window, click the Finish button.
  • 17.  Using My Computer verify a folder called MyFirstProject is on the F drive and that the .class and .java files are in the correct subfolders per Figure A-27.
  • 18.  Now the easy part, select NewProject in the Package Explore, click File then Import.
  • 19.  Specify File System as the source and click the Next button.
  • 20.  Specify F:MyFirstProject as the From directory, then in the tree click the MyFirstProject’s checkbox and then click Finish.
  • 21.  At the Question window, click the Yes To All button.

Looking in NewProject should show that the myFirstPackage folder and its contents were imported. You can confirm that the import was successful by running EmployeeApp.

The “problem” with exporting the entire project is that structure the holds the package with the .class files is more complicated than the Tutorial example (which simply exported the package). This means that the classpath value has to be changed to point to this new location rather than the F: drive. If you are using the bat file, it must be modified to issue the correct set classpath command.

Results of the Tutorial

Let’s check the results:

  1. A new Java project called NewProject.
  2. NewProjectsrcmyFirstPackage and F:MyFirstProjectsrcmyFirstPackage each have two source files.
  3. F:myFirstPackage and F:MyFirstProjectinmyFirstPackage each have two bytecode files.
  4. The JRE successfully installed and the Employee_Application.bat file created on the F: drive.
  5. Two printouts of the commands in the Employee_Application.bat file.

Review Questions

  1. What is the function of the JVM?
  2. Which are executable: java files, class files, or both?
  3. What does a batch file hold?
  4. What is the classpath?
  5. What is exporting?
  6. What is the relationship between source code, machine language, and bytecode?

Review Exercise

You will export the shipment application to the F: drive and create a batch file to set the system variables and run the application. Because all the setup work has already been done, you will see how relatively easy it is to install the application.

  1. Export the entire ReviewEx project (including the source code) to the F drive.
  2. Start notepad and open F:Employee_Application.bat.
  3. Save the file as F:Shipment_Application.bat. (This is a little tricky. If you are having problems, review the Creating a Batch File tutorial.)
  4. Because ShipmentApp is in a different location than EmployeeApp, change the set classpath command to specify the correct location.
  5. Change the java statement so that ShipmentApp in c2 is executed not EmployeeApp.

Results of the Review Exercise

The results are:

  1. The two shipment class files are stored in F: ReviewExinc2.
  2. The Shipment_Application.bat file is stored on the F: drive.

Check that the Exercise Was Done Correctly

Finally, let’s check it was done properly.

  1. Verify that on the F: the folders ReviewEx, bin, and c2 were created and that the two shipment class files are contained within c2.
  2. Start a Command Prompt session.
  3. Enter F:Shipment_Application.bat (or substitute the correct drive letter for your computer) and press Enter.
  4. Verify that the five shipment variables are displayed.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.50.156