I'd like to learn GWT, and I like the fact that it compiles to Javascript. My question is, how much of Java I can really use with GWT? My guess would be that limitations apply mostly for client side, while on the server side I should be able to make use of any existing Java library, right? Or, will I be only able to use a small subset , because of the compilation to Javascript thing?
What are it's limitations? I am interested in what it's not able to do, or things that require too many workarounds to implement. I need to know if learning GWT is a good choice for a possible freelance carrier in web development.
The GWT website has this documentation exactly to answer that question.
See the JRE emulation docs. Those are the supported out of the box emulated classes that you can use.
"Google Web Toolkit includes a library that emulates a subset of the Java runtime library. The list below shows the set of JRE packages, types and methods that GWT can translate automatically. Note that in some cases, only a subset of methods is supported for a given type."
You can also provide your own emulation for other classes using <super-source/> in your gwt.xml to point to a package that will provide replacement Java classes for those that can't be directly compiled to JavaScript.
Related
I want to create a mod for Minecraft, and I am aware it uses Java. I am currently learning JavaScript, and was wondering if I am able to use JavaScript for the SDK.
Yes and no.
Java is not Javascript...but a Java project can interpret Javascript
Java and Javascript are two completely different languages. However, there is a javascript interpreter created in Java, that you can plug in to java, called Rhino. However, although Rhino makes it easier to embed Javascript into your Java code, its not a simple drop in solution that would allow you to simply script what ever you want with out going through the effort of makin the proper connections. Definitely achievable, but you wont likely be able to start scripting without making that time investment to connect Java and Javascript.
Background story
The relationship between Javascript and Java is a rather shallow one. The similar name comes from a marketing plan back when it was being released by Netscape (which most developers ended up moving to the non-profit Mozilla). They made a deal with Sun (bought by Oracle) to share that similar name, but purely for marketing purposes.
Yes, it is possible to run JavaScript within a Java program, using the Rhino Javascript engine (for example).
However, this would not be a good way develop a Minecraft plugin / mod. None of your knowledge of the Javascript APIs would be relevant. Everything you did to interact with Minecraft would entail using Java classes and methods in the Java or Minecraft libraries.
My advice:
If your aim is to avoid learning Java ... don't be lazy. (You'll end up having to learn the Java APIs anyway. And learning another language will be good for you ... assuming you aspire to be a professional programmer.)
If your aim is to integrate some pre-existing Javascript code-base, it might work. But you might be better off porting the Javascript code to Java.
Sorry, Java and JavaScript are totally different languages. The "Java" in both of them was a marketing decision from ancient times.
They do share some of the same syntax that many languages share, however, so if you have learned JavaScript it might be a little easier to get started with Java. They are definitely NOT interchangeable, though.
Have a look at JDK1.6's ScriptEngine, the interface whose methods provide basic scripting functionality. Using these methods you can execute javascript. Numerous examples can be found on usage of this.
script support is avail from jdk 6 onwards:
reference link
However, this is not a full implementation of Rhino.
As I've recently started using JRuby, more specifically building Java applications using Ruby code, I've started using Java Libraries such as LWJGL and Slick.
I know JRuby changes Java method names to a more ruby-esque structure, my question is, is there any current way to generate Ruby documentation, either from source or by conversion of current documentation or even based on what JRuby exposes the methods themselves as?
At some point when JRuby 1.6.7 is out I plan on cleaning this really rough project for just such a thing:
https://github.com/enebo/noridoc
The intention is it will weave both Java and Ruby syntax together and give reasonable documentation for a Rubyist wanting to know all Ruby methods. In it's current form you should be able to generate a reasonable set of HTML docs of Java code showing you all ruby aliased methods. You will need to screw around with the javadoc comment.
Oh and we plan on making this tool available out of the box in JRuby once it is good enough to merge.
If I have implemented a Java Library (that offers certain functionality), could I transform this into a JavaScript library, such that the same functionality can be offered?
I know this may be an ask, but, I was wondering if there are frameworks existing that help in this?
No, in general this is not possible, Java and JavaScript are more or less completely different languages.
However there are a couple of Java to JavaScript translators that you can try. Java2Script is one such tool. Apparently the Google Web Toolkit (GWT) does this as well. Source.
While you could probably do some sort of conversion, it's important to note that Java and JavaScript, while similarly named, are not at all related. Unfortunately, I think you'll be hard pressed to find a framework or system that does a good job converting one to the other. :(
I have a Java application that runs on BlackBerry (JDE 4.5). I want to port this application to Android, and be able to maintain the 2 applications simultaneously. I may also want to port this application to other Java platforms (J2ME ?).
I understand that a good part of the code will have to be specific to each platform (UI and other stuff). But I also feel that a lot of the code could (should) be shared (domain related classes).
What is the best way to achieve this, and what are the pitfalls to avoid?
I have been able so far to create a JAR with all my shared classes, that I have been able to integrate into my BlackBerry application (using preverify and rapc). But:
The JAR is a J2SE library. How can I make sure that it will run (or even compile) on BlackBerry, Android or J2ME?
I am also using a JSON library targeting J2ME (https://github.com/upictec/org.json.me/). This library seems to make use of some kind of preprocessing directives (CLDC, see https://github.com/upictec/org.json.me/blob/master/src/main/java/org/json/me/JSONObject.java#L392). How can I use (or convert) this library using the right preprocessing definitions?
This is likely to be difficult:
As you have already identified, the UI code will have to be different for each platform.
There are major differences between Java SE / Android and Java ME-based platforms. For example, ME doesn't have the Collections framework, or the java.io or java.nio stacks.
It is hard to predict from the information you've provided, but there's a fair chance that you'll spend more time fighting the platform dependencies than you are saving by sharing the code-base.
These days, the biggest stumbling block to sharing code this way is that the BlackBerry VM and Android VM both support different versions of the Java language. BlackBerry uses a subset of Java 1.3, Android uses a subset of Java 1.5. (As an aside, neither platform implements a Java VM, both use their own VMs. Java is used as the programming language. Java bytecodes must be transformed to the appropriate native VM format before they can run on the platform.)
The biggest difference you will find as a library implementor is that the BlackBerry lacks the things that were introduced in 1.5, very important things like generics and enums. Even worse, the Collections classes are missing from the BlackBerry. It is unfortunate, but that is the way it has been for a long time now.
This means that to be truly portable you have to write to the lowest-common denominator, which means using (very) old-style classes like Hashtable and Vector, not having generics, rolling your own enums (as in the 1st edition of Effective Java) and so on.
Or you build two libraries, a modern version for Android and a stripped-down version (with just the bare stuff you need) for the BlackBerry.
Hard to say what`s right for you.
Rather than prepackage your shared library, I would consider sharing the library project and having it as a dependency in your mobile applications' build process. That would allow you to share the code base, but have it built by the appropriate builders for your target devices. With a bit of IDE magic and some attention to detail, you should be able to pick up errors before anything is shipped out.
Alternatively, set up your library project to use two separate builders to pick up errors. That would allow cleaner distribution, but you may run into problems trying to convince your IDE to treat the project as being device specific in order to identify problem areas.
It would be likely that you would end up supporting the lowest common denominator device (cough Blackberry), and forgoing the additional facilities of the more extensive Java implementation on Android.
Unfortunately the answer will be one of experimentation. Try it and see what happens.
The article Porting Android code to BlackBerry has some good detail on how to work with code shared between the two platforms.
it will be very difficult to create shared library for blackberry and android.
if you want simple method, create your application as web app.
using
phonegap with jQtouch
I am interested to create a drag-and-drop layout designer using only JavaScript, HTML and CSS. The designer will allow the user to drag the page elements from one place to another (something like Blogger's layout designer) to create a site layout. But I don't want to hand code everything in JavaScript, I would prefer to write my application in .NET (preferably) or Java and rely on a compiler to compile it to JavaScript and HTML.
What are the .NET or Java to JavaScript compilers that you have used and can recommend? For Java to JavaScript I know GWT is available. What about .NET to JavaScript? Microsoft did come out with Volta, but the project seems to be no longer available.
Look no further, you already mentioned GWT pick that!
It has a very good API and many good applications have use them.
Even JavaScript frameworks like http://extjs.com/ have GWT support.
I use it for an small JavaScript calendar recently.
To be honest, I don't really like JavaScript that much. Most of the times the errors are hard to track (specially for a non JavaScript guy as me) and the workarounds included some plug-ins for the explorer just to get exactly what a compiler should do. Catch silly error early.
In the other hand I'm very familiar with the Java Programming language, and many of the libraries (if not the most important) such as java.lang and java.util have been ported to GWT.
Plus, the guy who wrote relevant parts of java.util is the same behind GWT (google Joshua Bloch.)
Check out Nikhil Khotari's Script# project. It allows you to write C# code and compiles it to JavaScript.
Script# has already been mentioned. It hasn't been updated since August 2008.
Milescript is another, but also has seen very little for 6 months.
Extsharp for the Ext library. Adds Ext support for Script#
Javascript compiler to Java (going the wrong way for you)
Java to script Eclipse plugin
My issues with Script# (a known issue) is it doesn't support jQuery yet. However it comes with a very lightweight library to tie in with the .NET framework, in Nikhil's sscorlib.js file and ssfx.core.js files. And also has support for lots of other Javascript APIs (mostly Microsoft, seeing as he is in the ASP.NET team).
I'd love to see a Script# extension for jQuery (I'm thinking about writing it if it's easy enough). As it stands, most don't provide full compilation yet but they're certainly getting there.
Update: I wrote a small extension to enable JQuery support Script# a few months ago. The project can be found here.
I'm going to second the use of GWT. I've used it for several projects and, when used in combination with a modern editor like Eclipse or IDEA, it really makes the mess manageable.
It's important to note that not only does it allow you to write in Java and have that transformed into optimized and obfuscated Javascript it also comes with a substantial subset of the core Java API. In addition to this they provide lots of additional classes for doing things like parsing and working with JSON and XML and communicating with a server via asynchronous HTTP. You can check out the docs to get an idea of what else they offer.
Another feature that might be of special interest to you for implementing drag and drop functionality is it's integration with javascript libraries like Ext and scriptaculous. Either through pre-built interfaces or via JSNI
Also for Java there is J2S.
Java2Script (J2S) Pacemaker provides
an Eclipse Java to JavaScript compiler
plugin and an implementation of
JavaScript version of Eclipse Standard
Widget Toolkit (SWT) with other common
utilities, such as java.lang.* and
java.util.*. You can convert your
SWT-base Rich Client Platform (RCP)
into Rich Internet Application (RIA)
by Java2Script Pacemaker.
This means that if you use the SWT IDE (drag and drop) you can then convert the generated code to JS + HTML.
I wouldn't hand write any Javascript for UI. This can lead to maintenance disaster. jQuery is what I am using but I still wouldn't use it to write full UI Javascript code. ExtJS is also another good option if you plan to write in Javascript. In general what I am saying here is that it's so much easier to main in Java/C# than Javascript. Check out cappuccino framework and Atlas. Never used GWT. Script# is similar to GWT but for ASP.NET framework. Also depends on the requirement, if your site is public facing then RIA isn't a good option. It's all about which extreme end you pursuit (hand written and web standard, or RAD or libraries like jQuery/ExtJS as the middle option).
Check out Axial, a .NET to JavaScript converter that works well in ASP.NET. It supports WebForms, jQuery and canvas. It's not very mature, but it's worth a look.
http://jsc.sourceforge.net/ is a C# to JavaScript, Java, Flash and PHP compiler.
JscriptSuite offers another free .NET to Javascript compiler. There is a big difference to Saltarelle (jsc, SharpKit# etc.). Developer write down and debug only C# code (or any other .NET langauge), like in GWT. Javascript will be generated für deployment only.