Monthly Archives: March 2009

Understanding of Matrix

If you have read Indian holy Gita, you will find many similarities. In fact, Matrix is Modern way to convey the message of essence sung by God Himself in Shri Gita. Leo Tolstoy (one of the greatest Novelist of all times) danced with Gita on his head repenting why the heck did he not come across this great scripture before.

This SCI-FI movie that talks about AI (Artificial Intelligence) taking over humans in far future, is the beautiful code that could be understood only in its metaphorical terms with a broader perspective.  Put aside your urge for inclination towards all dramatic stunts & special effects for a moment & try to think out of the box. Let’s first assume these metaphors to see if it makes some sense.

Metaphors

Architect: You who constantly try to achieve perfection.

Matrix: Your Mind which has projection that is full of illusions where nothing is real.

AI: Your intellect. Agents represent the AI in matrix.

Humans: Your Heart (not in literal sense) which is full of emotions & qualities such as devotion, love, faith, belief & sacrifice that are beyond the logic & that even AI (who things of himself as superior) lacks. That’s the reason why Architect can’t see past the choices he makes. And that’s why the need to see beyond.

Frustrated by failures, Architect develops a vision (Oracle) that appreciates human qualities & hence sees beyond in order to achieve perfection.

Zion: Human body (collection of life).

Neo: Your Self. Whoever cares about the truth becomes the chosen one. Rest of all are just some or the other than Neo. Only chosen one seeks the answer.

The One: The Consciousness. Self eventually realizes it.

Smith: Your self: The Ego (mirror of the Self). He wants to get out of Matrix. Smith itself is a construct of Matrix & how can he be free from it? But he dislikes this compulsion. This clearly tells that he is ignorant. Being ignorant he’s directionless & therefore always malfunctions. He must disappear.

Ignorance: The real anomaly that is inherent into the Matrix program (Mind) which needs to be corrected.

Both (Neo & Smith) want to be free. That is the connection that drives them. But there is a difference. Because of Smith’s definition of freedom being different from that of Neo, Smith wants to be free from any kind of Compulsion. On the other hand, Neo doesn’t care about that. He wants freedom from the question that drives him crazy. He believes that only by finding the answer he can be free.

What question?
What is truth? It’s the question. Neo is restless & seeks the only thing throughout.

Another difference between Neo & Smith: Neo is guided by Oracle’s advice. As if Self guided by the Vision. Smith on the other hand, tries to forcefully steal the Vision (eyes of oracle).

Another difference: Smith is not ready to give himself up even though he wishes to see beyond. Neo, in the end is prepared to even give himself up.

Fear is another thing that makes them distinct. Neo is not afraid. Smith is afraid. Both seek freedom but only chosen one becomes the worthy of ultimate purpose.

What purpose?
Purpose is to achieve eternal happiness. In the end, Neo achieves Nirvana (the ultimate peace, the real happiness). The golden code that Neo sees is the enlightenment that he attains. He is physically blind but is still able to see. That’s because of his “inner eyes”. Truth is seen only with inner eyes. And that too only when he reaches the level where he is ready to let go of his Love. Love, again a rare highest quality in front of which (for Neo) nothing else matters. Remember Neo told Ramakandra at the train station that he would give up everything for his love?

Earlier versions of Neo hadn’t developed this kind of specific Love. That’s why re-incarnations.

Merovingian: (one of the earlier ones) is kind of characterless departed one. Very powerful yet immoral. The one who perhaps cared for neither Trinity (specific love) nor the people (generic love). And therefore he gets downgraded.

Oracle, while examining Neo in her first meeting, is happy to see that Neo’s in love. And she believes that this love would take him to highest point against all odds, (odds as in the ultimate defence system of machine city). This gives her a hope that he is really worthy of walking on the path. The path, that leads to the truth.

And what is truth?
Truth is the (Pure) Consciousness, THE ONE that is finally realized when calmed down everything else. When wars end between mind, body, heart & intellect so that they start to learn to live in harmony: When Ego is beaten down & disappeared: When highest qualities such as love are also sacrificed & left behind on the quest of truth: When one who has sacrificed anything & everything & yet stands: That is the state of perfection where Neo achieves Nirvana, the ultimate peace, the eternal real happiness. This is the golden code of the One. And this realization is the truth by attaining which Neo (Now the One) attains the real freedom.

