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

ll350

macrumors member
Original poster
Oct 23, 2004
94
0
Chapel Hill, NC
OK, I'm taking Comp Sci classes at my university (Which requires everyone to have a laptop, but if it isn't an IBM, you get no tech support) Anyway, after struggling through my first couple of Java assignments, and then having Eclipse freeze up on too much for me to take, I went back to trying to use Xcode.

In all the other IDE's I worked with, I could define a main method in each class of a project, then I could go through and adjust the build/run settings to select which main method I wanted to execute. When I tried doing this in Xcode, I found that no matter what I tried, I couldn't create Two Java Tool Targets, and have each one compile and run different main methods. Basically I liked to write each class and include a main method for each so I could test them individually for debugging purposes.

NOW: Was the reason that I couldn't set up more than one separately executable Target because In a Java (Tool) Project I should only have one main method that executes?

Bear in mind that I'm a beginner, so the complexity of my programs to date encompasses enumerating strings passed as command line arguments.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
I'll dance around your question since I have no Java experience using XCode.

First, I would suggest you don't use an IDE as you learn initially. You won't get full exposure to all the "cool" command line java tools that way and it will help you understand fully what happens. Perhaps using a text editor with hooks into java,javac,jdb,javadoc, etc would be a better idea. Many have been suggested on these forums.

Second, usually a better approach to testing is to write separate standalone classes that will instantiate and test other classes - using inheritance as needed if you need to test protected/default methods. Using a framework such as JUnit can give you a more formal approach...

Good luck.
 

Prelude2Tragedy

macrumors regular
Apr 9, 2005
150
0
New Jersey
Well this isnt a yes or no and im not even sure if this will help, but im a CS major also and im taking a java class. Ive found that the program BlueJ is a pretty easy to use java environment and it works well on mac. Just another option for ya if you dont like using Xcode.
 

ll350

macrumors member
Original poster
Oct 23, 2004
94
0
Chapel Hill, NC
Thanks for the replies, I'll ask my professor when our fall break is over, but there seems to be a communication disconnect between us, everytime I ask a question, he doesn't seem to understand exactly what I asked. I guess that is what happens when you work for M$, yep he used to work for the evil empire.

And as far a BlueJ, I tried it out, but it seemed like it was way to simple for what I needed, since I was going to have to be importing and using other libraries, maybe I didn't give it enough of a chance.

An a related note, has anyone had trouble with JBuilder Foundation? I wrote one of my programs using it, but I couldn't get the debugger to work.
 

plinden

macrumors 601
Apr 8, 2004
4,029
142
This doesn't really help you, but I agree with not using an IDE until you're comfortable with command line coding.

With ant, JUnit and my own special "universal" (not really universal, but I need to make just minor changes for different projects) build.xml, I can create and test just about any project.

It's only when a project begins to get complex, with several hundred classes with multiple interdependencies that I turn to an IDE. And even then, it's usually only if I need to do refactoring.

If I were teaching Java, I would make learning how to use ant, JUnit and build.xml my first priority. I don't really think you can understand Java just by writing HelloWorld.java using Eclipse. But that's just me ...
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
ll350 said:
An a related note, has anyone had trouble with JBuilder Foundation? I wrote one of my programs using it, but I couldn't get the debugger to work.
<half rant>
I guess that was our point in suggesting that you NOT use an IDE.

An IDE will introduce problems (and complexity) you shouldn't have to worry about or have to pursue when initially learning a programming language. Don't let the tool get in the way early on until you have a solid understanding of the language (and its compiler). Some people take them for granted and then when problems arise, they get lost leading to lost hours which could have been better spent learning the language instead...

</half rant>
 

jalagl

macrumors 6502a
Jun 5, 2003
802
1
Costa Rica
Eclipse 3.1 + Ant

Get Eclipse 3.1 (did you try a previous release? The difference in performance between 3.0 and 3.1 is like night and day). It runs pretty well on my laptop, and the IDE is just so versatile and powerful, it'll be worth it that you learn it. I only needed to turn off the background compilation for an extra performance kick (I think it has to do with my laptop only having 512MB RAM).
As for buliding the application, it is worth it that you learn to use Ant. It has become the defacto standard for builds everywhere. If needed, you'll learn XML on the way, which is also worth it.
 

ll350

macrumors member
Original poster
Oct 23, 2004
94
0
Chapel Hill, NC
OK, well I think you guys are mostly right about not using an IDE, until you have a solid grasp of the language, However, this actually my second programing class, the first was "Introduction to Programing" where we learned pretty much just the syntax of the language, however I took that so long ago I probably forgot most of it. Now I'm taking "Foundations of Programming" So I guess this is the appropriate time to learn to use an IDE?

I've used IDE's before and the past, they've been helpful, I don't know why they won't cooperate with me now. The IDE we are supposed to use is Eclipse 3.1, which I tried, but couldn't get it to work. Then after I tried BlueJ, which told me to install Java 1.5, all of sudden Eclipse works. Except for the fact that it keep hanging up on my iBook 800 Mhz G4, 640 MBRAM, maybe I'll take jalagl's suggestion and give it another shot. I must admit that I was pretty impressed with Eclipse when I had it working.

