This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes fetch values from one package into another package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "fetch values from one package into another package" Watch "fetch values from one package into another package" New topic
Author

fetch values from one package into another package

muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
Hi,

I've one package, with in this package i've one method. in this method i've one variable just like below

package XXX;
public class schema
{
public void validateschema
{
boolean verror;

}
}
i want to fetch the variable "verror" in to my another package...

please help me...

--
with thanks
M. Bharathi
Senthil Kumar
Greenhorn

Joined: Jul 17, 2007
Posts: 21
package test1;
public class Schema
{
public boolean validateSchema()
{
boolean verror;
statements;
return verror;
}
}


In your next package, say for example test2,

import the package test1 and access the validateSchema() by creating the Object of that Class(Schema) , now you can get the value verror.


Preparing for SCJP 1.6
muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
hi senthil,


ok. i need the syntax in java


--
with regards
M. bharathi
Senthil Kumar
Greenhorn

Joined: Jul 17, 2007
Posts: 21
This is the Syntax.

pack pack1;
class ClassName{

public datatype method(){

statements;
return datatype;
}
}

pack pack2;

import pack1.*;

class ClassName2 {

public static void main(String arg[]){

ClassName object = new ClassName();
datatype var1 = object.method();

}
}
muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
hi senthil,


thanks a lot... now i've another doubt

package xxxx
class schema
{
public void method1()
{
boolean validation;
}
}
i want to access the variable "validation" from main program

--
with regards,
M. bharathi
Senthil Kumar
Greenhorn

Joined: Jul 17, 2007
Posts: 21
package xxxx
class schema
{
public void method1()
{
boolean validation;
}
}

validation is a local variable, so you cannot access this in your main method. better use validation as Instance Variable.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38436
    
  23
Better still to provide a predicate method which returns the validation boolean value.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11249
    
  16

muthu bharathi wrote:I've one package, with in this package i've one method.

Actually, you have one package, and in that package, you have one CLASS, and in that CLASS, you have one method. In that method, you have a variable.

and here's the key thing... that variable only exists inside that method. Even if you create an object of type Schema (and class names should have their first letter capitalized), unless you are running that method, it doesn't make sense to talk about getting that value.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
Hi,

i've got it.. thanks a lot.


--
With thanks,
M. Bharathi
 
jQuery in Action, 2nd edition
 
subject: fetch values from one package into another package