Jimmy's Blog

Java

Java ME (J2ME) JSON Implementation For Array Object

by jimmy on Sep.13, 2011, under English, Java, Programming

One of the comment in JSON ME tutorial (http://jimmod.com/blog/2010/03/java-me-j2me-json-implementation-tutorialsample/) asking about how to parse this kind of JSON :

{\”api_status\”: \”OK\”,\”threads\”: [{\"tid\": \"2\",\"title\": \"First Title\" }, { \"tid\": \"4\", \"title\": \"this is 2nd Title\"}]}
 <a href="http://jimmod.com/blog/2011/09/java-me-j2me-json-implementation-for-array-object/#more-246" class="more-link">(continue reading...)</a>
2 Comments :, , , , , , more...

Jimmy’s Blog – ISO 8583 Tutorial – Build and Parse ISO Message using JPOS library

by jimmy on Jul.26, 2011, under English, Java, Programming

ISO 8583 Tutorial article

In the beginning

OK after my article about ISO 8583 let’s go deeper into programming using Java + JPOS library.

Quote from JPOS website:

jPOS is a Java® platform-based, mission-critical, ISO-8583 based financial transaction library/framework that can be customized and extended in order to implement financial interchanges.

So first thing to do is download JPOS from it website.

Then we setup our development environment by creating Java Project using your favorites IDE. Add to the project all jar in JPOS library.
Here’s my Eclipse  package explorer looks like.
(continue reading…)

17 Comments :, , , , , , , , , , , , , more...

Jimmy’s Blog – Slide Number Puzzle Game with Echo2 Framework

by jimmy on Feb.14, 2011, under English, Java, Programming

I’m checking Echo2 framework these couple days and try to make a simple game just to get to know the framework better.
Since I’m not a JavaScript expert it’s good to know that there’s framework that I can use to create AJAX web app with desktop feel easily.
The game is about re-ordering number by moving number to the empty space. It’s simple and fun, this sample is hardcoded to only support 3×3 size.

I assume you know Java, JSP, Servlet basics.
Download Echo 2 from : Echo2 Website
I personally use Eclipse for my IDE.

Step by step:
(continue reading…)

Leave a Comment :, , , , , , , more...

Jimmy’s Blog – Send & Receiving SMS on specific Port with J2ME Application

by jimmy on Feb.10, 2011, under English, Java, Programming

It’s been a while since I write an article, personal and work have been taken my time much lately.

What I will write is not a new things, maybe a lot of article already write this kind of feature. But yesterday I see this kind of project request in freelancer.com so I decide to create a simple sample and write an article about it.

Java Mobile (J2ME) application have a capability to send or receive SMS, but the phone need to support JSR-120 (Wireless Messaging API – WMA 1.0) or JSR-205 (WMA 2.0)
How to check if the phone is supporting this? Easy way if the phone’s brand website. For example for Nokia E72 we can see the technical specifications at http://developer.nokia.com/Devices/Device_specifications/E72/
If your phone doesn’t have WMA library the application will prompt error (the error can be different from one phone to another)
(continue reading…)

45 Comments :, , , , , , , , more...

Basic LWUIT tutorial/sample with Eclipse Pulsar

by jimmy on Apr.17, 2010, under English, Java, Programming, Technology

I was really want to try LWUIT since several months ago. It’s look promising and it’s developed by SUN so I think every Java ME developer should take a look on this technology.
I’m also still new in LWUIT so there won’t be a lot that I can share for now, but at least I will show you a basic demonstration of how to use Form, Label, Command, and 3D Form transition (sound cool huh :p)

REQUIREMENT

What you need:

  1. LWUIT
  2. Eclipse Pulsa
  3. Emulator like Sun WTK
  4. Know basic Java ME programming :) (continue reading…)
47 Comments :, , , , , , , , , , , , , more...

Java ME (J2ME) JSON Implementation Tutorial/Sample

by jimmy on Mar.03, 2010, under English, Java, Programming

JSON is one of the most popular format used for communicating between (Java ME) J2ME client and App Server. Strangely it’s hard to find JSON implementation sample in J2ME. So I decide to write a sample.

(continue reading…)

30 Comments :, , , , , , , , more...

Bind JBoss to specific IP address

by jimmy on Dec.28, 2009, under Java, Linux

Simple but I think it will help JBoss newbie (like me :]) when searching the internet.

By default when you run JBoss ( ./run.sh in Linux) it will bind to localhost/127.0.0.1
This will cause the JBoss default port 8080 cannot be access from other computer, because you need to open http://127.0.0.1:8080/ instead of your IP http://<your IP>:8080/ (continue reading…)

6 Comments :, , , , more...

Java Application – Make sure only single/one instance running – with File Lock and ShutdownHook

by jimmy on Jul.21, 2008, under English, Java, Programming

Often we want to make sure that only 1 instance our application running.
Because something terrible could happen when more than 1 instance running (for example the whole server would exploded and that would make you fired ;) )

Nevertheless what the reason, one of the way to make this happen is by creating a lock file as a sign that an instance is currently running.
So you application will have this flow: (continue reading…)

23 Comments :, , , , , , more...

Using mock object with jmock 2

by jimmy on Dec.26, 2007, under English, Java, Programming

Okay, finally you decide it’s time to create a unit testing for your project (after a long ad hoc programming life :p).
When you create a sample unit testing, it’s all seem so simple.. you fascinate by the junit easiness, how it can do reflection and make it simple.

When you want to create a real unit testing for your project, you realize that a ‘real’ method is not like just adding 2 int argument and return a result. It’s more complex and using interface as parameter is common…
Now a thought cross your mind “do I have to create all stupid classes to implement all the interface I need?”, you starting to think that creating unit testing is really waste of time & you don’t want to do it anymore :p

It’s time mock object framework come to rescue… before you fall to the darkness of untested code :)
There’re several mock object framework like jMock, easymock, etc

