Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Coder's Corner Lounge (http://www.programmingforums.org/forum11.html)
-   -   how to tell C++ from Java source code? (http://www.programmingforums.org/showthread.php?t=15835)

bcouch39 May 15th, 2008 4:23 PM

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

Freaky Chris May 15th, 2008 4:29 PM

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

iEngage May 15th, 2008 4:31 PM

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...

bcouch39 May 15th, 2008 5:46 PM

Re: how to tell C++ from Java source code?
 
Quote:

Originally Posted by Freaky Chris (Post 145258)
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 May 15th, 2008 5:49 PM

Re: how to tell C++ from Java source code?
 
Quote:

Originally Posted by iEngage (Post 145259)
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?

titaniumdecoy May 15th, 2008 6:28 PM

Re: how to tell C++ from Java source code?
 
Quote:

Originally Posted by bcouch39 (Post 145264)
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.

iEngage May 15th, 2008 6:48 PM

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.

JAlexBrown May 15th, 2008 9:04 PM

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.

iEngage May 15th, 2008 9:07 PM

Re: how to tell C++ from Java source code?
 
Quote:

Originally Posted by JAlexBrown (Post 145274)
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

big_k105 May 16th, 2008 7:09 AM

Re: how to tell C++ from Java source code?
 
:

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


:

  1. class helloWorld {
  2.     public static void main(String args[]) {
  3.         System.out.println("Hello World");
  4.     }
  5. }



All times are GMT -5. The time now is 10:06 AM.

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