GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes what can be static??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what can be static???" Watch "what can be static???" New topic
Author

what can be static???

Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
what can be static??? classes??? methods??? variables???what happens inside JVM when I have an class whith some static code, and then I create 2 objects with this class. If I try to access a static method which is not synchronized and try to access a non-static method Which is not synchronized using those 2 objects simultaneously. The jvm treats static and non-static methods equally??? The execution of method main, causes a thread. The most important thread. Which is not daemon. Is this true???
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
A method can be static. A variable can be static. Static variables are shared by all users of the class. Static methods are simply methods that can be executed without instantiating the class they are in.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
a static variable can't be a reference variable, and a static method can be easily accessed without creating an instance of the class where that method lies.
[ December 14, 2002: Message edited by: Melliholic Michael ]

a beginner in java
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
I'm very young with java. I wrote a code and it compiled:
import javax.swing.JButton;
public class test{
static int a=10;
static JButton button=new JButton("button");
}

in this case button is a static variable, which has a reference type! isn't it???
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
leandro oliveira,you are right, I made a mistake!
A final var can't be a reference variable!!!
Thanks for your reminding!
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
Originally posted by Melliholic Michael:
leandro oliveira,you are right, I made a mistake!
A final var can't be a reference variable!!!
Thanks for your reminding!

Um, not sure what you are saying here? Both final variables and static final variables are not limited to primitives only. For example:

Returns:

Note how the contents of the final static StringBuffer can change, although the reference itself cannot. :roll: :roll:
 
GeeCON Prague 2014
 
subject: what can be static???