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

chadi

macrumors member
Original poster
Apr 20, 2007
74
7
Canada eh?
Good Evening,

I'm taking a course on Java programming and I was planning to use Xcode as my IDE. I am a bit worried though about the requirements of the course. Here is a blurb from my course materials:

Please note: all your assignments must be capable of compiling and running directly from the command line without project files (that is, using only .java and .class files). This is to ensure that the tutors can run programs whichever IDE has been used. jGRASP will meet this requirement. Some IDEs like JBuilder (also on the CD with the text) use additional project files, so should be avoided for this course. You are responsible for your learning how to use your IDE. Your tutor cannot support the range of IDEs in the market place.

Does Xcode use additional project files, I'm assuming it does because when I create a new java application I get a bunch of crap in the directory I saved it to...and is there a way to ensure that I get basic command line compiling compatibility?

Thanks in advance for your help,
Chad
 
I'm not too familiar with Xcode, however, I used to TA introductory computer science courses at the University of Washington and I have seen people use Xcode to create and compile their Java assignments. I assume that if Xcode creates project files that are necessary in order to organize your code into a notion of a "project," then it should either be possible to do away with such project files or to use Xcode in such a way that project files are not created. If you create a small Java program, take the .java file and compile it as you would using the terminal, does your program work? I would imagine that it would since it should be a valid .java file.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
The "crap" is just caches and indexes of your code to make building, debugging and editing faster in the IDE.

The kinds of apps you are likely to make in a CS class using Java won't be so unwieldy that you cannot build an executable from the command line.

You could always use any text editor for the source files and compile on the command line from the start. Smultron might be good for you (beginner). Xcode has gotten more and more obtuse as it has evolved with feature creep and simpler-is-better design methodology.
 

jsw

Moderator emeritus
Mar 16, 2004
22,910
44
Andover, MA
I think eclipse might be a better solution for you, as it handles Java better than Xcode.

However, as mentioned, none of your projects should be extensive enough to make it really matter which IDE you use. Just create a shell script to build the thing on occasion, just to be sure.

It'd be nice if they'd get you to use ant to build with, as eclipse will use ant files as well.
 

chadi

macrumors member
Original poster
Apr 20, 2007
74
7
Canada eh?
The last time I did a course like this I used jGrasp for Windows. It was a very boring / plain IDE that worked. My friend Patrick, who is much farther ahead with regards to programming then I am, swears by eclipse.

Since I'm new to the Mac world (Windows/Linux past) I thought I would try out Apples own IDE...

On that note, I figured out that I can just create a 'pure java' app from within Xcode and I don't end up with all the 'crap' ;) The only problem is the build / compile / etc; options are all greyed out.

When I try to go to the terminal and do a java filename.java I get the

'Exception in thread "main" java.lang.NoClassDefFoundError:

error. In windows it means you didn't install the SDK properly (usually relating to your class paths). Now since I got my mac I believe the only programmingish thing I installed was Xcode (did a full install). I don't recall downloading the java sdk...

So my two issues are

1) why can't I compile my basic (non-project) .java file in Xcode

2) Do I need to install some Java SDK that doesn't come with Xcode or OS X 'out of the box'.


Thanks,
Chad
 

garethlewis2

macrumors 6502
Dec 6, 2006
277
1
It should be an obvious error. It can't find a main method, which is the starting point of the entire Java program.

You don't install a JDK. Apple have supplied one as Sun MS don't support OS X.
 

chadi

macrumors member
Original poster
Apr 20, 2007
74
7
Canada eh?
It should be an obvious error. It can't find a main method, which is the starting point of the entire Java program.

You don't install a JDK. Apple have supplied one as Sun MS don't support OS X.

Ok, here is the code pasted below: It WILL NOT compile on the command line on my mac or on my linux box, but if I use Geany (very simple Linux IDE) it compiles and works just fine...the code is actually an example from the text book for the course.

I do remember getting the same error on my Windows box and had to install that Sun SDK and I THINK that solved it. At least I don't recall doing anything else.

Anyway, here is the code...please tell me why it's not finding main


import java.io.*;
public class NameDriver
{
static class Name
{
String first;
String last;
String middle;

public Name() throws IOException
{
BufferedReader in;
// Instantiate in using System.in
in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter first name: ");
first = in.readLine();
System.out.print("Enter last name: ");
last = in.readLine();
System.out.print("Enter middle initial: ");
middle = in.readLine();
}

public String firstLastFormat ()
{
return first + " " + last;
}

public String lastFirstMiddleFormat()
{
return last + "," + first + "," + middle + ".";
}
}

// Driver for testing Name Class
public static void main(String[] args) throws IOException
{
Name testName;
testName = new Name();
System.out.println("Name in first-last format is " + testName.firstLastFormat());
System.out.println("Name in last-first-initial format is " + testName.lastFirstMiddleFormat());
}
}


The error again if you are just tuning in and skipped over the other posts:

'Exception in thread "main" java.lang.NoClassDefFoundError:

Thanks,
Chad
 

cbougher

macrumors member
Oct 19, 2006
34
0
Atlanta, GA
I had no problem compiling your code as is. You will, however, get that error if the class you are trying to run can't be found in your class path. try using this command to run your program

java -classpath . NameDriver

that will force java to look in your current directory for the classes you are trying to run. You could also add this to your environment variable to avoid having to do it each time.
 

chadi

macrumors member
Original poster
Apr 20, 2007
74
7
Canada eh?
Did you make a project in XCode?

I just started a 'pure java file' instead of a whole project. I was trying to minimize the number of extra files created by the program so I can submit it easier.

I'm assuming if I create a project I can still just take the .java I write and send that to my tutor for marking?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.