Computer Science (CSCI) Department
College of Engineering, Computer Science, & Technology (ECST)

JETT Workshops
Java Basics

Fall 2004


Programming Environments

Exercise - compiling and executing an application from the command line

  • make yourself a new directory (folder) and enter it
  • right click and save this Java application source file into your new directory: HelloWorldApp.java

  • open a command window and change to your directory
    • start >>> programs >>> accessories >>> Command Prompt
    • type
      cd <your directory name>
      to switch to your directory (replace the <...> with your directory name)
  • check to see that the source file is there and named correctly
    • type
      dir
      to get a directory listing - you should see HelloWorldApp.java listed
  • compile the source
    • type
      javac HelloWorldApp.java
      to compile the source code
    • type
      dir
      
      
      to get a directory listing - you should see both HelloWorldApp.java, and HelloWorldApp.class
  • execute the program
    • type
      java HelloWorldApp
      to execute the program
    • you will see the output of the program appear in the command window

 

Exercise - compiling and executing an applet from the command line

  • right click and save this Java applet source file into your directory: HelloWorld.java
  • right click and save this HTML file into your directory: Hello.html

  • open a command window and change to your directory
    • start >>> programs >>> accessories >>> Command Prompt
    • type
      cd <your directory name>
      to switch to your directory (replace the <...> with your directory name)
  • check to see that the source file is there and named correctly
    • type
      dir
      to get a directory listing - you should see HelloWorld.java and Hello.html listed
  • compile the source
    • type
      javac HelloWorld.java
      to compile the source code
    • type
      dir
      
      to get a directory listing - you should now see HelloWorld.class in addition to the other two files
  • run the applet using appletviewer
    • type
      appletviewer Hello.html
      to run the applet
    • you will see an applet window pop up with the output in it

Exercise - using TextPad

  • start TextPad (it should be in your start menu)
  • open the Tools menu and note the three shortcuts defined at the bottom
  • open the File menu and Open HelloWorldApp.java
  • compile the Java source
    • type
      Ctrl+1
      to compile the source
  • bring the new window, Command Results, to the front
    • there were no errors, so it will say "Tool completed successfully"
  • execute the program
    • type
      Ctrl+2
      to execute the program
    • a command window will appear with the program output in it
  • see what happens when there is a compilation error
    • create an error by changing a word in the source file
    • for example, change "class" to "clas"
    • type Ctrl+1 to compile
    • bring the Command Results window to the front if necessary
    • note the error message
    • double click on the first line of the error (the line with the line number in it)
    • it will take you to that line in the source so you can fix it