Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 16th, 2008, 3:38 PM   #11
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 213
Rep Power: 3 Seif is on a distinguished road
Re: how to tell C++ from Java source code?

http://en.wikipedia.org/wiki/Compari...va_and_C%2B%2B
Seif is offline   Reply With Quote
Old May 16th, 2008, 6:23 PM   #12
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: how to tell C++ from Java source code?

10 points to BigK!

(And I guess Seif too.)
Sane is offline   Reply With Quote
Old May 17th, 2008, 3:31 PM   #13
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 203
Rep Power: 2 Fall Back Son is on a distinguished road
Re: how to tell C++ from Java source code?

I can't imagine how useful knowing whether or not you're looking at c++ or java could possibly be. That being said, I also don't agree with some of posters in here. If your job requires you to know something, and we tell you... who cares how you learned it, if you know it? Its not cheating for exactly that reason... as long as you know what your job requires you to know, then great. I doubt your employer cares how you learned it. No amount of information we tell you will change that.

1) Like Big K said, the 'main' method is declared as public static void main(String[] args).
Some indicators that this is Java code are:
-The keyword 'static', which indicates that a method is for the whole class, not for one particular object of that class. 'static' is also in c++, I think, so beware.. but you wouldn't see it used along with the main method.
- the statement 'String[] args', because in C++, it would look like "int main(int argc, char *argv[])". String[] args is an array of String objects in Java. C++ might use Strings as well, so don't generalize this information... but it is useful to know that the statement String[] args in the main method definition means its Java and not C++.

2) In c++ code you will see pointer dereferencing and you will see address assignment. How will you know if you are seeing these things? the symbol & = address assignment and the symbol * = dereferencing. The basic idea is that if you have the address of something stored in a variable, using the * symbol will dereference it, i.e., it will get you the value of whatever is stored at that address. You will not see the use of these in Java programs because Java does not allow the programmer access to either of these operations. Use of these might look like

int* myVariable;
myVariable = &myOtherVariable;
^^ In this case, the '*' symbol just means it IS a pointer to another location, and CAN be dereferenced... not that you are actually dereferencing it.

*myVariable = 15;




ok I'm bored now so. Hope that helps. If my code example was off, anyone, feel free to correct it. In any case, you would not see use of those symbols in a Java program, since Java does not support them. There are other words you'd see in cpp but not Java, such as 'Cout' and 'Cin'
Fall Back Son is offline   Reply With Quote
Old May 17th, 2008, 4:10 PM   #14
jamesdman
Newbie
 
Join Date: Apr 2005
Location: NC,USA
Posts: 17
Rep Power: 0 jamesdman is on a distinguished road
Re: how to tell C++ from Java source code?

Re: how to tell C++ from Java source code? The c code won't execute through the java compiler duh...

import
#
jamesdman is offline   Reply With Quote
Old May 17th, 2008, 5:43 PM   #15
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 203
Rep Power: 2 Fall Back Son is on a distinguished road
Re: how to tell C++ from Java source code?

His question was asking how to tell by looking at it, not by attempting to run it.
Fall Back Son is offline   Reply With Quote
Old May 17th, 2008, 7:02 PM   #16
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
Re: how to tell C++ from Java source code?

Quote:
Originally Posted by Fall Back Son View Post
1) Like Big K said, the 'main' method is declared as public static void main(String[] args).
What about Javascript, no main function at all.
Jabo is offline   Reply With Quote
Old May 17th, 2008, 8:14 PM   #17
iEngage
Newbie
 
iEngage's Avatar
 
Join Date: May 2008
Location: teh interwebz
Posts: 22
Rep Power: 0 iEngage is on a distinguished road
Re: how to tell C++ from Java source code?

Quote:
Originally Posted by Jabo View Post
What about Javascript, no main function at all.
true, but the original question was just between Java and C++.
__________________
iEngage
iEngage is offline   Reply With Quote
Old May 19th, 2008, 12:47 PM   #18
JAlexBrown
Newbie
 
Join Date: May 2008
Posts: 11
Rep Power: 0 JAlexBrown is on a distinguished road
Re: how to tell C++ from Java source code?

Quote:
Originally Posted by iEngage View Post
/* */ is for multi-line comments. it's found in quite a few languages actually, including Java
I did know that /**/ was a multi-line comment, but I didn't know it was supported by Java. Thanks for that information.
JAlexBrown is offline   Reply With Quote
Old May 19th, 2008, 1:23 PM   #19
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 499
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: how to tell C++ from Java source code?

Quote:
Originally Posted by Fall Back Son View Post
I can't imagine how useful knowing whether or not you're looking at c++ or java could possibly be. That being said, I also don't agree with some of posters in here. If your job requires you to know something, and we tell you... who cares how you learned it, if you know it? Its not cheating for exactly that reason... as long as you know what your job requires you to know, then great. I doubt your employer cares how you learned it. No amount of information we tell you will change that.
You are absolutely correct about that. I spent the past 20+ years programming and quite a bit over the last couple years was searching the net for answers to job related questions. And my supervisor(s) WANTED me to do that You turn a one-programmer shop into a million-programmer shop for free by doing that.
__________________
I Like Ike. Vote for Dwight Eisenhower this November.
--This message brought to you by the the Procrastinators Club Of America.
Ancient Dragon is online now   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting 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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Presenting source code within html Wizard1988 Other Web Development Languages 21 Mar 20th, 2007 8:37 PM
java code question lakitu Java 5 Mar 6th, 2006 6:53 PM
Different IDE's Different code 357mag Java 1 Mar 26th, 2005 3:42 PM
Game ideas and source code code10 Coder's Corner Lounge 1 Mar 19th, 2005 11:24 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC