-
What version control systems do you know?
Git, SVN, Bazaar, Mercurial
-
How are SVN and Git different?
-
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.
-
GIT saves the metadata of changes, while SVN saves entire files. This saves space and time.
-
-
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.
-
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.
-
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
MyClass
when the real types are created. That is, a type parameterT
is 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
T
used to declare an object by nameobj
:T obj;
Instead,
T
the real type will be substituted, which will be specified when creating an object of the classMyClass
. The objectobj
will be an object of the type passed in the type parameterT
. IfT
the type is passed in the parameterString
, then the instanceobj
will have the typeString
.Consider the constructor
MyClass()
:public MyClass(T obj){ this.obj = obj; }
The parameter
obj
is of typeT
. This means that the actual type of the parameterobj
is determined by the type passed in the type parameterT
when the class object was createdMyClass
.A type parameter
T
can 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 lettersK
andV
are the key types and value (Key/Value), and the letterT
(and optionally the lettersS
andU
) is any type.Generics only work with objects.
int
Therefore, you cannot use elementary types like or as a parameterchar
.*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:
-
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:
-
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
-
Tell us about extends and super in Generics?
To impose a restriction on a wildcard, you must use constructions like:
? extends SomeClass
means 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
extends
andsuper
the 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
-
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.
-
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.
Level 35
Questions/additions/criticism are welcome.
GO TO FULL VERSION