In our introduction, we have discussed the different steps leading to the creation of a program. We know that we should start by thinking, conceptualizing, and planning the sequence of instructions we aim to realize. Then, we will translate this conception into a known programming language, such as Java. Then we will go through several steps, of compilings, testings until we finally reach the creation of program, executable on a computer. Now, we will enter the heart of the matter and acquire the tools necessary to begin writling little Java programs. A program is simply a sequence of instructions operating on data. The notion of "sequence of instructions", is closely realted to the notion of processing. Processing operate on data, they can modify these data's values. In turn, the data impact the processing, since, depending on the nature of these data, different processing will be performed. Let us suppose, for example, that we wish to write a brief program able to solve a quadratic equation of this kind. Let us think of the the adequate sequence of instructions. The first step is probably to ask the user to provide us with the coefficients b and c, which will let us know concretely what equation we're going to solve. I now have the first data. Starting with these data, we can perform other processing, such as, for example, calculating the delta. Then, depending on the value of this delta, we will perform different processing. For example, if delta is negative, we will simply print that there is no solution. Otherwise, we will treat the other cases. For example, if delta is 0, we can calculate the unique solution and print this solution. Otherwise, we have the case with two solutions, which we will not discuss here explicitly. Here, we can clearly see that processing impact data. For example, here, the processing held compute an arithmetic expression. This processing indeed impacts the data, for it will calculate a new data, which is delta. The other way around, we can also see that data impact processing. Typically here, depending on delta's value, we will perform different actions. We can draw two important observations based on this example. The first one is the notion of expression, which is fundamental in order to start expressing processing. The notion of expression will be a chapter later in this course. The second one is bound to the notion of data. Here, the data "b² - 4c" is stored in a container, delta. We need to associate this data to the name "delta" since we use delta several times in the program. We want to be able to find this data, whenever we need it. The fact to associate a name to a data, delta to b² - 4c is what we call in programming, the notion of variable. This will be the topic of this episode. The goal of this introductory course is to introduce the basic tools, permitting to formulate basic processing and to manipulate data in an adequate way. We have seen, in the previous example, how important the notion of expression was, to which the notion of operator is related. We will discuss operators later in this course, though. Today, we will discover the notion of variables, associated with the notion of data. The notion of variable will let us associate data with a name in a program. You have here a small glimpse of the remaining fundamentals, which will be studied during this introductory programming course. In programming, a variable is a named memory area usually called the identifier, where we will store a value. We can see this here. A fundamental fact is that variables must be associated with a type. Java is a language demanding that we specify the type of the data we wish to manipulate. When we wish to use a variable, a named area in the memory, it will be necessary to specify its type, what type of data we want to use. For example, it may be necessary to use data of the integer type, of the character string type. Every time we wish to manipulate data of a particular kind, we will have to specify it through the type. How should we proceed, in a Java program if we wish to declare a variable, namely to memorize a data through a variable ? You have here, a little shell of a program ready to welcome your instructions. Now, let us declare a variable. First of all, we should decide the name of this variable; if possible, this name should be eloquent, somehow describing the role of the variable. Here, we will call this variable "nombre". (TN: nombre means number ) Now, we should come with an initial value, for example, 4. And, of course, we should specify its type. Here, I will precise that the number is an integer. In Java, we write integer "int". This line of code, we have just written in the editor corresponds to what we call, the declaration of a variable. In a program, we have to declare that we wish to use a variable of a given type. You have here two examples of valid variable declarations in Java. In the first case, we give an initial value to the variable at the moment where we declare it. In the second case, we simply declare a variable without giving it an initial variable. We can see here the fundamental syntax elements we have introduced earlier. The variable type must necessarily be specified Same goes for its name, its identifier. As we have seen, during its declaration, a variable can be initialized, namely, we can give it an initial value. This corresponds to this situation in the memory. It is good practice; indeed, it is always desirable for a variable to have a known value. We have just seen that it was entierely possible, in Java, for a variable to be declared without any initial value. Here, we are declaring a variable nCarré, of type int. (TN: nCarré means nSquared). We are not giving it an initial value. This corresponds to this situation in the memory. We have here a variable nCarré, not storing anything known. What we should know is that Java does not permit, in a program, to use a variable which has not been initialized. For example, if, after having declared this variable nCarré, We try to print its value (we are anticipating on the next episodes, regarding the printing of a value). So, the printing of the variable nCarré will be realized as follows. If we try, right after the declaration of a variable, to print its value, we will obtain an error upon compiling. The compiler will call us to order, signifying that nCarré has not been initialized. Therefore, we cannot use it. However, this implies that, after declaring a variable, without giving it a value, we have the possibility to give it a value later in the program. This is what we will discuss now, introducing the assignment notion. This will make it possible, after this instruction, to modify, to store a value inside the variable nCarré through the so-called assignment. Regarding types, we already encountered, in the previous examples, the integer type, spelt "int" in Java. Thus, if we wish to use a data corresponding to an integer we will use the int type. Naturally, there are other usable types. For example, if we wish to use decimal numbers, we can use the predefined type double, which will allow us to work with decimal-type variables. What you have to know, is that once we go through a declaration such as this, each variable has its own type. This type, will remain unchanged for the whole course of the program. We cannot change the type of a variable once the declaration has been made. Concretely, this means that our variable n here, can only contain integers. Similarly, the variable x can only contain decimal numbers. let us review these essential points. In Java, the declaration of a variable, follows this syntax. We specify the type of the variable, follow by its identifier, its name. And we do not forget the famous semicolon which closes the declaration. We have also seen that it is always recommanded to give an intial value to our variable, during the declaration. We will generally adopt a declaration-initialization instruction, which goes as follows : The variable type, followed by its name, then, after the =, the initial value and, of course, the semicolon at the end, closing the declaration- initialization instruction. Once the variable type has been defined, it is clear that we can not change it later. In Java, it is valid to declare several variables on the same line. We will declare, on the same line, variables of the same type. Therefore, we only specify the type once. Here, we declare int-typed variables p and q, separating the declaration of the different variables with a comma. You have here a second example where we declare two double-typed variables on the same line. The difference from the previous example, is that, for the variable y we do not specify an initial value. This is also possible. Regarding methodology, keep in mind that it is not recommanded to overuse these sorts of formulation, for they impede the program's readability. There are a few rules, by which you must abide when choosing a variable's identifier. This identifier can only be constituted of letters, digits or either of these specific characters : underscore (_) or dollar ($). The first character has to be either a letter. It can also be one of the specific characters underscore (_) or dollar ($), however, this is not part of the usual conventions of Java programmers, which we will discuss later on. Naturally, the identifier cannot be one of the Java reserved keywords. Capital letters are authorized, but they are not equivalent. For example, if we choose the identifier, "ligne" with a lower case "l", it is not equivalent to the identifier "Ligne", with an upper case "L". You can see here examples of valid identifiers. Here constituted of letters only, here constituted of letters and digits. Here, you can see some invalid identifiers. Here, an identifier can neither contain a blank space. nor the symbol minus (-) and cannot begin with a digit. In addition to the naming rules imposed by the Java language, which are to be strictly respected, there are certain usual conventions, not required by the compiler but nonetheless respected by most Java programmers. Typically, you will see the variable naming with this form here. If the name of the variable, the identifier, is constituted of several words, we will separate the words, starting every word with a capital letter. Also, the convention is that every variable's identifier is to start with a lower case letter. Thus, you will encounter this type of formulation, rather than this one, starting with a capital letter, or this one, using underscores (_). We have already understood that the notion of type is essential for variable declaration in Java. The two elementary types for the manipulation of numerical data, that is, the declaration of numerical variables, are int and double; we have already encountered them in several of our previous examples. Naturally, there are many another predefined type. For example, if, in a program, we wish to manipulate the usual characters of the alphabet, for example A and Z, we can resort to the predefined type char. We will have the opportunity, throughout this course, to expand on predefined types in Java. Now, you know how to declare a variable, making it possible to memorize a data, usable in a program. Now, how should we proceed, if we wish to change the value of a variable, previously declared ? To that end, we will resort to the notion of assignment. We have already had the opportunity to encounter a few informal examples. In order to realize an assignment, we will use the symbol equals (=), respecting the following syntax : On the left side of the expression, we specify the variable's identifier. Then comes our equal symbol (=) and, finally, the new value that we wish to store inside our variable. It is very important to understand - we will come back to this later - that an assignment is not a mathematical equality. its purpose is to modify the value of a variable, in the course of the program's execution. Let us suppose that, in a program, we declared two variables n and nCarré. n has been declared and initalized to 4 while nCarré has not been initialized. We wish to store a value inside nCarré, using the assignement notion. How will such an assignment unfold ? You must understand that the execution of such an instruction, will occur in two distinct steps. The first is the evaluation of the expression on the right-hand side of the = symbol. Here, this evaluation will give us the value 16. In a second time, we will store the value thus computed in the variable nCarré. As a result, the variable nCarré, will contain the value 16. To sum up, the assignment syntax in Java is as follows : we specify the name of the variable, followed by the equals symbol (=), followed by an expression, valid in Java. This expression can be something elementary, such as a literal value, like here. It can also be much more complex, like here. We will come back to expressions and further discuss them later. The critical point is that the type of the value computed by the expression must be the same as the variable's one Another syntactic detail : do not forget the semicolon (;) at the end of the assignment instruction. Now, let us go back to the comparison between the mathematical equality and the assignment. Both use the equals sign (=) and the notion of variables. Self-evidently, if, in mathematics, we write such an expression, we signify that the variables a and b will always have the same value over time. On the other hand, the assignment in programming is a different mechanism entierely; it is dynamic and will thus depend on time. Let us take a concrete example. Let us imagine that a contains the value 1 and b contains the value 2. If we execute now this first instruction, we start by, as we have just seen, evaluating the expression on the right-hand side of the assignment; this will give us the value 2. Then, we will store this value, this 2, inside the variable a which leads us to this result. Now, let us analyze the second instruction with the exact same starting conditions, that is a containing 1 and b containing 2. Now, if we execute this instruction, as before, we start by evaluating what stands on the right side of the assignment, returning 1. Then, we store this 1 inside b, which results in this situation. Thus, we see that in programming, in both cases, a and b have the same value but these values are not the same over time. Moreover, if, at some point, one of the two variables is modified, the other remains unaffected. For example, if a is then modified to 3, b will keep its value, for example 1, in the second assignment. Another example : if, in mathematics, we write such a relation, it means that a and b will awlays verify this relation, regardless of the time. However, if we write the exact same thing in programming, we will see that the result for a and b is decidedly different. Thus, here, we start by executing this instruction, resulting in the variable a contaning 5. Then, we execute this assignment instruction. As we have seen before, we will start by evaluating "a + 1", returning 6 and storing this 6 inside the variable b, resulting in this situation. At this point, a and b indeed verify this relation. However, if we move on to the next instruction, we will modify a's value to 2. We now see that the relation is not verfied anymore. Due to what we have just seen, it is licit, in programing to resort to similar formulations. By the way, this formulation, which you will often encounter, along our examples is particularly useful. Now, what happens if we execute such an instruction ? Let us start with a concrete example, with a initialized to 1. As we have just seen, we start by evaluating this part of the assignement, returning 2. In a second time, we will store this 2 inside a, leading to this result. Thus, when we write that kind of things in programming, we do not signify, as is the case in mathematics, that the relation "a = a + 1" must always be respected, (in the context of mathematics, this particular expression may lead to problems) In programming, we simply signify that we are adding 1 to the value of a. Now to the last chapter regarding variables : the notion of constant. We have seen that the assignment permits to modify the value of a variable after its declaration. There are situations, though, where this is not desirable. Let us suppose that, in a program, we need to work with the speed of light. We all know that the speed of light is a constant. Its value will thus not be modified over the course of the program. Therefore, we will precise that this data cannot change. In such a case, we proceed by adding the reserved keyword "final" just before the variable declaration. This means that, once an initial value has been attributed, we cannot modify the value of the variable anymore. Here, in this example, we declared our constant as follows : the constant VITESSE_DE_LA_LUMIERE (TN:vitesse de la lumière means speed of light) If, later on, we try to modify the value through an assignment, this will result in a compiling error. By the way, there are certain conventions regarding the naming of constants in Java. Here, the identifier of our speed of light constant is constituted by different words, all written in capital letters and separated by underscores (_). This is a usual convention regarding the naming of constants. We warmly recommand you to follow these conventions.