• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

What is a framework, specifically Spring?

 
Ranch Hand
Posts: 121
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I keep reading this term framework and spring but I don't know what they mean. Doing a google search and youtube search the best I could gather is that a framework is like a program one downloads on top of like Eclipse or the JVM, don't know if I am using the words right. And once that program is downloaded you now have access to all these premade functions that someone wrote. So could it be thought of like Scanner? like when you import Scanner that gives you access to all these functions you wouldn't have had before? Is that right?

Please help,
Thank you!
 
Ranch Hand
Posts: 234
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can import any API (like Scanner, Spring or Hibernate) and access its functionalities. I think that what distinguishes a framework API from a typical library API is that a framework API solves a recurring high level problem. For example, the Servlet framework solves the recurring high level problem of receiving a particular type of network request (typically HTTP) and generating a response. The Collections framework solves the recurring high level problem of storing and processing the data efficiently. The Spring framework solves a bunch of recurring high level problems.
 
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring is actually really deep.  It has lots of functionality in it.  I can speak to Spring MVC for you, which is a subset of Spring.  Spring MVC standardizes the code you write on your server side web application.  It gives you tools as well as prescribes a solution in which you write your code in.  The best way to understand how Spring MVC works is to walk through a transactions lifecycle.  

1) You post form parameters to a spring MVC application from the browser to a URL that Spring is configured to listen for.  Typically on the browser you either have a classic HTML form or a more advanced browser side framework like WebRocketX or Angular.
2) Spring has this URL mapped to a method in its controller object using annotations.  The parameters from the request are mapped to land in a java object that is an input parameter to this method.  This java object has setters that match the parameter names and the framework takes care
of matching all this data up for you.
3) At this point in the controller method your code is running plain old java.  You can take the data sent by the parameters and do whatever you want with it, like send it to a database, perform a query etc.  Often there is another api layer called a service layer at this point. That sits between your controller method and the database.
4) Mostly likely inside this controller method you will retrieve information that you will send back to the user.  That info will come in the form of a javaobject populated with data.  The controller method puts this data into a model attribute, which is a annotated java object and then hands over control to a jsp.
5) The JSP has HTML in it and certain points where dynamic data will be written into it.  The best way to render data into this places is using JSTL.  You can use JSP scriptlets but they are messy and therefore out of fashion.  The JSTL tags read the information from the model attribute that came from the controller.
6) This JSP renders HTML text which is sent back to the browser.  The browser renders it directly as a full page or includes it in just parts of the page.
7) The user enters input presses a button and the fun starts all over again.
 
Matt Keller
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.  Some small corrections and some of my code.  I should know better than to fully rely on my memory.  Step 4.  The model attribute is not annotated.  Here is an example controller method.



I have used Struts 1.x, Spring, and JSF.  Call me old fashioned but I prefer struts.  Struts is a good framework if developers don't make a mess of it.  Next is Spring.  Then JSF.  I don't like that JSF tries to take HTML away from me and write it for me, but that is just my opinion.
reply
    Bookmark Topic Watch Topic
  • New Topic