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();
}
}
}
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.
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.
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/.
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.