Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old May 15th, 2008, 5:23 PM   #1
bcouch39
Newbie
 
Join Date: May 2008
Posts: 0
Rep Power: 0 bcouch39 is on a distinguished road
how to tell C++ from Java source code?

All right, I admit I'm not a programmer (I took a couple of courses and have done a smattering in Fortran and Databus, but...I'm not a programmer). However, I need to know - if someone showed me their source code, how would I recognize whether I'm looking at C++ or Java? Without asking them, of course. Why? Because I've been tasked with figuring this out as part of a technical interview for a job. I appreciate your help. - Bill
bcouch39 is offline   Reply With Quote
Old May 15th, 2008, 5:29 PM   #2
Freaky Chris
Professional Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 444
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: how to tell C++ from Java source code?

if this is an interview for a job sureley it is no good asking someone to tell you. If you can't do it and it is needed for the job then if you get the job then what will you do?

Edit: Why don't you look at some examples of C++ programs and Java Programs and see where they differ, that would be the best idea.

Chris
__________________
Steven Skiena - Algorithms

,[->+>+<<]>>[-<<+>>]>++++++++[-<++++++++>]<+[-<->]>+<<[[-]+++++++++++++++.[-]>]>>[+++++++++.[-]],
brainf**k -- It's such a pretty language
Freaky Chris is offline   Reply With Quote
Old May 15th, 2008, 5:31 PM   #3
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?

I recommend just looking up tutorials of the two different languages and becoming familiar with the differences in syntax

of course the most obvious thing would be if you have the source files then you can tell by the file extensions...
__________________
iEngage
iEngage is offline   Reply With Quote
Old May 15th, 2008, 6:46 PM   #4
bcouch39
Newbie
 
Join Date: May 2008
Posts: 0
Rep Power: 0 bcouch39 is on a distinguished road
Re: how to tell C++ from Java source code?

Quote:
Originally Posted by Freaky Chris View Post
if this is an interview for a job sureley it is no good asking someone to tell you. If you can't do it and it is needed for the job then if you get the job then what will you do?

Edit: Why don't you look at some examples of C++ programs and Java Programs and see where they differ, that would be the best idea.

Chris
I'm not interviewing for a job as a programmer. I've been told that I'll need to be able to distinguish between the two. Surely there's something to look for in the code that would let me do so. For instance, some sample Java programs I've seen begin with:
// <program-name>.java
Do all Java programs begin this way? Do C++ programs begin differently?
bcouch39 is offline   Reply With Quote
Old May 15th, 2008, 6:49 PM   #5
bcouch39
Newbie
 
Join Date: May 2008
Posts: 0
Rep Power: 0 bcouch39 is on a distinguished road
Re: how to tell C++ from Java source code?

Quote:
Originally Posted by iEngage View Post
I recommend just looking up tutorials of the two different languages and becoming familiar with the differences in syntax

of course the most obvious thing would be if you have the source files then you can tell by the file extensions...
Thanks. The file extension for a Java program would be .java, right? What about for a C++ program?
bcouch39 is offline   Reply With Quote
Old May 15th, 2008, 7:28 PM   #6
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 934
Rep Power: 4 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Re: how to tell C++ from Java source code?

Quote:
Originally Posted by bcouch39 View Post
Thanks. The file extension for a Java program would be .java, right? What about for a C++ program?
I sincerely hope you are joking. If one of the questions you are asked in an interview is what language a file ending in .java is written in, one can only imagine the high expectations your would-be employer must have of you.
titaniumdecoy is offline   Reply With Quote
Old May 15th, 2008, 7:48 PM   #7
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?

file extension for C++ files is usually .cpp

although like titanium decoy says, if all you have to know is what different file extensions mean then how good could that job really be?

as for your other question, yes there is something in the code that will tell you which it is, but you have to do what Freaky Chris said. You need to actually take the time to look at different code examples and learn to recognize the syntax.
__________________
iEngage
iEngage is offline   Reply With Quote
Old May 15th, 2008, 10:04 PM   #8
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?

Before I go any further, I must say that if this is a skill you must possess to perform your work task, it's not wise to simply ask a forum how to tell the difference. That would be the equivalent of a cheat sheet. Does good on the test, but then it has no practicality in the real world.

That being said, I'd suggest reading lots of code and picking out the differences for yourself. As for your question, // doesn't indicate rather the code is C++ or Java. // is simply a comment, and it's a comment in C++ and Java. Perhaps someone could correct me if I'm wrong, but I don't think a /**/ comment is a Java comment. I believe that's exclusively a C++ comment, but I may be wrong.
JAlexBrown is offline   Reply With Quote
Old May 15th, 2008, 10:07 PM   #9
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 JAlexBrown View Post
Perhaps someone could correct me if I'm wrong, but I don't think a /**/ comment is a Java comment. I believe that's exclusively a C++ comment, but I may be wrong.
/* */ is for multi-line comments. it's found in quite a few languages actually, including Java
__________________
iEngage
iEngage is offline   Reply With Quote
Old May 16th, 2008, 8:09 AM   #10
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,667
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
Re: how to tell C++ from Java source code?

cpp Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. int main() {
  4. std::cout << "Hello World" << std::endl;
  5. return 0;
  6. }

java Syntax (Toggle Plain Text)
  1. class helloWorld {
  2. public static void main(String args[]) {
  3. System.out.println("Hello World");
  4. }
  5. }
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   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 9:37 PM
java code question lakitu Java 5 Mar 6th, 2006 7:53 PM
Different IDE's Different code 357mag Java 1 Mar 26th, 2005 4:42 PM
Game ideas and source code code10 Coder's Corner Lounge 1 Mar 19th, 2005 12:24 PM




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

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