Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Java to objective C [closed]

I'm trying to convert a Java code to Objective-C. The class below is the extension of TestCodeRequest. Wondering how to convert this to an objective C equivalent. I'm finding it a bit confusing because Java is statically typed, and configuration over convention. Whereas Objective-C is dynamically typed, and convention over configuration. I have a sample code below. Any small hint should be really great.

package com.TestCode.api;

import java.io.IOException;

import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;

import org.json.JSONObject;

public class Categories extends TestCodeRequest {

    public Categories(String apiKey, String apiSecret) {
            super(apiKey, apiSecret, "categories");
    }

    public Categories field(Object... fields) {
        super.field(fields);
        return this;
    }

    public JSONObject getCategories() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException {
        return this.get();
    }

    public Categories categoriesField(Object... fields) {
        return this.field(fields);
    }

}
like image 722
Siddharthan Asokan Avatar asked Aug 23 '13 16:08

Siddharthan Asokan


1 Answers

There are several good Java to Objective C translators. For code that simple, all of them should work. Where translators usually have a lot of trouble is translating calls to runtime libraries because of their divergent philosophies (especially in the area of look-and-feel and user interaction). To do a good job here, they need to go from syntax back to semantics, and this is extremely difficult for software to do.

Your phrase "Java is statically typed, and configuration over convention. Whereas Objective-C is dynamically typed, and convention over configuration" can't but refer to this. Specifically GUI development. This aspect of the languages is not intrinsic to them, but belongs to the libraries that developers usually employ, in many cases dependent on specific Operating Systems. So, we are probably not talking as much about converting Java to Objective C as of converting from a Swing look-and-feel and mode of interaction to an iOS one.

All considered, I'd recommend you to use automatic conversion tools as learning tools. You will see that the generated pieces of code (as they become more complex and/or incorporate user interfaces) even if they work, are not suitable for maintenance or further development and need to be re-coded if not redesigned. But again, as learning tools they are very useful.

  • Google J2ObjC
  • java2objc
  • JCGO This one converts to C. If the purpose is to have something working, this could be good enough. Not if the purpose is to learn Objective C in all its splendor.
like image 185
Mario Rossi Avatar answered Sep 30 '22 09:09

Mario Rossi