So far, we saw that every program manipulates data and that these data are stored in so-called variables. We also saw that in Java, every variable must be associated with a type, which represents the kind of values that we want to store in the variable. So far the types we had a look at are simple types, for example integers, doubles or booleans, that allow us to model data of elementary types; for example, dimensions, logical expressions, and similar things. In many situations, it is necessary to represent more sophisticated data, to manipulate sets of data as a whole. This is the goal of this episode. The objective of today's lectures is to go beyond simple types such as integers, double, characters or booleans and to learn how to manipulate more sophisticated data by combining data of elementary types. Generally speaking, in computer programming, a structured, composed or advanced data type will essentially allow to manipulate a set of data as a whole. For example, in a program, if I need to model a set of ages, which is a set of homogeneous data, integers in this case, it is natural to think of something that would look like a table, an array of data that I can manipulate as a whole. I can also imagine sophisticated representations of this nature wherever the nature of data is heterogeneous, like here for example, a sequence of characters, a double and an integer. More simply, we can also consider that a sequence of characters is a composed type, as a sequence of characters is a set of characters, letting us manipulate a set of characters as a whole. Today, we are going to continue exploring the building blocks that allow us to build a program in terms of computations and data in Java. Today we are mostly going to have a look at the data component and see how it is possible to work with arrays of data, more precisely, we'll work with fixed-size arrays in today's episode. To illustrate the use of arrays in computer programming, here's a small introductory example. Imagine for example that you want to write a small program that manipulates players' scores. Here, the goal is simply to print the score of each player, to compute the mean of all the scores, and to print the deviation from the mean of every score. We'll initially try to write a Java program capable of doing this computing, but by using only what we have learned so far, that is data of elementary types. To begin with, we won't be too ambitious. Let's imagine that we simply have to represent two players. So we have to model the scores of two players, which can be done by the existing means using two integer-type variables: the variable score1 and the variable score2. We consider that in this program, these values are obtained through some keyboard interaction, like here. Once these values are obtained, the computation of the mean can simply be done by summing the two scores and dividing the sum by two. We can then proceed to printing the score and the deviation from the mean for each score. We here print score1 and the deviation from the mean of score1, and we do the same with score2. A question that will naturally arise is how do we proceed with more players ? Obviously, we'll have to add as many variable as there are players and typically, in the context of this example with five players, we would be obliged to to declare five variables "score", one for every player, which is already relatively laborious. The computation of the mean becomes more complex as we now have to sum up the values of five variables, and also, how do we print the results? For every score, we must repeat the instruction line that prints the score and the deviation from the mean. We'd like to get around this rather laborious task, repeating every instruction and naturally we'll think of using a loop. How would we proceed if we wanted to print the different scores and the deviations from the mean using a loop? A natural solution would be to use a for-loop, which would allow us to iterate over every score and for every score to print what is needed. We can therefore imagine writing the loop in this spirit. We'd have a counter which would iterate from the first score to the last one and for every score, we would print what is needed. However, if we examine this program in more detail, the for-loop and even the entire program, we realize that this approach doesn't meet all the needs we can consider in this context in a completely satisfactory way. Let's imagine fore example that I want to have more than 5 players, like 100 or 1000. In this case the program would take unmanageable dimensions, we'd for example have to introduce thousands of variables, complicate the computation of the mean. Furthermore, if we have a look at the way we wrote the score here to access the i-th score of the sequence: in fact, this is not a valid Java syntax to designate the i-th element of a sequence. And final point, our approach doesn't satisfactorily respond to the situation where the number of players isn't initially known. So if we want to write a program of this nature, the tools that we have at our disposal so far don't satisfactorily respond to our needs in this context. "Arrays" are the solution to this. To give you a concrete idea of what the notion of array is, here's how the previous program would be written using that concept. So the idea would be to use a new type of data, the type "array of integers", of which we'll see the syntax more in detail later in this video. Primarily, when declaring an array, we can manipulate a sequence of data as a whole, and access the i-th element of the sequence by using indexation. So we can see that the previous program can be written more concisely, in particular we can manage the part that reads the scores in a unified way with a for-loop. Then, whatever the number of scores, we'll write the program the same way, whether we have 5 or 1000 players and we can now also manage the case when the number of players isn't initially known and therefore read the number of scores before executing the computation that we want to do on the scores. In computer programming, an array is a type of data that allows us to manipulate a collection of homogeneous values as a whole. In an array, values are all of the same type. Here you have an example representing an array of integers. All the values contained in the array score are of 'int' type. Of course, in Java we can define arrays of any known type, arrays of integers, doubles, chars and any other known type, including arrays of arrays. Generally, in computer programming, we can consider that there exists four types of arrays, depending on the answers to the following questions. First question: is the array's size initially known? That is, when I begin writing my program do I know which size the array has, or don't I (know which size the array has)? We can have two possible answers to that question. Then, second question: can the size vary while using the array? That is, once I've set a size to my array, can I vary that size while the program runs or will that size be fixed once and for all? The type of array that is the more flexible, the more general, and that responds to as many needs as possible is certainly the one that has this configuration, an array whose initial size isn't known when I write the program. We can set that size when the program executes, but I don't know it when I'm writing the program and this size can also vary while the program runs. For example, let's imagine that I want to write a program that manages the ages of the people registered to this course. That number isn't known when I write the program but will be determined when I start the execution of the program with the effective number of registered people that I get at that moment, and we can imagine that during the execution, I have new registrations, so the array's size will grow. I can also imagine that people will unsubscribe from the course, in which case the array's size will decrease. At the other extreme, there exists arrays the size of which is known when I write the program and whose size isn't going to change during the execution of the program; so this configuration here. For example, if I want to write a program that manipulates two-dimensional vectors, so I know that my vector has 2 dimensions; it has two components and no more. So, a component for X and a component for Y and I know that a two-dimensional vector will remain a two-dimensional vector during the whole program's execution and therefore it's size won't change while I run the program. Intermediate situation: the case where an array has a size which isn't known when I write the program, but once that size is set, it doesn't change anymore during the program's execution, so this case here. We can for example imagine that I'm writing a game which is played by 2 to 7 players. When I execute the program, I don't know exactly how many players are going to be in the game. So when the program starts it will ask how many players there are. For example, there're 5. Once these 5 players are in the game, it must take place with the 5 players and no more. The array's size isn't going to evolve while the program runs. Last case finally, maybe more difficult to illustrate, a bit less intuitive: the case where the array's size is known when I write the program and can vary while the program executes. For example, I want to represent the number of "cantons" [= districts, provinces] of a country. This number of cantons is set, it is known a priori. So when I write the program, I know for example that there are 26 of them. [TN: this is the case in Switzerland] We can also imagine that at a given moment a new canton is created in the country or that two cantons merge into one. So the array's size will increase or decrease while the program runs. This last case is probably the least natural and the least frequent in practice. Most programming languages don't offer any specific tools, dedicated to the management of each case presented here. For example, in Java we mainly dispose of two tools, the one that allows us to manage dynamic size's arrays. Here for example, with the use of a predefined type of Java called "ArrayList", which responds to the needs of situations number 1 and 2. And then arrays of fixed size, on which we will focus in the context of today's videos, and which respond to the needs of situations number 3 and 4.