Filed under java, Spring on March 22 | 0 comments
I just completed 4 days in a class room on this subject.
A little bit overwhelming.
A lot of good material but it is way too much to digest in just 4 days.
I wish training companies would offer scheduling alternatives to these straight X days hellish setup. I think that offering 2 half days a week for a month would be easier to digest.
After taking this course I have a voucher to go try the exam. I will take it and to prepare I received a few advices that I like:
- Set a date for the exam so you have the deadline motivation working for you
- Use the study guide questions from Spring Source
- Write all the answers on a cheat sheet and carry it with you every where you go to read it over and over
- Redo all the labs and test alternative solutions
So by Monday I will have my schedule written down and I will start on my certification path. I know that it will be a lot of work but I see all the benefits from it and that motivates me more than the deadline.
Filed under code, java on February 24 | 0 comments
I spent a few days doing the pom.xml for a project. The difficulty was all these ancient libraries that the project depends on and that are not in any Maven repository. Ended up creating dependencies from my local repo and writing all the pom files for each library. Blamed it on the technical debt of this project.
One thing that I learned on this one was how to create the assembly file. This is very useful to bundle the project and be ready to deploy. This project is not a purely web app so we have all sorts of other files to bundle to be ready for deployment.
Maven has good documentation but when you are new to everything it takes a little while to sometimes find the right syntax to do what you want.
There was good documentation in this blog entry from Andrew E. Bruno to give me some basic understanding of what I needed to do. The key thing was that the assembly file needs to be in src/assemble and can be named as you wish. It also tells you what to add to your pom.xml to make this work.
I also had to read the Maven documentation about all the keywords that can be used in the assembly file. I wanted to remove the project name from the path in my tar.gz file. I simply needed to add:
<includeBaseDirectory>false</includeBaseDirectory>
right after the formats and everything was clean for my assembly process.
There is probably a few other things I will want to complete with other plugins but this is a good start to simplify the deployment of this project.
Filed under code, java on February 19 | 0 comments
I was not sure where to specify the Main-Class to get Maven to pick it up. Searched a bit and there was this recommendation on the Apache site about creating a src/main/resources/META-INF directory and it talked about the MANIFEST.MF. I must have read things wrong because I was never able to get that to work.
I found this other reference to add it to the pom.xml as a build section under the dependencies. That worked like a charm within seconds.
So here is my pom.xml with the Main-Class addition:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cinq.test</groupId>
<artifactId>project1</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<name>project1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<mainClass>com.cinq.test.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
References:
http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR
http://www.avajava.com/tutorials/lessons/how-do-i-specify-a-main-class-in-the-manifest-of-my-generated-jar-file.html
Note:
I initially forgot to specify the version for the maven-jar-plugin and maven gave me a detailed message to get it fixed:
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.cinq.test:mvntest:jar:0.1.0
[WARNING] ‘build.plugins.plugin.version’ for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 28, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
Filed under code, java on November 27 | 0 comments
This week I was told that my way of going through each elements in an ArrayList was not the most efficient. I should be using an Iterator.
No reason to doubt an experienced programmer so I changed my code.
I never trusted anyone when I did troubleshooting before. I always need to see the evidence for myself. So I decided to do this code to check the validity of the data I was given:
/**
* Testing the performance of different ways to go through a list of items
*/
package com.cinq.test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* @author mc
* @version 0.1.0
*
* last updated on 2011-11-27
* initial release of these tests
*/
public class Performance {
/**
* @param args
*/
public static void main(String[] args) {
long dstart = 0;
long dend = 0;
// Allocate an ArrayList
ArrayList<String> data1 = new ArrayList<String>();
ArrayList<String> data2 = new ArrayList<String>();
for ( int i = 0; i < 10000; i++ ) {
data1.add("abc" + String.valueOf(i));
data2.add("xyz" + String.valueOf(i));
}
// Start going through all the elements with a get index method
dstart = System.currentTimeMillis();
for ( int j = 0; j < data1.size(); j++ ) {
data1.get(j);
for ( int k = 0 ; k < data2.size(); k++) {
data2.get(k);
}
}
dend = System.currentTimeMillis();
System.out.println("Get Index for " + data1.size() + " by " + data2.size() + " elements took " + (dend - dstart) + " ms.");
dstart = System.currentTimeMillis();
for ( String s1 : data1 ) {
for ( String s2 : data2 ) {
// nothing
}
}
dend = System.currentTimeMillis();
System.out.println("For each for " + data1.size() + " by " + data2.size() + " elements took " + (dend - dstart) + " ms.");
dstart = System.currentTimeMillis();
Iterator<String> it1 = data1.iterator();
try {
while ( it1.next() != null ) {
try {
Iterator<String> it2 = data2.iterator();
while ( it2.next() != null ) {
//nothing
}
} catch ( NoSuchElementException e0 ) {
//ignore
}
}
} catch ( NoSuchElementException e1 ) {
// ignore
}
dend = System.currentTimeMillis();
System.out.println("Iterator for " + data1.size() + " by " + data2.size() + " elements took " + (dend - dstart) + " ms.");
}
}
The output I get from this is:
Get Index for 10000 by 10000 elements took 12 ms.
For each for 10000 by 10000 elements took 271 ms.
Iterator for 10000 by 10000 elements took 166 ms.
This makes no sense. I should see the performance of the Iterator way of doing things to be faster than my get(index) way. I will have to ask my co-worker tomorrow why I am getting this bad performance. Conclusion to follow in the next few days.
Filed under code, java on October 28 | 0 comments
Sometimes you have this basic question that you are too shy to ask around because you should know. Reality is that I always have a few of those and eventually you have to look around for what others are doing if you want to get better.
I just completed some code and I was wondering if using the return code for errors was a good idea or if I should have used exceptions everywhere.
After reading a few articles I think that I did the right thing.
One key sentence that I like is: exceptions are for exceptional conditions. So you should see an exception if the failure is not expected and abnormal to the working of your application. A good point.
Others are saying that you should crash loudly. They are saying to use exceptions as much as possible so that it gets your attention and you fix the issue sooner than later.
The argument that return code makes the application more stable seems to be a bit simplistic because you might be hiding issues that will be more difficult to identify later.
There is room for both approach and I think that experience tells you what to do. Always using one or the other does not seem to make sense. Balance.
Return code makes sense right now because this Java code needs to integrate with some Bash code. If the solution was purely Java I think that I would need to change this strategy.
I may start using more checked exceptions since it gives me a better sense of balance and allows to have more information about the failure.
Continuous improvements.
Filed under java on October 20 | 0 comments
I was searching on how to use some library in my Java code and I came across the GrepCode.com site.
It was great help to find the documentation/code for the library I was using. They only claim to have index for Java, JBoss and Eclipse but the F5 library was there as well.
I installed the Eclipse plugin because that could save some time when searching why I am getting a certain error or why some code is not working as expected.
You find new things every day.
Filed under java on October 20 | 0 comments
I have not started to use Java 7 but I have started to read on the differences. This is a great blog post to learn a few new tricks to optimize the JVM:
http://marxsoftware.blogspot.com/2011/10/javaone-2011-definitive-set-of-hotspot.html
It is also funny that the small, almost irrelevant, option is the one that will relieve a serious pain for me:
-XX:+PrintGCDataStamps If this works as I expect we will be able to read GC logs and easily figure out when events have happened
Filed under code, java on September 23 | 0 comments
Wow.
This new type of debugger is something on its own.
It allows you to record your application executing and then replaying it has you need to figure out where the errors are. You simply need to watch their video to get the “wow” factor right away.
It simplifies the code you have to do and gives you a better insight in your application.
I am quite curious to know how it would work on JBoss servers running multiple apps.
http://www.chrononsystems.com/
Filed under code, java on January 6 | 0 comments
I am in the middle of adding features to a web application that uses the Spring Framework and since I have not had any training I am learning as we go. As much as I know better this is where I am anyway.
I have been fighting for a few days with a java.lang.NullPointer issue and it was driving me crazy. I knew that it was some small details that was escaping me but I just could not put my finger on it.
I got a breakthrough yesterday evening by re-reading a form post about the fact that you can’t use the new operator on objects that are wired by the Spring Framework. I was also missing the getter and setter method for that entity and then everything started to work. Small victory that certainly pleased me because it was starting to get to my self esteem.
I was a bit mad at myself for not understanding the tip that was given in the forum on the first read. I was looking for something else and the truth was starring me so obviously. The madness will certainly make sure I remember to pay attention to every recommendation experienced people make when answering other beginners like me.
Understanding how the framework does its things is starting to sink in and I am starting to see the full potential this framework has to quickly develop web application.
If I can just spend some time to read on it and understand all the libraries and a few more founding concepts I could stop wasting my time fighting with it.
Filed under code, java on January 4 | 0 comments
The trivial issues are the one that drive you nuts because you waste too much time for something that should have taken 2 minutes at most.
Today I was fighting with a spring application that uses hibernate to talk to an embedded derby database.
So simple.
Because I am getting a java null pointer exception when I am trying to save an entity I decided to empty the embedded derby database directory so I could start fresh and make sure that this was not the issue. Again simple.
I started to have all sorts of issues in my spring application logs telling me that it could not create the database (I have the property for derby set to create=true).
All I needed to do was to the delete the directory itself and not just the content.
An hour wasted searching on Google and no one was as dumb as I and posted anything about this issue.