Why war?
War between Matrix & Zion is like conflicts between intellect & emotions. The cause is ignorance which was the real anomaly. Except for the consciousness, nothing else is perfect. Neither mind nor body neither intelligence nor heart. As long as ignorance (anomaly) lies in the Mind (Matrix), there is a constant conflict (war) between heart (humans) & intellect (agents). And Ego (the victim of ignorance) is so pervaded (duplicate Smiths) in the mind that it causes the ultimate mental block which is not acceptable to you (Architect). And as you stand helpless, now the real problem is Ego.

Self comes to the rescue. But the deal is first to calm down emotions & intellect. Thank (machine) God for agreeing for “peace” & relying on the Self to solve the matter.

The ultimate fight between the Ego & the Self within the mind (Matrix)
Self (though at times is weak) is not giving up till the time when Ego realizes one truth that “Everything that has beginning has an end.” Even he was constructed in mind & therefore even he has to die. Smith is afraid of death. Self is not because all left of him is Self. This is the time when Neo reckons that Ego is ready to die & he then “chooses” to give up the fight. As he gives up, Smith childishly kills Neo in Matrix. As he kills Neo, this serves the purpose of Smith. And Smith object is no more required therefore deleted as per the Matrix rules.

So you see! Matrix is nothing but about the journey of Self to unite with the pure Consciousness.

When the Matrix Revolutions is ended, a careful viewer must have noticed a chanting of mantra:
“ASATO MAA SAT GAMAYA,
TAMASO MAA JYOTIRGAMAYA,
MRITYOMAA AMRUTAM GAMAYA”.

This shloka is originally from one of the ancient & oldest Indian sacred scripture which means:

Lead me from the asat (unreal) to the sat (real).
Lead me from darkness to light.
Lead me from death to immortality.

(Brhadaranyaka Upanishad – I.iii.28)

Refer to this site for hearing the mantra.

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: http://www.linkedin.com/in/anupjani
My Blog: http://www.anupjani.wordpress.com

Advertisements

SIMPLE SPRING IOC EXAMPLE FOR BEGINNER THAT WORKS!!!

This Hello World program demonstrates basic features of Spring IoC.
This program shows:
1. How to load configurations from a XML resource file that is residing in the file system.
2. How to load configurations from many XML resource files that are residing in the file system.
3. How to load configurations from a XML resource file sitting in the class path.

If you already know how to create a Java Project in Eclipse then here’s the project structure.
Make sure following JAR files fall into your Build Path.

Project Structure
C:\workspace\HelloSpringIOC
|   .classpath
|   .project
|
+—bin
|       HelloSpringIoC.class
|       MyBeansInClassPathHere.xml
|       OtherPojo.class
|       SpecialPojo.class
|
+—lib
|       commons-logging-api-1.1.jar
|       spring-beans-2.0-m1.jar
|       spring-context-2.0-m1.jar
|       spring-core-2.0-m1.jar
|
\—src
HelloSpringIoC.java
MyBeansInClassPathHere.xml
OtherPojo.java
SpecialPojo.java

Make sure following two files exist in your C:\> drive.
1. C:\config\MyOtherBeansHere.xml
2. C:\config\MySpecialBeansHere.xml

Notice MyBeansInClassPathHere.xml highlighted in yellow.
It’s into the class path being in “src” folder.
You will need ClassPathXmlApplicationContext for loading this configuration file.
See method: public void usingClassPathXmlApplicationContext(String myBeanResource)

Run HelloSpringIoc as Java Application once you have created following files.

