Blogs

Google Guice 2.0 in Beta

Tagged:  

For those following dependency injection frameworks in Java, Google Guice has released its beta snapshot (stamped 2008-10-16) for Guice 2.0.

What's coming in Guice 2.0?

  • A tree-like structure for Injectors, i.e., an Injector can have children that inherit all of its bindings.
  • An introspection API: like reflection but for Guice bindings.
  • The ability to inject members of sets and maps using Multibinder and MapBinder respectively.
  • Private modules.
  • Pluggable type converters that convert constant string bindings to other types, i.e., Dates, URLs, etc.
  • And more...

The official word is now that Guice 2.0 will be released in Fall 2008. (The Id Software release schedule: it'll be done when it's done!)

JavaScript Support in Java 6 Update 10

Tagged:  

The minor release with major features, Java 6 Update 10 brought a host of improvements to the long-neglected Java applet. One of these improvements was better interoperability with JavaScript, which was delivered to the new Java plug-in in the form of LiveConnect technology. As Sun's entrant into the RIA race, JavaFX, comes closer to a 1.0 release, such interoperability is crucial to the success of this effort.

While it has always been possible (to a certain extent) to call between an applet and JavaScript running the same browser, LiveConnect vastly improves the technology by

  • Improving reliability. A number of bugs involving the stability of the browser when making JavaScript<-->Java calls have been fixed.
  • Improving performance. Dramatically better performance...always a good thing.
  • Making it more consistent across different browsers. Support for JavaScript interoperability was always a little better on Mozilla browsers, but now the functionality is more consistent across different browsers with the new plug-in.
  • Increasing the functionality. It's now possible to instantiate new Java objects from JavaScript, call methods on them, as well as reference third-party packages on all browsers.

Calling Java from JavaScript

The following code shows how to invoke methods on an applet through JavaScript:

Java:

package org.example;

public class MyApplet extends Applet {
     public String getMessage() {
          return "Hello World!";
     }
}

HTML/JavaScript:

<applet id="myApp" archive="helloworld.jar" code="org.example.MyApplet"/>

<script type="text/javascript">
     var msg = myApp.getMessage();
     alert(msg);
</script>

Public fields in the Java class can also be called from JavaScript, as well as static fields and methods. Due to a new synthetic keyword, Packages, that is now attached to every applet, it is now possible to instantiate/call methods on classes that are not applets. For example, if we add a new class in the org.example package,

package org.example;

public class MyNonApplet {
     public String getOtherMessage() {
          return "This is NOT a hello world!";
     }
}

we can now create an instance of this class from the JavaScript and do things with it. Using the example above, let's modify the script a little:

<script type="text/javascript">
     var other = new myApp.Packages.org.example.MyNonApplet();
     alert(other.getOtherMessage());
</script>

