Saturday, March 21, 2009

J2EE and traditional MVC (Part 1)

A short note to new visitors: this blog documents my vision on how to build database web applications. Normally I do this by presenting a two hour presentation know as "A Database Centric Approach to J2EE Application Development". First given at Oracle Openworld 2002. You can find the original paper here (it's the one titled "A First Jdeveloper Project"). Since the Mayday Miracle gathering in Helsinki Finland, the message now carries the flag: The Helsinki Declaration. Over the next few weeks, (probably months) I will document this presentation that has been given many times by now. This is why you will often see powerpoint slides in the blog posts: they are from the actual presentation materials and help me deliver the message in the same way as when giving the presentation.

After presenting the four historical observations (see previous four blog posts), I now proceed in giving my "layman's understanding" of this beast called "JEE".

The(?) JEE Architecture

Here's a way to look at JEE.

In this architecture we discern three (some say four) "tiers".
  • The data tier
  • The middle tier (which holds two "containers")
  • The client tier
The data tier holds the data managed most likely by some DBMS. The middle tier holds the web-server container and the application-server container. The former runs servlets (and JSP's in the "old days"), the latter runs enterprise java beans (EJB). Both containers communicate with the data tier using the JDBC protocol. The client tier represents the device that sits at the end user: typically a PC running a browser that displays an html page. But it could also run a Java applet inside the browser. And last but not least the architecture allows for a java program running inside a JVM of the operating system.

The JEE architecture allows us to write code everywhere:
  1. Inside the web container we develop servlets and (old fashioned) JSP's using Java.
  2. Inside the application container we develop the EJB's in their various sorts, also with Java.
  3. Inside the browser we use Javascript to increase the user experience of the application.
  4. Inside the JVM of the browser we develop rich internet applications with Java.
  5. Inside the JVM offered by the client operating system we can do the same.
  6. And of course, allthough the JEE architecture does not mention this in any way whatsoever: at the data tier we can write code inside the x-VM of the DBMS. In the case of Oracle this would be the pl/sql-VM.
What all this means, is that there is no such thing as the JEE architecture.

There are many ways you can use JEE to develop a database web application. It all depends on where you want to write the "application logic" for your application. I will return to exactly this particular subject in-depth in upcoming posts.

A very popular design pattern in the JEE world is the Model-View-Control design pattern. Commonly referred to as just MVC. Whenever the end user triggers some event inside the user interface (UI) typically the application code needs to perform something. Code that investigates the event and determines what to do next is called Control code. More often than not, the application will have to query and/or transact data at this time. Code that performs this is called Model code. And finally the UI needs to be refreshed/modified: this is done by View code. The MVC design pattern dictates that these three types of code are not to be merged in one another, but specifically coded into separate modules that communicate with eachother.

Note the "traditional" adverb in the title above. Of course it's not traditional ... , yet! This is a mainstream design pattern used in almost every JEE project. However I believe it should be traditional at some point in time in the near future :-).

To clarify in more detail what the MVC design pattern is about I show my audience two animations. The first one animates how a pre-MVC built web application would handle a browser request.

The browser sends a request to the webserver (due to some event triggered by the end user).
  1. Apache accepts the request and,
  2. Forwards it to the web server container.
  3. The web container loads a class file from the filesystem
  4. The web container instantiates an object from this class file, and invokes a method on the object.
  5. The method then performs all relevant application logic, including,
  6. rendering the html for the next web page that is to be displayed inside the browser of the end user.
The servlet would be "fat": it takes care of the Control+Model+View responsibilies. Since this created hard-to-maintain web application code a better approach would be to follow the MVC design pattern shown below.

The same scenario described above now goes as follows.
  1. Browser sends a request.
  2. Apache forwards the request to the web container.
  3. The web container loads a Control class.
  4. And instantiates a Control object.
  5. The control object investigates the request, and might decide that some querying and/or transacting needs to be done. However it does not perform this, instead it,
  6. Loads a Model class, instantiates an object from it, and invokes a method on the object.
  7. This method then performs all necessary model logic and communicates the result back to the control object.
  8. The control object then determines what the next page of the application should be and loads/instantiates/invokes a view class (eg. a JSP) to perform so.
  9. The JSP might communicate with the model object to retrieve some cached data that needs to be embedded in the html output stream that it sends back to the browser.
There you have it: MVC in its full glory.

In the next post I will discuss seven (2 power 3 minus 1) alternative ways to use the MVC design pattern. To be continued...


  1. provides J2EE in hyderabad with best faculties on real time projects. We give the best online trainingamong the J2EE in Hyderabad. Classroom Training in Hyderabad India

    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

  2. For Free IT Study Materials,IT Certification Materials,Interview Questions and Job references.

    For All SAP Modules.
    Testing Tools
    Bigdata Technologies
    Oracle Technologies
    IBM Technologies
    BI Tools


  3. Some of them were feeling very difficult to learn programming language. Once they are familiar with programming language they decided to learn the language in a simple way. Start to learn Java courses at FITA. They are providing a wonderful training with best MNC experts.
    Java Courses in Chennai | J2EE Training in Chennai | JAVA Training in Chennai

  4. Thank You for sharing your article. I like it. It is great information about J2EE. We provides TIBCO Online Training in Hyderabad.

  5. That really great information....keep me informed.
    learn j2ee online

  6. Excellent post!!! The future of .net application development is on positive note. It offers huge career prospects for talented professionals all over the world. Training on .net technology will ensure good salary package. Best DOT NET Training in Chennai | .NET Course in Chennai

  7. These all are notable facts… I stick with responsive website design for my business. With the mobile marketing is at its peak stage, having website that goes comfy on all devices will help your business. You can check my website for more details on the importance of responsive website design. PHP Training in Chennai | Best PHP training in Chennai

  8. Thanks for providing the best information it's very useful sap basis learners.

    SAP BASIS Course in Hyderabad
    Online SAP BASIS Training in USA

  9. I agree with your thoughts!!! As the demand of java programming application keeps on increasing, there is massive demand for java professionals in software development industries. Thus, taking training will assist students to be skilled java developers in leading MNCs.
    Java Training in Chennai

  10. .Net is most preferred programming language among software developers all over the world. It is also considered as most trusted and effective platform to build high performing desktop or enterprise application. DOT NET Training Institutes in Chennai

  11. In near future, big data handling and processing is going to the future of IT industry. Thus taking Hadoop Training in Chennai | Big Data Training in Chennai will prove beneficial for talented professionals.

  12. Thanks for sharing informative article on web design and development. As every business is moving towards online marketing, there is huge demand for trained and skilled web designers and developers. Web designing Training in Chennai

  13. article is so convincing that I never stop myself to say something about it. Wow this blog is very nice.............
    R12 SCM Online Training

  14. This article is too good.good in formative.thanks for sharing such a

    valuble fusion procurement online training

  15. Nowadays, most of the businesses rely on cloud based CRM tool to power their business process. They want to access the business from anywhere and anytime. In such scenarios, salesforce CRM will ensure massive advantage to the business owners. Cloud Computing Training in Chennai | Cloud Computing Courses

  16. ERPTREE handles oracle fusion HCM training and its modules maintaining classroom based training with the self-paced videos. An expert having ten plus years of self-experience handles the training period through online and explains each and every point perfectly. We recently launched our institute in the USA and getting
    the best reputation over there.

    Oracle fusion HCM Online Training

    Oracle Fusion HCM Training

  17. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor
    lead live training in Oracle Fusion Financials online Training , World Class Virtual Instructor led training on Oracle fusion Financials Online Training. We have industry expert trainer. We provide Training Material and Software Support. calfre has successfully conducted 100000+ trainings in India, USA, UK, Australlia,
    Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.

  18. Very nice article this would definitely help the beginners, coding made easy with the help of example you shared. Java Training in Chennai

  19. perfect explanation about java programming .its very useful.thanks for your valuable training in chennai | java training in velachery


  20. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

  21. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    Android App Development Company

  22. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin.Keep update more blog.
    Dot Net Training in Chennai

  23. Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.i am expecting more updated posts from your hands.
    iOS App Development Company
    iOS App Development Company

  24. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...
    Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text
    Mobile Marketing Services
    mobile marketing companies
    Sms API

  25. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Mobile Marketing Service
    Mobile Marketing Companies
    Sms API
    Texting API

  26. article is so convincing that I never stop myself to say something about it. Wow this blog is very nice
    Attend free demo classes at igofusion for Oracle Fusion Online Financials coaching

  27. Such a great articles in my carrier, It's wonderful commands like easiest understand words of knowledge in information's.

    Core Java Online Training Hyderabad

  28. Thanks for sharing informative article… Know about How to Change BSNL WiFi Password from techfizy.

  29. According to Oracle, 3 billion devices run on Java. The TIOBE Programming Community Index is updated monthly and regularly lists Java as the most popular programming language. Why the constant popularity? Because it has many real-world applications. IEEE Spectrum ranked it as #2 among the 2016 top programming languages.
    Java training institute in chennai

  30. Spring is one of the most popular enterprise application frameworks in the Java landscape today. It is so popular that it’s even considered the de-facto standard for building large scale applications in Java today.Spring is not just a framework. It’s also a complete ecosystem of supporting frameworks and tools that provide you everything you need to build complex applications. It provides support for various common things that most enterprise applications need, like connecting to the database, managing business services, security and so on.
    spring mvc validation example

  31. Dear, I like all your post. Everything looks so sweet, I admire this kind of life and the best wishes for you. Hope that we can communicate with each other. By the way, anybody want to boost app ranking ? This one is useful.

  32. Wow, this blog is very nice I really like your blog and Impressive thank you very much for posting this blog...................Get more information about Oracle Fusion Financials Course details at our Erptree website

  33. Your good knowledge and kindness in playing with all the pieces were
    very useful. I don’t know what I would have done if I had not
    encountered such a step like this.

    java training in chennai

    java Training in Bangalore

  34. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog...Java Training in Chennai