my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Valid Variable modifiers ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Valid Variable modifiers ?" Watch "Valid Variable modifiers ?" New topic

Valid Variable modifiers ?

Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
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

SCJP 2 1.4
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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"
synchronized methods only
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.

SCJP2. Please Indent your code using UBB Code
Rajinder Yadav

Joined: May 13, 2003
Posts: 27
Also you can have one or more synchronized blocks within a method.

When faced with an easy thing to do and a hard thing to do, always pick the right thing to do!<p><a href="" target="_blank" rel="nofollow">Rajinder Yadav</a>
Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
thanks for some input. Do you allow transient and volatile in an interface or abstract ?
I agree. Here's the link:
subject: Valid Variable modifiers ?
It's not a secret anymore!