JavaRush /Java Blog /Random EN /Level 36 Answers to questions for an interview on the top...
Level 40

Level 36 Answers to questions for an interview on the topic of the level

Published in the Random EN group
Again, I looked all over, I did not find the answers. Well. I'll post mine, although I wrote them purely for myself, and as briefly as possible. But anything is better than nothing. So the questions were: Level 36  Answers to questions for an interview on the topic of level - 1Interview questions:
  1. What is MVC ?
  2. What is DAO and DTO ?
  3. What is POJO ?
  4. What is an Entity ?
  5. What list collections do you know?
  6. What collections-sets do you know?
  7. What is a map , how is it different from a " dictionary "?
  8. What is Queue and Dequeue ?
  9. What classes that implement the Queeue interface do you know?
  10. What is a tree ?
And now my answers:
  1. MVC is an application design pattern in which the application is divided into three separate parts: model (model), view (view) and controller (controller). The model provides data and responds to controller commands by changing its state. The view is responsible for displaying model data to the user in response to model changes. And the controller interprets the user's actions, notifying the model of the need for changes. Thus, each of the components of this circuit is loosely coupled to other components, due to which the flexibility of the program is achieved. Most often, all business logic is placed in the model, although sometimes it is also contained in the controller. In the first case, the model is called thin, in the latter - thick.

  2. DAO (Data Access Object) is an object whose main task is to store data in the database, as well as retrieve them from it. DTO (Data Transfer Object) is an object designed to transport data. Therefore, its main task is to store this data. It doesn't contain any logic. Also, it must be serializable, as object transport is usually done via serialization-deserialization.

  3. POJO translates to "Old Style Java Object". They are contrasted with EJB objects. The latter follow a special convention and are usually hardwired to a particular enterprise framework (for example, they must have a public constructor with no parameters, they must have getters and setters for fields, they must be serializable, etc.). POJO is, accordingly, an ordinary class that does not inherit from any special classes and does not implement any special libraries. Usually a POJO doesn't do anything special and only contains state.

  4. Entity Bean is a bean whose purpose is to store some data. The logic of such a bean has a built-in mechanism for saving itself and its fields to the database. Such an object can be destroyed and then recreated from the base again. But other than storing data, it has no logic. And the bean, in turn, is a special class that must comply with the following rules:

    • The class must have a parameterless constructor with the public access modifier. Such a constructor allows tools to create an object without the additional complexity of parameters.
    • Class properties must be accessible via get, set, and other methods (called accessors), which must follow the standard naming convention. This easily allows tools to automatically detect and update bean content. Many tools even have specialized editors for different types of properties.
    • The class must be serializable. This makes it possible to reliably save, store, and restore bean state in a platform- and virtual machine-independent manner.
    • The class must have the equals(), hashCode() and toString() methods overridden.
  5. All list collections implement the List<E> interface and inherit from the AbstractList<E> abstract class. Among them are ArrayList<E> and LinkedList<E7gt;. ArrayList7lt;E> is an array based list, while LinkedList<E> is a classic doubly linked list.

  6. Set collections in Java implement the Set<E> interface and inherit from AbstractSet<E>. Sets are collections of data in which all elements are unique. Among them, Java has HashSet, LinkedHashSet and TreeSet. The first collection stores its objects based on hash codes. The second is a modified first, in which the elements are also located in a linked list, so they are all in the order they were added. The third collection provides sorting of its elements.

  7. Map is a kind of collection that stores its elements as key-value pairs. Moreover, all keys must be unique. Implementations include HashMap and TreeMap. The first implementation stores elements using hash codes. The second one stores the elements in sorted order by key.

  8. A Queue is a data structure that operates on a first-in, first-out basis. That is, elements are added to the queue from one end, and removed from the other. dequeis a two-way queue. In this queue, elements can be added both to the beginning and to the end, and elements can also be taken from the beginning and from the end of the queue. Accordingly, there are methods that allow you to put an element (these are the add (e) and offer (e) methods), and there are methods that allow you to remove the element from the queue (these are methods such as remove () and poll ()). In addition, there are methods that allow you to simply get an element from the queue without removing it from there (these are the element() and peek() methods). The Deque interface additionally has methods for adding elements to the beginning and end of the queue, removing elements from the beginning or end, and getting elements from the beginning or end of the queue (without removing them from the queue).

  9. Simple implementations include ArrayDeque , LinkedList , and PriorityQueue . There are also many classes in Concurrent Collections that implement these two interfaces (both or just one of them).

  10. A tree is a connected graph without loops or multiple edges. Usually, if there are N vertices in the tree, then the number of edges is at least N-1. Also, one vertex in the tree is chosen as the root. The remaining vertices are declared branches. Branches that do not have their own branches are called leaves of the tree.
    In programming, trees are used quite widely, and many types of this tree have already been invented. One of the most widely used trees is the binary tree. In this tree, each element has at most two children (that is, it can be from 0 to 2). One type of binary tree is BST - binary search tree. In this tree, the elements are subject to a rule: the left child of the element must be less than it in value, and the right child must be greater than or equal to it in value.
    There are also red-black trees. This is a kind of binary search tree. In red-black trees, one more element property is introduced - color. Color can be black or red. Also, each red-black tree must meet the following requirements:

    1. the root of the tree is black;
    2. the node is either red or black;
    3. all the leaves of the tree are black;
    4. both children of the red node are black;
    5. every path from a given node to any leaf node that is its child contains the same number of black nodes.
These rules allow the tree to be balanced. A tree is balanced when the length of the path from the root to any leaf node differs by no more than 1. (That is, in a simple way, there are no skews and long branches in the tree.)