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