The Artima Developer Community
Sponsored Link

Articles Forum
Compiling Java to JavaScript

8 replies on 1 page. Most recent reply: Mar 8, 2007 11:32 PM by Badri nath

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Compiling Java to JavaScript Posted: Dec 21, 2006 8:30 PM
Reply to this message Reply
In this interview, Scott Blum said that writing Web applications in Java, and then automatically translating Java source code to JavaScript, lets you take advantage of Java developer tools and libraries. At the same time, he also said that JavaScript is a powerful language. What do you think of Blum's comments about JavaScript?

What do you think of this approach to creating JavaScript?

Leo Lipelis

Posts: 111
Nickname: aeoo
Registered: Apr, 2006

Re: Compiling Java to JavaScript Posted: Dec 21, 2006 10:09 PM
Reply to this message Reply
I'm a little skeptical about this approach. The issue is that with GWT what you debug is not what you deploy. Yes, Java is easier to debug, I agree...but the point easy Java debugging is kind of moot if you don't deploy Java. So the feature is also a problem.

I think Javascript is a nice enough language that's worth learning and using directly.

Also, I read somewhere that GWT test browser phones home to Google when you use it. Maybe now that it's open source someone can patch that out. But it's a little fishy in my opinion, if it's true.

In my experience, frameworks that depend heavily on code-generation are crappy, because they are using generation to hide some kind of flaw that should be addressed directly rather than with a tool. So, my feeling is that this approach is "guilty until proven innocent". So I think I'll let other people be the guinea pigs for this one.

GWT seems like a heavy-weight framework, with its own test browser, compiler, etc.... You really have to buy it wholesale, it seems. I prefer light-weight yet elegant and clever approaches that are transparent and KISS-compliant. Just because something is written in few lines of code and doesn't come with a compiler doesn't mean it's not powerful. It's all about the amount of thought behind it, not in the amount of code and tools that ships with it.

Leo Lipelis

Posts: 111
Nickname: aeoo
Registered: Apr, 2006

Re: Compiling Java to JavaScript Posted: Dec 21, 2006 10:56 PM
Reply to this message Reply
One more note --

I believe that the only time code generation should be used is when the source and target languages offer different abstraction levels. If the source and target language offer a similar abstraction level, then the intent of code generation more likely than not becomes to sweep something under the rug. And sweeping things under the rug is never good, imo.

It makes sense for compilers to translate high level languages into lower level ones. It also makes sense for decompilers to do the reverse. But if you're not jumping across abstraction levels, you really should not be generating any code, imo.

I don't hold to the above dogmatically/religiously, but when I hear "Java-to-Javascript compilation", then a red flag goes off in my mind.

Sandy McArthur

Posts: 2
Nickname: sandymac
Registered: Jun, 2006

Re: Compiling Java to JavaScript Posted: Dec 21, 2006 11:20 PM
Reply to this message Reply
Don't knock it until you've tried it. GWT is still a young product but what it does do it does very well.

As for phoning home, it does a version check. The version check provides about as much info as your browser's user agent (platform and version). You can see the source at:

Frank Silbermann

Posts: 40
Nickname: fsilber
Registered: Mar, 2006

Re: Compiling Java to JavaScript Posted: Dec 22, 2006 1:38 PM
Reply to this message Reply
Leo's concern about code generation reminds me of my early experiences with COBOL. Because of inherent insecurities in the language (e.g. no bounds checking on arrays), debugging sometimes required the ability to read assembly-language-oriented coredumps (write in COBOL but debug in assembly language). However, I do not have this problem with Java, even though the compiler is a code generator for the interpreted bytecode. So the appropriateness of the GWT's approach really depends on how well the abstraction was thought out.

Leo admits that it's valid to generate code from a higher abstraction level to a lower one. Though Javascript is indeed a high level language, the same cannot be said for XML, HTML and CSS -- which are key part of the browser's execution language. So code generation does seem to me to be the correct approach. There would be a value to this approach even if one doesn't care about AJAX. It has long been established that the abstraction facility offered by full object orientation with inheritance can facilitate code re-use. Browsers require HTML, which is NOT object-oriented. Webmasters deserve an object-oriented notation that eliminates the need to write in non-OO notations such as HTML, CSS and XML.

Instead of having the developer write in Java to generate the HTML, CSS, XML and client-side JavaScript, I suppose Google could have built tools that let the developer work in (equally high-level) server-side JavaScript. However, server-side JavaScript is much less popular than Java, so again I think they made the right choice.

Leo Lipelis

Posts: 111
Nickname: aeoo
Registered: Apr, 2006

Re: Compiling Java to JavaScript Posted: Dec 22, 2006 2:43 PM
Reply to this message Reply
Frank, I don't think they made a wrong choice, but I don't think it's right either. It's just *a* choice.

With GWT you cannot innovate client-side. Since all development happens on server side, for example, then the way a table widget looks is set by the GWT. You can't add features to it, because if you wanted to add features to client side widgets, you have to test them...guess where? On client side.

And a reply to the poster above:

If I am only allowed to have an opinion after trying something, then what will stop me from trying everything? And if I try everything, then I won't have time to deepen myself in any particular thing. A smart thing to do is not to try everything, but to try only those things that intuition tells you to try. So even before I try it, I evaluate it to see if I should try it. So, it's valid and correct to have an opinion before trying something.

Is it possible that I can be mistaken? Of course! But mistakes are good and should be encouraged. There is no shame in making a mistake at all. There is nothing good about being correct either.

Tali garsiel

Posts: 1
Nickname: talig
Registered: Dec, 2006

Re: Compiling Java to JavaScript Posted: Dec 23, 2006 12:30 PM
Reply to this message Reply
I'm a web developer for many years.
It seems to me , that it would be best if there was an IDE which provided the following:

1. A real good javascript support (the same you get with other languages , like eclipse for java)

2. Client side widgets pallete (dojo for instance) with real WISIWYG

3. An easy integration of your server side objects to your widgets

4. A "debug mode" and "production mode" (production mode will compress and optimize your javascript)

I think the place for browser specific code is inside the widgets , dojo , for instance does a beatiful job.

I think that making the whole suff to be in java is to extreme! I would much rather the aproach I suggested

Bril Pappin

Posts: 1
Nickname: brill
Registered: Jan, 2007

Re: Compiling Java to JavaScript Posted: Jan 23, 2007 1:24 AM
Reply to this message Reply
Very cool to be able to unit test my javascript code before it ever hits a browser.

My main complaint is that the tool-chain is very limited in it options (output for instance).

For instance, a Maven 2 plugin has been developed (can be found in the codehaus sandbox), although its not very mature... however because the compiler is so limited its very hard to get it to do things "The maven way"...

Badri nath

Posts: 1
Nickname: bnath
Registered: Mar, 2007

Re: Compiling Java to JavaScript Posted: Mar 8, 2007 11:32 PM
Reply to this message Reply
GWT converts java code to java script,
What would be the size of the page when we convert 5kb of java file, because the efficiency of page is always on the loading time.

Flat View: This topic has 8 replies on 1 page
Topic: The State of Swing Previous Topic   Next Topic Topic: Refactoring the EJB APIs

Sponsored Links


Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us