Coding C++ and Java

Joined
Oct 30, 2009
Messages
136
Reaction score
0
Points
16
Location
The Milky Way
Your Mac's Specs
iMac Core i5 2.66GHz - RAM 4GB - OS X Snow Leopard
Hi Guys

I am a university student, and we are currently learning how to program in C++ and Java.

How can I Program Java and C++ Code on my iMac ? What do I need ? Are there settings that need to be played with ?

let's assume I have a file called { mycode.java } how can I run that code ?

I would greatly appreciate any help.

Thank You.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
The JDK should be pre-installed. Open up Terminal and type the following (assuming the java code is found in mycode.java):
Code:
javac <directory where mycode java file is>/mycode.java
Press enter and that will compile your code. Then type the following to run it:
Code:
java <dir where mycode class file is>/mycode
Note that when running java to run the class, there is no extension.

As for C++, install the Xcode dev tools off of the install discs (I think it's disc 1) or get them from the Apple developer site.
 
OP
Ciwan
Joined
Oct 30, 2009
Messages
136
Reaction score
0
Points
16
Location
The Milky Way
Your Mac's Specs
iMac Core i5 2.66GHz - RAM 4GB - OS X Snow Leopard
Will the JDK be the latest version ?

Thanks
 
OP
Ciwan
Joined
Oct 30, 2009
Messages
136
Reaction score
0
Points
16
Location
The Milky Way
Your Mac's Specs
iMac Core i5 2.66GHz - RAM 4GB - OS X Snow Leopard
I can't find anything called Development Tools !

There is a program called { XCode 3.2.4 and iOS SDK 4.1 } which I have downloaded.

Though I'm not sure if that is what I was suppose to download !

Also there is a link to Developer Downloads, and once I click that I get a long list of stuff, but none of them is { XCode Development Tools }

I'm stuck :\
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Xcode = the developer tools. If there was any confusion, that was my fault.

I have Java 1.6.0_20 on my machine. You can always check yours by executing "java -version" at the CLI. That will give you the version of the Java runtime and I assume that the JDK would be the same version.
 
OP
Ciwan
Joined
Oct 30, 2009
Messages
136
Reaction score
0
Points
16
Location
The Milky Way
Your Mac's Specs
iMac Core i5 2.66GHz - RAM 4GB - OS X Snow Leopard
Thanks vansmith

Just to clarify, as I have already mentioned, I have downloaded the { XCode 3.2.4 and iOS SDK 4.1 } And I understand you've said the XCode is the Developer Tools, but mine has iOS SDK with it !!!

Would that cause any issues ? Plus how big is it ? Cause I don't like having stuff that I won't need.

Finally I asked my lecturer and he said we're using Java version 6. And my version of Java is the same as yours !! { 1.6.0_20 } does that mean we are way behind on Java Updates ?

Thanks
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
As you can see here, Java 6 refers to version 1.6.0. Yes, the version numbers are weird. Your best bet would be to clarify with your prof and ask them whether or not you have the required tools.

I have no idea how much extra is installed if you install the iOS SDK. AFAIK though, there is a version of the Xcode dev tools that doesn't have the iOS SDK.
 
OP
Ciwan
Joined
Oct 30, 2009
Messages
136
Reaction score
0
Points
16
Location
The Milky Way
Your Mac's Specs
iMac Core i5 2.66GHz - RAM 4GB - OS X Snow Leopard
OK Thanks Vansmith.

One last question, say I have a C++ file called { mycode.cpp }

How do I run it ? do I open the terminal and type cc mycode.cpp ? or is this different ?

Thanks
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I'm not a GCC pro but this looks like it might help.

As an aside, isn't your prof supposed to teach you how to do all of this?
 
OP
Ciwan
Joined
Oct 30, 2009
Messages
136
Reaction score
0
Points
16
Location
The Milky Way
Your Mac's Specs
iMac Core i5 2.66GHz - RAM 4GB - OS X Snow Leopard
LOL He has, but on Windows :)

I'll read the article and see whether I can get it to work.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
The commands to compile a Java program are the same across OS. The GCC commands should be the same as well. That is irrelevant though if your prof doesn't use GCC.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top