How can Java code be quickly converted to .NET (specifically, ASP.NET)? - java

Are there any tools available to simplify the conversion?
What percentage of Java code is converted exactly to .NET code by these tools?

You can try IKVM. Saxon, an extremely popular Java XQuery/XSLT engine by Michael Kay, uses IKVM.
IKVM.NET is an implementation of Java
for Mono and the Microsoft .NET
Framework. It includes the following
components:
* A Java Virtual Machine implemented in .NET
* A .NET implementation of the Java class libraries
* Tools that enable Java and .NET interoperability
http://www.ikvm.net/

You could try this one
http://mayaf.org/janett/
Janett translates Java syntax, constructs and calls to Java libraries to C# / .Net counterparts.

Java is roughly equivalent to c#, so translating to c# should be relatively straightforward.
The path from a Java webserver to ASP.NET is less clear.

You might try to the Java Language Conversion Assistant from Microsoft. I think they may have dropped support, but now ArtInSoft seems to have a related product:
http://www.artinsoft.com/pr_jlca.aspx
There's also Octopus from Remotesoft:
http://www.remotesoft.com/octopus/
The issue with porting from Java is usually not so much the language itself, which is pretty similar to C#, as it is the libraries.
Of course, a web app will present an additional layer of complexity. If the app doesn't have too much code at the page rendering phase, it shouldn't be very difficult. If the page is riddled with code, then you may be better off re-writing it than trying to port directly.

Have you considered using J#? It's no longer supported but if you're just trying to get onto a .NET language, that might be the fastest path.

Related

Python Integration with Java / C

