programming

RPC in the Java Platform

In distributed computing, there is an essential need for the applications in the distributed environment to be able to use the functionalities offered by each application without knowing how these functionalities are implemented. One common possibility for this is the Remote procedure call (RPC), which is an Inter-Proccess communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network). Java Remote Method Invocation is the Java implementation of Remote Procedure Call. In the solution for this "Problem", we will take a look at the mechanism of Java RMI.

Factory Method Pattern example in Java

Here is a sample code for the Factory Pattern in Java. Programmer can use the abstract class Toy to create 3 types of toys Pokemon, BabieGirl, SuperMan in runtime without having to explicitly define the type of the Toy in compile time (see the class FactoryMtdDemo)

import java.util.*;

abstract class Toy {
public abstract void play();
public abstract void stopPlay();

public static Toy factoryMtd(String toyName) throws Exception {

if (toyName == "Pokemon")
return new Pokemon();

if (toyName == "BabieGirl")
return new BabieGirl();

if (toyName == "SuperMan")
return new SuperMan();

throw new Exception("No toy called " + toyName );
}
}

class Pokemon extends Toy {
Pokemon() {}

public void play() {
System.out.println("Pokemon : play");
}
public void stopPlay() {
System.out.println("Pokemon : stopPlay");
}
}

class BabieGirl extends Toy {
BabieGirl() {}

public void play() {
System.out.println("BabieGirl : play");
}
public void stopPlay() {
System.out.println("BabieGirl : stopPlay");
}
}

class SuperMan extends Toy {
SuperMan() {}

public void play() {
System.out.println("SuperMan : play");
}
public void stopPlay() {
System.out.println("SuperMan : stopPlay");
}
}

public class FactoryMtdDemo {

public static void main(String args[]) {
String toyNameLst[] = {"BabieGirl", "SuperMan", "Pokemon", "SuperWoman"};
ArrayList toyAryLst = new ArrayList();
try {
for(int i = 0; i < toyNameLst.length; i++) {
toyAryLst.add(Toy.factoryMtd(toyNameLst[i]));
}
}
catch(Exception e) {
System.out.println(e);
}

Iterator iter = toyAryLst.iterator();

Toy toy = null;
while (iter.hasNext()) {
toy = (Toy)iter.next();
toy.play();
toy.stopPlay();
}
}
}

Taggings:

Speed up communication between Application and MySQL Database

There are some ways to improve performance of executing SQL Statements on a distant Database Server.

In case of SELECT queries it can be useful to analyze the queries and determine if all data which has been retrieved is really necessary. Size of the result can be drastically decreased, if you just retrieve specific fields instead of using SELECT * FROM xy WHERE ...
There is also the possiblity that you can put logic from application into a query, so only one query has to be sent to Database Server, instead of executing several queries and then process the result on Application Server.

In case of many similar INSERT or UPDATE statements several optimization processes can be done.

First of all it is useful to use PreparedStatements instead of normal statements as this takes load from Database Server as statements don't have to be generated new on every request.

In an second attempt it is useful to gather all statements into a Batch Job. And when you are finished with generating all statements you execute the Batch. So all data is sent together to the MySQL Database.

If you have several batches which have to be processed and should not return the result immediatly it is very useful to disable "AutoCommit". So you can execute all batches and commands and when you are finished sending all comands to server, you can execute COMMIT and everything is processed at once on database server. (Dont forget to enable "AutoCommit" afterwards again)

For my Internet Application these steps have increased the processing time of a large data update from about 3-4 Minutes down to 3 seconds.

Slow MySQL execution over Network under Java

If an application and the connected database is developed and tested on one single machine, code optimization and design of queries may suffer due to instant access time and nearly no transfer time between database and application. However, if you put the Application and Database on different machines such design flaws can lead to horrible processing times. There are several fields that may cause problems in that case. One problem is transferring of many records from or to database. Another problem is execution of hundreds of single independent SQL statements in a very short time, where the application always has to wait for response of database.

JSON - The better way than XML to return complex data from server to Rich Internet Applications client (ajax) or Flash

JSON, short for JavaScript Object Notation, is a lightweight computer data interchange format.

In some application, server has to return complex data to client, and it is better to use JSON since it is object and we can access its attribute easily like in object-oriented languages.

Taggings:

Using RDF(S) without XML.

RDF can be written in some ways: A RDF triple could be represented through a RDF graph, through FOL expressions like P(X,Y), or - most common used for web development - through XML. There are some good RDF/XML parsers for the most common web development languages like Perl or Python. But is there another way of writing RDF, which is supported by a parser for programming/script languages?

