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

steveca

macrumors 6502
Original poster
Mar 9, 2005
256
0
Malta
Hello everyone...

I am very new to Java and programming in general. At university we use Windows and write Java code in a program called TextPad, that also caters for compiling and running the program. We still write very very basic code. The files, saved as *.java can be read from Xcode and it gives you the code.

Now... the problem is that i am not able to run these small programs. In TextPad we compile and then run but in :apple: XCode almost all the options under build etc are greyed out.

Please help... thanks :)
 

Osarkon

macrumors 68020
Aug 30, 2006
2,161
4
Wales
You could always do it through the terminal.

1. navigate to the folder where your java file is via the 'cd' command.
2. type in ' javac *.java' - this will compile all .java files in that directory.
3. type in 'java' then the name of the class that contains the Main.
 

mlw1235

macrumors 6502
Jul 16, 2004
270
0
Milwaukee, WI
hate to hijack this thread but....
Is there anyway you could do this from within XCode?
Either by making a full project or from just within the java editor?

It can be very frustrating to continously switch back to Terminal.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Simplest way is to do what toddburch suggest, ie create a new Java tool project in Xcode and call it whatever your main class is called. Then you can hit the run button and Xcode will compile and run it. The alternative is to reuse the same project but use a manifest file that specifies which is the main class.

b e n
 

Osarkon

macrumors 68020
Aug 30, 2006
2,161
4
Wales
You could install Eclipse.
http://www.eclipse.org/

It's cross-platform, free java development software, and you can run your programs from inside it. It also compiles on-the-fly so you know straight away if something is wrong and it'll give a good indication of what it is.

The interface can be daunting and takes getting used to, but once you get used to it, it does prove invaluable.
 

ryan

macrumors 6502
May 17, 2002
283
0
Denver, CO
You could install Eclipse.
http://www.eclipse.org/

Eclipse, along with IntelliJ, Netbeans, etc., should not be used by someone who is interested in learning Java or else they run the risk of learning the tool, not the language. Assuming the original poster is interested in learning Java, they really should stick to using the command line as much as possible and a simple editor such TextMate, TextWrangler, JEdit, etc.
 

Osarkon

macrumors 68020
Aug 30, 2006
2,161
4
Wales
Eclipse, along with IntelliJ, Netbeans, etc., should not be used by someone who is interested in learning Java or else they run the risk of learning the tool, not the language. Assuming the original poster is interested in learning Java, they really should stick to using the command line as much as possible and a simple editor such TextMate, TextWrangler, JEdit, etc.

Well in it's base form Eclipse does pretty much that. The fact you can install plug-ins to make things easier doesn't deter from the fact it's an extremely useful editor.

However I do see your point, I've only recently started using it, was using BlueJ beforehand when I started learning.
 

ryan

macrumors 6502
May 17, 2002
283
0
Denver, CO
Well in it's base form Eclipse does pretty much that. The fact you can install plug-ins to make things easier doesn't deter from the fact it's an extremely useful editor.

As someone who has been using Eclipse for close to 5 years I know how useful it can be. :)

Code completion/refactoring, dynamic class (re)loading, remote debugging, in-line documentation are all extremely useful features. But, I've seen far too many junior (and higher!) developers and students unable to write code if they don't have access to their favorite crutch of an IDE.


However I do see your point, I've only recently started using it, was using BlueJ beforehand when I started learning.

And I see you point, but Eclipse is far more than an editor. As I said above, if the original poster really wants to learn Java and not a tool they should really avoid using a full blown IDE.
 

cruzrojas

macrumors member
Mar 26, 2007
67
0
USA
Eclipse, along with IntelliJ, Netbeans, etc., should not be used by someone who is interested in learning Java or else they run the risk of learning the tool, not the language. Assuming the original poster is interested in learning Java, they really should stick to using the command line as much as possible and a simple editor such TextMate, TextWrangler, JEdit, etc.

I would say try using Emacs with Syntax Highlighting and a Terminal Window, once you feel comfortable in Emacs you will find yourself coding faster.
 

LisaQ

macrumors newbie
Apr 11, 2007
1
0
I am also a student learning Java. Eclipse is NOT the answer. I've installed it and it's WAY over my head. I cannot easily figure out how to open something, and once I did I have no idea how to run it. I can't figure out how to do anything with XCode, either, because every option in the menu seems to be mysteriously grayed out. My tutor recommended DrJava, which is exactly the sort of simplicity I need--but it won't run 1.5, and is therefore pretty useless to me. :(

Now, I have an assignment due tomorrow, and I have no way of compiling it or running it, let alone printing out the results for my professor. I don't want to learn how to use a program; I have enough to learn already.

Does anyone have a real answer for this?
 

pMay

macrumors member
Mar 24, 2007
30
0
@LisaQ: Well ... when you learn a programming language it comes to a point
where you HAVE TO learn to use some tools too. An IDE is one of those basic
tools. Maybe you should buy an Eclipse Book or look for some Tutorials in the
internet (Google)...
 

abcfob

macrumors newbie
Apr 10, 2007
5
0
Vi

I guess this shows how far back I go, but I actually, would recommend you look at vi. The best thing is should already be on your machine, just type vi. You'll want to google up some websites for the basics.

I currently use Eclipse, and it is a great tool, especially for Java. For writing complex java apps, its the best. In my opinion an integrated IDE (including XCode) is not really good for beginning programmers.

For one thing, it teaches programmers to be lazy, which is REALLY bad in the beginning stages of learning the language. I didn't even notice how lazy I got, until I had to do some coding outside of Eclipse. Using a manual text editor teaches respect for simple stupid mistakes like the missing semi-colon, missing paren, double quote, etc. While an IDE will make sure you never make this mistake, who knows when you have to fix someone else's code which is in some other IDE, or no IDE at all. Who knows if you have to do it over a terminal, meaning no IDE at all.

Since you're fairly fresh, I would say look into VI. Its a bit higher learning curve, than TextPad, or something of that sort, but its totally worth it. Its actually a good idea to learn it at this stage, since the code is easy, you can put more effort into learning VI. Once the code gets complicated, you won't want to be futzing around trying to learn VI.

When you get good at it, you'll be able to code much faster using the more sophisticated features, and of course the UNIX geeks would approve.
 

kiang

macrumors regular
Apr 8, 2007
129
0
I learned java using BlueJ, Eclipse and NetBeans, and I AM capable of creating a full java program, only using a text-editor.
so: just download netbeans...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.