Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

abhishekit

macrumors 65816
Original poster
Nov 6, 2003
1,297
0
akron , ohio
I am trying to get started with java...using xcode..so i m a total beginner to java as well as xcode..can someone please give me simple steps how to compile n run a java program on xcode, as a standalone app..like this
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
when i open xcode, what should i select as new project..if i select java awt app, it makes a bunch of files..keeps indexing lot of .class files...and if i double click on .java file in that list...it already has a whole lot of code..
so can anyone please help....
thanks a lot...i wd really appreciate it
 
java, javac

the cli is your best friend :)

to start with, just use an app like SubEthaEdit, save the file, compile, run, etc. No need to use Xcode when you're just starting ;)
 
You do not want an AWT App (for this case). AWT = Abstract Window Toolkit. If you choose that you are building a cross-platform GUI application so XCode generates a lot of the boiler plate stuff for you. If you want a command line app the choose Java Tool (the last item in the Java templates for me).
 
Just choose Java AWT Applet

But they all do the hello world thing, so you can choose any way of doing Java and the world thing will be in there already. Read their code and see how it works.

EDIT: Might also want to look into doing it with Cocoa-Java, get the interface of Cocoa and code of Java. It makes making a gui program so easy because you can create the Java code from the interface you create in interface builder.
 
ARGGH dont use xcode. Its interface is really too slow and convoluted, especially for a basic Java programmer. I suggest trying Netbeans or Jext instead. Much better interfaces, though Netbeans kind of has a PC GUI look to it and accepts only PC functions (i.e.: its control-c to copy, not command/apple-c). Netbeans has some really neat functions, like red underlining of code that is incorrect and finding of braces that dont match up (makes it much easier to run a program knowing the basic problems such as syntax are taken care of precompilation). Jext is very simple and runs fast, though you need to compile from the terminal if you use it.

I suggest making a single folder for all your code for easy compiling. Put it in your documents folder and every time you need to compile from the terminal type:

cd /Users/(your user name)/Documents/(folder name)

Afterwards to compile type:
javac (file name).java

And to run the program after compiling:
java (filename)


Simple as that.


public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello world");
}
}
:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.