edwin

My 6 Days in Phuket

On last February, i spent almost 1 week at Phuket, Thailand. It’s been a wonderful Sea-Sand-and-Sun experience, very recommended for those who enjoy beaches very much. But Phuket is more than just beaches, so many activities and places to visit in this remarkable island.

Let me start with my guide on my 6 days visit to Phuket and how much i spent for each accomodation.

On the first day, i landed and straight went to a 3 star hotel. Which cost me around 1000 baht per night. If you want a much more cheaper rate, you could try a guest house which cost you around 300 bath per night. Luckily my hotel located very near from Patong Beach’s Bangla Road which is famous for its night life.

On the second day, i took a trip to the famous Phi-Phi Island. The Phi-Phi island tour has 2 packages, the Speedboat and the Bigboat packages. The Speedboat is more expensive but cover more islands than Bigboats. I paid around 1100 baht per person for Phi-Phi tour using Bigboats. If you are lucky you could get a much cheaper price by searching for tour packages located outside your guesthouse. Phi-Phi island offer a snorkeling experience surrounded by beautiful islands.

On the third day, i went for a city tour which cost me around 2400 baht per car for 9 hours. I went to wonderful Karon Beach, visit Phuket Aquarium (100 baht per person), visit the Big Buddha, visit Kata View Point and did some culinary hunting (delicious Tom Yum soup).

On the forth day, i took a trip to James Bond Island. The island is famous because the 1974 Bond film “The Man with the Golden Gun” was filmed there. The island is located within the Ao Phang Nga National Park, the place is beautiful and the entire surrounding area is spectacular. The package price in the brochure is around 2900 baht each person, but you can bargain until 1/3 price in low season. I was lucky to got 1500 baht per person despite on high season. James Bond island offer a canoeing or kayaking experience around lots of beautiful islands.

On the fifth day, i rented a “Tuk-Tuk” (traditional thai transportation) for around 800 baht a day and did a Phuket Shopping tour. So i went to Jungceylon Shopping Mall, Phuket Pearl Factory, Phuket Silver Jewelry, went to Butterfly Garden (300 baht per person), Pornthip Store, Phuthai Souvenir Market. On the night, i went to see a Thai Boxing match, it cost me around 1000 baht per person.

On my last day, i spent on beach sightseeing for a while and straight went to airport.

So the conclusion is : if you enjoy beaches so much just like me, Phuket is like a heaven on earth. And if I am offered the second chance to visit Phuket again, I won’t hesitate for a moment.

Here are some pictures i took there,

bangla road performer
bangla road performer, you need to pay 100 baht to take picture with them.


tuk tuk
Tuk-tuk, traditional Thai vehicle.




James Bond island.



Big Buddha Phuket.





Just some random scenery photos

My Wedding Day

February 11th 2012 is my Wedding day

Here are some picture from my Wedding.

Btw please guess, which one is me 😀

(L)

NullPointerException When Using JPA

I got this weird error while trying to select a data using Eclipselink JPA on my Glassfish AppServer

[#|2012-02-02T00:47:09.746+0700|SEVERE| glassfish3.0.1|javax.enterprise.system.std.com.sun. enterprise.v3. services.impl|_ThreadID=31;_ThreadName=http-thread-pool-8080-(1);| java.lang.NullPointerException
	at com.edw.xxx.dto.Account._persistence_set(Account.java)

here is the complete details of my error

[#|2012-02-02T00:47:09.746+0700|SEVERE|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3. services.impl|_ThreadID=31;_ThreadName=http-thread-pool-8080-(1);| java.lang.NullPointerException
	at com.edw.xxx.dto.Account._persistence_set(Account.java)
	at org.eclipse.persistence.internal.descriptors.PersistenceObjectAttributeAccessor. setAttributeValueInObject(PersistenceObjectAttributeAccessor.java:46)
	at org.eclipse.persistence.mappings.DatabaseMapping. setAttributeValueInObject(DatabaseMapping.java:1367)
	at org.eclipse.persistence.mappings.DatabaseMapping. readFromRowIntoObject(DatabaseMapping.java:1258)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildAttributesIntoObject(ObjectBuilder.java:331)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:660)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildWorkingCopyCloneNormally(ObjectBuilder.java:582)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObjectInUnitOfWork(ObjectBuilder.java:551)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:491)
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder. buildObject(ObjectBuilder.java:443)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery. buildObject(ObjectLevelReadQuery.java:635)
	at org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:838)
	at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:464)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:997)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1021)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2857)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1181)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:453)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:714)

