dshrenik
asked on
Differentiate between function in Java and C
Please tell me the easiest way to differentiate functions in C and Java.
Also, if a function signature is of the form "return_type function_name()", is it is sufficient to conclude that it is a C function?
Does the function "toCharArray()" exist in C/C++?
Thanks!
Also, if a function signature is of the form "return_type function_name()", is it is sufficient to conclude that it is a C function?
Does the function "toCharArray()" exist in C/C++?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think in C++ there is a function ToCharArray():
http://msdn.microsoft.com/en-us/library/system.string.tochararray%28v=vs.71%29.aspx
But still toCharArra() - starting with lower case looks more like Java to me.
Of course you cannot rely on such things - no one prevents someone to
write in C function with such name
ASKER
Thanks for the detailed explanations.
Can you tell me if "len = s.Length" is C or Java?
Can you tell me if "len = s.Length" is C or Java?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think one simple way is to look at the top of the program - in C you'll usually
see a bunch of "include"'s, in Java - a bunch of "import"'s
see a bunch of "include"'s, in Java - a bunch of "import"'s
ASKER
s is an array.
Is "s.Length" in Java? (L is in caps)
I have access only to the function code...
Is "s.Length" in Java? (L is in caps)
I have access only to the function code...
ASKER
Do all Java functions need the qualifier "public" / "private", etc?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No, nota ll of them need it - they have no access qualifie - that is called
"default" access - just you may write
float sqrt1(float x){...}
"default" access - just you may write
float sqrt1(float x){...}
it is return type which is mandatory in Java - even if returns nothing it should have "void" in frtont; I guess in C - if it returns nothing "void" is just good practice but not an error
But one exception is that constructor in the class has no return type - but its name should be identical to the name of the class - so if compiler ebcounetrs declaration of method which has no return type and does not match exactly the class name where it finds this method - then Java compiler will report an error
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
return_type function_name()
is always C function
there maybe any number of Java Methods
like that, say,
float my_function()
You need to have the context.
One very imporatnt difference that in Java all methods
should be within a class, whereas in C++ there may be
functions and methods not within any class