View Full Version : some problems
nojtb
11-24-2007, 04:51 PM
1. How do i import a variable from another java file.
and how do i import all the variables from a .java file with only one class (public) and no functions
2. Solved
3. is there a maximum to the amount of coding in a class with no functions? (just pure variable .java file)
DELOCH
11-25-2007, 04:40 AM
you create the other file as an object and then call it's variable
MyNewReallyLongClass class = new MyNewReallyLongClass();
int i = class.i;
that should work :P
replace MyNewReallyLongClass with the class you wanna import variable from
and i with any variable you want to import from that class
nojtb
11-25-2007, 05:15 AM
i dont know how to import much, only a few things and only 2 of witch that i actually know what are used for. i never found any toutrails on importing.
suggestion?
Aradon
11-25-2007, 05:01 PM
If your java file is in the same folder as the file you're trying to get the variables from, then there is nothing you need to import.
And if you're variables are public, then as previously stated you can get the variables by using a variable name and then the variable names. So, if you had some class with a public boolean variable j you could do:
someClass sc = new someClass();
boolean thisBoolean = sc.j;
Also, if your someClass has a method called getVariable where Variable is the name of the variable, then you can indeed use it in the same sense...
someClass sc = new someClass();
boolean thisBoolean = sc.getJ();
in which we assume in the someClass there is a method like this:
boolean j = false;
public boolean getJ()
{
return j;
}
Second.
So assuming that y and z are a minimum and maximum respectivly, then you can do a statement like
if(exp >= y && exp <= z) // meaning that exp is in between either y or z inclusive
{
// do something
}
nojtb
11-26-2007, 05:26 AM
[If your java file is in the same folder as the file you're trying to get the variables from, then there is nothing you need to import.
And if you're variables are public, then as previously stated you can get the variables by using a variable name and then the variable names. So, if you had some class with a public boolean variable j you could do:
someClass sc = new someClass();
boolean thisBoolean = sc.j;
im guessing you mean the variables are in a public class?
Also, if your someClass has a method called getVariable where Variable is the name of the variable, then you can indeed use it in the same sense...
someClass sc = new someClass();
boolean thisBoolean = sc.getJ();
if the class is public, theres no point in having methods, all the math of changing what the varibles = is in the main .java
in which we assume in the someClass there is a method like this:
boolean j = false;
public boolean getJ()
{
return j;
}
im lost know, i really dont even see how this is possible.
So assuming that y and z are a minimum and maximum respectivly, then you can do a statement like
if(exp >= y && exp <= z) // meaning that exp is in between either y or z inclusive
{
// do something
}
thanks i got mixed up when thinking about this one.
Aradon
11-26-2007, 09:28 AM
im guessing you mean the variables are in a public class?
No, I mean the variables are public. When you don't declare a variable in a class as private or static, the default value is public / non-static.
if the class is public, theres no point in having methods, all the math of changing what the varibles = is in the main .java
If the variables are public I suppose this is true, however this is a horrible view of Object Oriented Programming. Granted, however, that in OO, most, if not all, variables would be private and would have get / set methods associated with them in order to preserve encapsulation.
im lost know, i really dont even see how this is possible.
That is just creating a basic method in someClass. If you want to learn more about that, you'll have to read up more about Java in general. My suggestion is the sun tutorial:
[url="http://java.sun.com/docs/books/tutorial/"]Java Tutorial[/quote]
thanks i got mixed up when thinking about this one.[/QUOTE]
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.