Introduction To Java - MFC 158 G
Fall 2000
Week 1 Assignment -
Learning development environments - August 29, 2000 and September 5, 2000
Due Tuesday (7pm) September 12
Objectives:
-
To become familiar with the NT operating system and Solaris
Unix operating system for use as a Java programming environment and runtime
environment
-
To become familiar with editing, compiling and running
various types of Java programs.
-
To set up your own web area on UBUNIX for displaying your
Java applets.
-
Nothing to hand in for this assignment.
Obtain
all the source code for the lab
1.
On your UBUNIX account, create a directory called week1_lab
2.
Copy the lab files from
~fineberg/mfc158labs/week1 directory into your week1_lab directory
3.
You're now ready to compile the programs
Compiling
Java Programs (applications and applets)
Using Java
version 1.2
You
should run the latest version of Java (1.2).
You can test which version you're running by entering:
>
java -version
You
should see something like:
java
version "1.2.1"
Solaris
VM (build Solaris_JDK_1.2.1_03, native threads, sunwjit)
Compiling your
source code
To
do this, issue the javac (java compile) commands for each of the source files
(as shown below) :
Ø javac
Hello.java
Ø javac
HelloSwing.java
Ø javac
Helloapplet.java
(You must supply the .java extension)
This
will create java bytecode executables called Hello.class, Helloswing.class and
Helloapplet.class
Executing your
compiled code - a non-windowed Java application (character-based)
To
execute a Java application, at the command line type:
> java Hello
You
must NOT supply the file extension (which is actually .class)
You
should see a simple "hellooooooo" statement
Executing your
compiled code - a Windowed Java application (using the Swing library)
To
execute a Java application, at the command line type:
>
java HelloSwing (with the following conditions noted below)
-
If
running from a Windows (95/98/NT) machine (using the NT version of JDK) or a
Sun workstation (using the Solaris version of JDK), a windows stating
"hello Javaworld" will pop up.
-
If
running from a Windows (95/98/NT) machine and executing from a telnet window,
you must have the product Exceed running, so that your workstation can emulate
the behavior of a Sun workstation. This
will allow the Xwindow to be displayed (containing the message "hello
Javaworld"). We will review Exceed
during the Lab.
You
should see a pop-up window with a message "Hello Javaworld". Click OK to terminate it.
Executing your
compiled code - an Applet
We
execute applets by displaying HTML pages which reference the applets. We don't actually call applets up by
themselves. The file Helloapplet.html
has the necessary reference to the compiled program (Helloapplet.class).
Running
applets locally - not using a web browser
To
execute this Java applet, at the command line type:
>
appletviewer Helloapplet.html (with the following conditions noted below)
-
If
running from a Windows (95/98/NT) machine (using the NT version of JDK) or a
Sun workstation (using the Solaris version of JDK), a windows stating
"hello Javaworld" will pop up.
-
If
running from a Windows (95/98/NT) machine and executing from a telnet window,
you must have the product Exceed running, so that your workstation can emulate
the behavior of a Sun workstation. This
will allow the Xwindow to be displayed (containing the message "hello
Javaworld"). We will review Exceed
during the Lab.
You
should see a page full of Hello world statements.
Publishing and
running your Helloapplet applet on the internet
-
If
you haven't yet activated your own UB personal web page area, you can get the
information off the references section of the course URL at: http://www.buffalo.edu/~fineberg/mfc158
-
Copy
the files: Helloapplet.html and
Helloapplet.class over to your WWW root directory. This should be located on the UBUNIX cluster in the directory
~your_user_name/public_html
-
Make
sure the files have at least READ permission.
-
Check
by doing the command > ls -l
-
You
should see the permissions in the left margin
-
R
= read w = write x = execute
-
To
give the minimum security access, you can execute the CHMOD command by:
-
> chmod 744 Helloapplet.html
-
> chmod 744 Helloapplet.class
-
You
can now access the the applet using a browser, at the following URL:
www.buffalo.edu/~your_user_name/Helloapplet.html
Modifying code
-
modify
the wording of ("hello world", etc.) in your copy of the code to see
the changes take effect (use javac
to compile all types of applications)
-
easy
to use editors are: Xemacs or pico in
Unix. Wordpad in Windows.
-
You may need to stop and start
your browser to see the changes take effect!
Some browsers may have a cache set to not reload a page.
-
Modify
all three programs and rerun
Two important
notes about names of files and classes in programs:
1.
The source file name must be the same as the class name.
2.
Case sensitivity is used even when compiling under
Windows
95
or NT!!!!!