method and class in Java

I am a learner.

I want to know what the difference is between the class and method. Because I saw a example "class FahrToCelsius". I think I can write a method FahrToCelsius in the main function instead of the class.

when should I write a class? method like this?

another think. because java is a oo, so the method should be called by the object, a instance of the class. but I read some example ,the class could call the method. why?

when does the call the method? object?

Thanks for anyone who will give me some hints.

[560 byte] By [lance82a] at [2007-11-27 8:46:25]
# 1
http://java.sun.com/docs/books/tutorial/java/index.html
CaptainMorgan08a at 2007-7-12 20:48:40 > top of Java-index,Java Essentials,New To Java...
# 2

> I want to know what the difference is between the class and method. Because I

> saw a example "class FahrToCelsius". I think I can write a method

> FahrToCelsius in the main function instead of the class.

There are times when a class seems to exist mainly to define one primary method,

see the Command Pattern:

http://en.wikipedia.org/wiki/Command_pattern

BigDaddyLoveHandlesa at 2007-7-12 20:48:40 > top of Java-index,Java Essentials,New To Java...
# 3
Hi thanks for replying.I guess if the method is static, then this method does not need to be called by class or object. just like a function in vbbut how about called by class. I am still reading. If someone could give me a instantly answer, that should be perfect
lance82a at 2007-7-12 20:48:40 > top of Java-index,Java Essentials,New To Java...
# 4
> but how about called by class. It's unclear what you mean by this. It might help if you could post some code.
BigDaddyLoveHandlesa at 2007-7-12 20:48:40 > top of Java-index,Java Essentials,New To Java...
# 5

> I guess if the method is static, then this method

> does not need to be called by class or object. just

> like a function in vb

If the method is static, you do not have to call it on an object, but you DO have to call it on a class.

> but how about called by class.

What do you mean?

> If someone could give me a instantly answer, that

> should be perfect

You probably don't mean to be rude here, but asking for something "instantly" or "urgently", "ASAP", etc. tends to irritate people. We answer questions here because we enjoy it, and we do so at our own pace. Being pushed for something "now" makes it less fun.

jverda at 2007-7-12 20:48:40 > top of Java-index,Java Essentials,New To Java...
# 6
like math.xx(),...xx() is a method and math is a class.
lance82a at 2007-7-12 20:48:40 > top of Java-index,Java Essentials,New To Java...
# 7
Like java.lang.Math.sin(x)? That is the syntax for invoking a static method.
BigDaddyLoveHandlesa at 2007-7-12 20:48:40 > top of Java-index,Java Essentials,New To Java...