December 31, 2014

Printing content of Java list

This is a very, very simple reference on how to print the contents of a Java List.  The idea is simple. I have a List and I want to loop over it and print whatever is stored in it. But do you really need to code a loop to do this?  Nope.  But I always forget how to correctly do it.  So here it is:

List< String > strings = new LinkedList< String >();
strings.add("one");
strings.add("two");
strings.add("three");

System.out.printf(
 "List< String >.toString()\n%s\n\n"
 ,strings.toString());
System.out.printf(
 "List< String >.toArray().toString()\n%s\n\n"
 ,strings.toArray().toString());
System.out.printf(
 "Arrays.toString(List< String >.toArray())\n%s\n\n"
 ,Arrays.toString(strings.toArray()));

The output looks like this:
List< String >.toString()
[one, two, three]

List< String >.toArray().toString()
[Ljava.lang.Object;@1ea87e7b

Arrays.toString(List< String >.toArray())
[one, two, three] 


Enjoy!


November 24, 2014

Beans Validation java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl

If you are using the Beans Validation framework (JSR 349), you may encounter this obscure exception when doing your validation.

java.lang.ExceptionInInitializerError
Caused by: javax.el.ELException: Provider com.sun.el.ExpressionFactoryImpl not found
Caused by: java.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImpl

This exception is caused by a missing key lookup in the ValidationMessages.properties file.  Make sure you have the the key in the properties file.

Enjoy!

November 17, 2014

DOS equivalent of Unix/Linux alias

The Unix/Linux alias command is great. But now you are stuck in a DOS environment. What do you do?  Use doskey!

The doskey command can be used in a DOS environment to simulate the kinds of things which alias does.  Here is an example from my alias.bat file:

doskey cdhome=cd c:\Users\michael

doskey tw=cd C:\Users\michael\workspace\ferris-tweial\ferris-tweial\ferris-tweial-app\target\unziped\ferris-tweial-app-1.0.0.0-SNAPSHOT

doskey twr=c:\Applications\java\jdk1.7.0_11\bin\java.exe -jar ferris-tweial-app-1.0.0.0-SNAPSHOT.jar 

As you can see, doskey is very similar to alias.  When on a DOS prompt, all you need to do is type tw or twr and that command will be executed. Of course make your own doskey values.

All of my doskey commands are in an alias.bat file.  This means anytime you open a new DOS prompt you need to execute alias.bat to load all the doskey command. Unacceptable! Instead, create a shortcut for either your desktop or toolbar and you edit the shortcut to execute the alias.bat file for you.  The shortcut will look something like this.

cmd.exe /K "c:\Users\Michael\alias.bat"

That's it.

Enjoy!