C# & Java conversion

This CSharpJavaMerger Framework is the work of Dr. Hongying Gu. Duplicated and adapted with her permission to promote CSharpJavaMerger.

This article is a part of CSharpJavaMerger Framework, an open source project. Join us now to make it better!

CSharpJavaMerger Framework is a research project from Dr. Hongying Gu in Zhejiang University. Dr. Gu developed the original concept and wrote the source code of the framework. When Dynamsoft started to develop Dynamsoft SCM Anywhere, we needed to target both Windows platform and other platforms. Our developers were highly familiar with C#, but not Java.  We needed a Java C# interoperability solution so we only needed to write our code in C#. We were lucky we came across Dr. Gu’s framework during our search. Dr. Gu’s framework turned out to be very helpful for our project.

With the permission of Dr. Hongying Gu, we are duplicating her project in this blog.

Welcome to the series of CSharpJavaMerger Framework, a free C# and Java conversion tool. The tool is used in our real world development of SCM Anywhere, a SCM tool with fully integrated version control, bug tracking and build automation. If you have any comments regarding C# and Java interoperability, feel free to send me an email.

  1. Introduction

  2. Download

  3. Get source code

  4. I’m a C# developer. How to use CSharpJavaMerger?

  5. I’m a Java developer. How to use CSharpJavaMerger?

  6. Architecture

  7. An example

  8. How to write C# code?

  9. How to write Java code?

  10. License

  11. Get involved

  • Pingback: Download | csharpjavamerger.org

  • Pingback: Using c # and Java code conversion tool (open source) CSharpJavaMerger Framework

  • Pingback: » I’m a C# developer. How to use CSharpJavaMerger?

  • jalpa

    convert this code in c#

    import java.util.*;
    import javax.activation.DataHandler;
    import javax.mail.*;
    import javax.mail.internet.*;

    public class ReadMultipartMail {

    public static void main(String args[]) throws Exception {

    String host = “192.168.10.205″;
    String username = “komal”;
    String passwoed = “komal”;

    Properties properties = System.getProperties();
    Session session = Session.getDefaultInstance(properties);

    Store store = session.getStore(”pop3″);
    store.connect(host, username, passwoed);

    Folder folder = store.getFolder(”inbox”);

    if (!folder.exists()) {
    System.out.println(”No INBOX…”);
    System.exit(0);
    }
    folder.open(Folder.READ_WRITE);
    Message[] msg = folder.getMessages();

    for (int i = 0; i < msg.length; i++) {
    System.out.println("———— Message " + (i + 1) + " ————");
    String from = InternetAddress.toString(msg[i].getFrom());
    if (from != null) {
    System.out.println("From: " + from);
    }

    String replyTo = InternetAddress.toString(
    msg[i].getReplyTo());
    if (replyTo != null) {
    System.out.println("Reply-to: " + replyTo);
    }
    String to = InternetAddress.toString(
    msg[i].getRecipients(Message.RecipientType.TO));
    if (to != null) {
    System.out.println("To: " + to);
    }

    String subject = msg[i].getSubject();
    if (subject != null) {
    System.out.println("Subject: " + subject);
    }
    Date sent = msg[i].getSentDate();
    if (sent != null) {
    System.out.println("Sent: " + sent);
    }

    System.out.println();
    System.out.println("Message : ");

    Multipart multipart = (Multipart) msg[i].getContent();

    for (int x = 0; x < multipart.getCount(); x++) {
    BodyPart bodyPart = multipart.getBodyPart(x);

    String disposition = bodyPart.getDisposition();

    if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT))) {
    System.out.println("Mail have some attachment : ");

    DataHandler handler = bodyPart.getDataHandler();
    System.out.println("file name : " + handler.getName());
    } else {
    System.out.println(bodyPart.getContent());
    }
    }
    System.out.println();
    }
    folder.close(true);
    store.close();
    }
    }

  • jalpa

    import java.util.*;
    import javax.activation.DataHandler;
    import javax.mail.*;
    import javax.mail.internet.*;

    public class ReadMultipartMail {

    public static void main(String args[]) throws Exception {

    String host = “192.168.10.205″;
    String username = “komal”;
    String passwoed = “komal”;

    Properties properties = System.getProperties();
    Session session = Session.getDefaultInstance(properties);

    Store store = session.getStore(“pop3″);
    store.connect(host, username, passwoed);

    Folder folder = store.getFolder(“inbox”);

    if (!folder.exists()) {
    System.out.println(“No INBOX…”);
    System.exit(0);
    }
    folder.open(Folder.READ_WRITE);
    Message[] msg = folder.getMessages();

    for (int i = 0; i < msg.length; i++) {
    System.out.println("———— Message " + (i + 1) + " ————");
    String from = InternetAddress.toString(msg[i].getFrom());
    if (from != null) {
    System.out.println("From: " + from);
    }

    String replyTo = InternetAddress.toString(
    msg[i].getReplyTo());
    if (replyTo != null) {
    System.out.println("Reply-to: " + replyTo);
    }
    String to = InternetAddress.toString(
    msg[i].getRecipients(Message.RecipientType.TO));
    if (to != null) {
    System.out.println("To: " + to);
    }

    String subject = msg[i].getSubject();
    if (subject != null) {
    System.out.println("Subject: " + subject);
    }
    Date sent = msg[i].getSentDate();
    if (sent != null) {
    System.out.println("Sent: " + sent);
    }

    System.out.println();
    System.out.println("Message : ");

    Multipart multipart = (Multipart) msg[i].getContent();

    for (int x = 0; x < multipart.getCount(); x++) {
    BodyPart bodyPart = multipart.getBodyPart(x);

    String disposition = bodyPart.getDisposition();

    if (disposition != null && (disposition.equals(BodyPart.ATTACHMENT))) {
    System.out.println("Mail have some attachment : ");

    DataHandler handler = bodyPart.getDataHandler();
    System.out.println("file name : " + handler.getName());
    } else {
    System.out.println(bodyPart.getContent());
    }
    }
    System.out.println();
    }
    folder.close(true);
    store.close();
    }
    }

  • http://www.theinterviewsuccess.com/ sunilkumar

    Good Tutorial indeed. Thanks for posting.

  • Pingback: CSharpJavaMerger Framework To Convert Between Java And C# « Jasper Blog

  • Pingback: [Java] Achieve interoperability between C# and Java with - DotA Forums

  • Pingback: Achieve interoperability between C# and Java with CSharpJavaMerger - BizHat Forums

  • Pingback: A free C#-Java conversion tool - CodeCall Programming Forum