Is There an Effective Tool to Convert C# Code to Java Code

Looking for the Code Converter which converts C# to Java

Disclaimer: No tool is perfect.

However, if you still want to try then there are these converters available:

  • CS2J
  • JCLA : Convert Java-language code to C#
  • Grasshopper
  • CSharpJavaMerger
  • Tangible Software C# to Java Converter

Not a converter but a bridge between .NET and the JVM:

  • JNI4NetBridge

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

I'd suggest building for Mono. You'll run into some gray area, but overall it's great. However, if you want to build for Java, you might check out Grasshopper. It's a commercial product, but it claims to be able to translate CIL (the output of the C# compiler) to Java bytecodes.

How can I convert my short C# code to java

This should produce the same result:

import java.security.*;
import java.io.*;
import java.math.*;

private static String GetMd5Sum(String productIdentifier) throws UnsupportedEncodingException, NoSuchAlgorithmException {
byte[] bytesOfMessage = productIdentifier.getBytes("UTF-16LE");
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(bytesOfMessage);
BigInteger i = new BigInteger(1, digest);
return String.format("%1$032X", i);
}

This answer is based on this answer but changed to use UTF-16LE to match C#'s Encoding.Unicode.

Convert an c# Winforms Application to Java

There are some tools for converting codes but they are only working correctly with little code blocks. An entire project requires a different complier, framework, libraries etc.. So yes, you must redo the entire code only with little convertings with that tools. But I don't recommend that. They may split apart your code integrity.

Port C# Code to Java

I assume that the above struct is actually used to overlay (effectively) an array of bits as a byte array or an int array.

You can't do that in Java. Your choices are:

  • Model it as a byte array, and take the performance hit when you are doing indexed copying.
  • Model it as an int array, and use bit shifting and masking to do the byte-wise operations.
  • Use native code; i.e. code the encryption / decryption in C or C++ and use JNI or JNA or similar to call that code from Java.

You could also look at the IntBuffer or ByteBuffer classes. These are (IMO) unlikely improve performance for your encryption / decryption operations taken in isolation, but when you combine them with NIO I/O (as an alternative to old-school I/O + copying to / from arrays) you may get better performance.


But it is also worth pointing out that this all has the smell of premature optimization. I'd recommend writing the Java code the simplest way first, and worry about performance later .... if measurement tells you that it is a real concern.



Related Topics



Leave a reply



Submit