tags:

views:

102

answers:

2

In XCode, I saw the template for Java but I could not get the output of my program written in one of the Java templates (Java Application). Does Xcode supports Java compilation? If it supports it, should I add any thing to my program to run? It is just a "Hello World" program.

A: 

Xcode goes not include gcj, but some people have managed to add it. No guarantees that this can be used to create iPhone apps though.

Ignacio Vazquez-Abrams
+3  A: 

XCode does support Java development.

I'm not sure if you're asking for this specific to the iPhone - it's listed in the tags but not mentioned anywhere in your question. The iPhone only supports program development in Objective-C - to get a Java program to run on the iPhone you'd have to run it through a cross-compiler to turn your Java program into an Objective-C program. XMLVM is usually the cross-compiler mentioned in regards to this.

So, if you're developing a regular Java app that's going to run as a desktop or web app hosted on a Linux/Windows/Mac computer - XCode will do that. If you're trying to develop a Java app for the iPhone, you'll have to develop the app in Java (using XCode of otherwise), run it through a cross-compiler to produce an Objective-C program (not something that XCode does), and then deploy that to the iPhone.

Nate
Sorry, I did not mention. But it is not for iPhone. I want to just write programs in Java. Which template will be good for it ?
srikanth rongali
Don't overlook the examples in `/Developer/Examples/Java`.
trashgod
The 'Java Application' project type is for making desktop Java applications. The application produced from the template uses the `message` value in `resources/string.properties` to paint directly on the frame. You could change this value to `Hello World`, or you could do something a little more standard, like remove the `paint(Graphics g)` method and add another component in your `JFrame`'s constructor - something like `this.add(new JLabel("Hello World!"));`
Nate
Thank you. It is working.But I have some doubts. When new project is created, AboutBox.java, HelloWorld.java, PrefPane.java are three files in src. Helloworld is my program name. What is the meaning of AboutBox.java and PrefPane.java ?
srikanth rongali
`HelloWorld.java` is your main `JFrame` class. `AboutBox.java` is for the `JFrame` that pops up when you choose the '<MyProgramName>/About' menu item. `PrefPane.java` is for the `JFrame` that pops up when you choose the '<MyProgramName>/Preferences...' menu item.
Nate
Thank you very much.
srikanth rongali