dlvhex - Semantic Web Reasoning

dlvhex is the name of a prototype application for computing the models of so-called HEX-programs, which are an extension of Answer-Set Programs towards integration of external computation sources. Not as in "pure" DLV you are not restricted to a certain knowledge base format. dlvhex allows you to reason on a large amount of knowledge bases, such as XML, RDF or OWL files.

dlvhex has some more advantages, which best can be explored at http://www.kr.tuwien.ac.at/research/systems/dlvhex/.

Taggings:

How to creat a new Seam Web Project using Eclipse

This is the solution of creating Seam Web Project on Eclipse, JBoss Tools and JBoss 4.2 (JBoss Application Server (or JBoss AS) is a free software / open source Java EE-based application server. Because it is Java-based, the JBoss application server is cross-platform, usable on any operating system that Java supports) as intented Web server to be deployed on: Prerequisites: 1) Eclipse and JBoss Tools are installed 2) JBoss AS 4.2 is installed If you have installed the prerequisted software in your PC or notebook, you just follow the instruction below: 1. Start up Eclipse with a brand new workspace. This can be achieved many different ways but the easiest is with a fresh installation of Eclipse and the second easiest is going to File -> Switch Workspace -> Other and browsing to a new directory to be the workspace. 2. With your new workspace, go to File -> Project. This will open the New Project wizard and you want to go down to the Seam folder and select the Seam Web Project (wizard). 3. The Seam Web Project wizard will guide you through the rest of the project configuration including setting up a target runtime and server. Start off by creating a new Target Runtime with JBoss v4.2 as the runtime type. Click next and follow the instructions by specifying the JRE and Application Server Directory for the JBoss 4.2 Runtime. Click Finish when complete. Now it’s time to create a new Server Runtime. Choose the JBoss AS 4.2 as the server type, click Next, and fill in the Name and Home Directory fields. Click next again then finish when completed. This will bring you back to the Seam Web Project wizard. With JBoss 4.2 as the target runtime and server, select “Dynamic Web Project with Seam 2.0 (technology preview)” as the configurations and click Next to continue. 4. Select the Project Facets you need for your project then click Next. The Web Module dialog allows you configure the web module settings. When completed, click Next. The JSF Capabilities dialog allows you to add JSF Capabilities to this web project. When done, click Next. 5. Now it’s time to configure the Seam Facet. First, let’s add a Seam Runtime. In the New Seam Runtime dialog, browse to the home directory of the Seam 2.0 runtime and make sure the Name and Version are filled in appropriately then click Finish. Now, we need to setup the database connection. Click the “New” button to create a new Connection profile and select “Generic JDBC Connection” as the connection profile type. Give a name to our new connection profile and click Next. Select a driver from the drop-down or click the “…” button to establish a new driver definition (this tutorial assumes no driver definitions have been specified). After clicking the “…” button, select the MySQL / 5.0 driver definition entry and click Add. Then, select the “MySQL JDBC Driver” driver template and make sure the box is checked to “Edit New Driver Definition Immediately”. Add the necessary jars to the driver files box and remove any that are not applicable or not found then click OK. Scroll down the driver definitions box and select the new MySQL JDBC Driver definition and click OK. Fill any applicable fields in the Driver and Connection Details dialog window then click Finish. Fill in the DB schema and catalog name if known and modify the Code Generation section as needed then click Finish. Clicking Finish, will prepare and create the Seam Web Project for Eclipse. That's it!!! I hope that this information is some usefull or will be usefull to you in the future.

Creating a new Seam Web Project using Eclipse

<p>First of all, I would like to give you a short information about JBoss Seam. JBoss Seam is a powerful new application framework for building next generation Web 2.0 applications by unifying and integrating technologies such as Asynchronous JavaScript and XML (AJAX), Java Server Faces (JSF), Enterprise Java Beans (EJB3), Java Portlets and Business Process Management (BPM). Seam has been designed from the ground up to eliminate complexity at the architecture and the API level. It enables developers to assemble complex web applications with simple annotated Plain Old Java Objects (POJOs), componentized UI widgets and very little XML. The simplicity of Seam will enable easy integration with the JBoss Enterprise Service Bus (ESB) and Java Business Integration (JBI) in the future.</p>

Installing JBoss Tools on Eclipse

<p>My aim is to figure out how should JBoss Tools be installed on Eclipse IDE. I guess probably most of you know already Eclipse IDE and possibly heard about JBoss Tools. As we are going to develop some Rich Internet Application, I need your advice for my statement.</p>

Pages

Subscribe to programming