Saturday, December 27, 2014

Observable: Reason for setChanged()

This is useful because it separates the part where you say that the Observable has changed, from the part where you notify the changes. (E.g. Its useful if you have multiple changes happening and you only want to notify at the end of the process rather than at each small step). This is done through setChanged().
- jbx http://stackoverflow.com/questions/13744450/interview-when-do-we-use-observer-and-observable

 ...setChanged is used like a flag I think. This is to avoid unnecessary updating
- James Poulson http://stackoverflow.com/questions/7271044/observable-in-java

But note possible race condition in Java's implementation of Observable where a second call to notifyObservers may not be completed and thus second parameter (if one is provided) is not sent. See answer by mab at http://stackoverflow.com/questions/4446718/why-observable-snapshot-observer-vector/11122611#11122611.

Saturday, December 13, 2014

How to specify JAXB root element

With no metadata specified we need to supply JAXB with a root element name (and namespace).
http://blog.bdoughan.com/2010/10/how-does-jaxb-compare-to-xstream.html
@XmlRootElement
public class Customer {
...

Friday, October 10, 2014

Iteration Syntaxes

http://www.javaworld.com/article/2461744/java-language/java-language-iterating-over-collections-in-java-8.html

Do each syntax on demand.

Sunday, October 5, 2014

Uses of targetNamespace

Example:
http://www.liquid-technologies.com/Tutorials/XmlSchemas/XsdTutorial_04.aspx

Ex. how to define in JAXB @XmlSchema annotation:
http://stackoverflow.com/questions/16584555/understanding-jaxb-xmlrootelement-annotation

Monday, September 29, 2014

Java wait() releases synchronization lock

Threads calling wait() release the synchronization lock on the current instance, i.e. the method with synchronized keyword is allowed to be entered by other threads.
http://tutorials.jenkov.com/java-concurrency/starvation-and-fairness.html

Saturday, May 10, 2014

HTTP POST vs PUSH

It's not as simple as Update vs Create.

According to the HTTP 1.1 specification, GET, HEAD, PUT and DELETE are idempotent, while POST is not.

http://jcalcote.wordpress.com/2008/10/16/put-or-post-the-rest-of-the-story/ Author states that there is no direct mapping between the HTTP and CRUD verb spaces and that a "higher level logic" should be added to complete the transformation.

Sunday, May 4, 2014

readObject and writeObject

Review the nuances of Java serialization, specifically see http://webcache.googleusercontent.com/search?q=cache:Q1Rpg2MReCIJ:www.javablogging.com/what-are-writeobject-and-readobject-customizing-the-serialization-process/+&cd=4&hl=en&ct=clnk&gl=us spells out how readObject and writeObject are called by ObjectOutputStream if present using getPrivateMethod. These are a way to customize serialization. Can call defaultReadObject/defaultWriteObject on ObjectInputStream/ObjectOutputStream before performing custom setup.

Thursday, May 1, 2014

Java vs. C# - Resource Auto Closing

       

            static String readFirstLineFromFile(String path) throws IOException {
              try (BufferedReader br =
                          new BufferedReader(new FileReader(path))) {
                      return br.readLine();
              }
            }
       
 
The above is similar and appears to have the same use case as the C# use statement, in that it allows you to omit the finally block so long as the resource in question implements java.lang.AutoCloseable (Java) vs IDisposeable .NET. The above was new in Java SE 7. ref: http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

Monday, March 17, 2014

Static Classes in Java and C#

The semantics of them are entirely different. In C# it connotes a utility class; in Java it denotes independence from containing class (top level static classes are not allowed in Java).

See Skeet's answer for details: http://stackoverflow.com/questions/7486012/static-classes-in-java