I implemented most of my projects in C++ and python. However, we recently got a new database interface that I could only use Java to retrieve data.
I want to stay with my Python/C++ tools but I am wondering if there is a good solution to integrate Java to my Python application. I heard about Jython, but it is a different python implementation and I am concerned some of my C++ tools will not work well with it. Jpype seems simple but it hasn't been updated since 2011, so a little concerned with the compatiablity with the current python/java.
Is there a good solution to this? all opinions are welcomed.
gcj (gcc compiler for java) supports java 1.5 syntax (1.4 is working better on it) and therefore some Java programs may be compiled to native code. gcjh (or javah) can produce headers for java libraries, so you can write C extensions for python. Of course some libraries could not be compiled with gcj (like Apache Commons Logging) because of using com.sun packages. Did not updated from 2009.
There is another Java to native compiler, commercial Excelsior Jet (it's another JavaVM, it supports Java 1.6 and soon Java 1.7). They said linux-64bit version of their product will be available in 2013-Q4. But I didn't try it well, I don't know, are headers for compiled library can be produced.
There is a lot packages at pypi, like JCC (from PyLucene creator) or Py4J that can use Oracle JavaVM through JNI or sockets.
One way to do this is to write web services. A web service can accept an HTTP request, marshal it into a data request, pass that to a Java class that get the data out, map the quert results into a response of some kind, and send it back.
Any client that can send an HTTP request, accept the response and unmarshal it can interact with that service. They need not know that it's implemented in Java.
You pay the price of an extra network roundtrip to get the benefit of language interoperability.
There are ways of wrapping C/C++ out there, but I can't speak to them.
Integrating with Java, however, is wonderfully simple. There's a distribution of Python called Jython which actually runs on the JVM. Using Java libraries is intuitive and easy:
from java.io.util import *
and for the most part it just works (some caveats apply in terms of threaded/async stuff). I love Jython. We used Jpype for a few projects but even if it were still fully maintained I'd still choose Jython over it any day for this sort of project.

From JS to Java?

I know GWT beeing able to code in Java and translate the cope on compilation to JS.
What about the other way around? Is there something that can translate JS to Java code?
You may want to take a look at Rhino.
From their site:
Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users. It is embedded in J2SE 6 as the default Java scripting engine.
Aside from Rhino (by Mozilla) there is also Nashorn (by Oracle) (which btw. means "Rhino" in German), which is an official JS implementation in Java.
It will be available OpenSource with Java8 in 2013.

Converting a Java Web Application to .Net

What is the process involved with converting a Java web application to something like ASP.NET with Silverlight or alike?
I know many Java frameworks have been proted to .Net (either C# or VB.NET), but haven't really seen many web applications done. (I might be very wrong here)
I also know very little about Java programming but know C#, VB.NET and ASP.NET. I haven;t looked at silverlight yet but know what it can do to some extent. I do know though that Java syntax is very similar to that of C, C# and C++ as they all the the "{}" brackets and layed out similarly.
For arguments sake (just to get a handle and example) what would it take to convert something like Alfresco to a .NET type web app? Also, just want to add that I am not planning on doing it but want to know that if its even worth investing time in looking into Java applications to port to .NET.
Microsoft used to distribute a 'Java Language Conversion Wizard' to convert Java code into C# code, including substituting some of the common framework classes. It needs a lot of cleanup after the fact, but may be useful depending on what sort of code you're trying to convert. If you have access to the VS 2005 tools you should be able to install it.
Other than that, it's heavily dependent on how the code's structured. Finding a web framework that's similar to the Java framework used would probably be helpful. In many cases, I suspect it would be easier just to port the database and master page templates/stylesheets across and build the rest from scratch.
This page on MSDN might be useful: http://msdn.microsoft.com/en-us/gg715299.aspx.
It does a conceptual mapping of concepts in Java to concepts in .NET.
Regarding Giacomo's mention of the Java Language Conversion Assistant (JLCA), it is in fact retired and I wouldn't recommend relying too heavily on it. As he says there's quite a bit of cleanup to do but much of that depends on how you architected your app.

Is there any language other than Java that will work as ubiquitous on mobile?

I'm trying to write a rogue-like game for my blackberry and hopefully
any other phone that supports some sort of JVM.
Because I use Java in my job I'm looking to write the game in another language but I cannot find a language that will work on multiple phones.
Am I stuck with Java?
If you're programming for Android, you could for example use Scala, see Scala on Android. Scala compiles to Java bytecode. There are also other languages which can be compiled to Java bytecode; I don't know how well-suited they are for Android programming.
You could try to use another language for the Java platform. Unfortunately you'll be rather limited there as well, because J2ME is based on a rather ancient version of Java SE and most modern languages for the Java VM need either Java 5 or at least Java 1.4.
Lua runs very well on small devices (I use it on my handheld), but it is designed to be coupled into a C API. You may well have to write glue code yourself, which is easy, but if the official APIs are Java APIs and there is no C API, you'll be out of luck.
Actually C++ is pretty universally supported at this point. However you are completely stuck with Java for Blackberry.
Technically, I think the second (JavaME being first) most widely deployed runtime worldwide is Flash Lite.
Whether it would be a good idea to use it for your game development is another matter entirely of course.
Number three is Symbian OS C++ but that won't work on your Blackberry.

Advantages of using Rhino (mozilla's rhino)

I've been reading about Rhino as a useful way to implement JavaScript inside my Java code.
After reading for a while, searching in google and here, I couldn't find a real reason for which I would use JavaScript inside Java.
Could you point some real world advantages you find on using Rhino for a regular Java application?
Note that since Java 6, the scripting API is in the standard Java library - see the documentation of the package javax.script. The API in javax.script is an adapted version of Rhino. The scripting API supports not only JavaScript, but many other scripting languages.
See Java Scripting Programmer's Guide
The front page there mentions some reasons you might want to use scripting:
Application extension/customization: You can "externalize" parts of your application - like configuration scripts, business logic/rules and math expressions for financial applications.
"Command line" shells for applications -for debugging, runtime/deploy time configuration etc. Most applications have a web-based GUI configuaration tool these days. But sysadmins/deployers frequently prefer command line tools. Instead of inventing ad-hoc scripting language for that purpose, a "standard" scripting language can be used.
An example: You can script Oracle Weblogic using Python scripts, for example to configure your application server domain, to start or stop the server and to do other administration tasks.
Processing XML with Rhino and E4X is a joy compared to most of the Java XML APIs
You have existing JavaScript that "just works" and you don't want to re-write it. This can happen if you have some calculation or processing happening on the client side and move it to the server.
All kinds of neat caching and code loading tricks.
Your problem is better solved by a more dynamic language then Java.
List comprehensions ;)
The benefit of embedding a script language like javascript into your software is that you can offer others a way to write plugins for your software without giving the source code away.
A reason to write the whole app in another language is that you are able to write an app for a company which deploys it in their Java EE environment without having to learn Java.
We use JS (via Rhino) for a DSL in one of our products. It isn't a great DSL, but that is a fault of how we use JS, rather than Rhino.
If you considering to .Net also, I suggests to get along with Rhino.
Besides Java enviroments, rhino is one of the best performance interpreter on .NET environment (using IKVM). On the other hands, nashorn is very slow on .net.
Porting your own Rhino project to .NET is not so difficult.

Categories