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...

47 comments:

  1. Ecorptrainings.com 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

    ReplyDelete
    Replies
    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

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

    sappractices@gmail.com

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

    Thanks

    ReplyDelete
  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.
    Regards,
    Java Courses in Chennai | J2EE Training in Chennai | JAVA Training in Chennai

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

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

    ReplyDelete
  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

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

    SAP BASIS Course in Hyderabad
    Online SAP BASIS Training in USA

    ReplyDelete
  8. 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.

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

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

    valuble blog.oracle fusion procurement online training

    ReplyDelete
  11. 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

    ReplyDelete
  12. 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

    ReplyDelete
  13. 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

    ReplyDelete
  14. 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

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

    ReplyDelete
  16. 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

    ReplyDelete
  17. I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.
    Best Java Training Institute in chennai

    ReplyDelete
  18. Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.
    rpa training in chennai

    ReplyDelete
  19. Ciitnoida provides Core and java training institute in

    noida
    . We have a team of experienced Java professionals who help our students learn Java with the help of Live Base Projects. The object-

    oriented, java training in noida , class-based build

    of Java has made it one of most popular programming languages and the demand of professionals with certification in Advance Java training is at an

    all-time high not just in India but foreign countries too.

    By helping our students understand the fundamentals and Advance concepts of Java, we prepare them for a successful programming career. With over 13

    years of sound experience, we have successfully trained hundreds of students in Noida and have been able to turn ourselves into an institute for best

    Java training in Noida.

    java training institute in noida
    java training in noida

    ReplyDelete
  20. Really awesome blog. Your blog gives very useful information. Thanks for sharing. Top Java training in Hyderabad.

    ReplyDelete
  21. Really awesome blog. Your blog is really useful for me.
    click here:Oracle Fusion Financials Training in Hyderabad

    ReplyDelete
  22. This is an awesome post.Really very informative and creative contents.This concept is a good way to enhance the knowledge.
    Java training in Chennai

    ReplyDelete
  23. After I read and try to understand this article in conclusion amazingwe are generally grateful for the nearness of this article can incorporate impressively more learning for each one of us. thankful to you.


    Accountants Brighton

    ReplyDelete
  24. I've been surfing on the web over 3 hours today, yet I never found any fascinating article like yours. It's enough worth for me. As I would see it, if all web proprietors and bloggers made exceptional substance as you did, the net will be basically more productive than at whatever point in late memory.

    Brighton Accountants

    ReplyDelete
  25. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    Oracle Fusion HCM Training in Hyderabad

    ReplyDelete

  26. Best Solidworks training institute in noida

    SolidWorks is a solid modeling computer-aided design (CAD) and computer-aided engineering (CAE) computer program that runs on Microsoft Windows. SolidWorks is published by Dassault Systems. Solid Works: well, it is purely a product to design machines. But, of course, there are other applications, like aerospace, automobile, consumer products, etc. Much user friendly than the former one, in terms of modeling, editing designs, creating mechanisms, etc.
    Solid Works is a Middle level, Main stream software with focus on Product development & this software is aimed at Small scale & Middle level Companies whose interest is to have a reasonably priced CAD system which can support their product development needs and at the same time helps them get their product market faster.

    Company Address:
    WEBTRACKKER TECHNOLOGY (P) LTD.
    C-67,Sector-63,Noida,India.
    E-mail: info@webtracker.com
    Phone No: 0120-4330760 ,+91-880-282-0025

    webtrackker.com/solidworks-training-Course-institute-in-noida-delhi

    ReplyDelete
  27. Good article, Thanks for sharing info on The Helsinki Declaration (IT-version). Node.JS training in india

    ReplyDelete
  28. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune
    Data science training in kalyan nagar

    ReplyDelete

  29. Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...

    Informatica online training in Hyderabad
    Informatica training in Hyderabad
    Best Informatica online training in Hyderabad

    ReplyDelete
  30. Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post
    java training in chennai | java training in bangalore

    java training in tambaram | java training in velachery

    java training in omr

    ReplyDelete
  31. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command

    java training in annanagar | java training in chennai

    java training in marathahalli | java training in btm layout

    java training in rajaji nagar | java training in jayanagar

    java training in chennai

    ReplyDelete
  32. This comment has been removed by the author.

    ReplyDelete

  33. Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...

    Hadoop training in Hyderabad
    Hadoop online training in india
    Bigdata Hadoop online training in usa

    ReplyDelete

Note: Only a member of this blog may post a comment.