• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which situations are possible the use of transient, synchronized, native and protected modifiers?

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which situations are possible the use of transient, synchronized, native and protected modifiers?

thanks,
AS
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I've just read, Transient is used for variable you wish to not be persisted in the sense of being serialized (where the variable is converted to a stream of bytes and stored to a file). The synchronized keyword protects code from being executed by more than one thread at a time. Protected is (I believe) used as a keyword for variables that can only be used through inheritance.

If you google these you will probably find actual code snippet of how these are used as well.

Justin
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But could you give any exemple please?

Really thanks for helping...

AS

 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

André Asantos wrote:But could you give any exemple please?


You'd probably get the answer faster by searching for it yourself. You can always then come back here, post the example, and say "I don't understand something here..."

We generally prefer folks showSomeEffort, rather than just asking for answers to homework problems.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

André Asantos wrote:Which situations are possible the use of transient, synchronized, native and protected modifiers?

thanks,
AS


here is a situation where you need: transient, synchronized, and protected. [but not "native"]
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Justin Fox wrote:Protected is (I believe) used as a keyword for variables that can only be used through inheritance.

The keyword protected allows access in the same package and in subclasses. Not quite "through inheritance." You have obviously been taught by somebody who thought it means the same as in C++ where (I believe) it does mena "thorugh inheritance."
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Masa,
thanks a lot for you attention... But sorry I did not understand your answer...
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

André Asantos wrote:Hi Masa,
thanks a lot for you attention... But sorry I did not understand your answer...

Nor did I.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want a member variable in your class such that it is accessible in any class in the same package your class belongs to or in other subclasses of your class in any other package, use Protected access modifier.
 
Masa Saito
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

André Asantos wrote:Hi Masa,
thanks a lot for you attention... But sorry I did not understand your answer...

Nor did I.


As the class implements Serializable, and and open Socket is "stateful" the Socket would need to be transient.
Writing to the socket's stream would require synchronization (that there are two methods that write is not relevant). the write and the incriment of "x" needs to be atomic. sync-ing only on the output stream would be best. To implement the Factory pattern, you can't have public constructors so you'd need to make the constructor protected. the subclasses would need to have the static factory methods. as static methods can't be abstract, i had to write in the comments the class needs extending.

anyway. take care.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic