<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Depth-First: Demystifying Java Applets Part 3: Failing Gracefully When Your Users Don't Have Java</title>
    <link>http://depth-first.com/articles/2008/03/12/demystifying-java-applets-part-3-failing-gracefully-when-your-users-dont-have-java</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Walking the Web of Chemical Informatics</description>
    <item>
      <title>Demystifying Java Applets Part 3: Failing Gracefully When Your Users Don't Have Java</title>
      <description>&lt;p&gt;&lt;a href="http://flickr.com/photos/brrtha/2099065164/"&gt;&lt;img src="http://depth-first.com/demo/20080312/wipeout.jpg" align="right"&gt;&lt;/img&gt;&lt;/a&gt;Contrary to popular misconception, Java applets are a mature technology ideally suited for building highly interactive Web content. Although this hasn't always been the case, a lot has changed since Sun's introduction of Java over a decade ago. Previous articles in this series have discussed why &lt;a href="http://depth-first.com/articles/2008/02/20/demystifying-java-applets-part-1-cross-browser-standards-compliant-pure-html-deployment-using-the-object-tag"&gt;the object tag alone can and should be used to deploy applets&lt;/a&gt; and how &lt;a href="http://depth-first.com/articles/2008/03/10/demystifying-java-applets-part-2-dry-deployment-with-the-javay-method"&gt;using the Javay deployment method&lt;/a&gt; can make life easier if you do. This article will address one of the most important questions of all when using applets: what happens if your user doesn't have Java?&lt;/p&gt;

&lt;h4&gt;Assume Your Users Won't Have Java&lt;/h4&gt;

&lt;p&gt;Java is ubiquitous, but it's not universal. Some users simply won't have a Java Virtual Machine (JVM) installed at all on their systems. Some will have one, but it will be disabled. Still others may have been browsing the Web for years, never realizing that Microsoft &lt;a href="http://java.sun.com/j2se/1.4.2/docs/guide/deployment/deployment-guide/upgrade-guide/"&gt;installed a hopelessly obsolete JVM&lt;/a&gt; on their machines without their knowledge, rendering useless a large amount of Web content.&lt;/p&gt;

&lt;p&gt;Regardless of why they might not have the JVM your applet requires, assume that a good number of your users won't and plan accordingly.&lt;/p&gt;

&lt;p&gt;But how?&lt;/p&gt;

&lt;h4&gt;The Javay Method and Deployment Failsafes&lt;/h4&gt;

&lt;p&gt;&lt;a href="http://depth-first.com/articles/2008/03/10/demystifying-java-applets-part-2-dry-deployment-with-the-javay-method"&gt;The Javay method&lt;/a&gt; for applet deployment can be broken down into three main parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Using the HTML 4 &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag - period. Neither &lt;tt&gt;&amp;lt;applet&amp;gt;&lt;/tt&gt;, which is deprecated, nor &lt;tt&gt;&amp;lt;embed&amp;gt;&lt;/tt&gt;, which isn't even part of HTML, are needed any longer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using Microsoft's conditional comments to create an opening object tag that will work with its browsers, but keeping it DRY by re-using the rest of the tag.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Suppressing the ridiculous "Click to activate" message in IE 6/7 with &lt;a href="http://jactivating.sourceforge.net/en/"&gt;jActivating&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In contrast to other approaches, with the Javay method, we can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Know our applet will instantiate on all major browsers, and many niche browsers as well.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Work only with standards-compliant HTML from start to finish.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stop using &lt;tt&gt;document.write&lt;/tt&gt; to create tags, a method which unless properly trapped will silently fail without any indication of what's wrong when JavaScript is disabled or if the script fails for some other reason.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But perhaps the biggest advantages of the Javay method are the ones most often overlooked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It offers a cross-browser method to display failsafe content should Java be disabled or not installed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It provides a highly effective, cross-browser method for users to install Java directly from the page displaying the applet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;How the Failsafe Works&lt;/h4&gt;

