Layers & File I/O Flashcards
What is an exception?
An exception is an unwanted or unexpected event that occurs during the execution of a program that disrupts the normal flow of the program’s instructions. Exceptions can be caught and handled by the program. When an exception occurs within a method, it creates an object. This object is called the exception object. It contains information about the exception, such as the name and description of the exception and the state of the program when the exception occurs.
What is the difference between a checked and unchecked exception?
Checked exceptions are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using the throws keyword. An unchecked exception is an exception that occurs at the time of execution. These are also called as Runtime Exceptions. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.
What is an enumeration?
Enumeration means a list of named constants. In Java, enumeration defines a class type. An Enumeration can have constructors, methods and instance variables. It is created using enum keyword. Each enumeration constant is public, static and final by default.
When should enums be used? When shouldn’t they be used?
Enums are used when we know all possible values at compile-time, such as choices on a menu, rounding modes, command-line flags, etc. In Java), enums are represented using enum data type. The main objective of enum is to define our own data types(Enumerated Data Types). Enums should not be used if you cannot limit a set of possible values to a few elements.
How does an application layer compare to classes and packages?
In our applications, we’ve used a package-by-layer approach in which the highest level packages reflect the various application “layers,” as in:
learn.app.domain
learn.app.model
learn.app.repository
learn.app.controller
What are the three layers in a minimal three layer architecture?
The presentation layer, or user interface; the application layer, where data is processed; and the data layer, where the data associated with the application is stored and managed.
What is the repository pattern?
Repository Pattern is an abstraction of the data access layer. It hides the details of how exactly the data is saved or retrieved from the underlying data source. The details of how the data is stored and retrieved is in each respective repository. The interface in the repository pattern specifies
What operations (i.e methods) are supported by the repository
The data required for each of the operations i.e the parameters that need to be passed to the method and the data the method returns
What is the MVC pattern?
Model, View, Controller. Model: Handles data logic. View: It displays the information from the model to the user. Controller: It controls the data flow into a model object and updates the view whenever data changes
What is dependency injection?
Simplest explanation: Dependency injection means giving an object its instance variables. Dependency injection provides the objects that an object needs (its dependencies) instead of having the object construct them itself. It’s a very useful technique for testing, since it allows dependencies to be mocked or stubbed out. Dependencies can be injected into objects by many means (such as constructor injection or setter injection). One can use specialized dependency injection frameworks (e.g. Spring) to do that, but they aren’t required.
How does dependency injection help you to create loosely coupled classes?
The basic principle of dependency injection is that the dependencies of a class should be configurable from outside of the class. This promotes loose coupling between the classes of an application as compared to having classes create instances of their own dependencies.