full list available here
This blog is supposed to keep track of all the small fixes, good tutorials and cheat-sheets I encounter in my binary life so I won't have to seek them on the web again.
Saturday, January 15, 2011
Sunday, January 9, 2011
New features Java EE 6.0
I found a nice article on this topic here: http://www.javabeat.net/articles/99-new-features-in-java-ee-60-1.html
Thursday, January 6, 2011
Linux Subdirectories of Root directory [cheatsheet]
- /bin - Common programs, shared by the system, the system administrator and the users.
- /boot - The startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
- /dev - Contains references to all the CPU peripheral hardware, which are represented as files with special properties.
- /etc - Most important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows
- /home - Home directories of the common users.
- /initrd - (on some distributions) Information for booting. Do not remove!
- /lib - Library files, includes files for all kinds of programs needed by the system and the users.
- /lost+found - Every partition has a lost+found in its upper directory. Files that were saved during failures
are here. - /misc - For miscellaneous purposes.
- /mnt - Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.
- /net - Standard mount point for entire remote file systems
- /opt - Typically contains extra and third party software
- /proc - A virtual file system containing information about system resources. More information about the
meaning of the files in proc is obtained by entering the command man proc in a terminal
window. The file proc.txt discusses the virtual file system in detail. - /root - The administrative user's home directory. Mind the difference between /, the root directory and
/root, the home directory of the root user. - /sbin - Programs for use by the system and the system administrator.
- /tmp - Temporary space for use by the system, cleaned upon reboot, so don't use this for saving any work!
- /usr - Programs, libraries, documentation etc. for all user-related programs.
- /var - Storage for all variable files and temporary files created by users, such as log files, the mail
queue, the print spooler area, space for temporary storage of files downloaded from the Internet,
or to keep an image of a CD before burning it.
Wednesday, December 1, 2010
The Filter Pattern - Selective Iterators
The following code is from: http://www.erik-rasmussen.com/blog/2008/01/18/the-filter-pattern-java-conditional-abstraction-with-iterables/
import java.util.Iterator;
import java.util.NoSuchElementException;
public abstract class Filter<T> {
public abstract boolean passes(T object);
public Iterator<T> filter(Iterator<T> iterator) {
return new FilterIterator(iterator);
}
public Iterable<T> filter(Iterable<T> iterable) {
return new Iterable<T>() {
public Iterator<T> iterator() {
return filter(iterable.iterator());
}
};
}
private class FilterIterator implements Iterator<T> {
private Iterator<T> iterator;
private T next;
private FilterIterator(Iterator<T> iterator) {
this.iterator = iterator;
toNext();
}
public boolean hasNext() {
return next != null;
}
public T next() {
if (next == null)
throw new NoSuchElementException();
T returnValue = next;
toNext();
return returnValue;
}
public void remove() {
throw new UnsupportedOperationException();
}
private void toNext() {
next = null;
while (iterator.hasNext()) {
T item = iterator.next();
if (item != null && passes(item)) {
next = item;
break;
}
}
}
}
}
Tuesday, November 30, 2010
A little insight on Java's 'type erasure' terminology
As everyone knows, generics have been introduced since Java 1.5 to enforce compile-time type-correctness. However, at run-time, all the type safety is removed via a process called 'type erasure'. So all typed Collections will have their type removed from the bytecode at runtime and explicit casts will be introduced when extracting elements from the Collections. For example List<Double> list = new ArrayList<Double>(); will be translated at runtime to List list = new ArrayList(); . As a result of type erasure, type parameters cannot be determined at runtime. This change has been introduced in ordered to ensure pre-Java 5 code (you may call it 'legacy code') inter-operates peacefully with the newly introduced generics.
Monday, November 15, 2010
[Spring Framework] Constructor vs. Setter injection
Following are a number of paragraphs stripped from "Spring in Action, 2nd Edition" ,by Craig Walls, published by Manning Publications in 2007, which illustrate in a rather friendly manner the ups and downs when opting for a particular type of mutator: [This goes in my blog as a future reference]
"There are certain things that most people can agree upon: the fact that the sky
is blue, that Michael Jordan is the greatest player to touch a basketball, and that
Star Trek V should have never happened. And then there are those things that
should never be discussed in polite company, such as politics, religion, and the
eternal “tastes great/less filling” debates.
Likewise, the choice between constructor injection and setter injection stirs up
as much discourse as the arguments surrounding creamy versus crunchy peanut
butter. Both have their merits and their weaknesses. Which should you choose?
Those on the constructor-injection side of the debate will tell you that:
• Constructor injection enforces a strong dependency contract. In short, a
bean cannot be instantiated without being given all of its dependencies. It is
perfectly valid and ready to use upon instantiation. Of course, this assumes
that the bean’s constructor has all of the bean’s dependencies in its param-
eter list.
• Because all of the bean’s dependencies are set through its constructor,
there’s no need for superfluous setter methods. This helps keep the lines of
code at a minimum.
• By only allowing properties to be set through the constructor, you are, effec-
tively, making those properties immutable, preventing accidental change in
the course of application flow.
However, the setter injection-minded will be quick to respond with:
• If a bean has several dependencies, the constructor’s parameter list can be
quite lengthy.
• If there are several ways to construct a valid object, it can be hard to come
up with unique constructors, since constructor signatures vary only by the
number and type of parameters.
• If a constructor takes two or more parameters of the same type, it may be
difficult to determine what each parameter’s purpose is.
• Constructor injection does not lend itself readily to inheritance. A bean’s con-
structor will have to pass parameters to super() in order to set private
properties in the parent object.
Fortunately, Spring doesn’t take sides in this debate and will let you choose the
injection model that suits you best. In fact, you can even mix-and-match construc-
tor and setter injection in the same application... or even in the same bean."
"There are certain things that most people can agree upon: the fact that the sky
is blue, that Michael Jordan is the greatest player to touch a basketball, and that
Star Trek V should have never happened. And then there are those things that
should never be discussed in polite company, such as politics, religion, and the
eternal “tastes great/less filling” debates.
Likewise, the choice between constructor injection and setter injection stirs up
as much discourse as the arguments surrounding creamy versus crunchy peanut
butter. Both have their merits and their weaknesses. Which should you choose?
Those on the constructor-injection side of the debate will tell you that:
• Constructor injection enforces a strong dependency contract. In short, a
bean cannot be instantiated without being given all of its dependencies. It is
perfectly valid and ready to use upon instantiation. Of course, this assumes
that the bean’s constructor has all of the bean’s dependencies in its param-
eter list.
• Because all of the bean’s dependencies are set through its constructor,
there’s no need for superfluous setter methods. This helps keep the lines of
code at a minimum.
• By only allowing properties to be set through the constructor, you are, effec-
tively, making those properties immutable, preventing accidental change in
the course of application flow.
However, the setter injection-minded will be quick to respond with:
• If a bean has several dependencies, the constructor’s parameter list can be
quite lengthy.
• If there are several ways to construct a valid object, it can be hard to come
up with unique constructors, since constructor signatures vary only by the
number and type of parameters.
• If a constructor takes two or more parameters of the same type, it may be
difficult to determine what each parameter’s purpose is.
• Constructor injection does not lend itself readily to inheritance. A bean’s con-
structor will have to pass parameters to super() in order to set private
properties in the parent object.
Fortunately, Spring doesn’t take sides in this debate and will let you choose the
injection model that suits you best. In fact, you can even mix-and-match construc-
tor and setter injection in the same application... or even in the same bean."
Saturday, October 9, 2010
Simple Apache Lucene tutorial courtesy of "Java Code Geeks"
http://www.javacodegeeks.com/2010/05/introduction-to-apache-lucene-for-full.html
Subscribe to:
Posts (Atom)