Skip to main content

Following URLs

Posted by daniel on August 25, 2003 at 6:49 AM PDT

In his latest blog entry URLs are your friend, James Gosling explains using URLs where you may have used other Java classes in the past.

Gosling provides two interesting examples. There are times when you are on the receiving end of a drag-and-drop from a file browser or a web browser and find yourself with a string instead of the object you may be expecting. Gosling's solution is:

to interpret them as other types. For example, if new File(s).exists() is true, I convert the file to a URL with new File(s).toURL(). If it doesn't look like a file, then I try new URL(s).openStream(). If this succeeds, then I use that URL as the data source. In either case, the data source looks like a URL.

His second example uses URLClassLoader to reference resources such as images that can live anywhere. He notes that a "Jar file is just a zipped archive of a bunch of files. Applying getResource to a URLClassLoader attached to a zip file returns a URL that, when opened, get's you to the file bundled as a component of the zip file."

I'm still getting my head around this approach. So far it feels much more like a cool technique than like a hack. I'm sure we can expect to see examples of this in future releases of Gosling's project for the presentation software huckster.

In today's featured Weblogs, Joshua Marinacci proposes a solution and a question in Swing Hack: Window Snapping. He creates a Component Listener that forces "windows to remain completely on screen and to snap to the screen edges". The flickering that results from his implementation leads him to believe that he isn't done yet. Stop by and give him a suggestion or two. Blogger Philip Brittan continues his Java vs .NET series with "Java is a language, .Net is not". He argues that "Java's language-specific solutions will isolate it" but does not make that parallel argument that .Net's platform specific solutions could isolate it.

In the Also Today section, we link to Chris Adamson's article on Making Media from Scratch. Chris continues his look at Quicktime for Java by creating a Quicktime movie that consists of a text track using Java calls. Tomorrow, the Java technology chat will focus on the next release of EJBs. Join the EJB 2.1 Specification chat August 26 at 11 AM PDT with spec lead Linda DeMichiel and Sun's lead architect for the implementation of the EJB2.1 container,Kenneth Saks.

From the Java Today News Page, news editor Steve Mallett, has gathered the following News Headlines .

Registered users can submit news items using our submission form. All submissions go through an editorial review before being posted to the site. You can also subscribe to the News RSS feed.

This blog is delivered weekdays as the Java Today RSS feed. Once this page is no longer featured as the front page of href=""> Java Today it will be archived at href=""> You can
access other past issues by changing the address appropriately.