PDA

View Full Version : Run simple java programs




steveca
Mar 24, 2007, 07:23 AM
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 :)



toddburch
Mar 24, 2007, 08:01 AM
Have you opened a New Project in XCode?

Osarkon
Mar 24, 2007, 08:40 AM
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.

steveca
Mar 24, 2007, 04:38 PM
thanks for the help guys... it works from the terminal like wonder :)

mlw1235
Mar 24, 2007, 06:03 PM
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
Mar 24, 2007, 08:49 PM
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
Mar 24, 2007, 08:50 PM
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
Mar 25, 2007, 11:39 AM
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
Mar 25, 2007, 03:23 PM
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
Mar 26, 2007, 12:08 AM
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
Mar 27, 2007, 01:05 PM
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.

pMay
Apr 6, 2007, 09:43 AM
I defenitly would use Eclipse to edit Java code

LisaQ
Apr 11, 2007, 05:49 PM
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
Apr 11, 2007, 06:32 PM
@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
Apr 13, 2007, 05:03 PM
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
Apr 14, 2007, 05:06 AM
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...