This opens up the intriguing possibility of accessing a rich set of Java APIs from client-side JavaScript. Take, for example, the ability to add SVG support in (ahem) the only major browser that does not support it*. With Apache Batik and the Java plug-in, full support of SVG in the browser--SVG JavaScript API and all--becomes a reality. (Batik 1.7, by the way, is one of the most compliant implementations of SVG. And SVG might just be a faster way into the web designer's heart than JavaFX, but I digress...)

Each time a call into an applet is made from JavaScript, it is handled by a worker thread that is associated with the applet (there is only one per applet).

Calling JavaScript from Java

All instances of JavaScript objects within Java code appear as instances of netscape.javascript.JSObject. There are essentially two ways of invoking JavaScript from Java:

  1. Calling the static JSObject.getWindow(Applet arg) method with the applet object passed in as an argument. This method returns a JSObject that represents the DOM Window. This JSObject can in turn be used to call() JavaScript functions or eval() JavaScript code. The API for JSObject is here.
  2. Add a method in your Java code that takes JSObject as a formal parameter. Communication can then be bootstrapped from the JavaScript side by calling this Java method and passing a JavaScript object as an argument. It's a little less convenient than option 1, but useful if some JavaScript code wants to delegate some work to the Java code.

Furthermore, you can actually modify the HTML DOM from the Java side using a common DOM API. For the purposes of compiling Java code written with references to JSObject, you would place the jre/lib/plugin.jar on your classpath. Note also that, since JavaScript is a single-threaded language, communication from Java to JavaScript is restricted to one thread at a time; so you should structure your code accordingly.

Other JVM Languages

Of course, the other interesting possibility is the idea of languages like Scala, JRuby, Groovy, Clojure, or Fan being able to run in the browser with support for JavaScript interaction. A truly sick mind (and you know who you are) might use the applet merely as a trojan horse in order to get his/her favorite language running in the browser. I'll leave it at that!

Sun's renewed interest in the applet--sparked in part by RIA and in no small way by the resurgence of alternative browsers--has opened a door many thought closed a long time ago. Interesting times, indeed.

* Even worse now that the Adobe SVG plug-in has been discontinued.

Sun Releases Java 6 Update 10

Tagged:  

Sun Microsystems has released Java 6 Update 10, the so-called "consumer JRE" because of its ability to be deployed in a lighter-weight footprint (the "Java Kernel" or the core JRE classes) and download other classes on the fly as needed. The move is considered a necessary precursor to Sun's push into the RIA (Rich Internet Applications) space, where the accumulated bulk of the JRE is considered a drawback to faster, easier end-user distribution. Many of the improvements in Java 6u10 also pave the way for the future release of JavaFX technologies.

The New Java Plug-In

The Java Kernel is the key to the "Next Generation Java Plug-In Technology" for web browsers, which makes its debut in Java 6 Update 10. The most significant improvement in the new Java plug-in is the ability to launch applets from Java Network Launch Protocol (JNLP) files. This allows Java applets to reuse some of the extensions which had been previously available only for JNLP/Java Web Start technology, including access to JavaFX runtime libraries, support for 3D graphics via OpenGL, persistent data storage, and local filesystem storage. Other improvements in the Next-Gen Plug-In include better Java to JavaScript interoperability, a unified deployment mechanism for JNLP and applets, multiple JRE version support, classloader caching, new parameter arguments to <applet>,<object>, and <embed> tags, as well as numerous small improvements to the reliability and usability of applets. A full list of the new features is here.

Java Quick Starter

Also new to Update 10 is the Java Quick Start service, which preloads portions of the JRE onto the system disk cache, substantially decreasing the startup time. It is turned on by default in Windows 2000 and XP systems, but turned off in Vista since Vista offers its own preloading mechanisms.

Nimbus Look and Feel

Update 10 also comes with a new Swing look and feel, Nimbus. Nimbus gives a much needed face-lift to some of the stock L&F's available in the base platform with a richer, more attractive set of widgets.

Other Items of Note

Patch in Place. Update 10 brings the ability to do a patch in place when updating the JRE/JDK, allowing the simple upgrading of your installation.

Direct3D Support. On Windows platforms, the Direct3D pipeline has been completely revamped, offering much-improved rendering of Swing or Java2D applications which rely on alpha compositing, gradients, arbitrary transformations, filtering and other more advanced 2D operations. This upgrade relies on hardware acceleration (video cards) as well as the DirectX 9c runtime.

A complete set of notes on the changes in Java 6 Update 10 is available here.

JS Strict Data Types - Released

We at Ajaxonomy are happy to announce the release of the first library in the Ajaxonomy Developer's Toolkit. The library is called JS Strict Data Types and attempts to provide a way to maintain strict data types in JavaScript. Strict data types are proposed in the next version of JavaScript, however it is hard to say when you will actually be able to use it in all browsers. So, JS Strict Data Types is an attempt to allow the use of strict data types now.

The library is very easy to use. Simply include the small 7K (uncompressed) js file in your web page or application and then you can start defining variable data types strictly through the methods used in the below example.

MyVar1 = new Int(12); //Creates an Integer variable MyVar2 = new Float(2.54); //Creates a Float variable MyVar3 = new String("Some Text"); //Creates a Sting variable MyVar4 = new Boolean(true); //Creates a Boolean variable

The library uses various methods to maintain the strict data type (if you choose not to use the methods in the library strict data types may not continue to be maintained). The below shows a few of the mathematical methods that are available in the library.

MyVar1.add(5); MyVar1.sub(2); MyVar1.mult(10); MyVar1.div(7);

Since there are quite a few methods that are used to guarantee that strict data types it is recommended that you read the documentation before using the library.

This beta 1.0 release of the library is released under the GNU Lesser GPL. So, it can be used for personal and commercial use. Because of this go ahead and use the library in other libraries or any JavaScript project.

You can see a demo page that uses the library and displays the results here.

You can download the library here.

You can go to the projects Google Code page here.

You can read the projects documentation here.

Learning the Yahoo! User Interface Library - Book

Tagged:  

I've been looking at a book from PACKT Publishing about Learning the Yahoo! User Interface Library. The book is one of the few good books available on the YUI. If you are like me you enjoy reading blogs for quicker reads, but for in-depth reads you find a traditional book better.

The book takes you from installing the YUI and and Code Placement through Ajax calls and Drag and Drop events. Learning the Yahoo! User Interface also takes you through debugging the YUI way and using content containers and tabs (just to name a few more topics).

Each chapter goes over a small example project about the topic of the chapter. For example Chapter 7 talks about navigation and AutoComplete with code for navigation options and a nice AutoComplete example. The book is well written and has an easy to follow format.

You can read the full table of contents here.

One thing that is really nice about books written by PACKT Publishing on an open source project is that they pay a royalty to the open source project. So, you not only get to learn about the open source project, but you also support it with the purchase of the book.

This book is a must for anybody that is interested in implementing a project with the YUI JavaScript library. I would recommend it for those of you that are new to YUI and even to those who have used it for a while.

You can purchase the book here (available in traditional and e-book formats).

If you want to see a fun application written with YUI check out World of Solitaire (watch out, you can spend quite a bit of time playing it!)

Day Two Summary @ The Ajax Experience

Tagged:  

The second day of The Ajax Experience is behind us and it was even better than the first. It all started off with a keynote by Brendan Eich as I described earlier. After that, I attended a session titled “Struts on Ajax: Retrofitting Struts with Ajax Taglibs” where my take-away was to not use Ajax Taglibs, ever. Then came the lightning rounds, which were a great way to get a wide variety of information in a short amount of time. After the lightning rounds, Microsoft had a keynote that covered Microsoft’s JavaScript developer tools, namely Visual Studio 2008 and Visual Web Developer 2008. There was also talk of the new IE8 developer toolbar, which is a great big step in the right direction for Microsoft. Strangely, the developer toolbar will be shipped with all instances of IE8. It includes features like:

  • DOM & CSS inspection
  • Live Editing
  • JavaScript debugger and profiler
  • Multiple Document Modes

I really enjoyed Joe Walker's "Advanced Web Application Security" session, where he covered a variety of security issues and complete solutions to help increase security. This is another great session to view once the videos are posted online.

Next up I attended back-to-back sessions by John Resig on Advanced jQuery and Visual Programming with JavaScript. These were two of the best sessions of the entire conference. Clear and concise lectures, chalk full of practical solutions and answers to complex problems.

The last session of the day was the "Ask the Experts Panel", moderated by Ajaxian.com co-founders, Ben Galbraith & Dion Almaer, featuring Brendan Eich, Douglas Crockford, John Resig, Joe Walker and Dylan Schiemann. There was some great discussion on JavaScript engines, Browsers, HTML5, ECMAScript, and more...

That's all for today! I'm looking forward to tomorrow for some more informative sessions.

Lightning Rounds at The Ajax Experience

Tagged:  

We had a great session today that was comprised of 10 “lightning rounds” each lasting about 5 minutes.

Topics included:

  1. Smushit.com – a web based tool that automates image optimization. You specify a URL, or batch upload images and smushit can greatly reduce the file size of your images without sacrificing any quality. A Firefox extension also exists to allow you to easily optimize the images on any page you visit.
  2. Adobe Dreamweaver CS4 – the latest web development tool from Adobe, which was just recently released. You can expect to see some great new features in this version, including:
    •    Workspace customization – coder, designer, compact preset workspaces
    •    JavaScript intellisense and validation, including advanced intellisense that works with any JavaScript library or custom JavaScript classes and objects.
    •    Live Code view – let’s you see changes to the document in real-time as you interact with it.
  3. Comet – discussed technique for Ajax push asynchronous message delivery from the server to the client
  4. Firebug. Enough said, if you don’t know what it is, go here.
  5. Making web apps faster – Steve Souders discussed manual vs. programmatic scripting to time web pages using Episodes, a proposed framework. Read more about Episodes.
  6. Hacking Netflix – Netflix API to be released soon (this week), more info will be available at:
  7. Interviewing JavaScript Gurus.
  8. 280 Slides / Objective-J , a strict superset of JavaScript
  9. shiftspace.org – client-side JS and interface
  10. milescript.org – new language that compiles to JavaScript, intended for large scale (enterprise) JavaScript solutions.

Day Two Begins at The Ajax Experience

Tagged:  

Tuesday morning here in Boston started off with a keynote by Brendan Eich, CTO of Mozilla and creator of JavaScript. The title of the session was “Faster than Light JavaScript”, where Brendan discussed JIT compilation of JavaScript in the browser and the performance gains we can expect to see in the future. In particular, a new JavaScript engine code-named “TraceMonkey”, based on the SpiderMonkey interpreter and the Tamarin-Tracing VM, is set to be released with an future version of Firefox.

Read more about TraceMonkey here

TraceMonkey is one of many current JavaScript engines, listed below:

  1. JavaScriptCore: The engine that powers Safari/WebKit (up until Safari 3.1).
  2. SquirrelFish: The engine used by Safari 4.0
  3. V8: The engine used by Google Chrome.
  4. SpiderMonkey: The engine that powers Firefox (up to, and including, Firefox 3.0).
  5. TraceMonkey: The engine that will power Firefox 3.1 and newer (currently in nightlies, but disabled by default).
  6. Futhark: The engine used in Opera 9.5 and newer.
  7. IE JScript: The engine that powers Internet Explorer.

John Resig wrote a good post earlier this month covering JavaScript performance in these engines, read it here.

Day One Summary @ The Ajax Experience

Tagged:  

As day one comes to an end, it's been a whirlwind of asynchronous requests, CSS Selectors, Chrome, performance and more as we flew through the Ajax Universe. We’ve seen some great comparisons between open source JavaScript frameworks, including the specific focus and goal of each framework that helps to differentiate them from the rest. We’ve also seen how frameworks are on a path of convergence, each with similar solutions to the same problems. However, the likelihood of a unification of the major frameworks is unlikely in the short term.

Of the three developer breakouts, I attended the jQuery sessions which were very insightful. I was surprised to see the growth jQuery has enjoyed over the last 4-6 months, but it’s not too surprising since it is an exceptional framework.

Another highlight of the day was Ben and Dion’s Ajax Universe session where they used created a script to sound a buzzer at random intervals so they would switch turns. This was hilarious and turned out to be a great idea. As they buzzed back and forth, they stepped through the progression of the web over the years, showing where we started and where we are today. Their slides and video should be posted online soon, just stay tuned to ajaxian.com.

Finally, we had a session titled “The Top 10 Cross-Browser Issues”. A panel of experts including Andrew Dupont (Prototype), Chris Heilmann (YUI), John Resig (jQuery), and Dylan Schiemann (Dojo) discussed how their respective frameworks handled browser issues. In particular, the discussion included the issue of browser user agent sniffing versus object/feature detection in order to create workarounds for browser issues. User agent sniffing has been the standard for all current libraries, but the next version of jQuery (1.3) will remove all browser sniffing and will rely solely on feature detection. John received some opposition from the other panelists about this approach, but was able to hold his ground and his vision of a more elegant approach for handling browser issues. John stressed that it is the responsibility of the JavaScript libraries to be good role models for coding practices and to encourage browser manufacturers to fix existing bugs instead of assuming that the developer community has already hacked around them.

The discussion continued around issues with the DOM API and the pain it can cause. Then we moved to a new topic: the influence JavaScript libraries have with the browser vendors (which seems to be getting better). The discussion was fast and insightful. I spoke with one of the staff here and was told that videos of the sessions will be posted online at some point. When they are posted, be sure to check out this session.

That’s all for today, it’s time to head to the Microsoft sponsored “Evening Event”!

Microsoft and Nokia adopt jQuery

Announced on the jQuery blog, and by John Resig here at the Ajax Experience, jQuery is being adopted by Microsoft and Nokia as part of their official development platform. Microsoft will distribute the framework with Visual Studio and will build UI widgets to run on top of jQuery. Nokia is looking to use jQuery to develop applications for their WebKit-based Web Run-Time. To make this news even sweeter, Microsoft and Nokia aren’t looking to make any modifications to jQuery (both in the form of code or licensing) - they plan to use it as-is. This is some very exciting news and we'd like to congratulate the jQuery team on this milestone!

Read the full post.

Syndicate content