Showing posts with label addition of two numbers using spring framework. Show all posts
Showing posts with label addition of two numbers using spring framework. Show all posts

Sunday, May 1, 2016

Addition of Two Numbers Using Spring Framework

I am very new in Java Enterprise Edition or J2EE programming particularly using Spring Framework. But I find it easy to learn once you have known the basic concepts and principles behind it. I am thankful that there is a video tutorial in YouTube that we can study to be specific the tutorial of Ankush Gorav here his website http://www.gontu.org.

I have learned a lot from his tutorial in YouTube. In gives me an idea how to get started this sample program that I wrote is based on his tutorial will ask the user to give two numbers and then our program will find the total sum of the two numbers.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output



Some Screenshots


Program Listing


Addition_Two_Numbers.java

package org.gontuseries.springcore;

import java.util.Scanner;

public class Addition_Two_Numbers {
int a=0,b=0,sum=0;
public void find_sum() {
 Scanner in = new Scanner(System.in);
 System.out.println();
 System.out.println("Addition of Two Numbers");
 System.out.println("\n");
   
 System.out.print("Enter First Value : ");
     a = in.nextInt();
     
     System.out.print("Enter Second Value : ");
     b = in.nextInt();
 
     sum=(a+b);
     
     System.out.println("\n");
 System.out.print("The sum of " + a + " and " + b + " is " + sum +".");
 System.out.println("\n");
 System.out.println("End of Program");
 
}

}


SpringConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean id="addition_two_numbers_Bean" class="org.gontuseries.springcore.Addition_Two_Numbers">
</bean>

</beans>


TestSpringProject.java

package org.gontuseries.springcore;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpringProject {

public static void main(String[] args) {
 @SuppressWarnings("resource")
ApplicationContext context = 
 new ClassPathXmlApplicationContext("SpringConfig.xml");
 
 Addition_Two_Numbers Add_Two_NumbersObj = (Addition_Two_Numbers) context.getBean("addition_two_numbers_Bean");
    
 Add_Two_NumbersObj.find_sum();
}
}