Afli
Level 41
Санкт-Петербург

Level 35

Published in the Random EN group
Questions/additions/criticism are welcome. Level 35
  1. What version control systems do you know?

    Git, SVN, Bazaar, Mercurial

  2. How are SVN and Git different?

    1. GIT is a distributed VCS, while SVN is not. In other words, if there are several developers working with a repository, everyone will have a FULL copy of this repository on their local machine. Of course, there is also a central machine from which you can clone the repository. This is similar to SVN. The main advantage of Git is that if suddenly you do not have access to the Internet, you can still work with the repository. Then only once to do synchronization and all other developers will receive the full history.

    2. GIT saves the metadata of changes, while SVN saves entire files. This saves space and time.

  3. What is GitHub? Do you have projects on GitHub?

    GitHub is a project hosting web service using the git version control system, as well as a social network for developers. Users can create an unlimited number of repositories, for each of which a wiki is provided, an issue tracking system, it is possible to conduct code reviews, etc. In addition to Git, the service supports getting and editing code through SVN and Mercurial.

  4. Why do we need version control systems?

    VCS makes it possible to return individual files to their previous form, return the entire project to its previous state, view changes that occur over time, determine who was the last to make changes to a module that suddenly stopped working, who and when introduced some kind of error into the code, etc. .. In general, if, using VCS, you spoil everything or lose files, everything can be easily restored.

  5. What is generic? How are they implemented in Java?

    Generics are parameterized types. With their help, you can declare classes, interfaces and methods, where the data type is specified as a parameter. Generics added type safety to the language.

    Implementation example:

    class MyClass<T>{
      T obj;
      public MyClass(T obj){
        this.obj = obj;
      }
    }
    class MyClass<T>

    The angle brackets use T , the name of the type parameter. This name is used as a placeholder for the real type name passed to the class MyClasswhen the real types are created. That is, a type parameter Tis applied in the class whenever a type parameter is required. The angle brackets indicate that the parameter can be generalized. The class itself is called a generic class or parameterized type.

    The type is then Tused to declare an object by name obj:

    T obj;

    Instead, Tthe real type will be substituted, which will be specified when creating an object of the class MyClass. The object objwill be an object of the type passed in the type parameter T. If Tthe type is passed in the parameter String, then the instance objwill have the type String.

    Consider the constructor MyClass():

    public MyClass(T obj){
      this.obj = obj;
    }

    The parameter objis of type T. This means that the actual type of the parameter objis determined by the type passed in the type parameter Twhen the class object was created MyClass.

    A type parameter Tcan also be used to specify the return type of a method.

    It is customary to use capital letters in type variable names. Typically, for collections, the letter is used E, the letters Kand Vare the key types and value (Key/Value), and the letter T(and optionally the letters Sand U) is any type.

    Generics only work with objects. intTherefore, you cannot use elementary types like or as a parameter char.

    *I also consider it necessary to mention generic methods. These are methods of the form:

    <T, ...> modifiers returnedType MethodName(T t, ...)

    As I understand it, if parameters are used as a type in the method signature, it is necessary to enumerate them before the return value type. Is this true?

    More detailed information can be viewed at the following links:

  6. What is type erasure?

    A generic class does not store information about its parameter type. This is called type erasure. At the compilation stage, the class object is cast to the type that was specified during the declaration.

    Example:

    Level 35
  7. What is a wild card?

    Wildcard is a generic of the form <?>, which means that the type can be anything. It is used, for example, in collections, where the base type for all collections is Collection<?>.

    Useful link: Java theory and practice. Experiments with generic methods

  8. Tell us about extends and super in Generics?

    To impose a restriction on a wildcard, you must use constructions like:

    • ? extends SomeClassmeans that any class derived from SomeClass can be used
    • ? super SomeClass- means that the class SomeClass can be used, or the parent class (or interface) SomeClass

    This is called a bounded wildcard.

    In order to make a choice between extendsand superthe PECS method was invented.

    You can read more about this at the link below: Using generic wildcards to improve the convenience of the Java API

  9. How to use wildcard?

    Wildcard example:

    List<?> numList = new ArrayList<Integer>();

    I did not understand the question, but in principle the use of wildcards is considered in the materials on the links above.

  10. What is the difference between ArrayList and ArrayList<?>

    An ArrayList entry is called a raw type. It is equivalent to an ArrayList<T> entry and is used for backwards compatibility. prior to Java 1.5 there were no generic collections. If possible, this form of notation should be avoided.

    ArrayList<?> is the supertype for ArrayList.

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION