May 23

Bob Brewin, CTO at Sun, on Spring

Java, Tech 6 Comments »

James Governor of RedMonk interviewed Bob Brewin at JavaOne on a bunch of topics.

I found it interesting that Bob seemed to sweat a little when James said that Spring Wins and that Sun needs to step it up (as BEA and Oracle have).

Bob didn’t really answer the question, but instead likened the situation to Hibernate “in the spirit of how things worked with Java persistence”.

That sounds like pushing Spring down a JPA / standards path… which would definitely be a win for Sun, on many ways. It doesn’t seem as easy a fit as JPA, since Spring is overarching and gets into so many APIs… to fix them.

May 21

Sun and Ajax

Ajax, Java, Tech 2 Comments »

After seeing the Gosling Outlines the Trouble With Ajax in a Sun feed, I glanced and found it funny to see NetNewsWire showing me:

  • Sample Ajax Components in Java Studio Creator
  • Using Ajax With Non-HTML Markup in JavaServer Faces
  • Gosling Outlines the Trouble With Ajax
  • Screencast Demo of the Java BluePrints Ajax Components
  • All About Ajax and Java Studio Creator
  • What Is Project jMaki?
  • Java Petstore 2.0 Reference Application
  • Ajax Impact News: Mix and match JavaScript widgets from different Ajax frameworks with jMaki
  • W3C Works on API Spec for HTTP Functionality
  • Giving jMaki a Whirl
  • Build Ajax-based Web Apps with Java Studio Creator (zip)
  • jMaki Google Ajax Search Component
  • jMaki Demo Screencast
  • Sun’s Tim Bray Discusses "AjaxBehaving Badly" and Other Misconceptions
  • Sun Joins the OpenAjax Alliance and Dojo Foundation
May 18

RubyFX Script Announced at RailsConf

Java, Ruby, Tech 18 Comments »

It has been a great couple of weeks for FX script lovers. First we have JavaFX Script at JavaOne, and then we have the new RubyFX Script announcement at RailsConf.

What is RubyFX Script?

Think of a declarative Ruby that will let you build rich UIs on top of Swing or Tk.

Examples

title_tracks = select :indexof => track + 1,  :from => album, :in => albums, track in album.tracks where track >< album.title

def factors(n)
select :from => i, :in => [1..n/2], :where => n % i >< 0;
end

x = %w{1 2 3}
insert :number => 10, :as => :first, :into => x; // yields [10,1,2,3]
insert :number => 6 :after x[. >< 2]; // yields [10,1,2,6,3]

This is just an alpha version. There is talk that the new version will add in python-like whitespace characteristics.

Congrats! :)

May 16

A Few Weeks Before JavaOne

Java, Tech 7 Comments »

… picture a room in Santa Clara, a few weeks before JavaOne …

  • Jonathan: “JavaOne is coming up. What do we have to announce?”
  • Rich: “Well, the open source piece is almost complete.”
  • J: “Ok, but that is a bit of an anti-climax.. ‘hey… we kinda did it’. What else?”
  • R: “Well, we should probably come out with something that puts forth our platform as a real competitor to Silverlight, Apollo, and the open Web”
  • J: “What do we have?”
  • R: “Hmm. This one guy has an interesting pet project”
  • J: “jMaki? Yeah, we can brand that as the Sun Ajax Framework. I mean, we ship the JDK with Rhino now, so JavaScript is finally… kinda JavaScript”
  • R: “I was actually thinking of another toy…. F3″
  • J: “Ah yeah, that is interesting tech. I like how <> is used instead of != which is so predictable and boring”
  • R: “We can combine it with SavaJe and make it seem like we have a single brand vision”
  • J: “Can we come up with a brand that fluffy and confusing?”
  • R: “Our lawyers thought JavaFX Script would be really confused with JavaScript”
  • J: “Ok, what can we demo?”
  • R: “How about porting a Flash example in 3 days, showing that you can do mouseovers?”
  • J: “Compelling. And noone will notice how slow the full J2SE is on the phones right?”
  • R: “I will make sure I stay on script and don’t make the poor girl in charge of the demo sweat”
  • J: “Great! We shouldn’t think about how JRuby and others can fit in with this should we?”
  • R: “Nah. It is better to send the message that although we have hired core JRuby members, and ship Rhino, we want to push a brand new language on people.”
  • J: “You have done a great job for the last year”
  • R: “You two. And so has the UN”
May 15

I’m a Ruby on Rails

Java, Ruby, Tech 5 Comments »

You know that the Mac ad campaign is doing well when you get parodies left right and center.

The latest is Rails vs. Java.

It is of course gratuitous and silly…. but it’s fun :)

May 14

Hiding your Ruby behind Java interfaces

Java, Ruby, Tech 6 Comments »

I often get side tracked seeing JRuby as just a cure for Rails deployment issues. Although it is huge to think of a fast Ruby container, and having access to JVM internals for management and such, JRuby also has a fantastic set of Java integration features.

This means that while you are in Java-land, you can actually hide Ruby implementations of features behind nice Java interfaces. Rob Harrop showed off some of this at his JRuby DSL talk at JavaOne last Friday.

Here is a simple example of having Java code doing some kind of calculation, and behind the scenes the implementation is in Ruby.

The pieces are:

  • Java client code that does the calculation
  • Factory to return the object that can do the calculation
  • Calculation interface
  • The Ruby object that does the work
  • The Ruby file that makes the object implement the interface

Java Client Code

Calculator c = CalculatorFactory.getCalculator();
String calculation = "1 + 3";
System.out.println("Calculate(" + calculation + ") = " +  c.calculate(calculation));

Calculation interface

public interface Calculator {
public String calculate(String calculation);
}

Calculator Factory

The factory loads up the Ruby code, and then munges the Ruby object to return it back to Java-land as the Calculator interface:

public static Calculator getCalculator() {
Ruby runtime = Ruby.getDefaultInstance();

try {
runtime.evalScript(getContents("rcalculator.rb"));
runtime.evalScript(getContents("makejcalculator.rb"));
} catch (Exception e) {
System.err.println(e.toString());
e.printStackTrace();
}

Object c = runtime.evalScript("RCalculator.new");
c = JavaEmbedUtils.rubyToJava(runtime, (IRubyObject) c, Calculator.class);
return (Calculator) c;
}

The magic is done in JavaEmbedUtils.rubyToJava(runtime, (IRubyObject) c, Calculator.class);.

Ruby implementation of Calculator

The Ruby implementation is simple:

class RCalculator
def calculate(s)
return eval(s).to_s
end
end

To make it implement Calculator we monkey patch it by also loading the makejcalculator.rb file:

require 'java'

class RCalculator
include Java::Calculator
end

You could obviously do this all at once, but this pattern can allow you to share the Ruby code, and you may have other Ruby that you can’t just hack on.

This pattern will be common, so having a java_implement RCalculator, Java::Calculator simple piece of meta-code is useful.

All in all, JRuby gives you everything you need to do as much of your business logic in Ruby, and never expose it. This gives me thoughts of working on a Java team and telling my team mates about the interfaces they can use, and writing the entire app in Ruby behind the scenes ;)

Apr 29

I am glad I am not a CSci prof

Java, Tech 9 Comments »

I bet some profs saw Java as a simple language to teach back in the day.

After seeing some of the generics hells that you can see in javadoc, we can also see a ’simple’ example of the future:

<R, T extends java.io.Closeable, throws E>
R with(T t, {T=>R throws E} block) throws E {
try {
return block.invoke(t);
} finally {
try { t.close(); } catch (IOException ex) {}
}
}

I am glad I don’t have to teach Java. I would be running to teach Scheme for data structures 101…. or Ruby/Python…. or Haskell/Erlang….

Apr 16

Running Ruby in the browser via script type=”text/ruby”

Ajax, Java, JavaScript, Open Source, Ruby, Tech 36 Comments »

I played around with getting Ruby to work in the browser while watching some cheesy TV this weekend.

I was able to get things slightly working, and put this work in progress up on Google Code here.

That link sends you to a page that will evaluate Ruby for you, both from a script tag, and from your own input.

If you take a look at the top of the file, you will see:

<script type="text/ruby">
#class Foo; def initialize; @foo = 'whee'; end; end; f = Foo.new; f
Time.now
</script>

This script is found by the Ruby in the browser system, and is run through JRuby via a little applet. The page takes the output at the end and throws it into the container HTML on the right.

You can also edit the text area at the bottom left and run your own Ruby code, and the output will be placed on the right too.

Now, this is just the first baby step to get to something feature full like:

<script type="text/ruby">
document.ready do |dom|
dom["table tr"] <<"<td>test</td>"
end
</script>

Just being able to run some Ruby doesn’t mean much. We need to give it rich support for the browser to be able to interact with the DOM and Ajax libraries to do cool things, using the power of Ruby.

So, there are a lot of TODOs here:

  • The applet is a download of JRuby complete, which is huge, and isn’t all needed. I need to work with the JRuby folk to produce a slimmed down applet version.
  • Come up with a solution that allows you to puts data out (maybe put that data in a div somewhere), and more importantly, talk to the DOM directly from Ruby. Since the applet can contain Ruby files themselves, we can create a Ruby module that lets you do DOM stuff, that becomes JavaScript which will be eval’d to run in the browser. Or, we just give direct access. I am still playing with what makes sense there
  • Only tested in Firefox. There are some known issues in Safari.
  • I am lazily using an applet tag instead of the magic object/embed stuff that would make this work in other places

Any direction make sense to you?

Apr 04

Web via MDA with JetBrains MPS

Java, Tech 4 Comments »

I have been watching the JetBrains MPS story for awhile, thinking that if someone can pull off MDA it would be JetBrains. And, Neal Ford keeps going on about it ;)

They did the smart thing and build a DSL builder that automatically gives you a nice IDE around your DSL.

A new demo screencast is out that shows webr which is a DSL way of building web sites in very short order indeed.

If I was going to write a book on it I would say “watch out Rails, MPS is going to kick arse”. Since I am not writing a book on it, I would say that it very interesting to watch and see. We are still some time out…. but I hope it reaches its potential.

Mar 19

Neal Gafter on Closures

Java, Tech 3 Comments »

I am still catching up on the activities around me and just found out that Neal Gafter is giving a talk on Closures in Java at the Silicon Valley JUG, tomorrow:

Dear SVJUG Members,

I very happy to announce that SVJUG has found it’s new home, Yes new home, there are few changes to our schedule.SVJUG meetings will be held on THIRD TUESDAYs of the month,instead of second wednesday.

SVJUG meetings will be held on Google Campus, instead of Netscape.atTunis Conference Room, Building 431600 Amphitheatre Parkway, Mountain View, CA 94043Special thanks to Neal Gafter, Google Inc for helping with the sponsorship. I will update the website with further logistics.

Also at the bottom of the message special Java One discount code for JUG members Looking forward for your continued support.Thanks,Venki Seshaadri

******* Begin SVJUG Annoucement **********
Meeting….: Silicon Valley Java Users Group (SVJUG)
Time…….: March 20,2007 (THIRD TUESDAY of each month)
Cost…….: Always FREE to all!
Topic……: Closures for JavaSpeaker….: Neal Gafter, Google Inc (http://www.google.com)
Description:We propose to add Closures  to the Java Programming Language. Closures simplify the use of APIs  that rely on the use of anonymous class instances, such as the concurrency  APIs and callbacks. More importantly, closures support control abstractions,  which are APIs that act as programmer-defined control constructs. This  talk describes the proposed language extension and its design rationale,  and shows how it will affect existing and future APIs
Speaker Bio:Neal Gafter is a software engineer and Java evangelist at Google. He was previously a senior staff engineer at Sun Microsystems, where he co-designed and implemented the Java language features in releases 1.4 through 5.0. Neal is coauthor of “Java Puzzlers: Traps, Pitfalls, and Corner Cases” (Addison Wesley, 2005). He was a member of the C++ Standards Committee and led the development of C and C++ compilers at Sun Microsystems, Microtec Research, and Texas Instruments. He holds a Ph.D. in computer science from the University of Rochester.
Agenda…..:18:30-19:00 Arrive & mingle with FoodDrinks & Snacks courtesy of — Google Inc 19:00-20:30 Presentation by Neal Gafter
Location…: Google, Inc.Tunis Conference Room, (Bldg. 43) 1600 Amphitheatre Parkway,Mountain View, CAMap available at http://svjug.org/Please enter from the
north side of the building, in the middle of the Google campus.

Time to show up and help push the direction of closures in the Java platform.