Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valid Variable modifiers ?

 
Robbie kyodo
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
transient - unserialized variable -- is it allowed in an interface ? why ?
strictfp - only for class and methods not for variables
volatile - what is it for ?
synchronized - methods only
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
transient is not allowed in interfaces. It only makes sense for instance fields. Fields in an interface are automatically public static and final.
___________________________________________________
"strictfp - only for class and methods not for variables"
True
____________________________________________
synchronized methods only
True
_____________________________________________
volatile is used to ensure that the changes to a primitive field, made by one thread, are always visible to others threads. It is like having synchronized the accessor and mutator methods of the field.
In the case the accesses to a variable occur through several threads, and they are not synchronized; declaring the variable as volatile --as an alternative to synchronizing the accesses-- might mean an advantage in performance.
 
Rajinder Yadav
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you can have one or more synchronized blocks within a method.
 
Robbie kyodo
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for some input. Do you allow transient and volatile in an interface or abstract ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic