Java Tips (memo)


In this page, I assume there is the next file which contains main method.

The package name is .

jar file



How to make a beep sound in Java.


How to make a program which can run in both as an applet and as an application.

There is a good utility class which is called com.sun.j3d.utils.applet.MainFrame in java3d. You can just new an applet and put it to the MainFrame for making an application. This code also works as an applet. Next is a sample code.

Can I handle an URL name or a file name transparently?

I found this information at Maeda Atusi's Java(tm)Tips. (In Japanese)

When you want to process both of a file name or an URL name transparently, the URL context helps you.

  URL context = new URL("file:" + new File(".").getAbsolutePath());
  URL url     = new URL(context, fileOrUrl);

In this case, the fileOrUrl is interpreted under the context. Then, you do not need to care a fileOrUrl is a filename or an URL.

  % java URLFile index.html
  url = file:/an/absolute/path/index.html
  protocol = file

  % java URLFile http://www/index.html
  url = http://www/index.html
  protocol = http

Copyright (C) 1997-2003 YAMAUCHI Hitoshi
Most recent update : :