Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > how to run java and c++?

how to run java and c++?
Thread Tools
sarahmacbook7
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 29, 2007, 12:27 PM
 
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.
     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Jun 29, 2007, 12:51 PM
 
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
     
sarahmacbook7  (op)
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 29, 2007, 01:08 PM
 
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!!!!
     
sarahmacbook7  (op)
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 29, 2007, 04:46 PM
 
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?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 29, 2007, 04:58 PM
 
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'."
     
sarahmacbook7  (op)
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 29, 2007, 05:14 PM
 
It gives me this message:

Exception in thread "main" java.lang.NoSuchMethodError: main

when I input java MyFile
     
black bear theory
Grizzled Veteran
Join Date: Aug 2005
Location: fairbanks AK
Status: Offline
Reply With Quote
Jun 30, 2007, 02:12 AM
 
Originally Posted by sarahmacbook7 View Post
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.
     
sarahmacbook7  (op)
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 30, 2007, 11:52 AM
 
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.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 30, 2007, 12:02 PM
 
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'."
     
sarahmacbook7  (op)
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 30, 2007, 12:20 PM
 
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.
     
sarahmacbook7  (op)
Fresh-Faced Recruit
Join Date: Jun 2007
Location: Seattle, WA
Status: Offline
Reply With Quote
Jun 30, 2007, 12:41 PM
 
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++!!!!
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jun 30, 2007, 01:40 PM
 
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'."
     
andi*pandi
Moderator
Join Date: Jun 2000
Location: inside 128, north of 90
Status: Offline
Reply With Quote
Jun 30, 2007, 03:28 PM
 
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.
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:07 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,