Archive

Archive for the ‘Programming’ Category

An awesome tutorial on SSH Tunnelling…

November 28, 2012 Leave a comment
Categories: Networking, Programming

What is a Java annotation?

October 15, 2012 Leave a comment

Ahhh… always had this question.
Consider the class below:

In this class, @ManagedBean and @SessionScope are annotations.

An annotation is nothing but a markup. That’s all….

But aren’t annotations interfaces? That’s what Google says.

So yes they are interfaces… Sun merely picked an interface cause developers at that time were aware of interfaces. Note that some annotations take affect at compile time and some at runtime (dictated by the retention policy of that annotation). So this is what happens when an annotation is encountered….

  1. An annotation is always processed by the respective container… this container could be a Spring container (if it is a Spring annotation), JSF container (if it is a JSF annotation), Hibernate container (if it is a Hibernate annotation) and so on. And Java itself if it is a Java annotation.
  2. The container has something called as an annotation processor. This processor scans the code before it runs. So it is the annotation processor does the actions associated with the annotation. The annotation processor has all the intelligence. So if you have two annotations on a class and the annotation processor expects one to be before the other, you will get an error (not sure if it is runtime or compilation time.)
Categories: Java

An awesome ANT tutotial…

October 8, 2012 Leave a comment
Categories: Java, Programming

Java Generics.

March 12, 2012 Leave a comment
Categories: Java, Programming

Core Java Understanding.

November 7, 2011 Leave a comment

There are three main things in Java.

  1. The JVM: This is the Java Virtual Machine. Now the deal is that this is an abstract concept.
  2. The JRE: This is the actual implementation of the JVM. You thus have a JRE for Windows, Linux, Mac etc.
  3. The JDK: This is the JRE + other stuff needed to program in Java. For instance, there is the Java Complier, the Debugger, the Profiler etc.
Categories: Java, Programming

Java JAR Tutorial

September 22, 2011 Leave a comment

Java JAR Tutorial link.

Categories: Java

JCA vs JMS vs Web Services

September 15, 2011 Leave a comment
Categories: Java

What is Struts….in a nut nutshell.

August 30, 2011 Leave a comment

Thanks to Mark Gorokhov and Mahesh Lavannis for this explanation…

Well Struts is nothing but a mapping layer… think about what happens when one goes to a URL?

Our URL in this case is http://www.foo.com/blah.do?param1=a&param2=b&param3=c.

Now because blah.do is not a request for a regular HTML page, our Webserver does not know how to render it…. but it knows that it is supposed to forward the HTTP GET request to the Application Server.

Our application server gets this request and it in turn looks up in the struts.xml file for a mapping between blah.do and an “action” class. The struts.xml could have lines as below:



<URL>blah.do</URL>
<action>BlahClass</action>
<form>BlahParameterClass</form>
<Forward name="some_return_string">some_view.jsp</Forward>
<Forward name="some_other_return_string">some_other_view.jsp</Forward>


So the application server now instantiates BlahClass; but how do we now pass those parameters to it? Well this is where the <form> comes into play. This tag defines a class that is something as follows:



public class BlahParameterClass {
String param1;
String param2;
String param3;


public String getParam1() {
return param1;
}


public void setParam1(String param1) {
this.param1 = param1;
}


public String getParam2() {
return param2;
}


public void setParam2(String param2) {
this.param2 = param2;
}


public String getParam3() {
return param3;
}


public void setParam3(String param3) {
this.param3 = param3;
}
}


So as we can see, this code is nothing special. It is merely a set of properties with their associated accessors. And since struts is aware of both of these classes, they are beans as well. (Remember a class becomes a bean when the framework is aware of it's existence and works directly with it). OK so when the struts framework instantiates the BlahParameterClass and sets the values of its parameters from the URL. The BlahParameterClass is then passed to BlahClass with the HTTPRequest and HTTPResponse objects. This BlahClass implements the execute () method as mandated by the struts JSR and the application server merely execute's the method. Internally it does whatever it has to and in its return code, it returns a string lets say some_string…. this string is mapped to the forward tag and then the appropriate jsp code / templating engine code (viz Velocity, Template::Toolkit etc) is called. It get's converted to HTML and returned to the Web Server. The web server then returns this information in a HTTP RESPONSE packet back to the client. Hooray you now know the base of struts… This is struts 1.0.

The real struts.xml file is as follows:



<action name="peersForm" path="/peers" scope="request" type="packageName.PeersAction"
validate="false" parameter="state">
<forward name="success" path="/peers.jsp"/>
</action>


  • The path maps to the URL.
  • The name maps to the action tag.
  • The type maps to the form tag.

Now what if instead of returning control to a form, we need to call another class to do its job, well; then we need to create parameters within the original class before forwarding the request to the other class. This is bad to say the least but this is struts 2.0.

Enjoy.....

Categories: Programming, Struts