These all use Graphviz to render graphics from generated .dot
files.
Q. Is Java Pass by Value or Pass by Reference? (See also: http://www.youtube.com/watch?v=dk3Iiqof6jA)
With primitives it is simple pass by value. Objects references are passed by value.
Q. Composition vs. Aggregation
Aggregation is a specialization of association, specifying a whole-part relationship between two objects. Composition is a stronger form of aggregation where the whole and parts have coincident lifetimes, and it is very common for the whole to manage the lifecycle of its parts.
Q. What's the difference between using synchronized on a method or in a block?
The main difference is that if you use a synchronized block you may lock on an object other than "this" which is a more flexible approach.
Q. Threads
Q. What is the Java volatile keyword?
Essentially, volatile is used to indicate that a variable's value will be modified by different threads. Declaring a volatile Java variable means: - The value of this variable will never be cached thread-locally: all reads and writes will go straight to "main memory"; - Access to the variable acts as though it is enclosed in a synchronized block, synchronized on itself.
Q. When would you use non-public modifiers on a class?
To make an inner class private.
A Set is a collection that has no duplicate elements. A List is a collection that has an order associated with its elements. A Map is a way of storing key/value pairs. A Map is similar to two-column table.
Q. What are the benefits of immutable objects? (From Brian Goetz: To mutate or not to mutate?)
Immutable classes, when used properly, can greatly simplify programming. They can only be in one state, so as long as they are properly constructed, they can never get into an inconsistent state. You can freely share and cache references to immutable objects without having to copy or clone them; you can cache their fields or the results of their methods without worrying about the values becoming stale or inconsistent with the rest of the object's state. Immutable classes generally make the best map keys. And they are inherently thread-safe, so you don't have to synchronize access to them across threads.
Q. How do you make a class immutable? (See also...)
> Ensure the class cannot be overridden - make the class final, or use static factories and keep constructors private. > Make the fields private and final. > Force callers to construct an object completely in a single step, instead of using a no-argument constructor combined with subsequent calls to setXXX methods (that is, avoid the Java Beans convention). > Do not provide any methods which can change the state of the object in any way - not just setXXX methods, but any method which can change state. > If the class has any mutable object fields, then they must be defensively copied when passed between the class and its caller.
Q. Statements vs. PreparedStatements
Prepared statements make formatting a non-issue, adds some security against SQL injection, and are pre-compiled.