• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Are all non-static methods called as functions

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Python there are methods and functions.  Methods belong to the instance of class. Regarding the functions, do they mean anything not belonging to the class, i,e static ? thanks.
 
Saloon Keeper
Posts: 15447
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:Methods belong to the instance of class.


Only non-static methods. Static methods belong to the class, not the instance.

Regarding the functions, do they mean anything not belonging to the class, i,e static ? thanks.


Functions don't belong to classes, but that means they are different from static methods, because static methods belong to a class.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

Non static methods, belong to instance of class.
Static methods, belong to class.
Functions, do not belong to class. Is it correct to day that they are just used to perform some task which may have not relation to the class ?

Is there something in java which is like functions of Python?
 
Stephan van Hulst
Saloon Keeper
Posts: 15447
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Monica Shiralkar wrote:Is it correct to day that they are just used to perform some task which may have not relation to the class ?


Sure.

Is there something in java which is like functions of Python?


No.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason I can think of for Java not having something like Python functions, is that Java is largely an object-oriented language whereas Python is functional as well as object oriented.
 
Marshal
Posts: 79054
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java® was designed specifically as an object‑oriented language. That is why it doesn't support methods outwith classes (or more precisely didn't before default methods in Java8).
 
Saloon Keeper
Posts: 27708
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if it's a formal definition, but a procedure. also known as a subroutine is a callable unit of code that is not associated with any object. A function is a subroutine that returns a result and is likewise not associated with any object.  A method is a procedure or function that is bound to an object instance (instance method) or class (static method).

These are the common terms, they may vary for different language environments and IT shops or schools.

Two of the most common types of programming languages are the procedural languages, such as Fortran, COBOL, Pascal, and so forth, and the Object-oriented languages, such as Java and C++.

C++ can be used either procedurally or OOP or both. Java can only be OOP, so I'd argue that a more accurate term for Java would not be object-oriented, but object-based. But generally people think of it as OOP.

Python started as a procedural language, but various hacks have been added to it to allow it to support OOP-style programming. I'd say that it's less OOP than C++. because I find that C++ has more of the syntactic sugar to simplify code than Python — I cannot count the number of times in Python I've burned myself for not prefixing an identifier with "self" where "this" would be optional in C++. But there you have it.
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Java® was designed specifically as an object‑oriented language. That is why it doesn't support methods outwith classes (or more precisely didn't before default methods in Java8).


Thanks
 
Monica Shiralkar
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote: — I cannot count the number of times in Python I've burned myself for not prefixing an identifier with "self" where "this" would be optional in C++. But there you have it.



Yes. And optional in java also.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic