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…
- IDE : I will be using STS. (SpringSource Tool Suite).
- Knowledge of Java
- 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..