This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes static method to call from other package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static method to call from other package" Watch "static method to call from other package" New topic

static method to call from other package

Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
would you be able to show me how static method call non-static method in same class?

I tried to put a simple of my two program below.

please show me how to fix this problem.



package pgm;
import pgm.*;

class A;

public static Map getValues(String ISBN_digit) {
Hashtable ht = new Hashtable();
String message = "from CCHKDigit() ";
Boolean IN60 = new Boolean(true);

CHKISBN(String ISBN_digit) // my problem is in this method???

ht.put("msg", message);
ht.put("error", IN60);

return ht;

public char CHKISBN(String isbn10) {

PXERCD = '0';
isbn10 = isbn10.toUpperCase().trim();
char[] theChars = isbn10.toCharArray();

//int val=0;
StringBuffer sb = new StringBuffer();

// 2. validation of input ISBN code's chacters
F = 10;
for (int X = 0; X<=9; X++) {

if (X < 9) {
RUNTOT += F * Character.getNumericValue(theChars[X]);
int val =NUMVALUES.indexOf(theChars[X]);
//System.out.println("INDEXOF-VAL:"+ val);
if(val == -1) {
PXERCD = '2';
return PXERCD;
}//end of if
}//end of for

XCHECK = Character.getNumericValue(theChars[isbn10.length() - 1]);
XXREST = (int)((long)(RUNTOT)%(long)(11));

if (XXREST == 0) {
}else if(XXREST == 1) {
// Check if error
if (Character.getNumericValue(isbn10.charAt(9)) != XXCHKD && XXREST !=1) {
PXERCD = '1';
}else if(isbn10.charAt(9) != XCCHKD && XXREST ==1) {
PXERCD = '1';
}else {
PXERCD = '0';
} //�end if-else

return PXERCD;

}//end of method of CHKISDN

package pgm;
class b{
public void checkDigits(String ITNO) {

ItemNo = ITNO;
Hashtable rValues = (Hashtable) CCHKDigit.getValues(ITNO);
String msg = (String) rValues.get("msg");
boolean error = ((Boolean)(rValues.get("error")) ).booleanValue();

System.out.println("Error" + error);
System.out.println("Message" + msg);
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
A static method in a class definition cannot directly access the instance methods. The instance methods only have meaning when you create an instance of the class.
Eung maeng
Ranch Hand

Joined: Feb 10, 2002
Posts: 68
thank, Keith,
Do you have any example source to get multiple return values from other class with instance method in instance of the class?

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I'm sorry, but I don't understand your question.

I don't see where you're trying to call an instance method in another class.

A method can't have multiple return types.

However, if you want to return multiple values, you can encapsulate them into an object.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: static method to call from other package
It's not a secret anymore!