"Another cool topic."

"The surprises just keep coming! Is it my birthday?"

"Today, I'll tell you about generics. Generics are types that have a parameter. In Java, container classes let you indicate the type of their inner objects."

"When we declare a generic variable, we indicate two types instead of one: the variable type and the type of the data it stores."

"ArrayList is a good example. When we create a new ArrayList object, it's convenient to indicate the type of the values that will be stored inside this list."

Code Explanation
ArrayList<String> list = new ArrayList<String>();
Create an ArrayList variable called list.
Assign an ArrayList object to it.
This list can only store String objects.
ArrayList list = new ArrayList();
Create an ArrayList variable called list.
Assign an ArrayList object to it. This list can store any values.
ArrayList<Integer> list = new ArrayList<Integer>();
Create an ArrayList variable called list.
Assign an ArrayList object to it.
This list can only store Integer and int values.

"Sounds super interesting. Especially the part about storing values of any type."

"It only seems like that's a good thing. In reality, if we put strings into an ArrayList in one method and then expect it to contain numbers in another method, the program will crash (terminate with an error)."

"I see."

"For now, we won't create our own classes with type parameters. We'll just use the existing ones."

"Can any class be a type parameter, even one that I write?"

"Yes. Any type except for primitive types. All type parameters must inherit from the Object class."

"You mean I can't write ArrayList&ltint>?"

"Indeed, you can't. But Java developers have written wrapper classes for each of the primitive types. These classes inherit Object. This is how it looks:"

Primitive type Class List
int Integer ArrayList<Integer>
double Double ArrayList<Double>
boolean Boolean ArrayList<Boolean>
char Character ArrayList<Character>
byte Byte ArrayList<Byte>

"You can easily assign primitive classes and their analogs (wrapper classes) to each other:"

Examples
int a = 5;
Integer b = a;
int c = b;

Character c = 'c';  //the literal c is a char
char d = c;
Byte b = (byte) 77;  // The literal 77 is an int
Boolean isOk = true;  // the literal true is a boolean
Double d = 1.0d;  // The literal 1.0d is a double

"Great. I think I'll try to use ArrayList more often."

undefined
7
Task
New Java Syntax, level 7, lesson 7
Locked
Remembering geometry
Take a look at what the program does. Add the final modifier to standard constants (variables with immutable values).
undefined
7
Task
New Java Syntax, level 7, lesson 7
Locked
Everything you need to know about Earth
Here is the Earth class — a collection of variables that describe certain characteristics of the planet Earth. Be sure that the variables of the Earth class are global constants. Don't forget to rename the variables so that they comply with code style conventions for global variables.
undefined
7
Task
New Java Syntax, level 7, lesson 7
Locked
Employee records
Here you have in front of you a digital employee record. It contains the employee's name, position and salary. The name of the employee is unlikely to change, but his or her position and salary might. These changes are made using the setPosition() and setSalary() methods. Of course, they are not wor