Wednesday, 2 October 2013

First Java Spring Program:

Having Basic Knowledge Of Spring Application Context and Container, We will look into a very basic Working Program developed in eclipse,
  • Pr-Requisites of spring framework:
    • Either Spring Tool Suite OR Eclipse need to be installed.
    • In Spring Tool Suite Create New --> Spring Project Will Do All necessary configurations.
    • In Eclipse, User Library need to be configured containing all jars of spring,
      • Menu Bar ->> Window -->> Preferences -->> Search for User Libraries -->> Create New Library -->> Add External Jars -->> add all jars listed in below figure into it.










Now We Going To write XML, Interface and Classes Which Are Used In Program, This Program Is Basically An Example Of Creating a Bean In Spring Framework

Create An Interface Called Figure: With draw() method


A Class Triangle Implementing Figure

Class Contains 2 property height and type, A Constructor accepting 2 argument (type and height), and implementation of draw method of Figure interface.

Create Spring.xml in src folder of project for triangle bean used to create in spring context

Finally The Implementation Class Which Uses Aplication Context to inject the Triangle Bean into container
 

 At Last the project Folder structure Should Look Like
 
 Note That  Spring user library into the project and an additional .jar for logging information/Error messages from spring to console.


The Output

Wednesday, 25 September 2013

Spring: Application Context

This Session Talks about the Flavors of Application Context,
  • ClassPathXmlApplicationContext : Loads Context Definition From XML File Located in Classpath
    • ApplicationContext context=new
      ClassPathXmlApplicationContext("bean.xml");
  • FileSystemXmlApplicationContext : Loads from an xml loacted in filesystem (absolute/relative path should must be mentioned)
    • ApplicationContext context=new
      FileSystemXmlApplicationContext("c:/bean.xml");
  • XmlWebApplicationContext : Loads From xml file existing with in web application context.
    • ApplicationContext context=new
      XmlWebApplicationContex("bean.xml");
  • Consider Following xml Bean definition,
    • <bean name="hello" class="org.srinidhi.beans.Helloworld">
    • getBean() method of context will actually get the instantiated object of Helloworld,
      public static  void main(String args[]){

      ApplicationContext context = new FileSystemXmlApplicationContext("c:/bean.xml");

      Helloworld hw = (Helloworld ) context .getBean("hello"); 

      hw.sayHello();             // Calling method of Helloworld Class.

      }

      Hope You like this session.

Monday, 23 September 2013

Why Java Spring? Continued...

In Last Session one of the question stood tall and went unanswered

How Spring Identifies The Bean?

The answer to this question actually drags us to a most popular and second important feature of Spring, Dependency Injection. we will surely look into it but let us concentrate on the current question,
  1.  All Our Application Components i.e. Beans will live within Spring Container
  2. Spring comes with several container implementations that can be categorized into two distinct types.
    • Bean factories (org.springframework.beans.factory.BeanFactory interface)
    • Application contexts (org.springframework.context.ApplicationContext)
  3.  Bean Information will be placed in xml based file inside the <bean> tag and this xml file will be loaded to the spring container then container will identify these beans along with the properties set inside <bean> tag
  4. the bean tag typically look like this
    • <bean id="hello" class="com.srinidhi.beans.Helloworld"/> 
    • The <bean> element is the most basic configuration unit in Spring. It tells Spring to
      create an object for you.
  5. once you specify the bean info in xml following code can be used to load xml to spring application context
    •  ApplicationContext context = new ClassPathXmlApplicationContext(
      "hello.xml");
well this is much of a concept and also we are still pending with our previous session question of  "What are The Configuration for setting up spring???"... also there is much to talk about the variants of Application Context. 
these topics will be taken care in further sessions, thank u for reading.


Sunday, 22 September 2013

Java Spring: An Ultimate framework.



Having Bundles of Frameworks floating around, the first question which arise is "is spring really necessary???"... (Bekitta Iga)... Well, The exact answer depends on the requirements and application complexity. What Spring targets is following features which is an improvement/addition to existing Frameworks.
  1. Unleashing the Power Of Simple POJO-
    • Spring never forces  you to implement a spring specific interface or extend class. At the worst case a class may be annotated with spring annotations.
      Example:

      Without SPRING:
      import javax.ejb.SessionBean;
      import javax.ejb.SessionContext;

      public class HelloWorldBean implements SessionBean{
      public void ejbActivate(){
      }
      public void ejbPassivate(){        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      }                                              ;Methods of SessionBean Interface foces you to
      public void ejbRemove(){         ; implement these method which are out of interest
      }
      public void ejbCreate(){
      }
      public void setSessionContext(Session Contextctx){
      }
      public String sayHello(){
      return "HelloWorld";
      }

      }

      With Spring Above code can be simply written,

      public class HelloWorldBean{
      public String sayHello(){
      return "HelloWorld";                 ;;;; Only Business Logic, Rest Is Left To Spring.
      }
      }

      Isn't it Effective???!
 With This Basic and very tiny Info about Spring Framework i'm Logging off today. but with unanswered questions like "How Spring Identifies The Bean?" and "What are The Configuration for setting up spring???" also there are lot more features pending to be discussed, Hope You Like This Post. Will Provide You those in coming posts.

Sunday, 28 October 2012

Automate Your Daily Routines With AutoIt...

Hi All, This Post Talks About Automating Ur Daily Stuffs, It May Be Logging into Ur Account Or Checking Availability For Trains, Filling Your Time Sheets, Opening And Reading Your Mail Box.....

It Just Needs Little Bit Of Programming Sense With Autoit Scripting.. It Provides API For Handling
  1. Windows Message Handling (WIN Api Management)
  2. Internet Explorer (IE Management)
  3. Gui Controls
  4. System Registry Handling And More....

Here Is Simple Example And Experience Of Mine, Filling Time Sheet Is A Daily Work For Any IT Employee Often We Show Disinterest Or We Forget. After 2 Or 3 Days We Receive Very Irritating Mail From Our IT Services Saying "NON Compliance". Its Because Mistakes Are Bound To Happen By We Humans... I Came Up With Solution Of Automating That Work So That Computer Will Do That Work In Favour Of Me...!! I Just Used Inet API Provided By AutoIt.... NOW, No Nasty Mails Filling My Inbox.. I Am Very Much Compliance With My Employee Policy... :-)