Definition of Scalability

"Scalability describes the ability to improve throughput or capacity when additional computing resources (such as additional CPU's, memory, storage, or I/O bandwidth) are added." Java Concurrency in Practice Read more

Pascal Triangle in Java

Pascal Triangle - Heuristic [code language="java"] void printTriangle(int rows) { for(int i=0; i<rows; i++) { for(int j=0; j<rows-i; j++) { System.out.print(" "); } int ... Read more

How to Recursively Delete .svn Directories

Windows: [code]FOR /F "tokens=*" %G IN ('DIR /B /AD /S *.svn*') DO RMDIR /S /Q "%G"[/code]   UNIX/Linux: [code]rm -rf 'find . -type d -name .svn'[/code]   Read more

Want a ConcurrentHashSet Now?

Most likely you came here because you know the java.util.concurrent.ConcurrentHashMap class but couldn't find java.util.concurrent.ConcurrentHashSet. Sorry, this is not in the Java API yet. The good news is that from Java 6 onwards the Collections API provides a method that allows one to obtain the java.util.Map's backing java.util.Set. Here it is: [code]java.util.Collections.newSetFromMap(Map map)[/code], the map passed must be empty. Let's say you need a Concurrent HashSet of Strings, just do the following: [code language='java'] Set<String> stringSet = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); [/code] Read more

Web Project’s “lib” Folder Cleanup

If your Maven-built Web project has a large number of dependencies or depends on projects whose version number is updated frequently, you may want to cleanup its .../WEB-INF/lib directory. After dabbling quite a bit with bat/bash scripts and some maven plugins I found out that an additional cleanup directory can be included to the Maven Clean Plugin. Below is the pom.xml excerpt to instruct maven-clean-plugin to delete all .jar files under the project's .../WEB-INF/lib directory. [code language='xml'] <plugin> <artifactId>maven-clean-plugin</artifactId>  ... Read more

Loading a Directory Structure into an N-Ary Tree

I am developing a Java application to create a backup of multiple directories into another location, in order to do some optimizations I needed to extract some information from the directory tree and keep it in memory. Java I/O provides a nice bidirectional structure (the tree can be traversed either starting from the root or the leaves), but in my backup program I needed additional attributes to each node, and be able to add events. Due to its ability to represent ... Read more

Puzzled? Try another Data Structure*!

You know those times when you find yourself from mildly to totally perplexed with the complexity of your own creation? Have you ever gotten a feeling that some more engineering would make your code much simpler, professional, and easier to maintain --- and that same engineering is something you ignore? The number of data structures a developer knows and the level of intimacy with each of them substantially impacts her or his ability to tackle problems. No matter the programming language, the ... Read more

Getting All Fields from a Class

The method java.lang.Class.getDeclaredFields() gets all the fields (public, private, and protected) in the current class, and the method java.lang.Class.getFields() returns all the accessible public fields of the class or interface represented by the java.lang.Class object. If you need to obtain all Fields from a class, including the inherited ones you must get holder of the class' superclass(es) and then get the declared fields from them. [java] private static Field[] getAllFields(Class<?> clazz) {  ... Read more

Speeding up JBoss 6 Deployments in Development Environment

For several I was convinced that the application deployment process implemented by WebSphere was the worst-performing in the world. Well, that happened until I met JBoss AS 6.  In order to properly deploy an application JBoss simply explodes all of its JARs into a temporary folder, “$JBOSS_HOME/server/<server>/tmp”.  This is a known JBoss bug, more details can be found here: Depending on the footprint of your application tens of JAR files will be unpacked into the aforementioned folder every time you deploy ... Read more

Getting Started with JNI

In this post I am sharing solutions for some problems I have faced while studying Java Native Interface (JNI). Pretty much the same steps found at were implemented, since I needed the simplest case study possible. Although this study is a Java experiment it involves several other technologies. Moreover, we'll be compiling platform-dependent code (the C++ part of it), which means that the the architecture of the operational system and the version of the JVM where our final JNI ... Read more
Page 1 of 212