*
The moose likes Beginning Java and the fly likes make the method in one java file available for a java program in another directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "make the method in one java file available for a java program in another directory" Watch "make the method in one java file available for a java program in another directory" New topic
Author

make the method in one java file available for a java program in another directory

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
How to make the method in one java file available for a java program in another directory?
e.g.
How to make the getTestKey method vailable for a java program in another directory?
GetTestKey.java



KeyClient.java



There are two compile errors:
Only a type can be imported. com.myutil resolves to a package KeyClient.java /XX/src/com/myutil/taglib line 9 Java Problem

The method getTestKey(String) is undefined for the type KeyClient KeyClient.java /XX/src/com/myutil/taglib line 80 Java Problem
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

albert kao wrote:Only a type can be imported. com.myutil resolves to a package KeyClient.java /XX/src/com/myutil/taglib line 9 Java Problem

The error message could be more clear, true. With imports you must either specify a class (e.g. java.util.List) or use a wildcard to import everything from the package (e.g. java.util.*). The former is preferred as it also avoids ambiguity (like java.awt.List and java.util.List when importing java.awt.* and java.util.*).

The method getTestKey(String) is undefined for the type KeyClient KeyClient.java /XX/src/com/myutil/taglib line 80 Java Problem

The getTextKey method is a static method of class GetTestKey. You are calling it directly so the compiler looks for the method in the current class (KeyClient). For instance methods you must use an instance to call a method (instance.instanceMethod(params)); for static methods you should use the class name (MyClass.staticMethod(params)).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Albert,

You will need to import the class & import statement shoud include the class name or .* after the package name.

You need to learn how to create instances of a class & execute the method.(using the "new operator")

I believe you are jumping from a procedural language to object oriented one so it would help
if you start reading the books mentioned on this forum.

Get a hang of OO concepts & Java basics. Head First Java is a good book to start with.

Keep on posting !!!


Regards,
Avishkar Nikale
Jan Hoppmann
Ranch Hand

Joined: Jul 19, 2010
Posts: 142

Avishkar Nikale wrote:
You need to learn how to create instances of a class & execute the method.(using the "new operator")


Since his method he wants to call is static, he doesn't need an object in this context.


Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
Avishkar Nikale
Ranch Hand

Joined: Aug 06, 2010
Posts: 173
Jan Hoppmann wrote:
Avishkar Nikale wrote:
You need to learn how to create instances of a class & execute the method.(using the "new operator")


Since his method he wants to call is static, he doesn't need an object in this context.


Oops !!! My Bad !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: make the method in one java file available for a java program in another directory
 
Similar Threads
Accessing default package classes
getting error while running small program
Clarification on classpaths
basic doubt!!
Package/sub-package problems...