But alot of the posters here have stated that using an IDE obscures your understanding of a language, and perhaps that is what occurred in my case. Which brings me back to my original yes or no question:

Should I only have one main() method in a simple project?

When the idea hit me it seemed to be so obvious all along, since there should only be one thing that a simple program does when you execute it, in fact maybe they went over it in my Introductory course and figured they didn't need to mention it again in the one I'm in now.

The only problem with this is, I've never had any problem writing a bunch of classes, each with their own main method that would either create an instance of it's class in main or access static data fields. Then I could go along in my project telling the IDE which class's main() to execute when I hit the "Run" button.

The only reason this question even came up, was because I couldn't make to different targets in an Xcode project that would run different main() methods depending on which target you set as the active target.

Eventually, by using the default class Xcode makes when you create a java project, as the class whose main() method is executed when I "Build and Go", I was able to do my programing assignment. I just imported all the other classes I had to write, and created instances of them in the main(), and that was that.

But I still want to know which approach is the correct way to do it.
 

gekko513

macrumors 603
Oct 16, 2003
6,301
1
There is no correct. There's just you. :)

I also use main methods all over the place to test my classes and I use Netbeans IDE.

If you want to use Xcode in a similar manner, I see no reason why your main main method can't just call MyClassUpForDebugging.main(args); as the first thing it does and then return. You'll have to comment and uncomment a line or two when you want to debug different classes, but I think it could be a possible work around.
 

Linkjeniero

macrumors 6502
Jan 6, 2005
255
0
ll350 said:
Should I only have one main() method in a simple project?

Yes.

You can have multiple mains and whatever you want for testing, as you've been told, but the project should only have one main when it's done (unless the project has a client and a server or something like that, but I wouldn't consider that so simple).
 

ll350

macrumors member
Original poster
Oct 23, 2004
94
0
Chapel Hill, NC
Thanks

Linkjeniero and gekko513, and everyone else, thanks for your responses. I guess we can consider this thread closed. I figured anyone on the programmers forums must get tired of n00bs always asking questions, so I had tried to make my question as succinct as possible. I think I'm going to use the rest of the weekend to go over all the questions I've had about our programing assignments, and then go see my Professor or the TA's during their office hours.

Thanks again for the help, BTW what ever happened to the macstudentdev blog? It hasn't been updated for over two months. Did the blogger just give up, or just been really busy?
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
ll350 said:
OK, well I think you guys are mostly right about not using an IDE, until you have a solid grasp of the language, However, this actually my second programing class, the first was "Introduction to Programing" where we learned pretty much just the syntax of the language, however I took that so long ago I probably forgot most of it. Now I'm taking "Foundations of Programming" So I guess this is the appropriate time to learn to use an IDE?

No! Don't use an IDE! I minored in compsci and I never used an IDE to write a class assignment. I use XCode and NetBeans on my own projects, but never on school work.

IDEs do too much for you, and most assignments are so simple there's no reason not to compile them and test them manually. Otherwise your IDE might do something you're not aware of, then when you turn your work in and somebody is compiling and running it without your IDE it doesn't work the same.

And there is absolutely no reason to need a debugger on homework assignments. Use printfs and walk through your code to understand what's going on.

If the teacher isn't showing you how to use the IDE and debugger, then you're also falling behind other students as you struggle to learn how to use them. Just don't use them. You can use XCode to write the java files, since the syntax coloring is nice, but compile and run all the files from Terminal.

Hate to be the curmudgeon here, but too many people want to jump in right away. Learn these things one at a time. If you want to learn more in your free time, then start your own project...write a checkers program in java and learn your IDE/debugging skills on *that* project -- not one you're getting graded on.
 

MarkCollette

macrumors 68000
Mar 6, 2003
1,559
36
Toronto, Canada
I've worked for years writing Java code, and also got a Computer Science degree. I agree with what people are saying about not using an IDE for school projects, at least for getting it to manage your compilation and execution. Why? Because your instructor won't have your same IDE. For every assignment, you should have a build script and an execute script, that you use, and that your instructor can use. If your instructor might use a different platform than you, then make sure you've made and tested scripts for their environment as well. Include a small Readme.txt file that explains the scripts, and includes your name and class info.

If you have multiple mains in several classes, then that's great. Simple make execute scripts for each of those.

Now, when you're done school, I recommend moving to using Ant to manage your builds instead of the adhoc scripts. I find that Ant is being mentionned more and more in job postings.

As well, you should probably start using CVS or SVN, right on your development computer, for code versionning. Check in frequently. When a bug pops up, you can easily do diffs against previous versions to see what you've changed that might have made the bug. Plus, you remove the possibility of accidently hosing all your files right before a deadline. Also, CVS and SVN show up in many job postings too.

IDEs are for great for speeding up tasks that experienced developers already know. If you're learning Java, then an IDE will only keep you from learning that stuff. Try to use a programming editor that does syntax highlighting, which will help you notice when you've forgotten to close braces or quotes, or have forgotten a semicolon, or other such beginner mistakes.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.