aspose file tools*
The moose likes Java in General and the fly likes methods in a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "methods in a class" Watch "methods in a class" New topic
Author

methods in a class

fadil alnassar
Greenhorn

Joined: Dec 16, 2005
Posts: 4
hi!

Is it possible in java to see how many methods i got or check if a method called 'blabla' is in the class.

what i want to do is that i neeed to provide a set of classes for a person who should add a class to classed i gave him and his class should include all functions or methods that i asked him to do so it will be like a marker system to test whther the person include all what i asked him for it so if possible i need to check if there is constructor or not, check the number of methods or check mame of methods and if possible any details for these methods like return vlaue and number of parameters.

i do not know if there is a API in JAVA provides these functionality but i wish some one can help me to acheive that.

apprecaite your help!


Regards<br /><a href="http://www.fadilalnassar.com" target="_blank" rel="nofollow">www.fadilalnassar.com</a>
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Yes. Have a look at the getMethod(), getMethods(), getDeclaredMethod(), getDeclaredMethods(), and related methods in the class java.lang.Class.


[Jess in Action][AskingGoodQuestions]
fadil alnassar
Greenhorn

Joined: Dec 16, 2005
Posts: 4
thanks for reply !!

i am beginner in java can you give me an example of that.

thanks for your help !!
Pradeep Kadambar
Ranch Hand

Joined: Oct 18, 2004
Posts: 148
You need to look into java.lang.Class documentation. You have everything in place there. Well I'll give what you asked for just to pamper you

Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Take a look at http://java.sun.com/docs/books/tutorial/reflect/index.html


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Stuart Ash
Ranch Hand

Joined: Oct 07, 2005
Posts: 637
Originally posted by fadil alnassar:
thanks for reply !!

i am beginner in java can you give me an example of that.

thanks for your help !!


Reflection is an advanced concept, so if you can hold your breath, you can get to it when it's due. For now, if this is to help you understand more about methods in a class and such, you create javadocs for your classes and refer to them.
[ January 03, 2006: Message edited by: Stuart Ash ]

ASCII silly question, Get a silly ANSI.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by fadil alnassar:

his class should include all functions or methods that i asked him to do


Why do you need to know this? It sounds to me that you are either:
1) writing some sort of exercise checking program
2) Writing an abstract base class with abstract methods

In the second case, a non-abstract class will have no abstract methods,
so that will force their implementation. But what are you really doing?


There is no emoticon for what I am feeling!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: methods in a class