Link to home
Start Free TrialLog in
Avatar of dshrenik
dshrenikFlag for United States of America

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!
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Of course  you cannot conclude that

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


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
Avatar of dshrenik

ASKER

Thanks for the detailed explanations.

Can you tell me if "len = s.Length" is C or Java?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
s is an array.

Is "s.Length" in Java? (L is in caps)

I have access only to the function code...
Do all Java functions need the qualifier "public" / "private", etc?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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){...}

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial