Archive for the tag 'Java'

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

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

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

Aug 03 2009

Java and the current work directory

Published by under Java

I spent some time looking this up and hopefully I will save someone else time on this. The current work directory for an application in Java is stored in the system property “user.dir”. This is the default directory that you application will write files to if you don’t specify an absolute file location. You can […]

No responses yet

Aug 02 2009

Maven pom.xml structure

Published by under Maven

I wanted to see the full Maven pom.xml structure and I found the following page on the Maven web site that contains all the elements and descriptions. http://maven.apache.org/ref/2.2.0/maven-model/maven.html

No responses yet