Spring 96 Java AQ
New NNFAQ!
- If the program we modify uses import java.awt.* and java.applet.*, do
we have to put in the class hierarchy everything that has java.awt.* and
java.applet.* or do we have to just put those that we use?
- Hierarchies come from inheritence - using the keyword extends to
create a new class from a previously defined class.
import is different from extends. When you import a class (import java.applet.Applet;) or collection of
classes (import java.awt.*;) you are just using previously
defined classes, not creating a new class from an old class.
- How do I make an array of objects in Java?
- When you make an array of objects, it is a 2 step process.
- create the array object:
TextField [] tf = new TextField[25];
- fill the array object with instances of the class it holds:
for (int i=0; i<25; i++)
tf[i] = new TextField;
Not-Necessarily-Frequently Asked Questions
- I have changed the "Hello World!" to "something else". I then compiled,
without error. Now when I go into Netscape and opened that address (of
the .html file), I still get "Hello World!"!!!!!! Why???
- When you recompile your java code and look at your page again, the
brouser does not reload the class file, just the html. So you have to
empty the cache before you can see the changes you made. Go to the
Options menu and choose Network Preferences... and then choose
the Cache page. Click on the Clear Disk Cache Now button. Then reload your
web page.
- I typed the code in exactly the way it was on the sheet/page/etc. but it won't compile. Is there something wrong with the compiler?
- Before calling CAEN or ITD about the compiler, check that you have capital letters where there are capital letters and small letters where there are small (Java is case sensitive),
be sure all your ( and { have matching ) and }, and be sure all your statements end with a ;
- Where exactly do i write the Java application, similar to the
Hello.java and the applet HelloApp.java applet?
- you can put your java code wherever you want to put it. If you
aren't sure where would be best for you, put it all in your
Public/html directory, along with your web page stuff, for now.
- I have put the location of the Java compiler and interpreter in my
path - what i have really done?
- You have just customized your UNIX computing environment. Your
path is a list of directories where UNIX searches for the commands
you type at the prompt. Your path is set up for you by the system
administrator when you get a UNIX computer account. You have added
a directory to that list. That means you don't have to type
/usr/contrib/java/java/bin/javac when you want to compile something -
you just type javac!
- How do I use the compiler?
- If you call your class MyName, then you must call your file
MyName.java. To compile your code, type
javac MyName.java
If it is an application, you run it with the interpreter which is called java.
java MyName
If it is an applet, you have to put it in a web page using the <applet>
tag (see the HTML wrapper example on the first assignment sheet) and then view
that web page using Netscape 2.0 (or greater).
- Were do i type the hello.java application and the helloApp.java applet
and where do i save it?
- Proly the easiest thing to do is to cd to your Public/html directory
and then edit a file using the name you want to call the file,
and then type in the code and save it. You can use any editor -
pico, vi, emacs, etc. are all fine. If you don't know how to edit in
UNIX talk to a counselor at one of the computing sites, or make an
appointment to see the professor or the TA.
- There is an error when running the HelloApp applet. I typed it exactly
as you gave us. Here is the error I get when I type java HelloApp:
In class HelloApp: void main(String argv[]) is not defined
- The java interpreter (java) is used to run java APPLICATIONS. If you want to
see your APPLET run, you have to embed the
applet in an html document (web page) using the <applet> tag, and
then look at the web page with Netscape 2.0 (or greater) or with appletviewer.
Last Updated by S.L Bartlett on 6/25/96