&lt;p&gt;When modern browsers such as Firefox and Internet Explorer encounter an &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag requesting a plugin they don't understand, they do two very useful things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;They render any valid HTML appearing after the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag's child &lt;tt&gt;&amp;lt;param&amp;gt;&lt;/tt&gt; elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They prompt the user to install the correct plugin to view the content - without redirecting them to another page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These two behaviors give us everything we need to gracefully fail if the Java plugin is unavailable. When the Java plugin is installed and enabled, users see the applet as planned. When the Java plugin is either not installed or disabled, users see both a placeholder of our choosing and a prompt, created by the browser itself, offering to install the missing plugin.&lt;/p&gt;

&lt;p&gt;The &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag lets us take this even further. We can specify, down to the revision level, the exact version of Java needed to run an applet. If that requirement changes, all we need to do is change the &lt;tt&gt;&amp;lt;object&amp;gt;&lt;/tt&gt; tag and users will be prompted to upgrade their JVM the next time they see our applet - if necessary.&lt;/p&gt;

&lt;h4&gt;Live Demo&lt;/h4&gt;

&lt;p&gt;Here's my company's 2D chemical structure editor, &lt;a href="http://metamolecular.com/chemwriter"&gt;ChemWriter&lt;/a&gt;, deployed with the Javay method:&lt;/p&gt;

&lt;p&gt;&lt;!--[if IE]&gt;&lt;object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab#Version=1,4,0,0"
width="480" height="350"&gt;&lt;script&gt;/*&lt;![endif]--&gt;&lt;script type="text/javascript"&gt;/**/&lt;/script&gt;
&lt;!--[if !IE]&gt;&lt;!--&gt;
&lt;object type="application/x-java-applet;version=1.4.2" width="480" height="350"&gt;
&lt;!--&lt;![endif]--&gt;
  &lt;param name="code" value="com/metamolecular/chemwriter/applet/EditorApplet.class"&gt;
  &lt;param name="archive" value="/applets/chemwriter.jar"&gt;
  &lt;param name="persistState" value="false"&gt;
  &lt;param name="licenseKey" value="4BC4-3C59-3E7D-182B-92B7-2E68"&gt;
  &lt;a href="http://metamolecular.com/java/"&gt;
    &lt;img src="http://depth-first.com/demo/20080310/chemwriter_plugin.png" style="padding: 125.0px 190.0px 125.0px 190.0px; border: 1px dashed red;"/&gt;&lt;/a&gt;
&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;And here's what the failsafe code looks like when it's rendered:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://metamolecular.com/java/"&gt;
  &lt;img src="http://depth-first.com/demo/20080310/chemwriter_plugin.png" style="padding: 125.0px 190.0px 125.0px 190.0px; border: 1px dashed red;"/&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;One More Thing&lt;/h4&gt;

&lt;p&gt;We can take failsafes to yet another level, if we'd like. Let's say Joe comes to our site without the an installed Java plugin. Internet Explorer 6 informs him via a popup that Java is needed. Impatient to see the site's content, he closes the dialog. Without being redirected, Joe can see all of the site's content, except for the parts requiring Java, for which he sees a custom "Plugin Not Found" placeholder. Discovering that the site's content consists of highly-relevant information, he decides he wants to install the Java plugin after all. Clicking on placeholder image takes him to a Java installation page.&lt;/p&gt;

&lt;p&gt;Unlike other Java installation pages Joe may have seen, this one is specific to his browser, Internet Explorer 6.&lt;/p&gt;

&lt;p&gt;This approach work very well in practice. For example, my company's website, &lt;a href="http://metamolecular.com"&gt;metamolecular.com&lt;/a&gt; uses it. Try visiting the &lt;a href="http://metamolecular.com/java/"&gt;default Java installation page&lt;/a&gt;, and if your browser is included below, you'll be redirected to the browser-specific Java installation page:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://metamolecular.com/java"&gt;Default Page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://metamolecular.com/java/firefox"&gt;Firefox Page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://metamolecular.com/java/ie6"&gt;Internet Explorer 6 Page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://metamolecular.com/java/ie7"&gt;Internet Explorer 7 Page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://metamolecular.com/java/safari"&gt;Safari Page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More information can be found in &lt;a href="http://metamolecular.com/articles/chemwriter-deployment"&gt;this article on deploying ChemWriter&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Last Thoughts&lt;/h4&gt;

