tutorials for developers using Android, Google Web Toolkit (GWT), Arduino, and much more...
Wednesday, July 30, 2008
façade pattern
Java: Date manipulation
public static Date getNextHour(Date date)
{
Calendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.HOUR, 1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date time = cal.getTime();
return time;
}
Tuesday, July 29, 2008
Single Purpose Principle
- Interfaces
- Classes
- Methods
- Whole Modules
Wednesday, July 23, 2008
Friday, July 18, 2008
Ambiguous Method Result
/** @deprecated TODO: this bad code, do not use it */
public TeamGame fetch(Game game)
{
Query query = getSession().createQuery("select gameSummary from TeamGame gameSummary where teamGame.game.id = " + game.getId());
List list = query.list();
if (list != null && list.size() > 0) { return (TeamGame) list.get(0); }
return null;
}
/** @deprecated TODO: this bad code, do not use it */
public TeamGame fetch(Game game)
{
Query query = getSession().createQuery("select gameSummary from TeamGame gameSummary where teamGame.game.id = " + game.getId());
List list = query.list();
if (list != null && list.size() > 0) { return (TeamGame) list.get(0); }
return null;
}
Use static methods whenever possible
private String getDayPlaceList()
{
Game game = winnerTeamGame.getGame();
String isDayOrNight = ((getHour(game)) > 17) ? " night at " : " at ";
return (getDayOfWeek(game.getStartDate()) + isDayOrNight + game.getLocation());
}
private static String getDayPlaceList(TeamGame teamGame)
{
Game game = teamGame.getGame();
String isDayOrNight = ((getHour(game)) > 17) ? " night at " : " at ";
return (getDayOfWeek(game.getStartDate()) + isDayOrNight + game.getLocation());
}
Wednesday, July 16, 2008
SQL: CONCAT(), GROUP BY and DATE formatting
SELECT
(CONCAT( MONTH(date_time), "/", DAYOFMONTH(date_time) ,"/", YEAR(date_time))) as date,
COUNT(*) as visits
FROM metrics_session mGROUP BY YEAR(date_time), MONTH(date_time), DAYOFMONTH(date_time);
"Did you find this post useful? Sponsor marathon for cancer"
Tuesday, July 15, 2008
Programming visualization exercise
The "if()" statements would be the corners where you make decisions where to turn.
The classes would be the buildings and the method interfaces the doors you would enter.
The bags you carry into these doors would contain the objects you need.
Oh, and the "Windows" would be the "exceptions" you would use to jump out off when everything goes bad.
Sorry, I had to put it in, I am a Mac guy.
iPhone and Android
I tested a few of them, but I will mention about that later...
First, I want to thank Google for creating Android.
Because of Android we have iPhone SDK, even if this is not 100% true, at least the prospect of thousands of Android developers made it easier for Apple to release it.
We also now have iPhones that are half the original price ($199) - probably to win the public before public learns that there is a real competition out there.
Most of all the intense competition will force both sides to strive for better solutions, and both of the sides win (sorry Winblows Mobile, Palm OS, CrackBerry you don't count anymore).
Why Android?
1) Java API - that fact alone wins Android for me, and thousands others, Apple really mess me up with Objective-C. Hear me out Apple: Java API, and if you want a clean, modern, dynamic language, use Groovy for JVM.
2) Linux core for stability and ability to run on multiple platforms (personally I love OS X UNIX core)
3) great user interface; mostly rip off from iPhone, but I cannot blame them -- there is nothing better out there.
I have a feeling that in some unexpected way there will be a bridge between the two, most likely Android Java apps running on top of iPhone (Java VM coming to the phone near you very soon).
Now, back to iPhone 2.0.
Steve Jobs is a very smart guy (OK, that is a severe understatement). He wanted to control three things, of which he mentioned only two: the quality of hardware and software.
Since Android will not control the hardware quality (open source), I expect that it will be hit-or-miss, some good, some bad. Just like Linux. I hope the big handset manufacturers (Nokia) offset the bad ones.
This brings me to the second control point, the software. The software from Apple is amazing, I had Treo before (Palm OS yuck!).
As I said before I downloaded a 3rd party AIM chat application, one of the most downloaded today and it crashes for most users!!!
This is precisely why Steve Jobs wanted iPhone to have Apple apps only, for the initial launch, smart guy. Android will have no control on quality of the apps, but hopefully they will get the market share.
Then there is the 3rd thing that Steve Jobs wants to control. Money. Almost every piece of good software written for iPhone (except for jailbreak.app) makes money for Apple directly (30% of the cost) or indirectly (iTunes traffic). Google may make more advertising money, but there is no money for them in Android, it is open source, so people can write and install their apps without asking Google, or anybody else.
I think it is worthwhile for us Java developers to learn Android, meanwhile I hope this article is formatted well on your iPhone.
Book "ProBlogger" by Darren Rowse and Chris Garrett
I've been blogging for the most of the last 7 years, still I was able to learned many useful tips from this book that help me put some direction into my blogs.

click me to shop
Monday, July 14, 2008
iPhone and Java...
Hello World, Android!
Wednesday, July 9, 2008
MYISAM vs. InnoDB
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE table_name1 TYPE = innodb;
ALTER TABLE table_name2 TYPE = innodb;
SET FOREIGN_KEY_CHECKS = 1;
Java: generic replace all method
public static String replaceAll(String phrase, String token, String replacement)
{
if (phrase == null || phrase.length() == 0)
return phrase;
if (token == null || token.length() == 0)
throw new IllegalArgumentException("The token you are looking for cannot be empty.");
if (replacement == null)
replacement = "";
int start = phrase.indexOf(token);
if (start == -1)
return phrase;
log.warn("Phrase: \"" + phrase + "\" token found at: " + start);
int end = start + token.length();
phrase = phrase.substring(0, start) + replacement + phrase.substring(end, phrase.length());
phrase = replaceAll(phrase, token, replacement);
return phrase;
}
Tuesday, July 8, 2008
Hibernate: disjunction
Junction junction = Expression.disjunction();
junction.add(Expression.or(Expression.eq("plurality", phrase.getPlurality()), Expression.eq("plurality", Constants.PHRASE_NEUTRAL)));
dcPhrase.add(junction);
Hibernate: detached criteria
DetachedCriteria dcSport = DetachedCriteria.forClass(PhraseSport.class);
dcSport.add(Expression.eq("sport.id", phrase.getSportId()));
List
sports = hibernateList(dcSport);
Monday, July 7, 2008
JUnit class not found (not loading) in Eclipse

Class not found com.ucc.csd.server.PhraseGeneratorTestjava.lang.ClassNotFoundException: com.ucc.csd.server.PhraseGeneratorTestat java.net.URLClassLoader$1.run(URLClassLoader.java:200)at java.security.AccessController.doPrivileged(Native Method)at java.net.URLClassLoader.findClass(URLClassLoader.java:188)at java.lang.ClassLoader.loadClass(ClassLoader.java:316)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)at java.lang.ClassLoader.loadClass(ClassLoader.java:251)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:683)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:425)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Running a single test class with Maven2
Thursday, July 3, 2008
Wednesday, July 2, 2008
Mysql installation on Mac
Hibernate equals(); hashCode(); toString() methods
Tuesday, July 1, 2008
SVN: commands
svn checkout svn://**.***.*.**:port# projectNameworkspace/$ svn checkout svn://x.240.1.10:3692/CSD csdA csd/pom.xml...