I'm quite new to Java.
My general question: how do I find out what package contains a particular method.
I want to use a method from an external library. Looking at the JavaDocs, it exists, and is here (http://twitter4j.org/javadoc/index.html).
However, I need to know how I can use that method. What should I import, and how can I use that method.
import twitter4j.this.package
maybe.something.before
.getMentionsTimeline()
.now.I.can.use.this
I looked for the longest time, but I'm still having trouble understanding the JavaDocs. Could someone clarify a general rule?
So say you want to use a method in ArrayList
, such as size()
, but you don't know what package to import.
The first step is to go to the javadoc for the class containing the method you want. Here's the ArrayList
online Javadoc:
See the little "java.util"
above the big header with the class name? That's the package you'll need to import. Or more specifically, that's the prefix to the class you need to import. So in this case you'll import java.util.ArrayList
.
Now, how you use the method depends on if it's an instance method or a static method. If it's an instance method you'll have to instantiate the class in question and call the method on the instance:
ClassName varName = new ClassName(possibleParameters);
varName.methodName(possibleParameters);
If it's a static method you can use it qualifying the method with the class name:
ClassName.StaticMethod(possibleParameters);