views:

4120

answers:

14

I'd like to create a basic "Hello World" style application for the IPhone using Java - can anyone tell me how?

+10  A: 

You can't code in Java for iPhone. The iPhone only supports C++/Cocoa.

flash
Correction: Objective-C/Cocoa (or, if you prefer, Objective-C++)
Ben Gottlieb
Yes that's wrong, it's Objective-C.
Iain
I read the slash as "or", not "with" - that is, I think he meant to say C++/Objective-C.
Sherm Pendley
Unless you Jailbreak...
Max Stewart
Or use XMLVM to translate Java to Objective-C
Ichorus
@Ichorus Didn't you hear, Steve Jobs banned all those converters ;). I don't know how they would know though.
Nathan Adams
+2  A: 

Short answer: you can't, Java isn't supported. Check out how to: http://developer.apple.com/iphone/
http://blogs.zdnet.com/Burnette/?p=338
Well, maybe it does support Java internally, but developers cannot use it yet. i

Steve
+8  A: 

Might want to check Alchemo for iphone never used it myself yet. It convert your CLDC 1.1 MIPD 2.0 code into native iPhone code. It even take care of the memory management.

pmlarocque
Didn't see your post before. Just removed mine and up-voted yours. The guys at innaworks are doing some rad things like this.
Feet
+1  A: 

As it stands right now, Java is not supported on the iPhone. You can use Objective C and then cross compile it into a Java application. Sun Microsystems is working with Apple to make the iphone java capable. As mentioned above Cocoa is the best language to use when developing applications for the iphone.

Dennis
Cocoa isn't a language. Objective-C is a language. Cocoa is a framework.
Sherm Pendley
A: 

Get on the Andriod train!

Its all java.

Google wrote the SDK (Googles VM, emulator, eclipse plugins and everything). Also when you develop an app for Andriod you get 70 percent of the profit.

OpenSource beats iPropriety everytime.

I was able to download it all and get a hello world app running out of the gate with the sdk very quickly.

mugafuga
Marked down. Irrelevant.
Rob Drimmie
I don't think this is irrelevant - upvote!
Iain
Yes this is RELEVANT its a way to code java on a new emerging phone technology and platform Rob!.. Are you some kind of google hater?
mugafuga
it is irrelevant, because it doesn't answer the question. The question is about developing on the iPhone.
Stimy
It IS relevant because it shows where he "can" do something on a phone that has virtually the same hardware as the iphone yet be able to do it in JAVA...... Just saying you can't do it doesn't help anyone.
mugafuga
Answering an entirely different question doesn't help anyone either. He asked about the real thing, not "a phone that has virtually the same hardware."
Sherm Pendley
It does help others who only know java and don't know cpp. Understanding that there are other options for their creative output is a good thing that "HELPS" people.I will not buckle to peer pressure on this one. My answer has value for some people who stumble upon this thread.
mugafuga
+5  A: 

There are 2 ways to develop for iPhone.

The best method is to use Objective-C and Cocoa.

The alternative is to create a web-based app with JavaScript which they can access through the iPhone browser (but this will only be available to users while connected to the web).

A good alternative if you want to create something similar in Java would be to target google's Android platform (e.g. the G1 handset)

Iain
+4  A: 

1) If you know J2ME, that is very easy. First you write the code.

2) Then download alcheMo for iPhone, contains translator to convert J2ME application source code to equivalent C++ source code for iPhone. alcheMo for iPhone is capable of converting J2ME applications utilizing an extensive subset of Java ME CLDC 1.1 and MIDP 2.0 (including touch screen support) and supports several JSR extension APIs including the JSR-256 mobile sensor API.

Agusti-N
+1  A: 

If you really want to develop java applications on an iPhone (or any other phone for that matter that supports some other language) you may be able to get the JVM (Java Virtual Machine) to work with C++/Cocoa (headers/wrappers) and then call your java code from C++ or through an interface to the JVM.

Although I'm not sure how much experience you have. Doing something like that would take some time and expertise, but I'm sure theres an interface for the JVM for C++ at least floating around somewhere that you could use in this fashion.

Dalin Seivewright
+5  A: 

I just stumbled upon this Google TechTalk video "Developing iPhone Applications using Java".

Nicolai Reuschling
+1  A: 

You can write the Java code and translate it to Objective-C using XMLVM.

Ichorus
+1  A: 

As has been said, Java is not officially supported. But if you absolutely must run Java, you can jailbreak your phone and run Java that way. I'm not going to provide instructions on Jailbreaking your phone, it is easy enough to google it.

Cydia, one of the applications/installers you install when you jailbreak, has a Java installer that you can use. It uses the JamVM, a small, lightweight JVM.

Through Cydia, you can also install some demo applications, including a sample HelloWorld console app. In addition, I have heard that people have gotten Jetty to work on the iPhone but have not tried it myself.

GUI development in Java on the iPhone is currently a work-in-progress. To find out more info, there is an iPhone-Java mailing list you can subscribe to. The Java layer is making native calls to the Objective-C layer and is not very Java-centric. You need to understand how to code in Objective-C to create a GUI.

Johann Zacharee
A: 

Finely I have not bought an iphone. That is why I cannot try any proposed solution. But Thanks a lot for each of you. I voted most of your answer.

TaintedLove
A: 

According to http://www.mono-project.com/Mono%3AIphone Mono has been ported to the iPhone and is available as a commercial product named MonoTouch. This might be a good way to get up and running quickly if you know C# but not Objective C.

Thorbjørn Ravn Andersen
A: 

if you jailbreak, you can use Cydia to find the java compiler, Jikes, and the required units, and you can write, compile and run on the iPhone. Of course, I would never, ever do that, as it breaks Apple's EULA :p

Michael