|
anybody can tell why the answer is B,? i think it should be D. thanks 1. public class test ( 2. private static int j = 0; 3. 4. private static boolean methodB(int k) ( 5. j += k; 6. return true; 6. ) 7. 8. public static void methodA(int i) { 9. boolean b: 10. b = i < 10 ... |
|
|
Ok, so I have a loop in my constructor that sets 5 variables with unique Strings every time it loops. I need to run those 5 variables through a couple of methods which decide whether to print the variables to a txt file or not. My problem is that the loop is apparently a static context, and I can't make the ... |
|
|
|
|
|
thanks for the reply, my prob should be like this----------- 1 static int value declared in a static class, now in another class in the same package ther is 1 int value and one button. whenever i press the button this local int value get assigned to that static int value, may be static class ab{ static int p; } class ... |
|
I am new to java and want to know more about static variables. Correct me if i am wrong a static variable is also know as a class variable. it is and can be accessed only using the class name and there is only( i am gonna use this word , i am sure it is not correct ) one instance ... |
later edit Actually this is an open-source project and I'm trying to modify a class. Is it somehow possible that they ( as in the authors of the code ) 'locked' the classes so that nobody else could modify them ? Every time I'm trying to add a method or a variable, I get a java.lang.NoSuchFieldError or java.lang.NoSuchMethodError. If this is ... |
|
17.4.1 Shared Variables Memory that can be shared between threads is called shared memory or heap memory. All instance fields, static fields and array elements are stored in heap memory. In this chapter, we use the term variable to refer to both fields and array elements. Local variables (14.4), formal method parameters (8.4.1) or exception handler parameters are never shared between ... |
lets say on the above case the The Adder class is running and updating the list every 10secs. and then in some point i decided to run my Test class invoking the getmyList() will this invocation give me the size updated by the Adder or will it just give me 0 since it's associated with a different instance of UpdateList(mybe not ... |
|
|
Not at all... I was trying to explain in a way a beginner can understand. What i meant to say was they can be called on (anything static) before a class or the block of code that contains them is created ( a new instance of) ignore the scope comment i made. |
} First control will goes to main and static variable there some calculation is going and result is storing in totalcost.In main method u r just initialising u r not modifying the totalcost calculation.So First result only comes. If u want the result of main method initialization values then u should override the totalcost calculation also after initialization like this way ... |
|
|
|
|
I put everything static because I want this class to be 1 single point that doesnt need to be instantiated, e.g. the program pours data into this model from multiple places and a GUI can extract data without knowing all different parts of the program are contributing. Also for the class to compile I need to set the methods as static. ... |
I've written a superclass a subclasses of it. Superclass is AtomicMove Subclasses are ForwardMove, BackwardMove, RightMove and LeftMove. All the subclasses need two static variables of type AtomicMove. I understand that the superclass cannot force a subclass into having a static variable as the variable is attached to the class itself. However they all share way of manipulating the variable, is ... |
Hi there, I am using a static HashMap and populate some data using a static method in to it. Now the problem is some oracle job will run on overnight and will update more data on to it. Since static block executed only once the data updated by the oracle won't be reflected in static map. Is there any way to ... |
|
|
|
Guys, If I use a static variable for a property of a class , am I violating OOD principles ? For instane , I have a class Bird . Colour is an attribute of any Bird . If for some reason I have to make colour static , it is just as saying that the colour of the bird exists even ... |
Let me put this to your understanding ! I know when we declare a method to be static, it gets registered to the class . It becomes a class member , other than a instance Method ! My question reveals Does it deal with any memory address reference constant. like static variable's ? or it is only about registering in the ... |
yawmark wrote: No. Static fields in Java classes are not static variables - as you point out, they are dynamically allocated, not static. This is one of the reasons Java calls fields 'fields' not variables - to differentiate them from the syntactically similarly constructs in C++, which are static variables. I can't off-hand think of any static variables in Java by ... |
Hi Big what makes you to think that I am going to make the class as a singleton.... I am going to create a separate instance evertime someone wants to access the class.My concern was the static variable because each instance is going to having its hand on the same static variable and one might corrupt the result. |
No, you're receiving a null from table.get because there is no mapping for x, or x is null, or x has been explicitly mapped to null in the table. Your table reference is fine, based on what you have posted. Your code snippet is incomplete, so really only you can determine what is null. Why bother with .get? test table == ... |
Hi, in an application i'm using a static variable to store certain values which are different for each user login. As soon as the login is successfull, i'm setting values to the static variable. but for different logins also it shows the values which is assigned to it first time. Is the values is assigned to the static variable only for ... |
I have a class (from an outside package) that uses a static main method to perform a task. I'd like to call this class multiple times with different arguments (passed in as args to the main). However, just calling the main multiple times doesn't seem to work since it is being used within the package to initialize other variables in other ... |
Because for example "argument" could be a path to a database, and "resource" needs to be a unique object representing that database and will be shared among multiple different Client object (again, in a thread safe way). In that case "argument" will be a constant and should lead to the creation of a single object. Static initialization is a given in ... |
Actually a non-static could be called from run()...if run() were actually a method of ManualMode. But it probably isn't. I think you've misinterpreted the error message somehow, or have cut-and-pasted your code in such a way as to obscure the real problem. My guess is that that run() method is inside an inner class, probably implementing Runnable, and that you're calling ... |
Hi Frndz, I am new to java programming. I have a doubt regarding the static primitive variable. class MyClass { public static int count; // other details } public class Test { main() { MyClass obj1 = new MyClass(); obj1.count++; // now count became 1 MyClass obj2 = new MyClass(); obj2.count++; System.out.println(obj1.count); } } Please tell me what will be the ... |
|
|
When i click x button it gives i as 20 and when i click y button it shows 10 since i is static it will have only one instance i.e. when the class is loaded for the first time, Irrespective of any number of objects u make; Then why am i not seeing the change made to i when i press ... |
|
OK, I guess this is a pretty basic question but I'm asking it anyway. Say I have a class (Class1) that contains a few static variables and a static method to initialize them all to default values. Can I then manipulate these variables in other classes (Class2 and Class3), without ever creating an instance of Class1? I understand that static means ... |
Hello In my class, I have some static variables. I run the application, change the value of these variables. Then I run the application again (still open the first). What about the value of thoese static variables?. Any problem when I have static variables and run the application multi-times in the same VM Thanks shuhu |
I don't understand the problem. What do you mean by "can't see public state final variable content"? Does the variable clienti appear to be null or refer to an empty string or?? I also don't understand why you can't change to non-static variables. Could you have done something wrong when trying? What do you the .jar file seems to require static? ... |
|
|
The first one can be changed by doing a Classname.StaticVariableName = SOME_OTHER_VALUE; The second one is a final value, it is static so can be accessed by any object / with just classname.variable name HOWEVER you can not change it's value.. i.e. StaticVariable = Some_Vlaue. It will cause an compilation error. Regards Ayusman |
|
|
OP, using static variables in an equals method will cause you problems long before you get anywhere near serializing it. since a static variable belongs to a class, it is effectively "always the same" for every instance of that class, so how can it be used to compare and differentiate between two instances?? serializing static variables is a waste of time. ... |
basicly what i got is a file editing program. which let the user modify objects stored in an arraylist that can be saved to a file. To identify objects a static variable is used to set the object number. the problem im having is when i open a file, all the objects currently in the arraylist are labeled. anything i add ... |
|
|
user8742475 wrote: I declare a variable inside a static method. Once I exit the method, is the variable eligible for garbage collection? All variables declared inside a method (including any method parameters) are local to that method and go on the stack. There's no GC involved. The variable simply ceases to exist when the stack frame is popped when the method ... |