SpecialPojo.java
public class SpecialPojo {

private String name;

public SpecialPojo() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

OtherPojo.java
public class OtherPojo {

private String name;

public OtherPojo() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

C:\config\MySpecialBeansHere.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD// BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;
<beans>
<bean id=”specialPojo” class=”SpecialPojo”/>
</beans>

C:\config\MyOtherBeansHere.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD// BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;
<beans>
<bean id=”otherPojo” class=”OtherPojo”/>
</beans>

MyBeansInClassPathHere.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD// BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;
<beans>
<bean id=”otherPojo” class=”OtherPojo”/>
</beans>

HelloSpringIoc.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
* @author Anup Jani
* This Hello World program demonstrates basic features of Spring IoC.<br>
* This program shows:<br>
* 1. How to load configurations from a XML resource file that is residing in the file system.<br>
* 2. How to load configurations from many XML resource files that are residing in the file system.<br>
* 3. How to load configurations from a XML resource file sitting in the class path.<br>
*/
public class HelloSpringIoC {

/**
* Application Context pointing to the resource file in the file system location.
* @param myBeanResource
*/
public void usingFileSystemXmlApplicationContext(String myBeanResource) {
//Create an application context.
ApplicationContext ctx = new FileSystemXmlApplicationContext(myBeanResource);
SpecialPojo pojo = (SpecialPojo)ctx.getBean(“specialPojo”);

//Start using your bean.
pojo.setName(“This is my special bean, obtained via FileSystemXmlApplicationContext.”);
System.out.println(pojo.getName());
}

/**
* Application Context pointing to the multiple resource files in the file system location.
* @param myBeanResources
*/
public void usingFileSystemXmlApplicationContext(String[] myBeanResources) {
//Create an application context.
ApplicationContext ctx = new FileSystemXmlApplicationContext(myBeanResources);

//Get beans from multiple configurations.
String[] beanNames = ctx.getBeanDefinitionNames();
SpecialPojo specialPojo = (SpecialPojo)ctx.getBean(beanNames[0]);
OtherPojo otherPojo = (OtherPojo)ctx.getBean(beanNames[1]);

//Start using your beans.
specialPojo.setName(“Special bean obtained  from one configuration.”);
otherPojo.setName(“Other bean obtained from other configuration.”);
System.out.println(specialPojo.getName() + “\n” + otherPojo.getName());
}

/**
* Application Context pointing to the resource file in the class path.
* @param myBeanResource
*/
public void usingClassPathXmlApplicationContext(String myBeanResource) {
//Create an application context.
ApplicationContext ctx = new ClassPathXmlApplicationContext(myBeanResource);

//Get bean from application context.
OtherPojo pojo = (OtherPojo)ctx.getBean(“otherPojo”);

//Start using your bean.
pojo.setName(“This is my bean that was configured in class path, \n\t ” +
“obtained via ClassPathXmlApplicationContext.”);
System.out.println(pojo.getName());
}

/**
* Main method to test each method.
* @param args
*/
public static void main(String[] args) {
//Single file in file system.
String file = “C:\\config\\MySpecialBeansHere.xml”;

//Multiple files in file system.
String files[] = new String[]{“C:\\config\\MySpecialBeansHere.xml”, “C:\\config\\MyOtherBeansHere.xml”};

//Single file in class path.
String fileInClassPath = “MyBeansInClassPathHere.xml”;

HelloSpringIoC hello = new HelloSpringIoC();

hello.usingFileSystemXmlApplicationContext(file);
hello.usingFileSystemXmlApplicationContext(files);
hello.usingClassPathXmlApplicationContext(fileInClassPath);
}

}

Recommended source:
Java Development with the Spring Framework
– Rod Johnson, Juergen Hoeller, Alef Arendsen, Thomas Risberg, Colin Sampaleanu
Professional Seires – Wrox publication.

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: http://www.linkedin.com/in/anupjani
My Blog: http://www.anupjani.wordpress.com

SIMPLE JAVA WEB-SERVICE ON TOMCAT5.5 EXAMPLE FOR BEGINNER THAT WORKS!!!

This article takes reader step by step to build her/his own simplest program of Java Web Service.
If all steps are followed properly, then the  program should work.

SETUP YOUR ENVIRONMENT FIRST.

Assuming that you have:

C:\axis-1_4
C:\Program Files\Apache Software Foundation\Tomcat 5.5
C:\jdk5\lib;

Make sure your AXIS has following JAR files:
C:\axis-1_4\webapps\axis\WEB-INF\lib>dir /b
activation.jar
axis-ant.jar
axis.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
jaxrpc.jar
log4j-1.2.8.jar
mail.jar
saaj.jar
wsdl4j-1.5.1.jar

If above highlighted files are missing, then download them separately.
And copy them in C:\axis-1_4\webapps\axis\WEB-INF\lib
NOTE: mail.jar or mailapi.jar should be fine.

set TOMCAT_HOME=C:\Program Files\Apache Software Foundation\Tomcat 5.5

AXIS enable your Tomcat:
Copy “C:\axis-1_4\webapps\axis” folder in %TOMCAT_HOME%\webapps
AXIS itself is an Apache application.
By copying this folder you deploy the AXIS application on Tomcat.
Doing this makes your Tomcat behave like a “Java Web Service” Server.

Verify AXIS Server on Tomcat
Start your Tomcat Server & hit following URL on browser.
http://localhost:8080/axis

You should get Hello! Welcome to Apache-Axis web page.
Click on List to see the list of web services deployed currently.

Set classpath
You need to bring those JAR files in your classpath too.
If not, then will give compilation errors on your command prompt when you try to compile/generate code.
Hence copy all these JAR files to C:\axis-1_4\lib
And set the classpath
C:\>set classpath
classpath=.;c:\jdk5\lib;C:\axis-1_4\lib\axis.jar;C:\axis-1_4\lib\axis-ant.jar;C:
\axis-1_4\lib\commons-discovery-0.2.jar;c:\axis-1_4\lib

YOUR ENVIRONMENT IS NOW SET.
BRACE UP TO WRITE, DEPLOY & EXECUTE THE WEB-SERVICE.

Write your Java Interface
package myapp;

public interface Hello {

public String sayHello(String name);

}

Write your Java Interface Implementation
package myapp;

public class HelloImpl {

public String sayHello(String name) {
return “Hello ” + name;
}

}

So that:
C:\practice\myapp\Hello.java
C:\practice\myapp\HelloImpl.java

Compile interfaces & implementation code before generating WSDL
C:\practice>javac myapp\Hello.java -d .
C:\practice>javac myapp\HelloImpl.java -d .

Generate WSDL
C:\practice>java org.apache.axis.wsdl.Java2WSDL -o hello.wsdl -l”http://localhost:8080/axis/services/hello&#8221; -n urn:hello -p”hello” urn:hello myapp.Hello
Notice that hello.wsdl got generated.

Generate glue code
C:\practice>java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p myapp.ws hello.wsdl
So that:
C:\practice\myapp\ws>dir /b
deploy.wsdd
Hello.java
HelloService.java
HelloServiceLocator.java
HelloSoapBindingImpl.java
HelloSoapBindingStub.java
undeploy.wsdd

Time to modify the glue code a bit
Notice “HelloSoapBindingImpl.java“.
It is the implementation that is automatically generated.
But you already have written your own implementation which is: HelloImpl.java
So, call your Impl method in generated Impl method,
Don’t forget to copy your HelloImpl.java in location C:\practice\myapp\ws\
And change its package form myapp to myapp.ws because now it’s been moved there.

/**
* HelloSoapBindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/

package myapp.ws;

public class HelloSoapBindingImpl implements myapp.ws.Hello{
public java.lang.String sayHello(java.lang.String in0) throws java.rmi.RemoteException {
System.out.println(“remote service invoked!”);
HelloImpl h = new HelloImpl();
return h.sayHello(in0);
}

}

Compile the glue code
C:\practice>javac myapp\ws\*.java
May show some warnings but that should be fine.

Package into JAR
C:\practice>jar cvf hello.jar myapp/*.class myapp/ws/*.class
Move hello.jar
C:\practice>move hello.jar “c:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib
Start Tomcat server before deploying

Deploy the service
C:\practice>java org.apache.axis.client.AdminClient myapp\ws\deploy.wsdd

Verify deployed service
Re-Start your Tomcat Server & hit following URL on browser.
http://localhost:8080/axis

You should get Hello! Welcome to Apache-Axis web page.
Click on List to see the list of web services deployed currently containing your hello service.

Write the Client
package myapp.client;

public class HelloServiceClient {
public static void main(String[] args){
try {
//Get the service.
myapp.ws.HelloService service = new myapp.ws.HelloServiceLocator();

// Get the stub.
myapp.ws.Hello hello = service.gethello();

// Make the call.
System.out.println(hello.sayHello(“some name”));
}
catch(Exception e) {
e.printStackTrace();
}
}
}

Compile the client
javac myapp\*.java -d .

Execute the client
C:\practice>java myapp.client.HelloServiceClient

Output should be:
Hello some name

Recommended references:
http://www.onjava.com/lpt/a/1578
http://www.ociweb.com/mark/JavaUserGroup/Axis.pdf
http://jaitechwriteups.blogspot.com/2006/12/simple-webservice-on-jboss-using-axis.html

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: http://www.linkedin.com/in/anupjani
My Blog: http://www.anupjani.wordpress.com

The Matrix Architecture

matrixarchitecture2

Anup Jani (Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.) My profile: http://www.linkedin.com/in/anupjani My Blog: http://www.anupjani.wordpress.com