|
|
how to run java and c++?
|
|
|
|
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status:
Offline
|
|
Hello! I'm taking Java and C++ classes this quarter and my instructors mentioned about the new macbooks having built in Java Environment (or something like that) and a C++ compiler (or I think he meant I can run C++ because the machine is UNIX based.. wow I'm lost there)
Anyway, my question is, how can I run the files? (compile c++ too)
I downloaded jEdit and TextWrangler so I have decent text editors. I don't know where to go from there.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
You'll need to get Xcode from developer.apple.com for C++ (it installs gcc). Then you can use g++ and javac to compile files from the terminal interface. Something along the lines of...
g++ mycplusplusfile.cpp -o aprogram
./aprogram
to compile "mycplusplusfile.cpp" into a program called aprogram, and then run it
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status:
Offline
|
|
Oh wow.. 923.2 MB!!
Okay, I'm downloading it now.
I'll report back my results once I finish installing xcode and running the my programs.
THANKS!!!!
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status:
Offline
|
|
I got it to work!!!
THANK YOU SO MUCH!!!
Now how can I test my Java codes?
Do I replace g++ with javac ?? same syntax?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
To use javac, you just give it the name of your Java source file as an argument. For instance, javac Something.java. It will create a file called (in this example) Something.class. You can then run that class file with java Something (note that you don't use the .class extension for the actual Java command).
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status:
Offline
|
|
It gives me this message:
Exception in thread "main" java.lang.NoSuchMethodError: main
when I input java MyFile
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Aug 2005
Location: fairbanks AK
Status:
Offline
|
|
Originally Posted by sarahmacbook7
It gives me this message:
Exception in thread "main" java.lang.NoSuchMethodError: main
when I input java MyFile
do you have a main function in your class?
Code:
public static void main (String args[]) {
}
(
Last edited by black bear theory; Jun 30, 2007 at 02:22 AM.
)
|
Earth First! we'll mine the other planets later.
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status:
Offline
|
|
Well, this is the sample code that we did.
public class Person
{
// single line comment
// instance fields
private String name;
private int height;
private char gender;
/**
* Creates a person given the name height and gender
*/
public Person(String theName, int theHeight, char theGender){
name = theName;
height = theHeight;
gender = theGender;
}
/**
* Prints the name height and gender of the Person
*/
public void speak() {
System.out.println(name);
System.out.println(height);
System.out.println(gender);
}
} it works alright when we run it in class
???
We use Windows and BlueJ by the way.
I think there's a Mac version for BlueJ but I want to know if I can use XCode instead.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Are you sure you aren't running some other class that's just using that one? There has to be a main function.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status:
Offline
|
|
Yeah, that's the code we wrote to test Java.
I'll download BlueJ and see if I get the same results I get when in school.
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status:
Offline
|
|
Yeah, it runs fine on BlueJ.
First I compile it. Then, the program prompts me to create an object and I have to input the Name, Height and Gender for that instance. Then I can view it on the terminal via method speak.
Hmm, I guess it just works on BlueJ.
I just wish I know how to run it using XCode.
Thanks for all the help. I'll stick with BlueJ since it works.
Thanks again for the help regarding C++!!!!
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I don't think you can "run it" using the standard Java tools. One class is not a Java program. BlueJ's console functionality, while handy, is a feature of that particular IDE, not how Java programs actually work.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status:
Offline
|
|
when I took java we didn't use Xcode, just terminal, and the syntax Chuckit described worked fine. There's nothing in your pasted code to indicate that it will prompt for info/creating the object. He's got to be right about there being other methods/parts of the program.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|