Here’s an example creatin HttpMethod mock-object with jMock 2 & JUnit 3

[sourcecode language='java']
public class sampleJMockTest extends MockObjectTestCase {
public void testCreateHTTPMethod() {
final HttpMethod httpMethod = mock(HttpMethod.class);
checking(new Expectations() {
{
allowing(httpMethod).getResponseBodyAsString();
will(returnValue(”sample response”));
}
});
SomeObject someObject = new SomeObject();
someObject.someMethod(httpMethod);
}
}[/sourcecode]
This sample will create an instance of HttpMethod (which is an interface) and when this mock object’s ‘getResponseBodyAsString’ method called it’ll return “sample response”.
So now we can easily create all interface implementation we need.Of course there’re more in jMock than just this simple feature, check it more at jMock Cookbook

Leave a Comment :, , , , , , , more...

Java – Adding new Classpath at Runtime

by jimmy on Dec.19, 2007, under English, Java, Programming

There are cases where we need to add classpath at runtime. For example adding jar to classpath, but depends on configuration or some logic at runtime.

The class who responsible for handling classpath list is URLClassloader.
You can get current system URLClassLoader with:
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();

If you check javadoc about this class you’ll see:

protected void addURL(URL url)
Appends the specified URL to the list of URLs to search for classes and resources.

So you’ll just need to call the addUrl method to add new path/jar file.
But wait a minute, the method is protected… :( do I need to create a subclass or put the caller class on same package?
Creating a subclass is one way to do it, but there’s simpler way (I’ll create article about creating URLClassLoader subclass next time :p)

Here come the savior : Reflection
By using reflection we can break OOP concept about encapsulating method. It’s feel good to break the rules right (warning : use this at your own risk, you know you’re breaking the OO rule. So I won’t responsible if your computer explode or you’ll fighting with OO fans because of this)

Here a sample how to called it with reflection:
[sourcecode language='java']
public static void addPath(String s) throws Exception {
File f = new File(s);
URL u = f.toURL();
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class urlClass = URLClassLoader.class;
Method method = urlClass.getDeclaredMethod(”addURL”, new Class[]{URL.class});
method.setAccessible(true);
method.invoke(urlClassLoader, new Object[]{u});
}[/sourcecode]
Happy reflecting.. :)

2 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...