Let us start the SPRING…

Hello Again..

It’s coding time now…and let us do some JAVA coding first then we will “Springify” that code using Spring Framework. It is a simple Java program with classes, interface, main class to bring together all classes to work as one application.

What will we do….

I know you guys will be sad because I promise to have some spring codes, but trust me staring with Springs right away will not that interesting…

Some Prerequisite…

  • IDE : I will be using STS. (SpringSource Tool Suite).
  • Knowledge of Java
That’s it for now..
Begin….
Let us create a simple Contact Manager Application.
  • Create a Java Project (File -> New -> Java Project)
  • Create a Package “com.springwelcome.model” and inside that create a class “Contact.java“. Here we are going to define what we need to store in as contacts. It is a simple POJO class with FirstName, LastName and PhoneNumber.
  • Let us now create another package that will contains the method dealing with data for Database Transactions. Here we are not going to use any database instead we will be using List to store information and return to our Service class. 
  • For this create a package “com.springwelcome.repo” and add a new class “AddToContactImplementation.java“. You must be wondering why am I used …Implementation. Yes, I will using an interface. Let me add the code to make it clear. 

  • Here the question arises why are we using interface here, where we can use the class name directly while creating the instance. You are absolutely correct. In future we are going to learn about spring and we are going to convert this application using springs. In Spring we have an important concept “Inversion Of Control”. Lets move into this later….
  • As we have the Data Storage Class A.K.A. DAO (Data Access Object). To know more about  DAO please follow the link. Now let us create the service which will return us the names in the contact. 
  • Let me create a new package and name it as “com.springwelcome.service” and create a new class inside it as well and name it as “ContactService.java“. 
  •  Similarly we will be implementing an interface here as well. 

  • Now we are almost done with all the parts of this application, We just need to bring together all parts into one. Let us create a new class without any package and name it “ContactManagement.java“. This will contain the  entry point for out application. the MAIN class. 

That is it..we are done with a java application which will be SPRINGIFY soon..

    Hoping you get along with this easily…till next time when we will be doing some changes to implement springs…
    Happy coding.. 🙂

    Thanks,

    Sovan
    Advertisements

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s