Start course
1h 15m

In this course, we will learn the concepts of Java EE 7 with a focus on Servlet Technology.

Learning Objectives

  • Java Servlet Technology with Request, Filter and Listeners

Intended Audience

  • Anyone looking to get Oracle Java Certification
  • Those who want to improve Java 7 EE knowledge
  • Java developers


  • Have at least 2 years of Java development experience 

Hello, dear friends. In this video, we will examine the MVC pattern. Let's begin. Design patterns concentrate more on the tactical aspects required to solve a low-level problem. But in big projects, you also need an architectural pattern. Architectural patterns focus on the strategic, high-level composite structure of a solution. They are usually implemented with multiple design patterns. They define the role of each subsystem in the overall solution. Now, the MVC is an architectural pattern. Model-view-controller, MVC pattern, is an architectural pattern found in many places including the Java foundation classes API. MVC separates presentation management from core application logic. Useful in applications where the user interface might frequently change, and MVC can be adapted to web applications. The Model-view-controller is a well-known design pattern in the web development field. It specifies that a programmer application shall consist of data model, presentation information, and control information. The MVC pattern needs all these components to be separated as different objects. The model designs based on the MVC architecture follow MVC design pattern. 

The application logic is separated from the user interface while designing the software using model designs. The MVC pattern architecture consists of three layers. The model contains only the pure application data. It contains no logic describing how to present the data to the user. The view presents the model's data to the user. The view knows how to access the model's data but it does not know what this data means or what the user can do to manipulate it. The controller exists between the view and the model. It listens to events triggered by the view and executes the appropriate reaction to these events. In most cases, the reaction is to call a method on the model. Since the view and the model are connected through a notification mechanism, the result of this action is then automatically reflected in the view. In Java programming, the model contains the simple Java classes. 

The view is used to display the data and the controller contains the servlets. Let's look at the advantages of MVC architecture. MVC has the feature of scalability that in turn helps the growth of application. The components are easy to maintain because there is less dependency. A model can be reused by multiple views that provides reusability of code. The developers can work with the three layers as model, view, and controller simultaneously. Using MVC, the application becomes more understandable. Using MVC, each layer is maintained separately. Therefore, we do not require to deal with massive code. The extending and testing of applications is easier. The model view controller, MVC, design pattern specifies that an application consists of a data model, presentation information, and control information. The pattern requires that each of these be separated into different objects. MVC is more of an architectural pattern but not for a complete application. MVC mostly relates to the UI or interaction layer of an application. You're still going to need a business logic layer, maybe some service layer, and a data access layer. 

That's all I have for now. Let's implement MVC to a small project. I want to create a small project for employee details. I'll define an employee before changing the values of that employee. Let's begin. First, we will start with model, class Employee. This will be an encapsulated class. So, we will define our properties: name, job, and employee registration number. Generate getters and setters. Now, we need a view. Class, EmployeeView. In this class, we will show employee's information to the users. Now, we will create our controller. First, in controller, we have to define model and view. In constructor, we will get these as parameters. Now, in controller, we also need getters and setters for the employee properties. Let's define an update() method also. Done. Now, our structure is ready, let's use. Let's define a method to fill model with employee's information. In a real project, this will be our database operation, but now we will set items manually. 

First, create an instance from employee model. Now, set values; Charles Dickens, Author, number is 12. Return model. Now, we will call this method. Let's define a view. Now, we need controller with view and model. When we call the update view model, we can see all information about Charles Dickens. Let's set new values to the model. Update() again. Done. When we run the project, we will see all information of Charles Dickens and John Verdon. Let's try. Look, Charles' registration is 12 and John's is 14. Great, we have now finished looking at the MVC model. In the next video, we will start examining the J2EE patterns. See you in the next video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics