On my Windows PC, why doesn’t my Applet reflect the changes of my program immediately?
If you are running Windows, this is probably due to the fact that the Java Applets are cached in your computer, which allows faster loading. During Applet development, however, you might want to follow the steps below to disable Java Applet caching.
Open the Windows Control Panel. You should see the Java Coffee Cup icon. Double click the icon to open the Java Control Panel.
In the Java Control Panel, select the General Tab.
In the General Tab, click Settings for Temporary Internet Files.
In the Temporary Files Settings window, uncheck the box next to the text, Keep temporary files on my computer.
Click OK twice to close the Temporary Files Settings and Java Control Panel windows. Close and restart the Web browser.
Why does my Applet work at home but does not work from the UH Web server?
Be sure the permissions of your .class
, .jar
, and .html
files allow the Web server to read them. Typically, this is done using the chmod
program.
$ ls -l -rw------- 1 yucheng uh 972 Aug 3 02:45 Behavior2$1.class -rw------- 1 yucheng uh 771 Aug 3 02:45 Behavior2$2.class -rw------- 1 yucheng uh 1147 Aug 3 02:45 Behavior2.class -rw------- 1 yucheng uh 217 Aug 3 02:45 Behavior2.html -rw------- 1 yucheng uh 2416 Aug 3 02:45 Behavior2.jar -rw------- 1 yucheng uh 1968 Aug 3 02:45 Behavior2.java $ chmod 644 Behavior2* $ ls -l -rw-r--r-- 1 yucheng uh 972 Aug 3 02:45 Behavior2$1.class -rw-r--r-- 1 yucheng uh 771 Aug 3 02:45 Behavior2$2.class -rw-r--r-- 1 yucheng uh 1147 Aug 3 02:45 Behavior2.class -rw-r--r-- 1 yucheng uh 217 Aug 3 02:45 Behavior2.html -rw-r--r-- 1 yucheng uh 2416 Aug 3 02:45 Behavior2.jar -rw-r--r-- 1 yucheng uh 1968 Aug 3 02:45 Behavior2.java
On my Mac, why doesn’t my Java Console not giving me any feedback when I ask for details?
Did you enable the Debugging options in the Java Preferences? The preferences are located in the Utilities folder in the Applications folder.
I found it helpful to turn on “Enable tracing”, “Enable logging”, and “Show applet lifecycle exceptions”. Without these options turned on, the Java Console won’t give you much information about what’s going on.
I also found it helpful to disable the Java cache, which is also located in the Java Preferences.
Why doesn't my Applet find my .class files? I used a package in my code.
If you use a package, then you need to place your .class file into a subdirectory that matches the name of the package. For example, if your package is “subdir” and the ./index.html file is in a directory called “dir” then the contents of “dir” should look like this:
./index.html ./subdir/Assignment.class
And the corresponding .html file would look something like this:
: <applet code="subdir.Assignment.class" width="450" height="100"> Your browser does not support Applets. </applet> :
But it's much easier to remove the package and keep your .class files next to your .html file.
./index.html ./Assignment.class
If you do want to use a package, then I recommend you place the class files into a .jar, keep the .jar file next to the .html file, and use the archive attribute as I described earlier in this tutorial.
For Assignment 1, what does it mean by “construct an internal data structure of a table representing a mapping between special characters and their escaped characters?”
In Java, data structures are implemented as objects. You need to decide what type of object to create that can store a mapping between special characters (e.g., #) and corresponding escaped characters (e.g., %23). For example, take a look at the Map<K,V>
interface from the java.util package
.
http://download.oracle.com/javase/6/docs/api/java/util/Map.html
For Assignment 1, I’m having trouble implementing the URL regular expression syntax parsing.
For this assignment, we do not need to write a URL parser. The Java runtime environment has already provided one. In other words, the regular expressions and grammar rules of URL syntax are implemented by the standard JRE, and we just need to use the appropriate Java object. Please check out the URL class in the java.lang
package.
http://download.oracle.com/javase/6/docs/api/java/net/URL.html
As we can see, a URL object can be constructed from a String. The class parses this string and provides accessor methods for the components of the URL. For example:
URL myURL = new URL("http://www2.hawaii.edu/~yucheng"); String myProtocol = myURL.getProtocol(); :
Then we could read the contents from this URL by opening an input stream. For example:
InputStream myStream = myURL.openStream(); :
If anything goes wrong during this procedure, such as failing to parse an invalid URL, a corresponding exception will be thrown. We will be able to catch any errors related to the URL syntax by handling these exceptions.
For Assignment 1, I was wondering if there was any other way to check if a string is a valid URL besides using the java.net.URL
constructor and waiting to see if it throws a MalformedURLException
.
The URL forms accepted by Java is a superset of the URL forms that we accept in this course. For example “ftp://a:b@c.d” is a valid URL that includes a user name (a) and password (b). But we don’t use that for this class according to the URL syntax reference provided on the course site.
Here’s another example: for something like “ftp:www”, Java recognizes it as a valid URL with “ftp” as the protocol and “www” as the relative path, and therefore no MalformedURLException
will be thrown. But if we were to look at the string returned by the .getHost
method, we would see that it did not parse a host name. In other words, we would not consider this URL as valid. So, we might need to look into the URL object, make sure it's absolute, has all the components, and so no. Overall, just make sure your application handles all exceptions gracefully when there’s a problem reading from a specified URL.
For Assignment 2, could you give me an example text output?
3\t2 1\t2\t0.7 1\t3\t1.2 ########## 3\t2 2\t3\t2.1 3\t1\t1.7
The output above indicates two graphs with the following configurations: