Are You Recruiter/Hiring Manager?
Cloud-based Candidate Screening | Online Tests
PMP 1600 Questions
PMP 1600 Questions
1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Tutorial Home

Hibernate

  • Advantage of Hibernate over JDBC
  • Hibernate Setup with an web Application
  • First Hibernate Application
  • Hibernate mapping with Database TABLE
  • Hibernate Data Type-Java Data Type - SQL Data Type mapping
  • One to Many Relation in Hibernate
  • One to Many Relation in Hibernate bi-directional
  • Many to Many Relation in Hibernate
  • HQL: The Hibernate Query Language
  • Criteria Queries
  • Criteria Queries : Equal (eq), Not Equal(ne), Less than (le), greater than (gt),greater than or equal(ge) and Ordering the results
  • Criteria Queries: And OR conditions
  • Hibernate generator to generate id (primary key)
  • prevent concurrent update in Hibernate,slate object updatation in Hibernate,version checking in Hibernate

    Struts


  • Model View Controller (MVC)
  • Model View Controller (MVC)
  • Struts Flow-How Struts Works?
  • Struts Tutorial - Struts Setup- First Struts Action class setup
  • Message Resources
  • Validation Framework
  • Validation Framework-client side
  • ForwardAction
  • IncludeAction
  • DispatchAction
  • LookupDispatchAction
  • DynaActionForm
  • DynaActionForm
  • Struts Tutorial - Mutli-click prevention using struts tokens-Prevent Duplicate Submission
  • Logic Iterate Map and List

    JSP


  • JSP Tutorial
  • Introduction to JSP
  • JSP Comments
  • JSP Syntax
  • JSP Scripting Elements :Scriptlet, expression, declaration
  • JSP Directives
  • implicit objects in JSP
  • JSP Actions
  • Introduction to JSP
  • jsp:useBean
  • The jsp:setProperty Action
  • The jsp:getProperty Action
  • Introduction to JSP

    Spring


  • Spring Tutorial
  • Introduction to Spring
  • Benefits of Using Spring Framework
  • Inversion of Control in Spring
  • Introduction to BeanFactory
  • Dependency Injection in Spring
  • Collections Setter Injection
  • Bean Scopes in Spring
  • Spring IOC Setup Step by Step
  • Bean Lifecycle in Spring
  • ApplicationContext
  • MessageSources in Spring
  • Web Spring MVC framework
  • Developing Your First Spring Web Application
  • Developing Your Second Spring Web Application with Spring Form
  • Developing Your First Spring Web Application with Spring Validation Framework with Code Example
  • Spring integration with Hibernate
  • Spring Tutorial Step by Step


    Spring Setup

    Here is the steps how to setup spring IOC

    Step 1. create the folders like mentioned below


    Folder Structure

    lib folder contains two jars (spring.jar and commons-logging.jar);

    Step 2. The springexample-test.xml is the spring configuration file

    springexample-test.xml contains all the informations related to beans objects with relations. ServiceIntegration class is the class which integrate the Email and SMS Servive in this Example. Put springexample-test.xml file into "spring" floder mentioned in the diagram.
    ServiceIntegration class has two property emailInterface and smsInterface so you should have two setter and getter method in ServiceIntegration class.

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>

    <bean id="service" class="springexample.service.ServiceIntegration">

    <property name="emailInterface">
    <ref bean="email" />
    </property>
    <property name="smsInterface">
    <ref bean="sms" />
    </property>
    </bean>



    <bean id="email" class="springexample.email.Email">
    <property name="smtpHost">
    <value>localhost</value>
    </property>
    <property name="fromEmail">
    <value>admin@techfaq360.com</value>
    </property>
    <property name="userId">
    <value>myuserid</value>
    </property>
    <property name="password">
    <value>mypassword</value>
    </property>
    </bean>

    <bean id="sms" class="springexample.sms.SMS">
    <property name="cellNumber">
    <value>8645378290134</value>
    </property>

    </bean>



    </beans>

    Step 3. ServiceIntegration class

    Place the ServiceIntegration.java to service folder mentioned in the diagram. ServiceIntegration class has two property emailInterface and smsInterface so you should have two setter and getter method in ServiceIntegration class. This means emailInterface and smsInterface objects are composition relation with ServiceIntegration. Here we don't directly create object. Spring IOC container read the springexample-test.xml file and create object for us. We have to use the getter method to access the objects.
    Like : ServiceIntegration.getEmailInterface() will returm Email Object.

    The Java Code is (ServiceIntegration.java)
    package springexample.service;
    import springexample.email.EmailInterface;
    import springexample.sms.SMSInterface;
    public class ServiceIntegration implements ServiceIntegrationInterface{

    private EmailInterface emailInterface;
    private SMSInterface smsInterface;

    /**
    * @return Returns the emailInterface.
    */
    public EmailInterface getEmailInterface() {
    return emailInterface;
    }
    /**
    * @param emailInterface The emailInterface to set.
    */
    public void setEmailInterface(EmailInterface emailInterface) {
    this.emailInterface = emailInterface;
    }
    /**
    * @return Returns the smsInterface.
    */
    public SMSInterface getSmsInterface() {
    return smsInterface;
    }
    /**
    * @param smsInterface The smsInterface to set.
    */
    public void setSmsInterface(SMSInterface smsInterface) {
    this.smsInterface = smsInterface;
    }

    public void startService(){

    if(getEmailInterface() != null){
    getEmailInterface().sendEmail();
    System.out.println("Email sent to: "+getEmailInterface().getFromEmail());
    }

    if(getSmsInterface() != null){
    getSmsInterface().sendSMS();
    System.out.println("SMS sent to : "+getSmsInterface().getCellNumber());
    }

    }
    }


    The Java Code is (ServiceIntegrationInterface.java)
    package springexample.service;

    import springexample.email.EmailInterface;
    import springexample.sms.SMSInterface;

    public interface ServiceIntegrationInterface {

    public EmailInterface getEmailInterface();

    public void setEmailInterface(EmailInterface emailInterface);

    public SMSInterface getSmsInterface();

    public void setSmsInterface(SMSInterface smsInterface);
    public void startService();

    }

    Step 3. Email class and SMS Class

    Both the class are offering services and ServiceIntegration class call both the service via IOC container. ServiceIntegration not creating objects of Email class and SMS Class . Spring IOC create object for ServiceIntegration.
    In the Spring IOC we can add some properties with the class also .
    For Example : Email class need smtpHost for sending email. You can see the springexample-test.xml where Email class is associated with smtpHost properties. So we can get hard coded constant value from XML also. Those values are set when IOC create object for the class.

    The Java Code is (Email.java)
    package springexample.email;

    public class Email implements EmailInterface {

    private String smtpHost;

    private String userId;

    private String password;

    private String fromEmail;


    public void sendEmail(){

    System.out.println("This is just Dummy Method for Testing Spring");
    }

    public String getFromEmail() {
    return fromEmail;
    }


    public void setFromEmail(String fromEmail) {
    this.fromEmail = fromEmail;
    }


    public String getPassword() {
    return password;
    }


    public void setPassword(String password) {
    this.password = password;
    }


    public String getSmtpHost() {
    return smtpHost;
    }


    public void setSmtpHost(String smtpHost) {
    this.smtpHost = smtpHost;
    }

    public String getUserId() {
    return userId;
    }


    public void setUserId(String userId) {
    this.userId = userId;
    }


    }


    The Java Code is (EmailInterface.java)
    package springexample.email;



    public interface EmailInterface {

    public void sendEmail();

    public String getFromEmail();


    public void setFromEmail(String fromEmail) ;


    public String getPassword();

    public void setPassword(String password) ;


    public String getSmtpHost() ;


    public void setSmtpHost(String smtpHost);


    public String getUserId() ;


    public void setUserId(String userId);
    }

    The Java Code is (SMS.java)
    package springexample.sms;


    public class SMS implements SMSInterface {

    private String cellNumber;
    public void sendSMS(){
    System.out.println("This is just SMS dummy method for testing Spring" );

    }


    /**
    * @return Returns the cellNumber.
    */
    public String getCellNumber() {
    return cellNumber;
    }
    /**
    * @param cellNumber The cellNumber to set.
    */
    public void setCellNumber(String cellNumber) {
    this.cellNumber = cellNumber;
    }


    }

    The Java Code is (SMSInterface.java)
    package springexample.sms;


    public interface SMSInterface {
    public void sendSMS();
    public String getCellNumber();
    public void setCellNumber(String cellNumber);


    }

    Step 4. Test Client

    Test Client from where we will get the ServiceIntegration object and start the service.
    ServiceIntegrationInterface si = (ServiceIntegrationInterface)appContext.getBean("service");
    si.startService();
    Form command promt you can run the TestClient.java and test the spring IOC.

    The Java Code is (TestClient.java)
    package springexample.client;

    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.ClassPathResource;

    import springexample.service.ServiceIntegrationInterface;





    public class TestClient {

    public static void main(String[] args){
    try
    {
    System.out.println("Example started");
    XmlBeanFactory appContext = new XmlBeanFactory(new ClassPathResource("springexample-test.xml"));
    ServiceIntegrationInterface si = (ServiceIntegrationInterface)appContext.getBean("service");
    si.startService();
    }
    catch(Exception e){
    e.printStackTrace();
    }
    }

    }

    Click here to get the tutorial code : Spring_Project.zip - Login with facebook

    Steps to run the downloded code :
    step 1. set ant in your machine
    step 2. unzip the SpringProject.zip file to D:\installable\SpringProject directory.
    step 3. Go to command prompt -- d:\testSpring\SpringProject
    step 4. run the command : ant -Daction=run
    You can do like below and see the Spring Magic.

    The information you are posting should be related to java and ORACLE technology. Not political.