And here is the code for my Account.java

@Entity
@Table(name = "account")
@XmlRootElement
@NamedQueries({ 
    @NamedQuery(name = "Account.findAll", query = "SELECT a FROM Account a")
    })
public class Account implements Serializable {
    
    private static final long serialVersionUID = 1L;
	
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "acc_no")
    private Long accNo;
	
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
	
    @Basic(optional = false)
    @Column(name = "pwd")
    private String pwd;
	
    @Basic(optional = false)
    @Column(name = "gender")
    private char gender;	

    public Account() {
    }

    // other setters and getters   
}

Actually, the main suspect here is the attribute “gender”. It shows NullPointerException due to “gender” is a basic type ( char ) while the row “gender” in database is null.

(&) Weird isnt it?

A Simple Java RMI Tutorial

Java Remote Method Invocation (Java RMI) enables the programmer to create distributed Java technology-based to Java technology-based applications, in which the methods of remote Java objects can be invoked from other Java virtual machines, possibly on different hosts. RMI uses object serialization to marshal and unmarshal parameters and does not truncate types, supporting true object-oriented polymorphism.

Let’s just say RMI is the “older version” of ejb remote. Because in EJB, enterprise beans are made available for remote clients using RMI.

In this example, im trying to create 2 different project, one is the RMI Server and another one is RMI Client.

First is a simple interface, i will use this interface to create invocation methods and implementations. This interface will be on both Server’s and Client’s side.

package com.edw.rmi;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Message extends Remote {
    void sayHello(String name) throws RemoteException;
}

and next is the implementation for my interface, it is exist only on the server’s side. It has to implements my interface and extends to UnicastRemoteObject class.

package com.edw.rmi;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class MessageImpl extends UnicastRemoteObject implements Message {

    public MessageImpl() throws RemoteException {        
    }
    
    @Override
    public void sayHello(String name) throws RemoteException {
        System.out.println("hello "+name);
    }
    
}

And next is creating my server side application. Im running on port 1099 for RMI port.

package com.edw.main;

import com.edw.rmi.MessageImpl;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Main {
    
    private void startServer(){
        try {
            // create on port 1099
            Registry registry = LocateRegistry.createRegistry(1099);
            
            // create a new service named myMessage
            registry.rebind("myMessage", new MessageImpl());
        } catch (Exception e) {
            e.printStackTrace();
        }      
        System.out.println("system is ready");
    }
    
    public static void main(String[] args) {
        Main main = new Main();
        main.startServer();
    }
}

And this is my client’s side application

package com.edw.main;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import com.edw.rmi.Message;

public class Main {
    
    private void doTest(){
        try {
			// fire to localhost port 1099
            Registry myRegistry = LocateRegistry.getRegistry("127.0.0.1", 1099);
			
			// search for myMessage service
            Message impl = (Message) myRegistry.lookup("myMessage");
			
			// call server's method			
            impl.sayHello("edwin");
			
            System.out.println("Message Sent");
        } catch (Exception e) {
            e.printStackTrace();
        }        
    }
    
    public static void main(String[] args) {
        Main main = new Main();
        main.doTest();
    }
}

This is the screenshot of what happen on my netbeans’ console, for my RMI client’s side

and RMI’s server side

and this is my netbeans’ project

While this is what RMI messages looks like

Have fun with RMI 🙂