tags:

views:

68

answers:

3

Please help me to conceptuallize meaning of following keywords with simple example :

  • strictfp
  • assert
  • transient
  • native
  • synchronised
A: 

See what a little google will get you. Question is, why didn't you google (bing, yahoo) it yourself?

http://en.wikipedia.org/wiki/List_of_Java_keywords

Although this page doesn't contain examples, each definition has a link to a much more detailed definition, and in some cases, resources that contain examples.

Robin
+1  A: 

All the replies you want are in the Java Language Specification :

  • strictfp (for classes, interfaces, methods) allows some specific coercion on algbraic operations
  • assert useful to write test statements in code, unfortunatly voided by Sun spec (and the need to enable it during both compilation and execution)
  • transient dirk is right, and I was wrong. transient relates to member fields that are not serialized.
  • native allows the call of so-called native code i.e. code compiled for platform (C compiled with the correct compiler args)
  • synchronized (which can be applied to both blocks and methods for always curious results)
Riduidel
I think, you confused `transient` and `volatile` in your answer (or my understanding of it is broken.) The keyword `transient` is related to Java's serialization mechanism, not to anything related to threads.
Dirk
... and `synchronized` actually does ensure visibility of memory changes, but you are omitting its use for synchronization (read: locking.)
Dirk
He isn't actually asking for the definitions, but coding examples to help explain them. Which as @danben pointed out is asking for five different things. Voted to close.
Robin
Yes, I think each of these keywords could deserve its own question. (Perhaps `synchronized` and `volatile` could be in the same question, but `volatile` wasn't in the list.)
Bruno
A: 
  • strictfp: Floating point computation depends on the architecture of the processor. There will be slight differences in the number representation format in the processor, which will influence the error margin of the floating point operations. Early versions of Java were forcing a common representation in all implementations, irrespectively of the underlying CPU (x86, PPC, ...). This meant that the floating point operations had to be interpreted and couldn't be done as fast as the processor would have done. Later versions of Java (1.2 if I remember well) removed that constraint, to make direct use of the processor for faster result, at the expense of making the floating point results depend on the CPU architecture. Classes or method with scrictfp will force the result to be independent of the CPU architecture.

  • assert: to enforce assertions/"contracts".

  • native: for JNI (linking to C libraries, for example).

  • transient: for (non) serialization.

  • synchronized: I can only recommend Java Concurrent in Practice.

Bruno