Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what can be static???

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mellihoney Michael
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic