How to rewrite or convert C # code to Java code?

I am starting to write a client-server application using .net (C #) for both the client and server sides.

Unfortunately, my company refuses to pay for the Windows license on the server box, which means that I need to rewrite my code in Java or switch to the Mono method.

Is there a good way to translate C # code in Java? The server application did not use any specific .net function, only cross-language tools like Spring.net, Hibernate.net and log4net.

Thanks.

+4
source share
8 answers

I suggest building for Mono. You will come across a gray area, but overall it's great. However, if you want to build for Java, you can check out Grasshopper . This is a commercial product, but it claims to be capable of translating CIL (C # compiler output) into Java bytecodes.

+6
source

Possible solutions, direct translations of programs written in one language into another language, are usually considered bad ideas and trade; - especially if this transfer is performed automatically. Even when this is done by a β€œreal” programmer, translating the application line by line often leads to a less desirable end result, because each language has its own idioms, strengths and weaknesses, which require things to be done slightly differently.

However painful it may be, it is in your interests, and for those who need to support this application in order to rewrite it in Java, if your employer needs it.

+4
source

I only know another way. Dbo4 is developed in Java, and the C # version is automatically generated from java sources.

0
source

There is no good way. My recommendation is to get started with Java, or, as you said, use Mono.

0
source

Although I think the first mistake was to choose an implementation language without providing a suitable deployment environment, nothing can be done now. I would think that the Mono way would be better. The requirement to rewrite the code would only increase the cost of the project, especially if you already have good code written in C #. I personally try to avoid rewriting code whenever possible.

0
source

Java and C # are pretty close in syntax and semantics. The real problem is the small differences. They will bite you when you do not expect it.

0
source

Grasshopper is really the best solution at this time if licensing works for you (the free version has some significant limitations). This is entirely based on Mono class libraries (which are actually pretty good), but works on top of standard Java virtual machines. This is good because Java virtual machines, it seems to me, are usually faster and more stable than Mono. However, it has more drawbacks than Mono when it comes to form / graphics related APIs, however most of this has not been ported to Java from Mono VM.

In cases where this works, it can be great. Performance is sometimes even better than running the same code in MS VM on Windows. :)

0
source

I would say in terms of maintenance rewrite the code. This will lead to the initial cost of the project, but will be less time consuming later for those who look at the code. As in previous posters, everything automatic, like this, cannot work as well as a "real" programmer, and doing a line-by-line conversion will not help either. You do not want to release the code in the future, but this is hell for support.

0
source

Source: https://habr.com/ru/post/1276703/


All Articles