?
Solved

Differentiate between function in Java and C

Posted on 2011-02-19
15
Medium Priority
?
872 Views
Last Modified: 2012-05-11
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!
0
Comment
Question by:dshrenik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 3
15 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 1668 total points
ID: 34935955
Java method should have in 100% of cases type in the signature or
the word "void"

If signature does not have return type unless it is cnstructor - that is C function
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1668 total points
ID: 34935963
Also this convention - starting word lower case - other words upper case - this is typical for Java, like toCharArray(). I guess in C standard functions
are mostly in lower case. Does not mean that someone might not write
some C funvtion folloing Java naming tradition - just one
name is not enough to guarantee that it is either C or Java
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34935971
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

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 47

Expert Comment

by:for_yan
ID: 34935984

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
0
 

Author Comment

by:dshrenik
ID: 34935989
Thanks for the detailed explanations.

Can you tell me if "len = s.Length" is C or Java?
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1668 total points
ID: 34935994
if s is a string then s.length is not Java, Java would be s.length()

On the other hand if s is array, then Java will have s.length - without parentheses
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34936000
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
0
 

Author Comment

by:dshrenik
ID: 34936009
s is an array.

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

I have access only to the function code...
0
 

Author Comment

by:dshrenik
ID: 34936013
Do all Java functions need the qualifier "public" / "private", etc?
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1668 total points
ID: 34936014
Now iit is all lower case, but it will have parentheses in the end -
this means it is a method
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34936024
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){...}

0
 
LVL 47

Expert Comment

by:for_yan
ID: 34936033
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
0
 
LVL 47

Expert Comment

by:for_yan
ID: 34936038
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
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 332 total points
ID: 34936810
>>Is "s.Length" in Java? (L is in caps)

That looks like .NET (in which case it could be C# - as could the rest)
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 1668 total points
ID: 34936819
.NET may apply either to C or to C#. It may be C# which is in general much closer to Java than C
Yes, in C# it really looks like length of the string is shown this way:
http://msdn.microsoft.com/en-us/library/system.string.length.aspx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question