Archive for the 'Java' Category

Jan 10 2014

External File Sort In Java

Published by under data-util,Java

How do you sort a lot of data in Java? It’s easy to sort small amounts of data in memory. For example if your data is in a List object, then with the help of the Collections class you can easily sort the data. You can provide a custom Comparator to control in what order your data […]

2 responses so far

Mar 04 2010

DbVisualizer auto commit problem

Published by under JDBC

I had some issues with DbVisualizer and auto commit. I wanted to be able to turn it off from the SQL commander. The official documentation states that you can do this using: The Auto Commit setting is enabled by default and can be adjusted in the Connection Properties. You may also adjust the  auto commit […]

No responses yet

Oct 08 2009

Java primitive data type sizes for byte, short, int, long, float, double and char

Published by under Java

A handy list for Java data types and sizes Integer Data Types Data Type Size Digits Min Max byte 8-bit signed 3 -128 127 short 16-bit signed 5 -32,768 32,767 int 32-bit signed 10 -2,147,483,648 2,147,483,647 long 64-bit signed 19 -9,223,372,036,854,775,808 9,223,372,036,854,775,807 Floating Point Data Types Data Type Size float single-precision 32-bit IEEE 754 floating […]

No responses yet

Oct 07 2009

How to find project dependencies in a Maven project

Published by under Java,Maven

It’s very useful to be able to see what is included in your class path especially when you’re trying to track down a troublesome dependency. Recently I had an issue with a JDOM dependency; however I had not defined a JDOM dependency in my pom.xml file and I couldn’t quite figure out why this dependency […]

One response so far

Sep 06 2009

Want to use Spring 3.0 milestone release from Maven?

Published by under Java,Maven,Spring

I wanted to add the Spring 3.0 M4 milestone early access release to a Maven project to test out some of the new features. However Spring  milestone releases are not readily available in the standard public Maven repositories, so what do you do? For the full explanation check out the link to “Spring/Maven Repositories” link […]

No responses yet

Aug 31 2009

JUnit 4 error: reference to assertEquals is ambiguous

Published by under Java,JUnit,Testing

This is a somewhat confusing compilation failure that sometimes happen when you write unit tests using JUnit 4. This is an example code snippet that produces this error (result.getValue() returns an Integer object): assertEquals(12345, result.getValue()); And when you try to compile your project it produces a compilation error like this: /projects/myapp/src/test/java/org/myapp/MyTest.java:[88,8] reference to assertEquals is […]

4 responses so far

Aug 26 2009

Spring XML and defining end of line characters in a bean property

Published by under Java,Spring,XML

If you need to define and end of line character (EOL) like n in your Spring XML files in a bean property you can’t do this <bean id=”some-bean-id” class=”some-class”> <property name=”my-property-name” value=”n”/> </bean> This simply wont work. You’ll end up with a backslash followed by the letter n. What you have to do is to […]

No responses yet

Aug 26 2009

Maven, Log4j and javax.jms

Published by under Java,Logging,Maven

Log4j version 1.2.15 added features which has new dependencies on sun and javax packages. When you try to build your project using Maven and log4j 1.2.15 you will see this: [INFO] Unable to find resource ‘com.sun.jmx:jmxri:jar:1.2.1’ in repository central (http://repo1.maven.org/maven2) [INFO] Unable to find resource ‘com.sun.jdmk:jmxtools:jar:1.2.1’ in repository central (http://repo1.maven.org/maven2) [INFO] Unable to find resource […]

No responses yet

Aug 21 2009

How to read environment variables in Java

Published by under Java

You can set environment variables or pass them in using the -Dvariablename syntax SET logfile=/location/to/my/log/file.log or java -Dlogfile=/location/to/my/log/file.log HelloWorld When you want to access these environment variables from your Java source file you can use Java 1.5 and newer: String logfileLocation = System.getenv(“logfile”); Java 1.4 and older: String logfileLocation = System.getProperty(“logfile”);

No responses yet

Aug 19 2009

What jar file does a Java class belong to?

Published by under Java

I found this very useful web site that allows you to search what JAR file a specific Java class belongs to. This has proven quite useful to me over the last couple of days when I had to deal with NoClassDefFoundError and ClassNotFoundException problems. You can just enter the name of the class or JAR […]

One response so far

Older Entries »