&lt;p&gt;Java applets gained a deserved reputation in the late '90s for being difficult to deploy, a view that's now worth reconsidering. Using some simple techniques, Web applications can fail gracefully if Java is unavailable and then take steps to quickly get users back on track.&lt;/p&gt;

&lt;p&gt;Getting software reliably and securely installed on any client system is difficult, especially on the open Web. But the Java plugin and the Javay deployment method make it about as straightforward as it can possibly be.&lt;/p&gt;

&lt;p&gt;It's time reconsider applets.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Image Credit: &lt;a href="http://flickr.com/photos/brrtha/"&gt;brrtha&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 12 Mar 2008 23:26:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:fb9fb0dc-5102-4259-92bf-09b1cc73e740</guid>
      <author>Rich Apodaca</author>
      <link>http://depth-first.com/articles/2008/03/12/demystifying-java-applets-part-3-failing-gracefully-when-your-users-dont-have-java</link>
      <category>Tools</category>
      <category>applet</category>
      <category>chemwriter</category>
      <category>deployment</category>
      <category>flashsatay</category>
      <category>jactivating</category>
      <category>java</category>
      <category>javay</category>
      <category>failsafe</category>
      <category>poka</category>
      <category>yoke</category>
    </item>
    <item>
      <title>"Demystifying Java Applets Part 3: Failing Gracefully When Your Users Don't Have Java" by Rich Apodaca</title>
      <description>&lt;p&gt;Delano, which platform/version? In OS X/FF 3b5, it works as expected.&lt;/p&gt;</description>
      <pubDate>Wed, 25 Jun 2008 09:28:53 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:32b92354-ab72-4408-913a-6b97e7aae2e4</guid>
      <link>http://depth-first.com/articles/2008/03/12/demystifying-java-applets-part-3-failing-gracefully-when-your-users-dont-have-java#comment-618</link>
    </item>
    <item>
      <title>"Demystifying Java Applets Part 3: Failing Gracefully When Your Users Don't Have Java" by Delano</title>
      <description>&lt;p&gt;Hey,
Seems like the demo applet doesn't work in ff3&lt;/p&gt;</description>
      <pubDate>Mon, 23 Jun 2008 09:12:57 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:74fb6638-bd60-4c56-93d2-da3bcceafb3d</guid>
      <link>http://depth-first.com/articles/2008/03/12/demystifying-java-applets-part-3-failing-gracefully-when-your-users-dont-have-java#comment-615</link>
    </item>
    <item>
      <title>"Demystifying Java Applets Part 3: Failing Gracefully When Your Users Don't Have Java" by Rich Apodaca</title>
      <description>&lt;p&gt;Wawrzek, good catch. Markdown gave me a stray tag. Try it now - it should work in IE7.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Apr 2008 08:49:31 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:f06bdab3-05e8-4614-97e8-0088b98ad1b9</guid>
      <link>http://depth-first.com/articles/2008/03/12/demystifying-java-applets-part-3-failing-gracefully-when-your-users-dont-have-java#comment-488</link>
    </item>
    <item>
      <title>"Demystifying Java Applets Part 3: Failing Gracefully When Your Users Don't Have Java" by Wawrzek</title>
      <description>&lt;p&gt;Seems that the demo applet doesn't work with IE7.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Apr 2008 05:33:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:61b3a709-505c-472e-97aa-35ff87575f8d</guid>
      <link>http://depth-first.com/articles/2008/03/12/demystifying-java-applets-part-3-failing-gracefully-when-your-users-dont-have-java#comment-487</link>
    </item>
  </channel>
</rss>
