java Method class


why java.lang package has class called Method.

what are other classes there in that and what is purpose of those classes.

when do we need to use them

please advise
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Please spend time reading this tutorial:
The Method class is part of the "reflection" API.  You rarely need to use any of this API in normal programming.

It tends to come up when you want to be able to do something like call a method - but you have the name of the method represented as a String.

It's the difference between:

MyClass myClass = new MyClass() ;
myClass.hello() ;


MyClass myClass = new MyClass() ;
Method helloMethod = getMethod(myClass, "hello") ;   <-- See how the name of the method is passed in as a string here ;

(NOTE: That's not real code - just giving you an idea of what reflection is all about).

As I say - it's unlikely you need this, so probably not something you should be diving into just now.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:

i also see methods like setShortDescription. I wonder what is use of args here and also methods like setShortDescription. please advise

     Class cl = Xyz.class;
         Class args[] = { };
         Method cToF = cl.getMethod("cT", args);
         MethodDescriptor cTDesc = new MethodDescriptor(cToF);
         cTDesc.setShortDescription("modify c to f");
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

That's moving into even more obscure corners.  Java has a concept of java beans that in some cases can be modified by external tools.  An example of this is using a debugger to connect into a running process and change the current logging level.

This API (I believe - I've never used it) supports that sort of operation.

This is way way off the beaten path.  I would recommend not delving into this area until you've mastered the basics - you will get very lost.

gudii9Author Commented: ;

call() is other method on the hello() method?

please advise if there is any link with sample code to understand this atleast at high level.
Sure the Java tutorials cover this in depth:

And yes "" is another way to call to the hello() method.  You get an object which represents the method itself (i.e. an object that represents a piece of program code) and then you call that object.

I see looking at the tutorial the actual method name is "invoke":

So I should have said "helloMethod.invoke()" in my pseudo code.

As I mentioned earlier - this is advanced stuff.  You could program professionally for 10 years in Java and never need to use this stuff - so proceed with caution :)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.