Java Tips (memo)


Assumption

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

      topdir/package/name/prog.java
The package name is topdir.package.name .

jar file


javadoc



Programming


How to make a beep sound in Java.

      java.awt.Toolkit.getDefaultToolkit().beep();

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 : :