proprep proprep
Why Proprep?
  • About Us
  • Press Room
  • Blog
  • See how it works
Pricing
Ask a tutor
Login
Start Free Trial
For Educators
proprep
  • Ask a tutor
  • Why Proprep?
    • About Us
    • Press Room
    • Blog
    • See how it works
  • Pricing
  • Login
  • For Educators
Home General Modules Principles of Programing Fundamental Programming Concepts
Module added

  • Player Size:
  • Shortcuts:
  • Speed:
  • Subtitles:
  • Download Workbook
Up Next
Watch next
Introduction 0/2 completed
  • Low level languages
  • high level languages
Basic syntax and semantics of a HLL 0/6 completed
  • Natural and Formal languages
  • Semantics and types of error
  • Exercise 1
  • Exercise 2
  • Exercise 3
  • Exercise 4
Variables and primitive data types 0/8 completed
  • Variables and datatypes
  • Introduction to BlueJ IDE
  • Program structure in Java
  • Exercise 1
  • Exercise 2
  • Exercise 3
  • Exercise 4
  • Exercise 5
Assignment And Expressions 0/10 completed
  • Assignment And Maths Operators
  • Comparison Logical And Bitwise Operators
  • Exercise 1
  • Exercise 2
  • Exercise 3
  • Exercise 4
  • Exercise 5
  • Exercise 6
  • Exercise 7
  • Exercise 8
Conditional Control Structures 0/11 completed
  • If Structure
  • If Else Structure
  • Switch Structure
  • Exercise 1
  • Exercise 2
  • Exercise 3
  • Exercise 4
  • Exercise 5
  • Exercise 6
  • Exercise 7
  • Exercise 8
Iterative Control Structures 0/12 completed
  • For loop
  • While loop
  • Do While loop
  • Exercise 1
  • Exercise 2
  • Exercise 3
  • Exercise 4
  • Exercise 5
  • Exercise 6
  • Exercise 7
  • Exercise 8
  • Exercise 9
Comments

Description

Sign up

Get unlimited access to 1,500 subjects including personalised modules.

Skip for now
{"Free":0,"Sample":1,"Paid":2}
[{"Name":"Introduction","TopicPlaylistFirstVideoID":0,"Duration":null,"Videos":[{"Watched":false,"Name":"Low level languages","Duration":"7m 53s","ChapterTopicVideoID":25524,"CourseChapterTopicPlaylistID":237667,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:04.350","Text":"Welcome to this first video on fundamental programming concepts,"},{"Start":"00:04.350 ","End":"00:06.945","Text":"where we will introduce some foundational knowledge"},{"Start":"00:06.945 ","End":"00:09.435","Text":"that sets us up for the rest of the course."},{"Start":"00:09.435 ","End":"00:11.040","Text":"By the end of this section,"},{"Start":"00:11.040 ","End":"00:15.509","Text":"you\u0027ll be able to describe the relationship between the CPU and machine language,"},{"Start":"00:15.509 ","End":"00:19.950","Text":"explain the need for and advantages of high-level languages,"},{"Start":"00:19.950 ","End":"00:24.945","Text":"compare methods of translation of high-level language to machine language,"},{"Start":"00:24.945 ","End":"00:29.810","Text":"and categorize languages according to programming paradigms."},{"Start":"00:29.810 ","End":"00:32.600","Text":"Let\u0027s get stuck in. The heart of"},{"Start":"00:32.600 ","End":"00:36.290","Text":"a computer system is commonly referred to as a processor."},{"Start":"00:36.290 ","End":"00:40.385","Text":"When I say heart, I don\u0027t mean it pumps blood around the inside of your computer."},{"Start":"00:40.385 ","End":"00:43.354","Text":"I mean, without it there would be no computer."},{"Start":"00:43.354 ","End":"00:46.910","Text":"It\u0027s the fundamental component within the system."},{"Start":"00:46.910 ","End":"00:50.450","Text":"Maybe a better word for it would be the brain of your computer."},{"Start":"00:50.450 ","End":"00:53.330","Text":"But computer scientists don\u0027t like that word being"},{"Start":"00:53.330 ","End":"00:57.860","Text":"used because it suggests that the computer can think as humans do."},{"Start":"00:57.860 ","End":"01:00.425","Text":"That certainly not the case."},{"Start":"01:00.425 ","End":"01:02.840","Text":"It\u0027s probably better to think of the processor,"},{"Start":"01:02.840 ","End":"01:07.490","Text":"which is more formally known as a central processing unit or CPU,"},{"Start":"01:07.490 ","End":"01:10.975","Text":"as a machine that faithfully carries out instructions."},{"Start":"01:10.975 ","End":"01:14.215","Text":"It\u0027s more like a calculator than a brain."},{"Start":"01:14.215 ","End":"01:20.650","Text":"Alongside the CPU, we need somewhere to store instructions and data."},{"Start":"01:20.650 ","End":"01:26.635","Text":"We also need a way of getting data into the CPU and out of the CPU."},{"Start":"01:26.635 ","End":"01:31.255","Text":"Put all these components together and you have a computer system."},{"Start":"01:31.255 ","End":"01:36.520","Text":"Early computer systems were made of individual electrical components such as switches,"},{"Start":"01:36.520 ","End":"01:39.730","Text":"relays, valves, and lights."},{"Start":"01:39.730 ","End":"01:44.605","Text":"These are all wired together and very basic processing operations could be carried out."},{"Start":"01:44.605 ","End":"01:49.885","Text":"Instructions and data could be input to the processor by turning on and off switches."},{"Start":"01:49.885 ","End":"01:52.820","Text":"Four switches, as we have here,"},{"Start":"01:52.820 ","End":"01:57.635","Text":"would allow us to input a binary value between 0 and 15."},{"Start":"01:57.635 ","End":"02:01.085","Text":"All the switches off would give us the number 0,"},{"Start":"02:01.085 ","End":"02:04.955","Text":"all the switches on would give us the number 15."},{"Start":"02:04.955 ","End":"02:14.225","Text":"Here, we could be inputting either a single 8-bit number or two 4-bit numbers,"},{"Start":"02:14.225 ","End":"02:16.250","Text":"one here and one here."},{"Start":"02:16.250 ","End":"02:19.445","Text":"Let\u0027s assume there are two 4-bit numbers."},{"Start":"02:19.445 ","End":"02:20.780","Text":"In this upper diagram,"},{"Start":"02:20.780 ","End":"02:23.240","Text":"two switches are on."},{"Start":"02:23.240 ","End":"02:26.570","Text":"Therefore, we have two 1s being input."},{"Start":"02:26.570 ","End":"02:32.195","Text":"Assuming the most significant bit is at the top representing a value of 8,"},{"Start":"02:32.195 ","End":"02:35.598","Text":"this would give us 4 plus 1."},{"Start":"02:35.598 ","End":"02:37.485","Text":"Given that this is 8,"},{"Start":"02:37.485 ","End":"02:39.495","Text":"4, 2, and 1,"},{"Start":"02:39.495 ","End":"02:42.780","Text":"the 8 and 2 bits are not set,"},{"Start":"02:42.780 ","End":"02:45.875","Text":"but the 4 and 1 bits are set,"},{"Start":"02:45.875 ","End":"02:50.975","Text":"giving us the decimal number 5 and that will be input into the system."},{"Start":"02:50.975 ","End":"02:52.940","Text":"In this lower diagram,"},{"Start":"02:52.940 ","End":"02:55.175","Text":"we\u0027ve again got a 4-bit number."},{"Start":"02:55.175 ","End":"02:56.450","Text":"Here is 8 here,"},{"Start":"02:56.450 ","End":"02:59.419","Text":"4 here, 2 here, and 1 here."},{"Start":"02:59.419 ","End":"03:03.270","Text":"Only the 2 and 1 are set and therefore,"},{"Start":"03:03.270 ","End":"03:04.705","Text":"this number is 3."},{"Start":"03:04.705 ","End":"03:08.555","Text":"We\u0027re inputting a value of 3 into the system."},{"Start":"03:08.555 ","End":"03:13.340","Text":"Results of operations can be shown as binary values by turning on lights."},{"Start":"03:13.340 ","End":"03:16.580","Text":"For example, adding these two 4-bit numbers could give us"},{"Start":"03:16.580 ","End":"03:19.790","Text":"a result that we could display on a set of lights,"},{"Start":"03:19.790 ","End":"03:23.649","Text":"each one representing 1-bit of the results."},{"Start":"03:23.649 ","End":"03:28.350","Text":"Here, adding these 2 numbers of 5 and 3 would obviously give us 8 and"},{"Start":"03:28.350 ","End":"03:34.205","Text":"the result is being shown on four lights with each one representing 1-bit of the result."},{"Start":"03:34.205 ","End":"03:39.110","Text":"The 8 here is the most significant bit with a 1,"},{"Start":"03:39.110 ","End":"03:44.045","Text":"meaning that it\u0027s going to be lit and all of the other bits are 0,"},{"Start":"03:44.045 ","End":"03:48.710","Text":"so none of the other lamps or lights will be on."},{"Start":"03:48.710 ","End":"03:52.370","Text":"Every CPU can carry out operations such as add"},{"Start":"03:52.370 ","End":"03:55.780","Text":"or subtract and we call these instructions."},{"Start":"03:55.780 ","End":"03:59.270","Text":"We know already how numeric data is encoded in binary,"},{"Start":"03:59.270 ","End":"04:01.175","Text":"but what about instructions?"},{"Start":"04:01.175 ","End":"04:04.190","Text":"Well, every CPU has a finite set of"},{"Start":"04:04.190 ","End":"04:08.480","Text":"instructions that it can carry out called an instruction set."},{"Start":"04:08.480 ","End":"04:13.625","Text":"Each instruction within the instruction set has its own unique binary value."},{"Start":"04:13.625 ","End":"04:16.610","Text":"For example, on one particular CPU,"},{"Start":"04:16.610 ","End":"04:27.085","Text":"11000110 is a unique binary value that represents an instruction to perform addition."},{"Start":"04:27.085 ","End":"04:32.450","Text":"Other unique binary values will be associated with other instructions."},{"Start":"04:32.450 ","End":"04:36.230","Text":"As well as the binary values that represent a specific instruction,"},{"Start":"04:36.230 ","End":"04:38.090","Text":"it\u0027s also necessary to supply"},{"Start":"04:38.090 ","End":"04:41.450","Text":"binary values that will represent the data that we\u0027re working with."},{"Start":"04:41.450 ","End":"04:45.020","Text":"The following binary values constitute a short program"},{"Start":"04:45.020 ","End":"04:48.665","Text":"that adds together the numbers 3 and 5."},{"Start":"04:48.665 ","End":"04:51.440","Text":"You may have noticed from the second line,"},{"Start":"04:51.440 ","End":"04:58.670","Text":"this bit pattern we saw earlier representing the instruction to add."},{"Start":"04:58.670 ","End":"05:02.675","Text":"The second bit pattern is the value,"},{"Start":"05:02.675 ","End":"05:04.850","Text":"in this case, 5."},{"Start":"05:04.850 ","End":"05:11.270","Text":"On this first line is a different instruction and the value 3."},{"Start":"05:11.270 ","End":"05:13.190","Text":"In the early days of computing,"},{"Start":"05:13.190 ","End":"05:16.820","Text":"this is how programs would have been written and entered into a processor."},{"Start":"05:16.820 ","End":"05:21.065","Text":"It\u0027s called machine language or machine code."},{"Start":"05:21.065 ","End":"05:22.880","Text":"This, obviously, has many problems."},{"Start":"05:22.880 ","End":"05:26.090","Text":"It\u0027s easy to make a mistake in a single bit being entered,"},{"Start":"05:26.090 ","End":"05:30.320","Text":"and the program would therefore be corrupted and would likely be invalid."},{"Start":"05:30.320 ","End":"05:34.130","Text":"It\u0027s also very slow to develop programs this way as many instructions and"},{"Start":"05:34.130 ","End":"05:39.455","Text":"binary data values have to be entered to achieve relatively simple results."},{"Start":"05:39.455 ","End":"05:42.290","Text":"Something called assembly language was developed"},{"Start":"05:42.290 ","End":"05:45.635","Text":"to allow slightly more meaningful program code to be entered."},{"Start":"05:45.635 ","End":"05:48.590","Text":"For example, the previous program will be much more easily"},{"Start":"05:48.590 ","End":"05:53.000","Text":"understood by using the following assembly language code."},{"Start":"05:53.000 ","End":"05:58.220","Text":"Here, we can see the numbers 3 and 5 in decimal,"},{"Start":"05:58.220 ","End":"06:01.280","Text":"which is much easier for us humans to make sense of."},{"Start":"06:01.280 ","End":"06:04.310","Text":"We can also guess the meanings of the instructions"},{"Start":"06:04.310 ","End":"06:07.310","Text":"being used using the short abbreviations,"},{"Start":"06:07.310 ","End":"06:09.185","Text":"which we call mnemonics."},{"Start":"06:09.185 ","End":"06:12.755","Text":"For a programmer using these instructions regularly,"},{"Start":"06:12.755 ","End":"06:19.850","Text":"that\u0027ll be much easier to remember than the long binary bit patterns for 00110 and so on."},{"Start":"06:19.850 ","End":"06:25.520","Text":"These assembly language instructions cannot be directly carried out by the CPU."},{"Start":"06:25.520 ","End":"06:27.980","Text":"They need to be translated into"},{"Start":"06:27.980 ","End":"06:33.550","Text":"machine language and that\u0027s done by a program called an assembler."},{"Start":"06:33.550 ","End":"06:39.260","Text":"A major issue with machine code is that it\u0027s specific to one particular type of CPU."},{"Start":"06:39.260 ","End":"06:42.740","Text":"You\u0027re probably familiar with the Intel CPU such as the i3,"},{"Start":"06:42.740 ","End":"06:45.020","Text":"the i5, or the i7,"},{"Start":"06:45.020 ","End":"06:47.150","Text":"which are commonly found in PCs."},{"Start":"06:47.150 ","End":"06:50.390","Text":"These are all developed from the same processor which originally appeared"},{"Start":"06:50.390 ","End":"06:54.470","Text":"in 1978 called the Intel 8086."},{"Start":"06:54.470 ","End":"06:59.105","Text":"These processors belong to what we call the Intel x86 family."},{"Start":"06:59.105 ","End":"07:01.625","Text":"Another type of CPU developed by a company called"},{"Start":"07:01.625 ","End":"07:05.165","Text":"ARM is found in the majority of mobile phones."},{"Start":"07:05.165 ","End":"07:12.620","Text":"The machine code for an Intel x86 CPU will not work on an ARM CPU."},{"Start":"07:12.620 ","End":"07:15.290","Text":"Each has its own instruction set with"},{"Start":"07:15.290 ","End":"07:19.325","Text":"its own unique binary codes for each available instruction."},{"Start":"07:19.325 ","End":"07:23.840","Text":"The binary value for an add instruction on an x86 CPU will"},{"Start":"07:23.840 ","End":"07:28.670","Text":"be different to the binary value for an add instruction on an ARM CPU."},{"Start":"07:28.670 ","End":"07:31.189","Text":"The same applies to assembly language,"},{"Start":"07:31.189 ","End":"07:33.695","Text":"which is also CPU specific."},{"Start":"07:33.695 ","End":"07:36.650","Text":"Collectively, machine code programs and"},{"Start":"07:36.650 ","End":"07:41.255","Text":"assembly language programs are known as low-level languages."},{"Start":"07:41.255 ","End":"07:42.815","Text":"In the next video,"},{"Start":"07:42.815 ","End":"07:45.890","Text":"we\u0027ll see how these difficulties with low-level languages were"},{"Start":"07:45.890 ","End":"07:49.910","Text":"overcome with the development of high-level languages."},{"Start":"07:49.910 ","End":"07:53.880","Text":"Thanks for watching, and I\u0027ll see you in the next one."}],"ID":26341},{"Watched":false,"Name":"high level languages","Duration":"8m 17s","ChapterTopicVideoID":25525,"CourseChapterTopicPlaylistID":237667,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:03.540","Text":"Welcome back, everybody. In the previous video,"},{"Start":"00:03.540 ","End":"00:05.565","Text":"we learned that early programmers used"},{"Start":"00:05.565 ","End":"00:09.400","Text":"machine code or assembly language to write their programs."},{"Start":"00:09.400 ","End":"00:14.230","Text":"This had a major disadvantage in that they were written for a specific CPU."},{"Start":"00:14.230 ","End":"00:16.730","Text":"In the case of machine code in particular,"},{"Start":"00:16.730 ","End":"00:21.290","Text":"it was very easy for errors to occur when writing and entering the program."},{"Start":"00:21.290 ","End":"00:23.360","Text":"To other companies problems,"},{"Start":"00:23.360 ","End":"00:24.830","Text":"other programming languages called"},{"Start":"00:24.830 ","End":"00:29.090","Text":"high level languages were developed from the 1950s onwards."},{"Start":"00:29.090 ","End":"00:31.310","Text":"Early high-level languages were concerned with"},{"Start":"00:31.310 ","End":"00:34.655","Text":"engineering and business-related applications."},{"Start":"00:34.655 ","End":"00:38.450","Text":"The languages allowed these sorts of applications to be developed and"},{"Start":"00:38.450 ","End":"00:42.440","Text":"maintained much more easily than was possible with machine code."},{"Start":"00:42.440 ","End":"00:47.785","Text":"Over time, a large number of high-level languages have emerged."},{"Start":"00:47.785 ","End":"00:50.775","Text":"Some are used in education,"},{"Start":"00:50.775 ","End":"00:53.630","Text":"some were attempting to improve on"},{"Start":"00:53.630 ","End":"00:56.959","Text":"the perceived failings of the earlier high-level languages,"},{"Start":"00:56.959 ","End":"00:59.844","Text":"and some were developed for specialist purposes,"},{"Start":"00:59.844 ","End":"01:05.200","Text":"such as creating interactive web pages or smartphone applications."},{"Start":"01:05.200 ","End":"01:08.140","Text":"High-level languages are called high level because they are"},{"Start":"01:08.140 ","End":"01:12.115","Text":"closer to the level of a human language than machine languages are."},{"Start":"01:12.115 ","End":"01:15.520","Text":"As you can see, the high level language is a little"},{"Start":"01:15.520 ","End":"01:20.755","Text":"closer to the human language than the machine code instructions are."},{"Start":"01:20.755 ","End":"01:23.185","Text":"As with assembly language,"},{"Start":"01:23.185 ","End":"01:27.520","Text":"the CPU cannot carry out high-level language instructions directly."},{"Start":"01:27.520 ","End":"01:29.710","Text":"They must be translated first into"},{"Start":"01:29.710 ","End":"01:34.284","Text":"machine code so the CPU can carry out each individual instruction."},{"Start":"01:34.284 ","End":"01:37.840","Text":"There are 2 ways of doing this depending on the language."},{"Start":"01:37.840 ","End":"01:41.395","Text":"When compiling, the original program code,"},{"Start":"01:41.395 ","End":"01:43.225","Text":"which we call source code,"},{"Start":"01:43.225 ","End":"01:45.520","Text":"is translated once,"},{"Start":"01:45.520 ","End":"01:51.235","Text":"and a new copy of the code translated into machine code instructions is produced."},{"Start":"01:51.235 ","End":"01:55.390","Text":"Imagine writing on a piece of paper with writing in"},{"Start":"01:55.390 ","End":"02:01.585","Text":"one language being written out onto a blank piece of paper in a different language."},{"Start":"02:01.585 ","End":"02:06.400","Text":"This, in effect, is what happens when you use a program called a compiler to"},{"Start":"02:06.400 ","End":"02:11.890","Text":"translate a high-level language from its source code into machine code."},{"Start":"02:11.890 ","End":"02:15.460","Text":"An alternative to compiling is interpreting."},{"Start":"02:15.460 ","End":"02:19.870","Text":"When interpreting, the source code is translated line-by-line"},{"Start":"02:19.870 ","End":"02:24.455","Text":"into machine code instructions by a program called an interpreter."},{"Start":"02:24.455 ","End":"02:27.454","Text":"The instructions are carried out by the CPU"},{"Start":"02:27.454 ","End":"02:30.935","Text":"as the program source code is being translated."},{"Start":"02:30.935 ","End":"02:34.580","Text":"Another way of looking at it is to imagine that this video you\u0027re"},{"Start":"02:34.580 ","End":"02:38.465","Text":"watching was recorded in a language that you can\u0027t understand."},{"Start":"02:38.465 ","End":"02:44.315","Text":"You could request a video that\u0027s been completely re-recorded in your own language."},{"Start":"02:44.315 ","End":"02:46.635","Text":"That is like compilation,"},{"Start":"02:46.635 ","End":"02:49.591","Text":"because the source material was being translated,"},{"Start":"02:49.591 ","End":"02:52.790","Text":"once and for all, into another language."},{"Start":"02:52.790 ","End":"02:55.370","Text":"The downside is you\u0027d have to wait until"},{"Start":"02:55.370 ","End":"02:59.450","Text":"the whole video is re-recorded before you could watch it."},{"Start":"02:59.450 ","End":"03:02.375","Text":"In the alternative method of translating,"},{"Start":"03:02.375 ","End":"03:08.375","Text":"interpreting, you could have someone who understands both languages sit with you,"},{"Start":"03:08.375 ","End":"03:13.310","Text":"who listens to the video and translates my spoken words and the"},{"Start":"03:13.310 ","End":"03:18.290","Text":"written on-screen text into your language as it\u0027s playing."},{"Start":"03:18.290 ","End":"03:20.840","Text":"They might occasionally have to pause the video whilst it\u0027s"},{"Start":"03:20.840 ","End":"03:24.755","Text":"playing in order to have time to speak out the translation,"},{"Start":"03:24.755 ","End":"03:30.260","Text":"but it works, and you don\u0027t need to take the time to re-record the whole video."},{"Start":"03:30.260 ","End":"03:33.110","Text":"Compilers and interpreters do the same job,"},{"Start":"03:33.110 ","End":"03:38.825","Text":"translate a high-level language into instructions that can be carried out by the CPU."},{"Start":"03:38.825 ","End":"03:42.875","Text":"Both have their own advantages and disadvantages."},{"Start":"03:42.875 ","End":"03:48.005","Text":"The advantage of compilation is that the translation takes place just once,"},{"Start":"03:48.005 ","End":"03:49.400","Text":"and then after that point,"},{"Start":"03:49.400 ","End":"03:51.980","Text":"just the translated code can be run."},{"Start":"03:51.980 ","End":"03:56.255","Text":"You don\u0027t need the compiler once the code has been translated."},{"Start":"03:56.255 ","End":"04:01.385","Text":"Another advantage is that some errors can be checked before you even run the program."},{"Start":"04:01.385 ","End":"04:07.130","Text":"The downside of compilers is you need to wait for the compilation process to complete,"},{"Start":"04:07.130 ","End":"04:12.410","Text":"and you have to do that every time you change even a single character of the code."},{"Start":"04:12.410 ","End":"04:17.795","Text":"Finally, the compilation process produces code for one particular CPU."},{"Start":"04:17.795 ","End":"04:20.615","Text":"If you want to produce code for a different CPU,"},{"Start":"04:20.615 ","End":"04:24.815","Text":"or even the same CPU running on a different operating system,"},{"Start":"04:24.815 ","End":"04:29.239","Text":"you need to run the compilation process again for that other CPU."},{"Start":"04:29.239 ","End":"04:32.900","Text":"Interpreters have their own advantages and disadvantages."},{"Start":"04:32.900 ","End":"04:39.683","Text":"An advantage is that code can be developed quickly and there\u0027s no compilation necessary,"},{"Start":"04:39.683 ","End":"04:43.205","Text":"so the changes can be very quickly tested and run."},{"Start":"04:43.205 ","End":"04:48.815","Text":"You don\u0027t need to compile several different versions of the program for different CPUs,"},{"Start":"04:48.815 ","End":"04:52.610","Text":"you just need a different interpreter for each different CPU."},{"Start":"04:52.610 ","End":"04:56.120","Text":"The downside is that every time the programs run,"},{"Start":"04:56.120 ","End":"04:59.720","Text":"every line of source code will need translating again."},{"Start":"04:59.720 ","End":"05:03.725","Text":"Not only is this slower in terms of the instructions being completed,"},{"Start":"05:03.725 ","End":"05:07.685","Text":"but the interpreter needs to be available each time the programs run."},{"Start":"05:07.685 ","End":"05:10.310","Text":"Also, for interpreted languages,"},{"Start":"05:10.310 ","End":"05:13.670","Text":"the source code needs to be available for the program to be run."},{"Start":"05:13.670 ","End":"05:17.240","Text":"This could mean security or intellectual property issues."},{"Start":"05:17.240 ","End":"05:20.300","Text":"Basically, someone can more easily steal or modify"},{"Start":"05:20.300 ","End":"05:23.405","Text":"your code if they can read the source code."},{"Start":"05:23.405 ","End":"05:26.195","Text":"As high-level languages develop through time,"},{"Start":"05:26.195 ","End":"05:29.300","Text":"different types emerged with different philosophies,"},{"Start":"05:29.300 ","End":"05:33.170","Text":"computer scientists call these programming paradigms."},{"Start":"05:33.170 ","End":"05:37.280","Text":"Most languages can be categorized as imperative languages."},{"Start":"05:37.280 ","End":"05:41.180","Text":"These languages consists of a series of commands that must be"},{"Start":"05:41.180 ","End":"05:45.475","Text":"completed in a specific order and without any deviation."},{"Start":"05:45.475 ","End":"05:48.530","Text":"Given that this is exactly how a CPU works,"},{"Start":"05:48.530 ","End":"05:52.670","Text":"it\u0027s not surprising that most high-level languages use this paradigm."},{"Start":"05:52.670 ","End":"05:57.305","Text":"Logic-based programming languages are built around rules and facts."},{"Start":"05:57.305 ","End":"05:59.870","Text":"Not every single detail of a program needs"},{"Start":"05:59.870 ","End":"06:02.900","Text":"specifying as is the case for imperative languages,"},{"Start":"06:02.900 ","End":"06:08.059","Text":"and there\u0027s information that can be logically deduced from the rules and facts."},{"Start":"06:08.059 ","End":"06:12.980","Text":"Procedural languages are a type of imperative language built around"},{"Start":"06:12.980 ","End":"06:18.110","Text":"blocks of code that the program can be built from, called procedures."},{"Start":"06:18.110 ","End":"06:21.740","Text":"The particular way that sections of program code can be"},{"Start":"06:21.740 ","End":"06:25.685","Text":"skipped or repeated is also a feature of procedural languages."},{"Start":"06:25.685 ","End":"06:27.080","Text":"Some early languages,"},{"Start":"06:27.080 ","End":"06:28.760","Text":"like Fortran and BASIC,"},{"Start":"06:28.760 ","End":"06:32.240","Text":"were later developed into procedural versions."},{"Start":"06:32.240 ","End":"06:36.470","Text":"Object oriented languages are another type of imperative language"},{"Start":"06:36.470 ","End":"06:41.555","Text":"that feature a concept called a class from which objects can be built."},{"Start":"06:41.555 ","End":"06:46.445","Text":"Objects generally interact with other objects to form a program."},{"Start":"06:46.445 ","End":"06:52.010","Text":"Finally, functional programming languages are an alternative to imperative languages,"},{"Start":"06:52.010 ","End":"06:57.665","Text":"where programs are made up of functions which map a set of values onto other values."},{"Start":"06:57.665 ","End":"07:01.730","Text":"Like logic-based languages and in contrast to imperative languages,"},{"Start":"07:01.730 ","End":"07:04.940","Text":"not every detail of what needs to be done in a program"},{"Start":"07:04.940 ","End":"07:08.765","Text":"requires explicit instructions to be given in the program."},{"Start":"07:08.765 ","End":"07:11.243","Text":"Whilst these categories are all useful,"},{"Start":"07:11.243 ","End":"07:12.350","Text":"and for some languages,"},{"Start":"07:12.350 ","End":"07:15.043","Text":"the most significant factor about the language,"},{"Start":"07:15.043 ","End":"07:18.215","Text":"most languages fall into more than 1 of the categories."},{"Start":"07:18.215 ","End":"07:22.430","Text":"For example, Java belongs to the object oriented paradigm,"},{"Start":"07:22.430 ","End":"07:25.970","Text":"but could also be considered an imperative language and has"},{"Start":"07:25.970 ","End":"07:29.525","Text":"some features that are borrowed from the functional programming paradigm."},{"Start":"07:29.525 ","End":"07:32.000","Text":"You could even write Java programs in a style that\u0027s"},{"Start":"07:32.000 ","End":"07:34.415","Text":"consistent with procedural programming."},{"Start":"07:34.415 ","End":"07:37.400","Text":"We will start this course by learning the basics of"},{"Start":"07:37.400 ","End":"07:41.525","Text":"programming in a high-level language using the procedural paradigm,"},{"Start":"07:41.525 ","End":"07:44.975","Text":"and then move on to the object oriented paradigm."},{"Start":"07:44.975 ","End":"07:48.230","Text":"That completes our introduction to this part of the course."},{"Start":"07:48.230 ","End":"07:50.270","Text":"Let\u0027s summarize what we\u0027ve covered."},{"Start":"07:50.270 ","End":"07:54.875","Text":"We\u0027ve learned how to describe the relationship between the CPU and machine language,"},{"Start":"07:54.875 ","End":"07:58.735","Text":"to explain the need for and advantages of high-level languages,"},{"Start":"07:58.735 ","End":"08:02.915","Text":"to compare methods of translation of high level language to machine language,"},{"Start":"08:02.915 ","End":"08:07.145","Text":"and to categorize languages according to the programming paradigms."},{"Start":"08:07.145 ","End":"08:11.180","Text":"Be sure to test your knowledge of what we covered here by completing the exercises,"},{"Start":"08:11.180 ","End":"08:15.770","Text":"and I\u0027ll see you in the next video where we look at the idea of syntax."},{"Start":"08:15.770 ","End":"08:18.120","Text":"Thanks very much for watching."}],"ID":26342}],"Thumbnail":null,"ID":237667},{"Name":"Basic syntax and semantics of a HLL","TopicPlaylistFirstVideoID":0,"Duration":null,"Videos":[{"Watched":false,"Name":"Natural and Formal languages","Duration":"4m 37s","ChapterTopicVideoID":25526,"CourseChapterTopicPlaylistID":237668,"HasSubtitles":true,"ThumbnailPath":"https://www.proprep.uk/Images/Videos_Thumbnails/25526.jpeg","UploadDate":"2021-05-11T08:20:52.1270000","DurationForVideoObject":"PT4M37S","Description":null,"MetaTitle":"Natural and Formal languages: Video + Workbook | Proprep","MetaDescription":"Fundamental Programming Concepts - Basic syntax and semantics of a HLL. Watch the video made by an expert in the field. Download the workbook and maximize your learning.","Canonical":"https://www.proprep.uk/general-modules/all/principles-of-programing/fundamental-programming-concepts/basic-syntax-and-semantics-of-a-hll/vid26343","VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:03.360","Text":"Hello, everybody and welcome to this video in which we\u0027ll learn"},{"Start":"00:03.360 ","End":"00:06.750","Text":"some concepts that underpin all high-level languages."},{"Start":"00:06.750 ","End":"00:08.130","Text":"By the end of this section,"},{"Start":"00:08.130 ","End":"00:11.150","Text":"you\u0027ll be able to explain the meaning of the term syntax,"},{"Start":"00:11.150 ","End":"00:15.065","Text":"describe the difference between syntax and semantics,"},{"Start":"00:15.065 ","End":"00:19.725","Text":"explain why a statement can be syntactically correct but invalid,"},{"Start":"00:19.725 ","End":"00:23.475","Text":"and distinguish syntax errors from other types of error."},{"Start":"00:23.475 ","End":"00:27.090","Text":"Let\u0027s start with a very basic definition of syntax."},{"Start":"00:27.090 ","End":"00:31.950","Text":"Syntax is a set of rules for a language that are followed or broken."},{"Start":"00:31.950 ","End":"00:35.180","Text":"The rules include only using words or symbols that belong to"},{"Start":"00:35.180 ","End":"00:39.800","Text":"the language and rules for structuring the words and symbols into larger sequences,"},{"Start":"00:39.800 ","End":"00:42.665","Text":"for example, sentences or paragraphs."},{"Start":"00:42.665 ","End":"00:47.360","Text":"Most human languages have a syntax that\u0027s evolved over a long period of time."},{"Start":"00:47.360 ","End":"00:51.185","Text":"Firstly through spoken language and later in written form."},{"Start":"00:51.185 ","End":"00:53.090","Text":"This mostly happens informally,"},{"Start":"00:53.090 ","End":"00:55.925","Text":"but sometimes it can happen through formal bodies."},{"Start":"00:55.925 ","End":"01:01.355","Text":"In France, a formal body called the Academie Francaise preserves the French language by"},{"Start":"01:01.355 ","End":"01:04.070","Text":"proposing alternative French words for"},{"Start":"01:04.070 ","End":"01:07.280","Text":"ones that have crept into everyday use from other languages."},{"Start":"01:07.280 ","End":"01:09.140","Text":"For example, the word Software,"},{"Start":"01:09.140 ","End":"01:10.850","Text":"which is English in origin,"},{"Start":"01:10.850 ","End":"01:14.290","Text":"was replaced with a word logy Cl."},{"Start":"01:14.290 ","End":"01:16.280","Text":"French is an exception."},{"Start":"01:16.280 ","End":"01:20.690","Text":"Most languages tend to develop very informally."},{"Start":"01:20.690 ","End":"01:24.020","Text":"We call human languages natural languages."},{"Start":"01:24.020 ","End":"01:28.985","Text":"Natural languages have the advantage that they are flexible and forgiving."},{"Start":"01:28.985 ","End":"01:34.160","Text":"You can say things 2 different ways and the meaning would be the same."},{"Start":"01:34.160 ","End":"01:38.179","Text":"Not only do these examples show the flexibility of natural languages,"},{"Start":"01:38.179 ","End":"01:40.490","Text":"as you can say the same thing in different ways,"},{"Start":"01:40.490 ","End":"01:43.640","Text":"but also show you how forgiving the language is."},{"Start":"01:43.640 ","End":"01:47.900","Text":"You don\u0027t mean that you\u0027re going to see someone in literally 60 seconds."},{"Start":"01:47.900 ","End":"01:50.150","Text":"It could be a little more or less."},{"Start":"01:50.150 ","End":"01:51.860","Text":"Everyone reading these statements"},{"Start":"01:51.860 ","End":"01:55.430","Text":"understands that a minute doesn\u0027t mean exactly a minute."},{"Start":"01:55.430 ","End":"01:58.265","Text":"It means a relatively short period of time."},{"Start":"01:58.265 ","End":"02:00.770","Text":"Natural languages are so flexible,"},{"Start":"02:00.770 ","End":"02:03.680","Text":"you could use exactly the same words"},{"Start":"02:03.680 ","End":"02:07.130","Text":"in a different order and the meaning could be different."},{"Start":"02:07.130 ","End":"02:11.915","Text":"You could even use the same words in the same order,"},{"Start":"02:11.915 ","End":"02:14.540","Text":"and they can have a completely different meaning"},{"Start":"02:14.540 ","End":"02:18.830","Text":"because of a single character of punctuation in this case."},{"Start":"02:18.830 ","End":"02:23.210","Text":"All of these examples show how ambiguous natural languages can be."},{"Start":"02:23.210 ","End":"02:26.870","Text":"With programming languages, the CPU needs clear,"},{"Start":"02:26.870 ","End":"02:31.475","Text":"unambiguous instructions that correspond to its own instruction set."},{"Start":"02:31.475 ","End":"02:34.160","Text":"When writing programs in assembly language,"},{"Start":"02:34.160 ","End":"02:41.225","Text":"there\u0027s a direct correspondence between mnemonics and machine code instructions."},{"Start":"02:41.225 ","End":"02:46.400","Text":"It\u0027s a simple task for an assembler to look up the binary machine code value for"},{"Start":"02:46.400 ","End":"02:54.375","Text":"a particular mnemonic or the binary value for data stated in decimal in binary."},{"Start":"02:54.375 ","End":"02:59.555","Text":"High-level languages are much more complex to translate than assembly language."},{"Start":"02:59.555 ","End":"03:03.560","Text":"Another category of language is called formal languages have developed in"},{"Start":"03:03.560 ","End":"03:07.910","Text":"the fields of logic, mathematics, and programming."},{"Start":"03:07.910 ","End":"03:13.865","Text":"These formal languages allow us to define language syntax in very precise terms."},{"Start":"03:13.865 ","End":"03:16.910","Text":"This allows us to then create compilers and"},{"Start":"03:16.910 ","End":"03:20.840","Text":"interpreters that follow the rules for the given language."},{"Start":"03:20.840 ","End":"03:23.690","Text":"The languages are generally made of a core set of"},{"Start":"03:23.690 ","End":"03:27.529","Text":"keywords and symbols particular to each language."},{"Start":"03:27.529 ","End":"03:32.239","Text":"In some cases, a single keyword or symbol can perform an operation."},{"Start":"03:32.239 ","End":"03:36.185","Text":"For example, divide 1 number by another."},{"Start":"03:36.185 ","End":"03:39.440","Text":"In other cases, keywords or symbols needs to be"},{"Start":"03:39.440 ","End":"03:43.805","Text":"combined with other keywords and symbols to have any meaning."},{"Start":"03:43.805 ","End":"03:50.000","Text":"For example, comparing 2 numbers and storing the highest of the 2"},{"Start":"03:50.000 ","End":"03:56.320","Text":"in memory requires a whole series of keywords and symbols structured in a particular way."},{"Start":"03:56.320 ","End":"03:59.240","Text":"Computer scientists have devised techniques that allow"},{"Start":"03:59.240 ","End":"04:03.350","Text":"high-level languages to be expressed in an unambiguous way,"},{"Start":"04:03.350 ","End":"04:08.285","Text":"which then makes possible translation into machine language."},{"Start":"04:08.285 ","End":"04:11.825","Text":"Let\u0027s now look at an improved definition of syntax."},{"Start":"04:11.825 ","End":"04:16.279","Text":"It\u0027s the set of rules that define the precise structure"},{"Start":"04:16.279 ","End":"04:21.005","Text":"of a restricted number of words and symbols in a language."},{"Start":"04:21.005 ","End":"04:25.370","Text":"We\u0027ll pause there so you can digest the idea of natural and formal languages."},{"Start":"04:25.370 ","End":"04:29.960","Text":"In the next video, we\u0027ll build on the idea of syntax and relate it to"},{"Start":"04:29.960 ","End":"04:33.110","Text":"semantics and show some practical examples of"},{"Start":"04:33.110 ","End":"04:37.860","Text":"syntax in high-level programming languages. I\u0027ll see you then."}],"ID":26343},{"Watched":false,"Name":"Semantics and types of error","Duration":"9m 11s","ChapterTopicVideoID":25527,"CourseChapterTopicPlaylistID":237668,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:01.950","Text":"Hello, everyone. Welcome back."},{"Start":"00:01.950 ","End":"00:06.390","Text":"In the previous video we\u0027ve finished on an improved definition of syntax,"},{"Start":"00:06.390 ","End":"00:11.730","Text":"to that let\u0027s add another definition that builds on the concept of syntax."},{"Start":"00:11.730 ","End":"00:15.075","Text":"Semantics referred to meaning,"},{"Start":"00:15.075 ","End":"00:21.300","Text":"the meaning derived from a set of syntactically valid statements and expressions."},{"Start":"00:21.300 ","End":"00:24.030","Text":"I could write a sentence in English which uses"},{"Start":"00:24.030 ","End":"00:27.180","Text":"the correct basic syntax but has no meaning."},{"Start":"00:27.180 ","End":"00:31.995","Text":"As you can see the syntax is valid only words that belong to the English language,"},{"Start":"00:31.995 ","End":"00:34.590","Text":"capital letters at the beginning of the sentence,"},{"Start":"00:34.590 ","End":"00:38.010","Text":"spaces between words and a full stop at the end of the sentence."},{"Start":"00:38.010 ","End":"00:44.375","Text":"The sentence is syntactically valid but no meaning can be derived from it."},{"Start":"00:44.375 ","End":"00:47.480","Text":"Natural languages have grammar rules which define"},{"Start":"00:47.480 ","End":"00:51.304","Text":"how the words in a language fit together to form sentences."},{"Start":"00:51.304 ","End":"00:54.020","Text":"For example, in a typical sentence in English,"},{"Start":"00:54.020 ","End":"00:55.640","Text":"you might see the following form."},{"Start":"00:55.640 ","End":"00:58.355","Text":"Subject, verb, object."},{"Start":"00:58.355 ","End":"01:00.950","Text":"The subject, that thing we\u0027re talking about,"},{"Start":"01:00.950 ","End":"01:03.275","Text":"the verb is what the subject is doing,"},{"Start":"01:03.275 ","End":"01:06.950","Text":"and the object is what the subject is doing it to."},{"Start":"01:06.950 ","End":"01:12.100","Text":"Grammar rules can be thought of as another stage after syntax rules,"},{"Start":"01:12.100 ","End":"01:17.870","Text":"however, even grammar rules can be followed and result in something that has no meaning."},{"Start":"01:17.870 ","End":"01:22.115","Text":"Natural languages must relate to some concept in the real world."},{"Start":"01:22.115 ","End":"01:24.740","Text":"If a statement follows syntax rules and follows"},{"Start":"01:24.740 ","End":"01:28.175","Text":"grammar rules but doesn\u0027t relate to concepts in the real world,"},{"Start":"01:28.175 ","End":"01:30.100","Text":"then it still has no meaning."},{"Start":"01:30.100 ","End":"01:34.325","Text":"In this example, a leaf is not capable of eating a panda,"},{"Start":"01:34.325 ","End":"01:39.785","Text":"so the statement makes no sense as no real-world concept relate to this statement."},{"Start":"01:39.785 ","End":"01:43.535","Text":"Even a sentence that has correct syntax, and correct grammar,"},{"Start":"01:43.535 ","End":"01:44.945","Text":"and has a meaning,"},{"Start":"01:44.945 ","End":"01:49.715","Text":"as an isolated sentence might not have meaning when you use out of context."},{"Start":"01:49.715 ","End":"01:51.680","Text":"Here the first sentence makes sense,"},{"Start":"01:51.680 ","End":"01:54.738","Text":"the red sentence in isolation also makes sense,"},{"Start":"01:54.738 ","End":"01:57.485","Text":"and the third sentence makes sense."},{"Start":"01:57.485 ","End":"02:00.530","Text":"But all 3 together in sequence,"},{"Start":"02:00.530 ","End":"02:04.350","Text":"the red sentence doesn\u0027t have any meaning in relation to the other 2."},{"Start":"02:04.350 ","End":"02:07.430","Text":"Humans are great at being able to deal with situations where data\u0027s"},{"Start":"02:07.430 ","End":"02:11.690","Text":"incomplete or inconsistent or even completely absent."},{"Start":"02:11.690 ","End":"02:14.390","Text":"They often use the context to guess at meaning"},{"Start":"02:14.390 ","End":"02:17.390","Text":"and just ignore anything not relevant to the context."},{"Start":"02:17.390 ","End":"02:19.130","Text":"In the paragraph here,"},{"Start":"02:19.130 ","End":"02:21.890","Text":"a human could easily ignore the red text."},{"Start":"02:21.890 ","End":"02:26.630","Text":"Machines can really struggle to cope with those same scenarios, for this reason,"},{"Start":"02:26.630 ","End":"02:30.470","Text":"formal languages don\u0027t rely on context and are, therefore,"},{"Start":"02:30.470 ","End":"02:36.545","Text":"called context-free languages or described as being the result of context-free grammar."},{"Start":"02:36.545 ","End":"02:37.955","Text":"In a formal language,"},{"Start":"02:37.955 ","End":"02:41.044","Text":"statements are either valid or invalid."},{"Start":"02:41.044 ","End":"02:46.225","Text":"When a compiler or interpreter comes across a statement which is invalid, it just stops."},{"Start":"02:46.225 ","End":"02:50.450","Text":"Contrast that with a human who would carry on when they don\u0027t understand"},{"Start":"02:50.450 ","End":"02:55.025","Text":"something and do the best job they can with whatever information is available."},{"Start":"02:55.025 ","End":"02:59.090","Text":"In formal languages, there are mechanical set of rules that must be"},{"Start":"02:59.090 ","End":"03:03.455","Text":"followed for statements or expressions in the language to be valid."},{"Start":"03:03.455 ","End":"03:08.705","Text":"A notation that can be used to create formal languages is called Backus Naur Form."},{"Start":"03:08.705 ","End":"03:11.810","Text":"Here, we can see that unsigned integers are being defined as"},{"Start":"03:11.810 ","End":"03:16.835","Text":"one or more digits that belonged to a set that\u0027s defined in the second line,"},{"Start":"03:16.835 ","End":"03:21.835","Text":"only those characters will be valid in an unsigned integer."},{"Start":"03:21.835 ","End":"03:24.975","Text":"Because a programming languages are formal language,"},{"Start":"03:24.975 ","End":"03:29.750","Text":"when a compiler or interpreter comes across an invalid expression or statement,"},{"Start":"03:29.750 ","End":"03:32.750","Text":"it will stop with a message we call a syntax error."},{"Start":"03:32.750 ","End":"03:35.885","Text":"The message may not include the word syntax but nonetheless,"},{"Start":"03:35.885 ","End":"03:40.684","Text":"is trying to tell the programmer that statement in the program is invalid."},{"Start":"03:40.684 ","End":"03:42.845","Text":"In this example,"},{"Start":"03:42.845 ","End":"03:47.975","Text":"most programming languages expect the line to be terminated with a semicolon."},{"Start":"03:47.975 ","End":"03:50.060","Text":"Here it\u0027s missing and, therefore,"},{"Start":"03:50.060 ","End":"03:54.275","Text":"the syntax error that appears is semicolon expected."},{"Start":"03:54.275 ","End":"03:57.125","Text":"In this particular error message,"},{"Start":"03:57.125 ","End":"03:59.900","Text":"we\u0027re seeing that there is an opening pair of"},{"Start":"03:59.900 ","End":"04:03.695","Text":"speech marks but no closing pair of speech marks here,"},{"Start":"04:03.695 ","End":"04:08.785","Text":"so the error message that\u0027s reported is unclosed string literal."},{"Start":"04:08.785 ","End":"04:13.850","Text":"Here, we\u0027re getting the message package system does not exist."},{"Start":"04:13.850 ","End":"04:18.710","Text":"That\u0027s because the word system over here has been spelled with a lowercase s,"},{"Start":"04:18.710 ","End":"04:21.425","Text":"many high-level languages are case sensitive."},{"Start":"04:21.425 ","End":"04:23.210","Text":"In this particular example,"},{"Start":"04:23.210 ","End":"04:28.100","Text":"the package of code that the print line command belongs to can\u0027t be"},{"Start":"04:28.100 ","End":"04:30.620","Text":"found because the compiler has been directed to"},{"Start":"04:30.620 ","End":"04:33.350","Text":"a package called system with a lowercase s,"},{"Start":"04:33.350 ","End":"04:37.085","Text":"which doesn\u0027t actually exist, hence the error."},{"Start":"04:37.085 ","End":"04:41.240","Text":"Now, this final statement here is actually syntactically correct."},{"Start":"04:41.240 ","End":"04:42.430","Text":"It has a semicolon,"},{"Start":"04:42.430 ","End":"04:46.250","Text":"has allowed operators and symbols but it just has no meaning."},{"Start":"04:46.250 ","End":"04:49.565","Text":"So that actually makes it a semantic error not a syntax error,"},{"Start":"04:49.565 ","End":"04:52.280","Text":"however programmers rarely call it that they would generally"},{"Start":"04:52.280 ","End":"04:55.545","Text":"call all of these types of error syntax errors."},{"Start":"04:55.545 ","End":"05:00.005","Text":"A better phrase might be a compile-time error because"},{"Start":"05:00.005 ","End":"05:02.240","Text":"for compiled languages they\u0027re picked up by"},{"Start":"05:02.240 ","End":"05:04.910","Text":"compiler before the programs ever able to run."},{"Start":"05:04.910 ","End":"05:08.900","Text":"Sometimes you might want the compiler or interpreter to deliberately ignore"},{"Start":"05:08.900 ","End":"05:13.055","Text":"some texts and to not even attempt to compile or interpret it."},{"Start":"05:13.055 ","End":"05:15.760","Text":"This is known as adding comments to the program."},{"Start":"05:15.760 ","End":"05:18.290","Text":"Adding comments allows you to annotate the program to"},{"Start":"05:18.290 ","End":"05:21.350","Text":"explain what a line or section of code is doing."},{"Start":"05:21.350 ","End":"05:23.840","Text":"The syntax varies according to the language but it\u0027s"},{"Start":"05:23.840 ","End":"05:27.635","Text":"usually a single symbol or 2 symbols."},{"Start":"05:27.635 ","End":"05:31.010","Text":"Here in Python, it\u0027s the hash symbol,"},{"Start":"05:31.010 ","End":"05:32.730","Text":"in C or C++,"},{"Start":"05:32.730 ","End":"05:36.020","Text":"it\u0027s 2 forward slashes and everything on"},{"Start":"05:36.020 ","End":"05:39.590","Text":"the line after the 2 forward slashes will be ignored,"},{"Start":"05:39.590 ","End":"05:41.835","Text":"in C++ and again,"},{"Start":"05:41.835 ","End":"05:44.285","Text":"Java from multi-line comment,"},{"Start":"05:44.285 ","End":"05:49.280","Text":"you can put forward slash and an asterisk character that will comment out"},{"Start":"05:49.280 ","End":"05:56.600","Text":"multiple lines until it encounters a asterisk and a forward slash which ends the comment."},{"Start":"05:56.600 ","End":"05:58.063","Text":"Just to reiterate,"},{"Start":"05:58.063 ","End":"06:01.655","Text":"anything after the comment symbol is ignored by the compiler or"},{"Start":"06:01.655 ","End":"06:05.990","Text":"interpreter so syntax rules don\u0027t apply, anything goes."},{"Start":"06:05.990 ","End":"06:08.990","Text":"There are 3 main categories of errors that you might come across"},{"Start":"06:08.990 ","End":"06:12.245","Text":"when developing programs and we\u0027ll state them here,"},{"Start":"06:12.245 ","End":"06:14.450","Text":"syntax or compile-time errors,"},{"Start":"06:14.450 ","End":"06:17.745","Text":"runtime errors, or logical errors."},{"Start":"06:17.745 ","End":"06:20.080","Text":"Syntax errors we\u0027ve already covered,"},{"Start":"06:20.080 ","End":"06:23.360","Text":"codes check to see whether it\u0027s valid or invalid when mechanically"},{"Start":"06:23.360 ","End":"06:27.005","Text":"following some rules around what is allowed and in this case,"},{"Start":"06:27.005 ","End":"06:30.050","Text":"we\u0027re missing a pair of closing speech marks,"},{"Start":"06:30.050 ","End":"06:33.320","Text":"we\u0027ve got the opening ones here but not any closing ones,"},{"Start":"06:33.320 ","End":"06:36.470","Text":"and the compiler is going to signal a syntax error when"},{"Start":"06:36.470 ","End":"06:39.800","Text":"this program is compiled or in an interpreted language,"},{"Start":"06:39.800 ","End":"06:42.515","Text":"the arrow will appear when this particular line is run."},{"Start":"06:42.515 ","End":"06:45.520","Text":"Runtime errors are more subtle type of error,"},{"Start":"06:45.520 ","End":"06:48.530","Text":"they involve some external dependency."},{"Start":"06:48.530 ","End":"06:50.810","Text":"The code is syntactically correct,"},{"Start":"06:50.810 ","End":"06:53.540","Text":"the keywords are known and the arrangement of keywords and symbols is"},{"Start":"06:53.540 ","End":"06:57.440","Text":"valid but an error occurs under certain situations."},{"Start":"06:57.440 ","End":"07:02.735","Text":"This type of error compiler would not signal an error because the code looks okay."},{"Start":"07:02.735 ","End":"07:07.100","Text":"Even an interpreter would run the line and it could work, however,"},{"Start":"07:07.100 ","End":"07:10.130","Text":"the interesting word there is that it could work,"},{"Start":"07:10.130 ","End":"07:15.965","Text":"it all depends on whether this file being opened is available or not."},{"Start":"07:15.965 ","End":"07:17.570","Text":"The file might have been deleted,"},{"Start":"07:17.570 ","End":"07:19.850","Text":"moved or renamed, and, therefore,"},{"Start":"07:19.850 ","End":"07:22.325","Text":"the system might not be able to find it."},{"Start":"07:22.325 ","End":"07:25.160","Text":"There\u0027s no way of the compiler knowing this in advance"},{"Start":"07:25.160 ","End":"07:28.130","Text":"the first time the interpret or to even check is it"},{"Start":"07:28.130 ","End":"07:31.010","Text":"when it tries to open the file and then it"},{"Start":"07:31.010 ","End":"07:34.505","Text":"fails and it will generate an error message and the program would stop."},{"Start":"07:34.505 ","End":"07:37.230","Text":"Same goes for compile program too."},{"Start":"07:37.230 ","End":"07:39.230","Text":"This gives us an indication of why"},{"Start":"07:39.230 ","End":"07:41.960","Text":"syntax errors are sometimes called compile-time errors,"},{"Start":"07:41.960 ","End":"07:45.365","Text":"they can be picked up before the programs even run."},{"Start":"07:45.365 ","End":"07:50.655","Text":"However, a runtime error can only be detected when the program is running."},{"Start":"07:50.655 ","End":"07:54.205","Text":"The final category is the logical error."},{"Start":"07:54.205 ","End":"07:56.710","Text":"In this program, we\u0027re supposed to output"},{"Start":"07:56.710 ","End":"07:59.980","Text":"a message saying which is the highest of 2 numbers,"},{"Start":"07:59.980 ","End":"08:01.570","Text":"a or b, however,"},{"Start":"08:01.570 ","End":"08:03.475","Text":"there is a logical error here."},{"Start":"08:03.475 ","End":"08:06.700","Text":"If a is exactly equal to b,"},{"Start":"08:06.700 ","End":"08:10.210","Text":"the program will output b is bigger than a."},{"Start":"08:10.210 ","End":"08:11.520","Text":"There\u0027s no syntax errors,"},{"Start":"08:11.520 ","End":"08:13.240","Text":"the syntax actually, all correct."},{"Start":"08:13.240 ","End":"08:15.115","Text":"There\u0027s no runtime error either,"},{"Start":"08:15.115 ","End":"08:18.340","Text":"as there\u0027s nothing in these lines that depends on anything external."},{"Start":"08:18.340 ","End":"08:20.560","Text":"The error is just that the program doesn\u0027t do what"},{"Start":"08:20.560 ","End":"08:22.690","Text":"we want it to do and it\u0027s the thing with computers,"},{"Start":"08:22.690 ","End":"08:24.190","Text":"they do what you tell them to do,"},{"Start":"08:24.190 ","End":"08:25.780","Text":"not what you want them to do."},{"Start":"08:25.780 ","End":"08:28.285","Text":"Beginner programmers are going to encounter"},{"Start":"08:28.285 ","End":"08:31.870","Text":"all 3 of these types of error when learning how to program."},{"Start":"08:31.870 ","End":"08:33.130","Text":"At the beginning,"},{"Start":"08:33.130 ","End":"08:35.155","Text":"syntax errors will be the most common,"},{"Start":"08:35.155 ","End":"08:37.620","Text":"then it\u0027ll be mostly logical errors,"},{"Start":"08:37.620 ","End":"08:43.025","Text":"runtime errors you only really encounter under quite specific circumstances."},{"Start":"08:43.025 ","End":"08:45.170","Text":"So you don\u0027t see them as often."},{"Start":"08:45.170 ","End":"08:49.700","Text":"So that\u0027s it for this video where we looked at the meaning of the term syntax."},{"Start":"08:49.700 ","End":"08:52.100","Text":"In this section, we learned how to explain the meaning of"},{"Start":"08:52.100 ","End":"08:56.195","Text":"the term syntax to describe the difference between syntax and semantics,"},{"Start":"08:56.195 ","End":"09:00.195","Text":"to explain why a statement can be syntactically correct but invalid and"},{"Start":"09:00.195 ","End":"09:04.340","Text":"to distinguish syntax errors from other types of error."},{"Start":"09:04.340 ","End":"09:07.940","Text":"Thanks very much and I\u0027ll see you in the next one where start to write"},{"Start":"09:07.940 ","End":"09:12.450","Text":"simple statements in high-level languages. Thanks, again."}],"ID":26344},{"Watched":false,"Name":"Exercise 1","Duration":"3m 38s","ChapterTopicVideoID":26926,"CourseChapterTopicPlaylistID":237668,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.050 ","End":"00:04.020","Text":"Hi everyone, welcome to this first exercise in which we"},{"Start":"00:04.020 ","End":"00:08.750","Text":"discuss the differences between natural and formal languages."},{"Start":"00:08.750 ","End":"00:10.470","Text":"The first part, Part A,"},{"Start":"00:10.470 ","End":"00:15.285","Text":"asks us to describe 2 advantages of natural languages over formal languages."},{"Start":"00:15.285 ","End":"00:18.570","Text":"Natural languages being ones spoken by humans."},{"Start":"00:18.570 ","End":"00:20.970","Text":"For example, English, Spanish, etc."},{"Start":"00:20.970 ","End":"00:23.760","Text":"Formal languages being things like maths,"},{"Start":"00:23.760 ","End":"00:27.209","Text":"logic, and programming languages."},{"Start":"00:27.209 ","End":"00:31.440","Text":"The first advantage we might want to talk about when we\u0027re talking about"},{"Start":"00:31.440 ","End":"00:35.970","Text":"natural languages would be the flexibility inherent in natural languages."},{"Start":"00:35.970 ","End":"00:38.570","Text":"Because there\u0027s many ways of saying things in"},{"Start":"00:38.570 ","End":"00:41.930","Text":"most languages to achieve some particular outcome."},{"Start":"00:41.930 ","End":"00:44.885","Text":"That\u0027s not the case for formal languages."},{"Start":"00:44.885 ","End":"00:47.765","Text":"They tend to provide a very limited set of"},{"Start":"00:47.765 ","End":"00:51.605","Text":"permitted operations and keywords to achieve whatever the outcome is."},{"Start":"00:51.605 ","End":"00:55.714","Text":"We\u0027d have a symbol that represents addition."},{"Start":"00:55.714 ","End":"00:59.930","Text":"There is only 1 symbol that has that function."},{"Start":"00:59.930 ","End":"01:02.945","Text":"Similarly for multiplication, division, and so on."},{"Start":"01:02.945 ","End":"01:07.295","Text":"But we would have a lot of words in natural languages perhaps,"},{"Start":"01:07.295 ","End":"01:11.225","Text":"to describe 1 particular thing and they all mean the same thing."},{"Start":"01:11.225 ","End":"01:13.700","Text":"That\u0027s not the case generally with formal languages are"},{"Start":"01:13.700 ","End":"01:17.330","Text":"much more restricted set of operations and keywords."},{"Start":"01:17.330 ","End":"01:21.349","Text":"The other difference would be around precision."},{"Start":"01:21.349 ","End":"01:25.370","Text":"You can get away with in natural languages, lack of precision."},{"Start":"01:25.370 ","End":"01:31.055","Text":"That\u0027s not something you can do in formal languages because you don\u0027t want to."},{"Start":"01:31.055 ","End":"01:36.425","Text":"Formal languages rely on context and conventions and any other information."},{"Start":"01:36.425 ","End":"01:39.665","Text":"When you\u0027re trying to understand the meaning of a particular statement,"},{"Start":"01:39.665 ","End":"01:41.570","Text":"a compiler has to understand the meaning and"},{"Start":"01:41.570 ","End":"01:45.245","Text":"ultimately the CPU has to carry out those instructions."},{"Start":"01:45.245 ","End":"01:47.940","Text":"Formal languages are very literal."},{"Start":"01:47.940 ","End":"01:50.750","Text":"If you were talking about a time, for example,"},{"Start":"01:50.750 ","End":"01:56.405","Text":"it would be an exact time or at a time within a certain range with a certain tolerance."},{"Start":"01:56.405 ","End":"01:58.280","Text":"If we say 30 seconds,"},{"Start":"01:58.280 ","End":"02:00.170","Text":"it will be exactly 30 seconds."},{"Start":"02:00.170 ","End":"02:04.100","Text":"If we say 30 seconds with a tolerance of 5 seconds,"},{"Start":"02:04.100 ","End":"02:07.190","Text":"then it would be 25-35 seconds."},{"Start":"02:07.190 ","End":"02:12.529","Text":"In that way, natural languages are a lot more flexible than formal languages."},{"Start":"02:12.529 ","End":"02:15.650","Text":"In Part B, we then are asked what feature of"},{"Start":"02:15.650 ","End":"02:19.325","Text":"natural languages makes formal languages necessary for programming."},{"Start":"02:19.325 ","End":"02:23.025","Text":"That really leads back to what we\u0027ve just said for Part A."},{"Start":"02:23.025 ","End":"02:25.640","Text":"It\u0027s the flexibility of natural language."},{"Start":"02:25.640 ","End":"02:28.255","Text":"That\u0027s an advantage, but also a disadvantage,"},{"Start":"02:28.255 ","End":"02:31.520","Text":"and that we can have some ambiguity."},{"Start":"02:31.520 ","End":"02:34.610","Text":"Statements in a natural language are"},{"Start":"02:34.610 ","End":"02:38.225","Text":"difficult for a compiler or an interpreter to translate"},{"Start":"02:38.225 ","End":"02:42.710","Text":"into the exact machine code instructions that a CPU"},{"Start":"02:42.710 ","End":"02:47.630","Text":"can understand because it can only understand machine code instructions ultimately."},{"Start":"02:47.630 ","End":"02:50.780","Text":"This formal language lets us have"},{"Start":"02:50.780 ","End":"02:55.130","Text":"a very restricted set of symbols and keywords and structures"},{"Start":"02:55.130 ","End":"02:59.100","Text":"that allow for unambiguous interpretation and we can"},{"Start":"02:59.100 ","End":"03:02.930","Text":"then directly translate those symbols,"},{"Start":"03:02.930 ","End":"03:06.080","Text":"keywords, and structures into machine code instructions in"},{"Start":"03:06.080 ","End":"03:09.935","Text":"a way that would be difficult to do with natural languages."},{"Start":"03:09.935 ","End":"03:14.840","Text":"That\u0027s really what we\u0027re looking for in those 2 parts of this exercise,"},{"Start":"03:14.840 ","End":"03:18.080","Text":"really this understanding that natural languages are great in"},{"Start":"03:18.080 ","End":"03:21.995","Text":"the sense that there\u0027s a lot of flexibility and informality with them."},{"Start":"03:21.995 ","End":"03:24.920","Text":"Formal languages by definition,"},{"Start":"03:24.920 ","End":"03:29.135","Text":"have a much more restricted set of operations."},{"Start":"03:29.135 ","End":"03:35.975","Text":"Therefore, they can be very easily translated into specific machine code instructions."},{"Start":"03:35.975 ","End":"03:39.030","Text":"That\u0027s it for this one, I\u0027ll see you in the next one."}],"ID":28018},{"Watched":false,"Name":"Exercise 2","Duration":"5m 12s","ChapterTopicVideoID":26927,"CourseChapterTopicPlaylistID":237668,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.850","Text":"Hello, again. In this exercise,"},{"Start":"00:02.850 ","End":"00:07.020","Text":"we\u0027ve been asked to agree with the statement with a definition here,"},{"Start":"00:07.020 ","End":"00:08.910","Text":"which is about syntax."},{"Start":"00:08.910 ","End":"00:12.030","Text":"It says syntax can be defined as the set of rules that define"},{"Start":"00:12.030 ","End":"00:17.070","Text":"the precise structure of a restricted number of words and symbols in a language."},{"Start":"00:17.070 ","End":"00:19.600","Text":"In part a, we were invited to say to"},{"Start":"00:19.600 ","End":"00:24.555","Text":"what degree that definition applies for a natural language."},{"Start":"00:24.555 ","End":"00:29.070","Text":"The implication there is for formal languages and natural languages,"},{"Start":"00:29.070 ","End":"00:33.720","Text":"this definition applies, but it applies less for 1 of those."},{"Start":"00:33.720 ","End":"00:38.330","Text":"I don\u0027t think it\u0027d be a surprise for you to workout that applies to both,"},{"Start":"00:38.330 ","End":"00:41.750","Text":"but to a lesser degree for natural languages."},{"Start":"00:41.750 ","End":"00:43.940","Text":"Because as we said previously,"},{"Start":"00:43.940 ","End":"00:48.980","Text":"they allow more flexibility due to less strict rules that are"},{"Start":"00:48.980 ","End":"00:51.455","Text":"applied when we are trying to"},{"Start":"00:51.455 ","End":"00:55.370","Text":"understand the meaning of some statement in the natural language."},{"Start":"00:55.370 ","End":"00:57.680","Text":"A lot of that is also to do with"},{"Start":"00:57.680 ","End":"01:04.025","Text":"the very large vocabulary that you\u0027d have in a typical human language."},{"Start":"01:04.025 ","End":"01:06.680","Text":"If you contrast that with a formal language,"},{"Start":"01:06.680 ","End":"01:08.240","Text":"a programming language like Java,"},{"Start":"01:08.240 ","End":"01:11.270","Text":"there\u0027s only about 60 keywords in Java."},{"Start":"01:11.270 ","End":"01:14.480","Text":"Whereas the average adult who is"},{"Start":"01:14.480 ","End":"01:18.875","Text":"an English speaker would know tens of thousands of words in English."},{"Start":"01:18.875 ","End":"01:22.580","Text":"There\u0027s a huge, huge difference in the size of"},{"Start":"01:22.580 ","End":"01:26.705","Text":"the vocabulary of natural and formal languages."},{"Start":"01:26.705 ","End":"01:32.045","Text":"That\u0027s the first part of the answer to part a."},{"Start":"01:32.045 ","End":"01:35.930","Text":"In part b, we\u0027re asked to describe how it\u0027s possible"},{"Start":"01:35.930 ","End":"01:39.890","Text":"for an expression in a language to use the correct syntax,"},{"Start":"01:39.890 ","End":"01:42.595","Text":"but to still be invalid."},{"Start":"01:42.595 ","End":"01:46.205","Text":"This is really about the understanding of the difference between"},{"Start":"01:46.205 ","End":"01:50.125","Text":"syntax being correct and semantics."},{"Start":"01:50.125 ","End":"01:54.020","Text":"This idea that semantics is all about the meaning of something."},{"Start":"01:54.020 ","End":"01:57.200","Text":"Somebody could be syntactically correct but have"},{"Start":"01:57.200 ","End":"02:01.625","Text":"no meaning and that would make it invalid in the language being used."},{"Start":"02:01.625 ","End":"02:04.490","Text":"We look at that for a natural language,"},{"Start":"02:04.490 ","End":"02:08.020","Text":"it might be down to grammar rules that have been broken."},{"Start":"02:08.020 ","End":"02:11.945","Text":"That would potentially make a statement confusing"},{"Start":"02:11.945 ","End":"02:15.680","Text":"or if it\u0027s serious enough grammar rule that has been broken,"},{"Start":"02:15.680 ","End":"02:18.295","Text":"it just could be completely meaningless what\u0027s being said."},{"Start":"02:18.295 ","End":"02:24.140","Text":"There could be an issue with a paragraph where there are multiple sentences"},{"Start":"02:24.140 ","End":"02:26.780","Text":"in a natural language where 1 of them makes"},{"Start":"02:26.780 ","End":"02:30.125","Text":"no sense in the context of the other sentences."},{"Start":"02:30.125 ","End":"02:32.405","Text":"Again, there\u0027s confusion there."},{"Start":"02:32.405 ","End":"02:36.185","Text":"It doesn\u0027t mean the whole paragraph is rendered meaningless,"},{"Start":"02:36.185 ","End":"02:38.000","Text":"but some of it is meaningless."},{"Start":"02:38.000 ","End":"02:41.600","Text":"Generally, we would tend to ignore them meaningless bits and"},{"Start":"02:41.600 ","End":"02:45.335","Text":"put the sentences into some overall context."},{"Start":"02:45.335 ","End":"02:51.710","Text":"Finally, the statement that\u0027s made could also make no sense essentially."},{"Start":"02:51.710 ","End":"02:53.825","Text":"Bears no relationship to"},{"Start":"02:53.825 ","End":"02:59.265","Text":"a real-world concept and that would also make it invalid in the example we gave."},{"Start":"02:59.265 ","End":"03:03.440","Text":"When we looked at this in the video was this idea of"},{"Start":"03:03.440 ","End":"03:08.795","Text":"an animal eating something vegetable or fruit."},{"Start":"03:08.795 ","End":"03:13.730","Text":"That makes sense but the fruit or vegetable could not eat the animal,"},{"Start":"03:13.730 ","End":"03:16.850","Text":"even though in the grammar it might be correct."},{"Start":"03:16.850 ","End":"03:19.520","Text":"It just doesn\u0027t make sense in the real world."},{"Start":"03:19.520 ","End":"03:22.385","Text":"That would also render it invalid."},{"Start":"03:22.385 ","End":"03:27.480","Text":"That\u0027s part b dealt with and the final part c,"},{"Start":"03:27.480 ","End":"03:32.030","Text":"what advantage do humans using natural languages have over machines using"},{"Start":"03:32.030 ","End":"03:38.780","Text":"formal languages in terms of longer sequences of expressions and statements?"},{"Start":"03:38.780 ","End":"03:42.620","Text":"This advantage that human has when they\u0027re using natural languages."},{"Start":"03:42.620 ","End":"03:48.560","Text":"They can just simply ignore things that are invalid because they can guess things using"},{"Start":"03:48.560 ","End":"03:51.590","Text":"the context or they can actually make use of"},{"Start":"03:51.590 ","End":"03:55.760","Text":"inaccurate or incomplete data and fill in the gaps."},{"Start":"03:55.760 ","End":"04:00.365","Text":"Or just recognize that something might not be fully accurate,"},{"Start":"04:00.365 ","End":"04:04.040","Text":"but it would be good enough in terms of information provided"},{"Start":"04:04.040 ","End":"04:08.150","Text":"to deliver on what the outcome was and a map is a great example of that."},{"Start":"04:08.150 ","End":"04:11.315","Text":"Someone can give you directions or someone could draw you a map."},{"Start":"04:11.315 ","End":"04:13.070","Text":"It\u0027s not fully accurate."},{"Start":"04:13.070 ","End":"04:15.485","Text":"It might even have some bits missing,"},{"Start":"04:15.485 ","End":"04:20.675","Text":"but you can still work out where you need to go from this map that\u0027s been drawn,"},{"Start":"04:20.675 ","End":"04:24.684","Text":"even if it\u0027s not completely accurate or complete."},{"Start":"04:24.684 ","End":"04:31.660","Text":"Contrast there is a machine just cannot do this when it\u0027s using a formal language."},{"Start":"04:31.660 ","End":"04:34.295","Text":"If it encounters an invalid statement,"},{"Start":"04:34.295 ","End":"04:38.385","Text":"it has to stop and report an error."},{"Start":"04:38.385 ","End":"04:40.620","Text":"That was it for this exercise."},{"Start":"04:40.620 ","End":"04:45.065","Text":"The 3 parts really are all about the differences between"},{"Start":"04:45.065 ","End":"04:48.530","Text":"natural and formal languages and the consequences of"},{"Start":"04:48.530 ","End":"04:52.700","Text":"those differences for us when it comes to programming,"},{"Start":"04:52.700 ","End":"04:55.295","Text":"because we are going to encounter errors,"},{"Start":"04:55.295 ","End":"04:59.630","Text":"and they will stop the CPU from being able to execute"},{"Start":"04:59.630 ","End":"05:02.690","Text":"any instructions or it might even stop"},{"Start":"05:02.690 ","End":"05:06.950","Text":"the compiler before we even get to the CPU running any instructions."},{"Start":"05:06.950 ","End":"05:10.385","Text":"It will simply stop and we can\u0027t go any further."},{"Start":"05:10.385 ","End":"05:13.580","Text":"That\u0027s it for this 1. I\u0027ll see you soon."}],"ID":28019},{"Watched":false,"Name":"Exercise 3","Duration":"4m 1s","ChapterTopicVideoID":26928,"CourseChapterTopicPlaylistID":237668,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.610","Text":"Hello, again. In this question,"},{"Start":"00:02.610 ","End":"00:05.175","Text":"we\u0027ve been asked to say whether"},{"Start":"00:05.175 ","End":"00:10.965","Text":"a compile time error might be a better way of describing a syntax error,"},{"Start":"00:10.965 ","End":"00:16.215","Text":"and we\u0027ve been told that compilers or interpreters may report a syntax error."},{"Start":"00:16.215 ","End":"00:19.380","Text":"What we\u0027re really trying to probe here is whether you"},{"Start":"00:19.380 ","End":"00:23.130","Text":"really understand what a syntax error actually is."},{"Start":"00:23.130 ","End":"00:25.500","Text":"The first part, we could say,"},{"Start":"00:25.500 ","End":"00:30.360","Text":"is that these errors can be picked up in advance of the program running,"},{"Start":"00:30.360 ","End":"00:33.360","Text":"and that\u0027s true for compilers and interpreters."},{"Start":"00:33.360 ","End":"00:36.270","Text":"However, for compilers, it\u0027s a little bit more obvious, I guess,"},{"Start":"00:36.270 ","End":"00:41.630","Text":"because the compiler has to translate the entire thing in one go,"},{"Start":"00:41.630 ","End":"00:44.780","Text":"the entire source code into machine code."},{"Start":"00:44.780 ","End":"00:49.640","Text":"So clearly, if it comes across any lines that it cannot make sense of,"},{"Start":"00:49.640 ","End":"00:51.460","Text":"it\u0027s going to report the error,"},{"Start":"00:51.460 ","End":"00:55.295","Text":"and no machine code is actually going to be produced at all."},{"Start":"00:55.295 ","End":"00:58.520","Text":"Whereas an interpreter would also do this,"},{"Start":"00:58.520 ","End":"01:00.110","Text":"but it does it line by line,"},{"Start":"01:00.110 ","End":"01:03.230","Text":"and it picks up those syntax errors as they are"},{"Start":"01:03.230 ","End":"01:07.820","Text":"encountered whilst the interpreter is trying to translate them into machine code."},{"Start":"01:07.820 ","End":"01:10.430","Text":"For a interpreted language,"},{"Start":"01:10.430 ","End":"01:13.370","Text":"the error occurs whilst the program\u0027s running and it"},{"Start":"01:13.370 ","End":"01:16.880","Text":"gets reported and the program then stops."},{"Start":"01:16.880 ","End":"01:18.440","Text":"Whereas in a compiler,"},{"Start":"01:18.440 ","End":"01:20.270","Text":"you would never have got to that stage."},{"Start":"01:20.270 ","End":"01:22.160","Text":"So for both of them,"},{"Start":"01:22.160 ","End":"01:25.370","Text":"you can actually check these types of error in advance."},{"Start":"01:25.370 ","End":"01:28.804","Text":"Although interpreted languages are not compiled,"},{"Start":"01:28.804 ","End":"01:32.570","Text":"they can have a compilation process run on them by"},{"Start":"01:32.570 ","End":"01:36.305","Text":"something called a pre-processor or syntax checker,"},{"Start":"01:36.305 ","End":"01:40.955","Text":"and they often run inside the editors for a programming language."},{"Start":"01:40.955 ","End":"01:44.150","Text":"JavaScript has quite a few pre-processes that will check"},{"Start":"01:44.150 ","End":"01:48.275","Text":"the syntax of the statements that are in the script,"},{"Start":"01:48.275 ","End":"01:51.170","Text":"and they can catch errors before you ever actually"},{"Start":"01:51.170 ","End":"01:54.395","Text":"try and launch the web page that contains that script."},{"Start":"01:54.395 ","End":"01:58.520","Text":"It is possible to check certain types of error in advance,"},{"Start":"01:58.520 ","End":"02:04.550","Text":"and that\u0027s why really compile time error is a fairly reasonable way to"},{"Start":"02:04.550 ","End":"02:07.565","Text":"describe this type of syntax error because"},{"Start":"02:07.565 ","End":"02:11.135","Text":"you can know about it in advance before the program ever runs,"},{"Start":"02:11.135 ","End":"02:12.905","Text":"and therefore, you can pick it up."},{"Start":"02:12.905 ","End":"02:15.290","Text":"That\u0027s the first part of the answer."},{"Start":"02:15.290 ","End":"02:19.640","Text":"The second one is talking about this term, syntax error,"},{"Start":"02:19.640 ","End":"02:22.850","Text":"is sometimes used to describe a different type of error,"},{"Start":"02:22.850 ","End":"02:26.135","Text":"and why is this strictly not correct?"},{"Start":"02:26.135 ","End":"02:30.020","Text":"Well, if the compiler or the interpreter can\u0027t"},{"Start":"02:30.020 ","End":"02:35.915","Text":"understand the meaning of something that is syntactically correct."},{"Start":"02:35.915 ","End":"02:38.915","Text":"That\u0027s a thing, it will have an error."},{"Start":"02:38.915 ","End":"02:41.690","Text":"It can\u0027t translate the expression into"},{"Start":"02:41.690 ","End":"02:44.390","Text":"machine code instructions and that will stop compilation,"},{"Start":"02:44.390 ","End":"02:46.520","Text":"or if it\u0027s an interpreted language,"},{"Start":"02:46.520 ","End":"02:49.085","Text":"it will stop execution and report an error."},{"Start":"02:49.085 ","End":"02:52.220","Text":"But actually, that type of error is not really a syntax error,"},{"Start":"02:52.220 ","End":"02:57.170","Text":"it\u0027s a semantic error because it can\u0027t understand the meaning of an expression."},{"Start":"02:57.170 ","End":"02:58.790","Text":"An example there would be,"},{"Start":"02:58.790 ","End":"03:01.670","Text":"if we had an expression and a line of code"},{"Start":"03:01.670 ","End":"03:05.435","Text":"that wasn\u0027t stored in a variable or was an output,"},{"Start":"03:05.435 ","End":"03:08.405","Text":"the compiler or the interpreter just doesn\u0027t know what to do with it,"},{"Start":"03:08.405 ","End":"03:11.540","Text":"even though the syntax for the expression is correct."},{"Start":"03:11.540 ","End":"03:14.390","Text":"It doesn\u0027t actually understand what the meaning of that would be,"},{"Start":"03:14.390 ","End":"03:15.995","Text":"what the purpose of it would be."},{"Start":"03:15.995 ","End":"03:17.645","Text":"It report it as an error,"},{"Start":"03:17.645 ","End":"03:20.510","Text":"and programmers would tend to call that a syntax error,"},{"Start":"03:20.510 ","End":"03:22.790","Text":"but it\u0027s not really a syntax error strictly speaking,"},{"Start":"03:22.790 ","End":"03:25.760","Text":"it\u0027s a semantic error as we learned previously."},{"Start":"03:25.760 ","End":"03:30.200","Text":"Semantics has to do with meaning rather than blind structure."},{"Start":"03:30.200 ","End":"03:34.870","Text":"That\u0027s really all we\u0027re looking for in this answer here,"},{"Start":"03:34.870 ","End":"03:37.250","Text":"is really finding out that"},{"Start":"03:37.250 ","End":"03:39.860","Text":"a syntax error is something that can be"},{"Start":"03:39.860 ","End":"03:42.740","Text":"picked up at a compile time for compiled languages."},{"Start":"03:42.740 ","End":"03:44.240","Text":"But if we wanted to,"},{"Start":"03:44.240 ","End":"03:47.960","Text":"we could also do it for interpreted languages through pre-processor."},{"Start":"03:47.960 ","End":"03:51.920","Text":"But we even use it as a catch-all for semantic errors sometimes as well,"},{"Start":"03:51.920 ","End":"03:53.780","Text":"and that\u0027s not strictly correct."},{"Start":"03:53.780 ","End":"03:57.290","Text":"That\u0027s the real-world. That\u0027s what programmers will talk about."},{"Start":"03:57.290 ","End":"03:58.950","Text":"That\u0027s it for this exercise."},{"Start":"03:58.950 ","End":"04:02.070","Text":"Thanks very much for watching and I\u0027ll see you in the next one."}],"ID":28020},{"Watched":false,"Name":"Exercise 4","Duration":"5m 23s","ChapterTopicVideoID":26925,"CourseChapterTopicPlaylistID":237668,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:03.270","Text":"Hi everyone. In this exercise,"},{"Start":"00:03.270 ","End":"00:05.580","Text":"we\u0027re being asked about other types of error other"},{"Start":"00:05.580 ","End":"00:07.988","Text":"than syntax errors because they\u0027re not the only type of errors,"},{"Start":"00:07.988 ","End":"00:09.450","Text":"it says in the question."},{"Start":"00:09.450 ","End":"00:13.005","Text":"We\u0027re being asked in part a why it\u0027s not possible to pick up"},{"Start":"00:13.005 ","End":"00:16.710","Text":"run-time errors in advance of the program being run."},{"Start":"00:16.710 ","End":"00:18.975","Text":"To answer this, we need to really say what"},{"Start":"00:18.975 ","End":"00:23.880","Text":"a run-time error is and compare it to syntax errors."},{"Start":"00:23.880 ","End":"00:27.150","Text":"Syntax and semantic errors are picked up in advance,"},{"Start":"00:27.150 ","End":"00:29.400","Text":"the program being run by the compiler or"},{"Start":"00:29.400 ","End":"00:32.640","Text":"the interpreter or pre-processor of the interpreter."},{"Start":"00:32.640 ","End":"00:35.520","Text":"But run-time errors can only be discovered once the"},{"Start":"00:35.520 ","End":"00:38.810","Text":"program\u0027s running because, by definition,"},{"Start":"00:38.810 ","End":"00:42.020","Text":"run-time errors have some dependency"},{"Start":"00:42.020 ","End":"00:45.500","Text":"that\u0027s external to the actual lines of code being executed."},{"Start":"00:45.500 ","End":"00:49.430","Text":"An example of that would be if a program was trying to open"},{"Start":"00:49.430 ","End":"00:53.420","Text":"a file and before it access the file,"},{"Start":"00:53.420 ","End":"00:55.729","Text":"that file got deleted or moved,"},{"Start":"00:55.729 ","End":"00:58.220","Text":"then at that point,"},{"Start":"00:58.220 ","End":"01:00.635","Text":"a run-time error will be reported."},{"Start":"01:00.635 ","End":"01:05.705","Text":"It couldn\u0027t ever know a compile-time that the file\u0027s there or not."},{"Start":"01:05.705 ","End":"01:09.320","Text":"Because even when the program runs, it might be there,"},{"Start":"01:09.320 ","End":"01:11.314","Text":"but it might be moved or deleted,"},{"Start":"01:11.314 ","End":"01:13.270","Text":"a microsecond before it\u0027s access,"},{"Start":"01:13.270 ","End":"01:17.410","Text":"so even if it did exist at one point it\u0027s when trying"},{"Start":"01:17.410 ","End":"01:22.295","Text":"to be accessed that it would generate an error if the file wasn\u0027t there."},{"Start":"01:22.295 ","End":"01:27.370","Text":"You cannot pick up a run-time error in advance of the program being run."},{"Start":"01:27.370 ","End":"01:31.550","Text":"The second part of this is asking about the other type of error,"},{"Start":"01:31.550 ","End":"01:33.485","Text":"which is logical errors."},{"Start":"01:33.485 ","End":"01:35.840","Text":"Why is it that experienced programmers spend"},{"Start":"01:35.840 ","End":"01:38.900","Text":"more time dealing with logical errors than syntax errors?"},{"Start":"01:38.900 ","End":"01:40.730","Text":"What is a logical error?"},{"Start":"01:40.730 ","End":"01:45.290","Text":"It\u0027s one where you can actually run the program because"},{"Start":"01:45.290 ","End":"01:49.790","Text":"there\u0027s no syntax errors and it also doesn\u0027t produce a run-time error either."},{"Start":"01:49.790 ","End":"01:51.620","Text":"It just doesn\u0027t do what it\u0027s supposed to do,"},{"Start":"01:51.620 ","End":"01:53.630","Text":"it doesn\u0027t produce the intended outcome."},{"Start":"01:53.630 ","End":"01:56.930","Text":"Logical errors tend to be more difficult to"},{"Start":"01:56.930 ","End":"02:00.590","Text":"track down and resolve whereas syntax errors are usually"},{"Start":"02:00.590 ","End":"02:04.019","Text":"very simple things that are the result of typing errors"},{"Start":"02:04.019 ","End":"02:08.210","Text":"or for beginners that doesn\u0027t understand the syntax exactly."},{"Start":"02:08.210 ","End":"02:11.765","Text":"You\u0027re obviously going to encounter those more frequently"},{"Start":"02:11.765 ","End":"02:15.635","Text":"when you\u0027re starting out and you\u0027ll have those less and less over time."},{"Start":"02:15.635 ","End":"02:20.720","Text":"Whereas any reasonably complex program just running first-time,"},{"Start":"02:20.720 ","End":"02:22.910","Text":"it\u0027s very unlikely that that would happen,"},{"Start":"02:22.910 ","End":"02:25.760","Text":"even if it does seem to work first-time round."},{"Start":"02:25.760 ","End":"02:28.955","Text":"It might work with some inputs but fail with others."},{"Start":"02:28.955 ","End":"02:31.190","Text":"Or it might work when it\u0027s in a particular state,"},{"Start":"02:31.190 ","End":"02:33.095","Text":"but not in another state."},{"Start":"02:33.095 ","End":"02:38.360","Text":"Even very experienced programmers have to keep testing and refining"},{"Start":"02:38.360 ","End":"02:45.340","Text":"their code until it produces the expected results under all possible circumstances."},{"Start":"02:45.340 ","End":"02:48.800","Text":"That\u0027s why logical errors are something that even"},{"Start":"02:48.800 ","End":"02:53.330","Text":"experienced programmer is going to spend quite a lot of time working on."},{"Start":"02:53.330 ","End":"02:58.250","Text":"The final part of this exercise is going a little bit more"},{"Start":"02:58.250 ","End":"03:00.800","Text":"into types of error just to"},{"Start":"03:00.800 ","End":"03:04.580","Text":"recognize whether which one of the errors that this one would be."},{"Start":"03:04.580 ","End":"03:08.855","Text":"It\u0027s talking about the amount of free memory available once the program"},{"Start":"03:08.855 ","End":"03:14.105","Text":"running can vary and what type of error that could cause and why."},{"Start":"03:14.105 ","End":"03:18.080","Text":"This comes back to the definition of a computer,"},{"Start":"03:18.080 ","End":"03:20.540","Text":"really lots of different types of computer"},{"Start":"03:20.540 ","End":"03:23.450","Text":"and the one that you\u0027re using is a personal computer,"},{"Start":"03:23.450 ","End":"03:26.960","Text":"there could be a computer embedded into some system like"},{"Start":"03:26.960 ","End":"03:31.144","Text":"a washing machine or a mobile phone is a computer."},{"Start":"03:31.144 ","End":"03:34.280","Text":"But for particularly personal computers,"},{"Start":"03:34.280 ","End":"03:36.290","Text":"memory availability is dependent on"},{"Start":"03:36.290 ","End":"03:39.110","Text":"what other programs are being run at any particular time."},{"Start":"03:39.110 ","End":"03:42.020","Text":"For example, they\u0027ll all have an operating system"},{"Start":"03:42.020 ","End":"03:46.070","Text":"and the operating system itself might be running a virus scan in the background."},{"Start":"03:46.070 ","End":"03:50.885","Text":"Or the user might be using some word processing software or playing some music."},{"Start":"03:50.885 ","End":"03:54.620","Text":"All of those programs are going to use memory,"},{"Start":"03:54.620 ","End":"03:59.390","Text":"so we can\u0027t know how much memory is available until we are actually"},{"Start":"03:59.390 ","End":"04:01.760","Text":"running the program which will give you a hint as to"},{"Start":"04:01.760 ","End":"04:04.745","Text":"the answer because if you launch another program,"},{"Start":"04:04.745 ","End":"04:07.670","Text":"it might load, but then whilst it\u0027s running,"},{"Start":"04:07.670 ","End":"04:10.610","Text":"it might request some memory to store its own data."},{"Start":"04:10.610 ","End":"04:14.885","Text":"That\u0027s in fact, quite a common thing in most programming languages."},{"Start":"04:14.885 ","End":"04:18.905","Text":"Therefore, that amount of memory might not be available"},{"Start":"04:18.905 ","End":"04:23.060","Text":"and it would generate a run-time error just like the file error we saw earlier,"},{"Start":"04:23.060 ","End":"04:26.075","Text":"you can\u0027t know how much memory is going to be available"},{"Start":"04:26.075 ","End":"04:30.320","Text":"because that can vary depending on what the circumstances are."},{"Start":"04:30.320 ","End":"04:34.085","Text":"The only way you will really know is when you\u0027re requesting the memory,"},{"Start":"04:34.085 ","End":"04:36.260","Text":"you will know whether there\u0027s enough memory or not."},{"Start":"04:36.260 ","End":"04:40.145","Text":"If there isn\u0027t, it will generate a run-time error and"},{"Start":"04:40.145 ","End":"04:44.705","Text":"your program may crash or it may report an error."},{"Start":"04:44.705 ","End":"04:47.495","Text":"It depends on how your program is written and in what language."},{"Start":"04:47.495 ","End":"04:50.060","Text":"But that would be a run-time error."},{"Start":"04:50.060 ","End":"04:56.765","Text":"That\u0027s distinct from a logical error or from a syntax error as we\u0027ve talked about before."},{"Start":"04:56.765 ","End":"05:00.770","Text":"That\u0027s it for all the exercises in this topic actually."},{"Start":"05:00.770 ","End":"05:05.615","Text":"It sets us up nicely for beginning to write some programs of our own."},{"Start":"05:05.615 ","End":"05:10.160","Text":"The first point really was to understand what errors we\u0027re encountering,"},{"Start":"05:10.160 ","End":"05:11.750","Text":"to manage our frustrations,"},{"Start":"05:11.750 ","End":"05:15.545","Text":"and to understand why they\u0027re happening and what specific"},{"Start":"05:15.545 ","End":"05:20.090","Text":"error category you\u0027re dealing with when you come across a problem."},{"Start":"05:20.090 ","End":"05:22.370","Text":"I\u0027ll see you in the next chapter."},{"Start":"05:22.370 ","End":"05:24.450","Text":"Thanks very much for watching."}],"ID":28021}],"Thumbnail":null,"ID":237668},{"Name":"Variables and primitive data types","TopicPlaylistFirstVideoID":0,"Duration":null,"Videos":[{"Watched":false,"Name":"Variables and datatypes","Duration":"16m 4s","ChapterTopicVideoID":25528,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.170 ","End":"00:05.700","Text":"Welcome everybody to this video in which we will learn how to define"},{"Start":"00:05.700 ","End":"00:10.349","Text":"the term variable to select an appropriate datatype for a variable."},{"Start":"00:10.349 ","End":"00:14.490","Text":"To create variables and store or change values in them and create"},{"Start":"00:14.490 ","End":"00:18.885","Text":"a basic program in which you can declare variables and output layer contents."},{"Start":"00:18.885 ","End":"00:21.540","Text":"The title of a classic computer science book is"},{"Start":"00:21.540 ","End":"00:25.875","Text":"Algorithms Plus Data Structures Equals Programs."},{"Start":"00:25.875 ","End":"00:28.320","Text":"Is actually a really clever title because what it"},{"Start":"00:28.320 ","End":"00:31.770","Text":"essentially says is that you can take a set of instructions,"},{"Start":"00:31.770 ","End":"00:34.650","Text":"apply them to store data and"},{"Start":"00:34.650 ","End":"00:39.040","Text":"the resulting interaction of instructions with the data is a program."},{"Start":"00:39.040 ","End":"00:43.700","Text":"The data structures mentioned in the book title are a variety of methods for storing,"},{"Start":"00:43.700 ","End":"00:46.445","Text":"modifying, and retrieving datary memory."},{"Start":"00:46.445 ","End":"00:48.920","Text":"Commonly, these data items being stored in"},{"Start":"00:48.920 ","End":"00:52.445","Text":"the data structure are related to the other items in some way."},{"Start":"00:52.445 ","End":"00:55.580","Text":"For example, we could store the marks for 8 students in"},{"Start":"00:55.580 ","End":"00:59.060","Text":"a class in a data structure called an array."},{"Start":"00:59.060 ","End":"01:02.075","Text":"But for a single item of data being stored,"},{"Start":"01:02.075 ","End":"01:06.200","Text":"which is not directly related to or grouped with anything else,"},{"Start":"01:06.200 ","End":"01:09.935","Text":"we can simply store it in a single memory location."},{"Start":"01:09.935 ","End":"01:12.935","Text":"Memory is labeled sequentially,"},{"Start":"01:12.935 ","End":"01:17.015","Text":"numbering each individual memory location starting from"},{"Start":"01:17.015 ","End":"01:22.610","Text":"0 and we call each memory location a memory address."},{"Start":"01:22.610 ","End":"01:25.880","Text":"Any individual memory location can be used to"},{"Start":"01:25.880 ","End":"01:29.570","Text":"store a single value at particular instance in time."},{"Start":"01:29.570 ","End":"01:32.870","Text":"In assembly language or a high-level language,"},{"Start":"01:32.870 ","End":"01:35.920","Text":"we\u0027d also give the memory location a name,"},{"Start":"01:35.920 ","End":"01:38.825","Text":"so that when we subsequently you want to read back the stored value,"},{"Start":"01:38.825 ","End":"01:41.585","Text":"or if we wanted to change the stored value to something else,"},{"Start":"01:41.585 ","End":"01:45.065","Text":"we use the name to refer to that specific memory location."},{"Start":"01:45.065 ","End":"01:47.660","Text":"We can now define the term variable."},{"Start":"01:47.660 ","End":"01:50.690","Text":"It\u0027s a named memory location used to"},{"Start":"01:50.690 ","End":"01:53.975","Text":"store data which can change while a program is being executed."},{"Start":"01:53.975 ","End":"01:57.355","Text":"Alongside this definition, let\u0027s also define a related term."},{"Start":"01:57.355 ","End":"02:00.665","Text":"Programmed state, sometimes just called state,"},{"Start":"02:00.665 ","End":"02:05.780","Text":"is the contents of variables at any particular point in the execution of a program."},{"Start":"02:05.780 ","End":"02:10.655","Text":"A fundamental idea in imperative programming languages is the concept of state."},{"Start":"02:10.655 ","End":"02:15.620","Text":"Variables are used to store data in memory and the contents of those variables at"},{"Start":"02:15.620 ","End":"02:17.960","Text":"any particular point in the execution of"},{"Start":"02:17.960 ","End":"02:21.685","Text":"the program are set to describe the state of the program."},{"Start":"02:21.685 ","End":"02:26.960","Text":"Instructions that are carried out by the CPU have the effect of changing the state of"},{"Start":"02:26.960 ","End":"02:33.020","Text":"the program as data is stored or changed in memory locations being used as variables."},{"Start":"02:33.020 ","End":"02:37.710","Text":"For example, we might want to represent the state of a program using 2 variables."},{"Start":"02:37.710 ","End":"02:40.790","Text":"One of which contains a count, and the other,"},{"Start":"02:40.790 ","End":"02:46.130","Text":"which contains the value false unless the count has reached 3."},{"Start":"02:46.130 ","End":"02:50.840","Text":"As you can see, the initial value of the start of the program is false for"},{"Start":"02:50.840 ","End":"02:55.280","Text":"it\u0027s finished and 0 for intCount."},{"Start":"02:55.280 ","End":"02:57.080","Text":"As the program progresses,"},{"Start":"02:57.080 ","End":"03:00.420","Text":"intCount goes up to 1 and then 2,"},{"Start":"03:00.420 ","End":"03:02.960","Text":"and then 3 and finally,"},{"Start":"03:02.960 ","End":"03:07.030","Text":"the conditions have been met so is finished turns to true."},{"Start":"03:07.030 ","End":"03:10.040","Text":"Because CPU hardware is designed around the ability"},{"Start":"03:10.040 ","End":"03:13.235","Text":"to carry out instructions which modify memory locations,"},{"Start":"03:13.235 ","End":"03:18.835","Text":"most high-level programming languages follow this imperative style."},{"Start":"03:18.835 ","End":"03:21.950","Text":"Now we\u0027ve established what a variable is and its purpose."},{"Start":"03:21.950 ","End":"03:24.500","Text":"Let\u0027s go a little bit deeper into the practical use of"},{"Start":"03:24.500 ","End":"03:28.505","Text":"variables by looking at the types of data that can be stored in a variable."},{"Start":"03:28.505 ","End":"03:31.130","Text":"A datatype is a property of variables that"},{"Start":"03:31.130 ","End":"03:34.145","Text":"determines how stored data should be interpreted,"},{"Start":"03:34.145 ","End":"03:37.340","Text":"constrained, and used in expressions,"},{"Start":"03:37.340 ","End":"03:38.645","Text":"as we\u0027ve seen previously,"},{"Start":"03:38.645 ","End":"03:42.485","Text":"a binary value in the memory of a computer can be interpreted in many ways."},{"Start":"03:42.485 ","End":"03:46.310","Text":"It could represent a machine code instruction and its data,"},{"Start":"03:46.310 ","End":"03:51.155","Text":"where here is the instruction and here\u0027s the data it\u0027s operating on."},{"Start":"03:51.155 ","End":"03:55.280","Text":"In fact, it\u0027s the very same instruction that we saw earlier,"},{"Start":"03:55.280 ","End":"04:00.005","Text":"which adds 5 to a previously held value in the CPU."},{"Start":"04:00.005 ","End":"04:04.220","Text":"Or it could represent a 2\u0027s compliment 16-bit integer,"},{"Start":"04:04.220 ","End":"04:11.920","Text":"which works out to be the value minus 14,843 in this case."},{"Start":"04:11.920 ","End":"04:15.350","Text":"It might instead represent a floating point number with"},{"Start":"04:15.350 ","End":"04:21.550","Text":"a 4-bit 2\u0027s compliment exponent in the lower 4-bits and at 12 bit."},{"Start":"04:21.550 ","End":"04:24.815","Text":"Two\u0027s complement mantissa, in which case,"},{"Start":"04:24.815 ","End":"04:29.795","Text":"it would represent the decimal number minus 14.5."},{"Start":"04:29.795 ","End":"04:33.500","Text":"It could even represent a single Unicode character,"},{"Start":"04:33.500 ","End":"04:36.200","Text":"which in hex would be this value and would"},{"Start":"04:36.200 ","End":"04:39.634","Text":"actually give us a symbol in the Korean alphabet,"},{"Start":"04:39.634 ","End":"04:41.240","Text":"which looks like this."},{"Start":"04:41.240 ","End":"04:46.550","Text":"What a bit pattern represents depends on how we choose to interpret that bit pattern."},{"Start":"04:46.550 ","End":"04:48.540","Text":"In a typical high-level language program,"},{"Start":"04:48.540 ","End":"04:50.000","Text":"when creating a variable,"},{"Start":"04:50.000 ","End":"04:52.580","Text":"you will state the name and also specify"},{"Start":"04:52.580 ","End":"04:55.565","Text":"what type of data will be stored in the variable."},{"Start":"04:55.565 ","End":"04:59.960","Text":"In this case, with defining a variable called my number,"},{"Start":"04:59.960 ","End":"05:03.620","Text":"that\u0027s the identifier and its datatype is integer."},{"Start":"05:03.620 ","End":"05:07.145","Text":"The variables datatype determines what we can and can\u0027t do with it."},{"Start":"05:07.145 ","End":"05:10.430","Text":"For example, an integer can be added to"},{"Start":"05:10.430 ","End":"05:14.570","Text":"another integer to produce the sum of the 2 integers."},{"Start":"05:14.570 ","End":"05:22.565","Text":"Or we could divide an integer by another integer and we\u0027d get the result 5 in this case."},{"Start":"05:22.565 ","End":"05:25.140","Text":"However, if we chose to divide"},{"Start":"05:25.240 ","End":"05:30.740","Text":"1 integer by another and the result was not a whole number,"},{"Start":"05:30.740 ","End":"05:36.020","Text":"we could not store the result accurately inside another integer variable."},{"Start":"05:36.020 ","End":"05:37.895","Text":"We\u0027d lose the fractional part."},{"Start":"05:37.895 ","End":"05:40.415","Text":"In this case, the 0.5."},{"Start":"05:40.415 ","End":"05:47.005","Text":"This was an implication of the original decision to make a variable an integer datatype."},{"Start":"05:47.005 ","End":"05:49.790","Text":"Some data types can allow you to choose between"},{"Start":"05:49.790 ","End":"05:53.480","Text":"several related types which vary in their size or precision."},{"Start":"05:53.480 ","End":"05:55.865","Text":"For example, if storing a number,"},{"Start":"05:55.865 ","End":"05:58.490","Text":"we could store it as an 8-bit integer,"},{"Start":"05:58.490 ","End":"06:02.840","Text":"a 16-bit integer, a 32-bit integer,"},{"Start":"06:02.840 ","End":"06:05.090","Text":"or a 64-bit integer."},{"Start":"06:05.090 ","End":"06:08.270","Text":"Each of these would be a different datatype and the range"},{"Start":"06:08.270 ","End":"06:11.600","Text":"of numbers we could store would vary depending on the type."},{"Start":"06:11.600 ","End":"06:14.450","Text":"Different high-level languages may differ in the number of"},{"Start":"06:14.450 ","End":"06:17.885","Text":"bits that a particular datatype occupies in memory."},{"Start":"06:17.885 ","End":"06:20.180","Text":"These examples of a Java,"},{"Start":"06:20.180 ","End":"06:22.160","Text":"but in the C programming language,"},{"Start":"06:22.160 ","End":"06:27.185","Text":"and int could be 16-bits on 1 system and 32-bits on another."},{"Start":"06:27.185 ","End":"06:30.380","Text":"The programmer is responsible for making sure they take account"},{"Start":"06:30.380 ","End":"06:33.820","Text":"of this when writing code in such languages."},{"Start":"06:33.820 ","End":"06:38.090","Text":"Most current computer systems use memory locations that are 16,"},{"Start":"06:38.090 ","End":"06:41.165","Text":"32 or 64-bits in size."},{"Start":"06:41.165 ","End":"06:43.625","Text":"If you\u0027re storing a single byte of data,"},{"Start":"06:43.625 ","End":"06:48.425","Text":"you could fit 2 bytes into a single 16-bit memory location,"},{"Start":"06:48.425 ","End":"06:52.085","Text":"or 4 bytes in a 32-bit memory location."},{"Start":"06:52.085 ","End":"06:57.095","Text":"Selecting data types for the variables which store numbers can require some thought."},{"Start":"06:57.095 ","End":"06:59.720","Text":"It\u0027s more efficient in terms of memory used to store"},{"Start":"06:59.720 ","End":"07:02.990","Text":"the numbers in the smallest datatype possible."},{"Start":"07:02.990 ","End":"07:07.175","Text":"For example, say we wanted to restore someone\u0027s age in a variable,"},{"Start":"07:07.175 ","End":"07:11.435","Text":"the oldest recorded verified human age is 122 years."},{"Start":"07:11.435 ","End":"07:14.810","Text":"If we wanted to store the age in years of a human,"},{"Start":"07:14.810 ","End":"07:21.215","Text":"we can fit that into 7 bits because 7 bits will allow us to store a number up to a 127."},{"Start":"07:21.215 ","End":"07:23.360","Text":"You could argue that there\u0027s no point in using"},{"Start":"07:23.360 ","End":"07:25.655","Text":"a larger amount of memory for the age variable."},{"Start":"07:25.655 ","End":"07:28.610","Text":"There\u0027d also be no point in storing a negative number in"},{"Start":"07:28.610 ","End":"07:32.530","Text":"the age variable as no human can have a negative age."},{"Start":"07:32.530 ","End":"07:36.500","Text":"A suitable datatype for the age variable would be a byte,"},{"Start":"07:36.500 ","End":"07:39.020","Text":"or even better for languages that support it,"},{"Start":"07:39.020 ","End":"07:43.812","Text":"an unsigned byte, which would give us a range from 0-255."},{"Start":"07:43.812 ","End":"07:48.380","Text":"Other numeric data types can contain floating point numbers,"},{"Start":"07:48.380 ","End":"07:51.185","Text":"that\u0027s numbers that have a fractional component."},{"Start":"07:51.185 ","End":"07:53.900","Text":"We call these real numbers or reals."},{"Start":"07:53.900 ","End":"07:56.390","Text":"Once again, these come in sizes so the choice"},{"Start":"07:56.390 ","End":"07:58.850","Text":"is more limited and in fact comprises just 2;"},{"Start":"07:58.850 ","End":"08:01.400","Text":"the float data type and the double data type."},{"Start":"08:01.400 ","End":"08:04.535","Text":"Here we\u0027re more interested in the precision of the number,"},{"Start":"08:04.535 ","End":"08:07.130","Text":"not necessarily the magnitude of the number."},{"Start":"08:07.130 ","End":"08:09.815","Text":"A double can store a larger number than the float,"},{"Start":"08:09.815 ","End":"08:13.700","Text":"but it can also store the fractional part with more decimal places."},{"Start":"08:13.700 ","End":"08:18.470","Text":"The numbers here have been written in scientific notation because they"},{"Start":"08:18.470 ","End":"08:20.300","Text":"had so many digits they wouldn\u0027t fit on"},{"Start":"08:20.300 ","End":"08:23.255","Text":"the screen and they can be quite hard to get your head around."},{"Start":"08:23.255 ","End":"08:28.250","Text":"To spell it out, the smallest number that can be represented by a float in Java has"},{"Start":"08:28.250 ","End":"08:33.230","Text":"44 zeros between the decimal point and the digits 14,"},{"Start":"08:33.230 ","End":"08:40.295","Text":"for a double, there are 323 zeros between the decimal point and the digits 49."},{"Start":"08:40.295 ","End":"08:44.015","Text":"Other data types can be used to store data that is not numerical."},{"Start":"08:44.015 ","End":"08:48.140","Text":"A character data type can be used to store a single character,"},{"Start":"08:48.140 ","End":"08:50.390","Text":"which is a symbol that can be typed or output"},{"Start":"08:50.390 ","End":"08:52.535","Text":"by the system and belongs to a character set."},{"Start":"08:52.535 ","End":"08:58.445","Text":"The amount of memory one character uses can be anything from 7 bits to 32 bits in size."},{"Start":"08:58.445 ","End":"09:02.930","Text":"The exact size is dependent on the programming language and the system is running"},{"Start":"09:02.930 ","End":"09:05.420","Text":"on how many bits are available for the character"},{"Start":"09:05.420 ","End":"09:08.105","Text":"determines what symbols can be displayed."},{"Start":"09:08.105 ","End":"09:14.180","Text":"Ascii encodings can only encode English or Western European characters."},{"Start":"09:14.180 ","End":"09:17.750","Text":"Unicode encoding such as UTF-8, 16,"},{"Start":"09:17.750 ","End":"09:22.355","Text":"or 32 allow characters from any languages to be stored."},{"Start":"09:22.355 ","End":"09:26.330","Text":"Characters can be strung together to form another datatype called a string."},{"Start":"09:26.330 ","End":"09:30.020","Text":"These are used to hold sequences of characters that could, for example,"},{"Start":"09:30.020 ","End":"09:34.325","Text":"represent words, names, sentences, or messages."},{"Start":"09:34.325 ","End":"09:35.810","Text":"In most programming languages,"},{"Start":"09:35.810 ","End":"09:38.270","Text":"strings are not classed as primitive data types,"},{"Start":"09:38.270 ","End":"09:41.435","Text":"but as composite or compound data types."},{"Start":"09:41.435 ","End":"09:46.309","Text":"That means they\u0027re constructed using primitive data types and other data structures."},{"Start":"09:46.309 ","End":"09:47.810","Text":"In the case of the string,"},{"Start":"09:47.810 ","End":"09:53.210","Text":"it\u0027s most commonly a composite using characters and a data structure called an array."},{"Start":"09:53.210 ","End":"09:56.390","Text":"We\u0027ll cover strings and arrays in detail later in the course."},{"Start":"09:56.390 ","End":"09:59.165","Text":"The final primitive datatype is the Boolean,"},{"Start":"09:59.165 ","End":"10:01.850","Text":"which can only contain 1 of 2 different values,"},{"Start":"10:01.850 ","End":"10:04.939","Text":"and therefore requires only a single bit of memory for storage."},{"Start":"10:04.939 ","End":"10:07.595","Text":"The bit is either 1 or 0."},{"Start":"10:07.595 ","End":"10:11.180","Text":"We interpret the value as either true or false."},{"Start":"10:11.180 ","End":"10:13.160","Text":"Whilst this might seem limiting,"},{"Start":"10:13.160 ","End":"10:15.260","Text":"Boolean variables are commonly used to provide"},{"Start":"10:15.260 ","End":"10:18.075","Text":"a signal from one part of the program to another."},{"Start":"10:18.075 ","End":"10:19.780","Text":"The signal is known as a flag."},{"Start":"10:19.780 ","End":"10:20.950","Text":"You think of a car race."},{"Start":"10:20.950 ","End":"10:23.500","Text":"The first car to complete the race is signaled with"},{"Start":"10:23.500 ","End":"10:28.140","Text":"a checkered flag being raised and waved about to signify that there is a winner."},{"Start":"10:28.140 ","End":"10:30.470","Text":"In a program, we might signal from one part of"},{"Start":"10:30.470 ","End":"10:33.260","Text":"the program to another part when some process"},{"Start":"10:33.260 ","End":"10:39.050","Text":"completes or we might set a flag to indicate whether some input data is valid or not."},{"Start":"10:39.050 ","End":"10:44.435","Text":"Or we might allow someone a second and final try to answer a question in a quiz."},{"Start":"10:44.435 ","End":"10:47.345","Text":"We need to know whether this is a first trial or not."},{"Start":"10:47.345 ","End":"10:50.630","Text":"All of these would be examples where we might use a flag variable."},{"Start":"10:50.630 ","End":"10:51.995","Text":"Variables need to have a name,"},{"Start":"10:51.995 ","End":"10:54.230","Text":"more formerly known as an identifier."},{"Start":"10:54.230 ","End":"10:56.389","Text":"There are rules around what constitutes"},{"Start":"10:56.389 ","End":"10:59.540","Text":"a valid identifier and also conventions that we should know about,"},{"Start":"10:59.540 ","End":"11:03.935","Text":"which make it easier to work with other programmers who adopt the same conventions."},{"Start":"11:03.935 ","End":"11:08.990","Text":"Most languages have very similar rules about what is and isn\u0027t allowed in an identifier."},{"Start":"11:08.990 ","End":"11:11.420","Text":"An identifier that is not valuable result in"},{"Start":"11:11.420 ","End":"11:15.680","Text":"a compile-time error or a syntax error in an interpreted language."},{"Start":"11:15.680 ","End":"11:18.380","Text":"Most generally the identifier can use"},{"Start":"11:18.380 ","End":"11:22.874","Text":"upper or lowercase characters in the ascii character set."},{"Start":"11:22.874 ","End":"11:27.080","Text":"Variables called myvariable, all in capitals."},{"Start":"11:27.080 ","End":"11:30.530","Text":"Myvariable with a M and V,"},{"Start":"11:30.530 ","End":"11:35.615","Text":"or myvariable with just the V are all valid identifiers."},{"Start":"11:35.615 ","End":"11:39.440","Text":"A limited set of other characters can also be used in identifiers,"},{"Start":"11:39.440 ","End":"11:41.570","Text":"depending on the programming language."},{"Start":"11:41.570 ","End":"11:44.225","Text":"Digits are allowed in most languages,"},{"Start":"11:44.225 ","End":"11:47.360","Text":"the underscore is also allowed in most languages."},{"Start":"11:47.360 ","End":"11:49.910","Text":"The dollar sign is allowed in Java,"},{"Start":"11:49.910 ","End":"11:53.195","Text":"a single quote is allowed in Haskell,"},{"Start":"11:53.195 ","End":"11:55.880","Text":"and the hyphen is allowed in lisp."},{"Start":"11:55.880 ","End":"11:58.910","Text":"It might also be possible to use non ascii characters"},{"Start":"11:58.910 ","End":"12:02.060","Text":"in the identifier in some languages as well."},{"Start":"12:02.060 ","End":"12:04.865","Text":"For example, Python version 3"},{"Start":"12:04.865 ","End":"12:08.870","Text":"onwards allows characters from any language in the identifier."},{"Start":"12:08.870 ","End":"12:12.925","Text":"A big no in virtually every language is the use of the space character."},{"Start":"12:12.925 ","End":"12:16.030","Text":"This is not allowed in identifiers because it makes the job of"},{"Start":"12:16.030 ","End":"12:19.620","Text":"the compiler or interpreter significantly harder."},{"Start":"12:19.620 ","End":"12:24.050","Text":"The underscore character is often used as a way of breaking upwards instead."},{"Start":"12:24.050 ","End":"12:26.930","Text":"Other common restrictions include not allowing"},{"Start":"12:26.930 ","End":"12:29.645","Text":"numerical digits at the front of identifiers,"},{"Start":"12:29.645 ","End":"12:31.970","Text":"in this case, the number 2."},{"Start":"12:31.970 ","End":"12:38.210","Text":"Also not allowing keywords from a language to be used as an identifier in this case,"},{"Start":"12:38.210 ","End":"12:42.140","Text":"finally, is a keyword in the language Java,"},{"Start":"12:42.140 ","End":"12:45.680","Text":"so would not be allowed as an identifier in Java."},{"Start":"12:45.680 ","End":"12:48.320","Text":"In summary, to be safe,"},{"Start":"12:48.320 ","End":"12:50.630","Text":"when you\u0027re choosing an identifier,"},{"Start":"12:50.630 ","End":"12:53.660","Text":"only ever use upper and lowercase letters."},{"Start":"12:53.660 ","End":"12:55.670","Text":"In the ascii character set,"},{"Start":"12:55.670 ","End":"12:59.779","Text":"digits are fine unless they\u0027re used as the first character."},{"Start":"12:59.779 ","End":"13:04.850","Text":"An underscore should be used to separate words if we need it and that\u0027s fine and be aware"},{"Start":"13:04.850 ","End":"13:07.235","Text":"of and avoid using"},{"Start":"13:07.235 ","End":"13:11.225","Text":"any identifies that match keywords available in your programming language."},{"Start":"13:11.225 ","End":"13:13.520","Text":"Those previous rules are just that, rules."},{"Start":"13:13.520 ","End":"13:14.885","Text":"They must be obeyed."},{"Start":"13:14.885 ","End":"13:17.615","Text":"If they are broken, the compiler will complain"},{"Start":"13:17.615 ","End":"13:20.855","Text":"or the interpreter will stop with a syntax error message."},{"Start":"13:20.855 ","End":"13:23.390","Text":"Conventions are not rules but accepted ways of"},{"Start":"13:23.390 ","End":"13:26.000","Text":"behaving in a particular field or situation."},{"Start":"13:26.000 ","End":"13:28.160","Text":"A typical classroom convention, for example,"},{"Start":"13:28.160 ","End":"13:30.905","Text":"is that you put your hand up if you want the teacher\u0027s attention."},{"Start":"13:30.905 ","End":"13:33.995","Text":"Identifier\u0027s have their own conventions."},{"Start":"13:33.995 ","End":"13:37.940","Text":"You mentioned that you cannot use spaces in an identifier."},{"Start":"13:37.940 ","End":"13:39.305","Text":"As an alternative,"},{"Start":"13:39.305 ","End":"13:41.450","Text":"you can use the underscore character."},{"Start":"13:41.450 ","End":"13:46.670","Text":"Separating words with underscores makes the identifier easier and quicker to read."},{"Start":"13:46.670 ","End":"13:50.983","Text":"In this example, there are no spaces and no underscores,"},{"Start":"13:50.983 ","End":"13:53.765","Text":"so the words and then the identifier are difficult to see."},{"Start":"13:53.765 ","End":"13:56.570","Text":"Adding underscores as we\u0027ve done here and"},{"Start":"13:56.570 ","End":"14:00.695","Text":"here makes it much easier to read the words within the identifier."},{"Start":"14:00.695 ","End":"14:04.025","Text":"The name given to this naming style is snake case,"},{"Start":"14:04.025 ","End":"14:06.290","Text":"I guess because the underscore looks"},{"Start":"14:06.290 ","End":"14:08.630","Text":"like a snake slithering along the bottom of the word."},{"Start":"14:08.630 ","End":"14:11.390","Text":"However, the underscore character can be tricky to find on"},{"Start":"14:11.390 ","End":"14:15.620","Text":"some keyboards and usually requires the Shift key to be pressed as well."},{"Start":"14:15.620 ","End":"14:19.520","Text":"Programmers are lazy or highly efficient depending on your point of view."},{"Start":"14:19.520 ","End":"14:22.880","Text":"They\u0027d prefer to type as few characters as possible."},{"Start":"14:22.880 ","End":"14:28.385","Text":"Hence, CamelCase, where each new word starts with a capital letter,"},{"Start":"14:28.385 ","End":"14:30.365","Text":"is preferred by many programmers,"},{"Start":"14:30.365 ","End":"14:35.060","Text":"seen here with a capital H and a capital N. The name comes from these capital letters"},{"Start":"14:35.060 ","End":"14:40.490","Text":"standing out above the lowercase letters appearing as a hump,"},{"Start":"14:40.490 ","End":"14:42.425","Text":"as you might find on the back of a camel,"},{"Start":"14:42.425 ","End":"14:44.960","Text":"where you do capitalize the first letter as well."},{"Start":"14:44.960 ","End":"14:47.435","Text":"This is known as upper CamelCase,"},{"Start":"14:47.435 ","End":"14:50.285","Text":"or sometimes called PascalCase."},{"Start":"14:50.285 ","End":"14:52.550","Text":"The only difference with the one above here is"},{"Start":"14:52.550 ","End":"14:56.060","Text":"this first letter here is also capitalized."},{"Start":"14:56.060 ","End":"15:01.220","Text":"Most programmers don\u0027t use snake case except for in a very particular situation."},{"Start":"15:01.220 ","End":"15:04.310","Text":"There\u0027s a type of variable that only has its value set once in"},{"Start":"15:04.310 ","End":"15:09.320","Text":"the program and whose value does not subsequently change whilst the program is running."},{"Start":"15:09.320 ","End":"15:10.819","Text":"We call this a constant."},{"Start":"15:10.819 ","End":"15:14.000","Text":"By convention, constants are usually identified in"},{"Start":"15:14.000 ","End":"15:19.355","Text":"all uppercase letters with an underscore separating each word."},{"Start":"15:19.355 ","End":"15:22.190","Text":"This is called upper Snake case."},{"Start":"15:22.190 ","End":"15:23.870","Text":"In some other languages,"},{"Start":"15:23.870 ","End":"15:28.070","Text":"a symbol might conventionally signify some meaning to the reader of the code."},{"Start":"15:28.070 ","End":"15:32.660","Text":"For example, a single or double underscore in"},{"Start":"15:32.660 ","End":"15:37.280","Text":"Python programs might mark that identifier to be treated differently."},{"Start":"15:37.280 ","End":"15:40.565","Text":"For example, it might mark it as a private variable."},{"Start":"15:40.565 ","End":"15:44.600","Text":"Avoid using underscores as the first or last characters in"},{"Start":"15:44.600 ","End":"15:48.905","Text":"identifiers unless you\u0027re a Python programmer and you know what you\u0027re doing."},{"Start":"15:48.905 ","End":"15:51.380","Text":"That\u0027s it for this video,"},{"Start":"15:51.380 ","End":"15:54.365","Text":"in it we defined the term variable"},{"Start":"15:54.365 ","End":"15:58.025","Text":"and we selected an appropriate datatype for a variable."},{"Start":"15:58.025 ","End":"15:59.390","Text":"In the next 2 videos,"},{"Start":"15:59.390 ","End":"16:04.980","Text":"you\u0027ll apply what you\u0027ve learned in a real programming language. See you then."}],"ID":26345},{"Watched":false,"Name":"Introduction to BlueJ IDE","Duration":"10m 1s","ChapterTopicVideoID":25529,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.910","Text":"Welcome everybody to this video where I\u0027m going"},{"Start":"00:02.910 ","End":"00:05.745","Text":"to introduce you to the BlueJ environment."},{"Start":"00:05.745 ","End":"00:12.225","Text":"BlueJ is a free program that you can download from the following URL, bluej.org."},{"Start":"00:12.225 ","End":"00:16.840","Text":"It\u0027s used in universities all over the world to teach beginner programmers."},{"Start":"00:16.840 ","End":"00:20.375","Text":"It\u0027s designed specifically for beginners."},{"Start":"00:20.375 ","End":"00:23.540","Text":"First things first is to get to this URL,"},{"Start":"00:23.540 ","End":"00:26.150","Text":"and then when this homepage opens,"},{"Start":"00:26.150 ","End":"00:27.695","Text":"if you scroll down,"},{"Start":"00:27.695 ","End":"00:30.215","Text":"you will see this area for downloads."},{"Start":"00:30.215 ","End":"00:34.650","Text":"Choose the relevant operating system that will suit you."},{"Start":"00:34.650 ","End":"00:38.360","Text":"The BlueJ install will download and"},{"Start":"00:38.360 ","End":"00:41.640","Text":"with it will be something called the Java Development Kit."},{"Start":"00:41.640 ","End":"00:44.210","Text":"The Java Development Kit, or JDK,"},{"Start":"00:44.210 ","End":"00:50.555","Text":"is a set of files which you will need in order to develop Java programs."},{"Start":"00:50.555 ","End":"00:52.800","Text":"You don\u0027t need it to run programs."},{"Start":"00:52.800 ","End":"00:55.835","Text":"You need something called the Java runtime environment for that."},{"Start":"00:55.835 ","End":"00:59.310","Text":"But you will need it to compile programs."},{"Start":"00:59.310 ","End":"01:02.730","Text":"It will come bundled with BlueJ or it should do."},{"Start":"01:02.730 ","End":"01:05.420","Text":"You don\u0027t have to worry about that too much."},{"Start":"01:05.420 ","End":"01:10.085","Text":"Once you have it installed and run it for the first time,"},{"Start":"01:10.085 ","End":"01:14.135","Text":"you will come across the following environment."},{"Start":"01:14.135 ","End":"01:18.440","Text":"Just to give you a quick overview of the program"},{"Start":"01:18.440 ","End":"01:22.010","Text":"that I\u0027ve seen has a standard menu across the top here,"},{"Start":"01:22.010 ","End":"01:24.200","Text":"and the first thing we\u0027re going to need to do in order to be able to"},{"Start":"01:24.200 ","End":"01:26.630","Text":"do anything is to create a new project."},{"Start":"01:26.630 ","End":"01:30.985","Text":"If you go ahead and create a project by clicking on New Project,"},{"Start":"01:30.985 ","End":"01:33.000","Text":"giving it a name."},{"Start":"01:33.000 ","End":"01:41.120","Text":"We\u0027re going to complete some exercises on variables first."},{"Start":"01:41.120 ","End":"01:47.395","Text":"Let\u0027s call it exercises variable and create that for us."},{"Start":"01:47.395 ","End":"01:49.175","Text":"Just go full screen."},{"Start":"01:49.175 ","End":"01:52.475","Text":"You will now see that the display has changed slightly."},{"Start":"01:52.475 ","End":"01:55.580","Text":"You\u0027ve got a little icon representing a piece of paper here."},{"Start":"01:55.580 ","End":"01:57.620","Text":"This is just created for you in every project"},{"Start":"01:57.620 ","End":"02:00.920","Text":"to allow you to create some project documentation,"},{"Start":"02:00.920 ","End":"02:04.790","Text":"just a Read Me file basically which you can edit and add things to,"},{"Start":"02:04.790 ","End":"02:06.379","Text":"to describe your project."},{"Start":"02:06.379 ","End":"02:09.245","Text":"But the most significant thing that\u0027s happened is"},{"Start":"02:09.245 ","End":"02:12.770","Text":"there\u0027s a box that\u0027s appeared over here on the right-hand side."},{"Start":"02:12.770 ","End":"02:17.885","Text":"Now, this is a really important area that we\u0027ll be using initially called the code pad."},{"Start":"02:17.885 ","End":"02:19.760","Text":"The code pad, if it doesn\u0027t appear,"},{"Start":"02:19.760 ","End":"02:20.780","Text":"first of all for you,"},{"Start":"02:20.780 ","End":"02:24.930","Text":"you might need to activate by just going up to the View menu"},{"Start":"02:24.930 ","End":"02:31.080","Text":"here and just making sure that Show Code Pad has a tick mark next to it."},{"Start":"02:31.080 ","End":"02:33.540","Text":"In this case, obviously, it does and it appears."},{"Start":"02:33.540 ","End":"02:37.760","Text":"What we can do with the code pad is we can actually type lines of Java"},{"Start":"02:37.760 ","End":"02:42.290","Text":"in here directly and immediately get a response."},{"Start":"02:42.290 ","End":"02:46.840","Text":"Without creating a file and typing all the commands in there and compiling it,"},{"Start":"02:46.840 ","End":"02:51.530","Text":"we can try things out interactively in this environment here,"},{"Start":"02:51.530 ","End":"02:57.540","Text":"which makes learning a little bit more interesting and interactive."},{"Start":"02:57.540 ","End":"03:00.590","Text":"For example, if I wanted to create a variable,"},{"Start":"03:00.590 ","End":"03:03.770","Text":"I can go ahead and type in a command that"},{"Start":"03:03.770 ","End":"03:09.710","Text":"would declare the variable and store a value in it."},{"Start":"03:09.710 ","End":"03:12.245","Text":"Pull lines in Java end with a semicolon."},{"Start":"03:12.245 ","End":"03:14.635","Text":"I\u0027m going to end it with a semicolon."},{"Start":"03:14.635 ","End":"03:19.290","Text":"It appears to have done nothing but rest assured it has actually done something,"},{"Start":"03:19.290 ","End":"03:21.560","Text":"it\u0027s created that variable which is an integer,"},{"Start":"03:21.560 ","End":"03:24.530","Text":"and it currently contains the value 1234."},{"Start":"03:24.530 ","End":"03:26.480","Text":"If I want to see the value of the variable,"},{"Start":"03:26.480 ","End":"03:29.000","Text":"I can just type in the name of the variable."},{"Start":"03:29.000 ","End":"03:31.325","Text":"No, I don\u0027t need a semicolon here."},{"Start":"03:31.325 ","End":"03:36.365","Text":"I can simply just type the name of the variable and it responds with the value."},{"Start":"03:36.365 ","End":"03:39.590","Text":"This area here is both showing me the commands that I\u0027ve"},{"Start":"03:39.590 ","End":"03:42.920","Text":"typed in and then the responses that I get back,"},{"Start":"03:42.920 ","End":"03:47.375","Text":"and current values of variables here are displayed in green."},{"Start":"03:47.375 ","End":"03:49.475","Text":"Now I\u0027ve declared my variable."},{"Start":"03:49.475 ","End":"03:51.530","Text":"I don\u0027t need to put the data type again,"},{"Start":"03:51.530 ","End":"03:54.200","Text":"but if I want to specify another value,"},{"Start":"03:54.200 ","End":"03:56.240","Text":"I want to assign a different value to it."},{"Start":"03:56.240 ","End":"03:57.620","Text":"I can go ahead and do that."},{"Start":"03:57.620 ","End":"04:00.290","Text":"Once again, I won\u0027t press the semicolon."},{"Start":"04:00.290 ","End":"04:05.480","Text":"I see immediately the value is changed and displayed back to me."},{"Start":"04:05.480 ","End":"04:07.910","Text":"If by the way, you want to just repeat the previous command,"},{"Start":"04:07.910 ","End":"04:09.890","Text":"you can just use the up arrow key,"},{"Start":"04:09.890 ","End":"04:11.960","Text":"and that will bring up the previous command."},{"Start":"04:11.960 ","End":"04:14.390","Text":"You can edit it or you can do whatever you like with it."},{"Start":"04:14.390 ","End":"04:17.435","Text":"Let\u0027s just see what happens if I do put a semicolon on the end."},{"Start":"04:17.435 ","End":"04:20.190","Text":"Let\u0027s have a different value in here now."},{"Start":"04:20.190 ","End":"04:22.555","Text":"Let\u0027s go back to 1234,"},{"Start":"04:22.555 ","End":"04:24.035","Text":"I put a semicolon."},{"Start":"04:24.035 ","End":"04:28.805","Text":"You\u0027ll see that there is no response because I\u0027ve entered a complete valid line of Java,"},{"Start":"04:28.805 ","End":"04:31.580","Text":"the interaction side of it, it\u0027s not applying."},{"Start":"04:31.580 ","End":"04:35.690","Text":"It doesn\u0027t immediately show me the value that\u0027s stored in myVar as it did"},{"Start":"04:35.690 ","End":"04:40.670","Text":"previously when I left off the semicolon."},{"Start":"04:40.670 ","End":"04:44.240","Text":"If I want to see now the value of myVar again,"},{"Start":"04:44.240 ","End":"04:47.375","Text":"you should see that it\u0027s changed to 1234,"},{"Start":"04:47.375 ","End":"04:49.787","Text":"even though it didn\u0027t show me the value,"},{"Start":"04:49.787 ","End":"04:51.710","Text":"so that\u0027s the code pad."},{"Start":"04:51.710 ","End":"05:01.095","Text":"It\u0027s a very useful way of interacting with the system and trying out commands basically."},{"Start":"05:01.095 ","End":"05:05.335","Text":"The first exercises you\u0027ll complete will make use of the code pad."},{"Start":"05:05.335 ","End":"05:10.070","Text":"Now just to give you a brief overview of some of the other windows here."},{"Start":"05:10.070 ","End":"05:12.365","Text":"On the left-hand side,"},{"Start":"05:12.365 ","End":"05:15.710","Text":"this panel here is called the object workbench."},{"Start":"05:15.710 ","End":"05:18.290","Text":"Java is an object-oriented language."},{"Start":"05:18.290 ","End":"05:22.310","Text":"So everything is based on things called classes,"},{"Start":"05:22.310 ","End":"05:27.920","Text":"and classes are used to make objects and we\u0027ll do more of that later in the course."},{"Start":"05:27.920 ","End":"05:34.565","Text":"But for now, just be aware that anything that we write needs to be inside a class."},{"Start":"05:34.565 ","End":"05:36.575","Text":"I\u0027m going to write a Java program."},{"Start":"05:36.575 ","End":"05:38.555","Text":"If we\u0027re going to create some code,"},{"Start":"05:38.555 ","End":"05:40.280","Text":"we\u0027d have to go up to the top here,"},{"Start":"05:40.280 ","End":"05:42.535","Text":"click on New Class,"},{"Start":"05:42.535 ","End":"05:43.800","Text":"give it a name."},{"Start":"05:43.800 ","End":"05:46.220","Text":"It should, by convention,"},{"Start":"05:46.220 ","End":"05:50.585","Text":"always name classes with a capital letter at the first letter."},{"Start":"05:50.585 ","End":"05:53.630","Text":"It\u0027s called capital camel case."},{"Start":"05:53.630 ","End":"05:58.770","Text":"I\u0027m just going to call it MyApp and then click on Okay."},{"Start":"05:58.770 ","End":"06:05.340","Text":"What you\u0027ll see is a little rectangular appears in orangey-yellow color."},{"Start":"06:05.340 ","End":"06:08.020","Text":"Its got these diagonal lines across it."},{"Start":"06:08.020 ","End":"06:11.120","Text":"What that means is the program hasn\u0027t yet been compiled."},{"Start":"06:11.120 ","End":"06:13.595","Text":"If I click on this button over here, Compile,"},{"Start":"06:13.595 ","End":"06:18.815","Text":"you\u0027ll notice those diagonal lines have gone away and that\u0027s now compiled."},{"Start":"06:18.815 ","End":"06:23.030","Text":"Now I haven\u0027t actually written any code and BlueJ will create"},{"Start":"06:23.030 ","End":"06:27.845","Text":"some sample code for you for every new class that you create with a particular structure."},{"Start":"06:27.845 ","End":"06:30.410","Text":"If you want to see that code and you want to edit that code,"},{"Start":"06:30.410 ","End":"06:37.040","Text":"you just double-click on the class itself and up comes an editor window."},{"Start":"06:37.040 ","End":"06:38.780","Text":"In this editor window,"},{"Start":"06:38.780 ","End":"06:45.395","Text":"you can now change the source code to whatever it is that you want."},{"Start":"06:45.395 ","End":"06:50.225","Text":"As I said, BlueJ already creates some sample code for you."},{"Start":"06:50.225 ","End":"06:59.170","Text":"What I\u0027m going to do is I\u0027m going to actually remove everything from inside the class,"},{"Start":"06:59.170 ","End":"07:02.240","Text":"except for this first line here,"},{"Start":"07:02.240 ","End":"07:03.870","Text":"which defines the class,"},{"Start":"07:03.870 ","End":"07:05.720","Text":"and this pair of brackets here,"},{"Start":"07:05.720 ","End":"07:07.310","Text":"braces we call them."},{"Start":"07:07.310 ","End":"07:10.309","Text":"Actually, programmers tend to call them curly brackets."},{"Start":"07:10.309 ","End":"07:12.050","Text":"Within those curly brackets,"},{"Start":"07:12.050 ","End":"07:14.405","Text":"I can type some code."},{"Start":"07:14.405 ","End":"07:18.380","Text":"We\u0027ll get into it in a bit more detail in the next video."},{"Start":"07:18.380 ","End":"07:22.235","Text":"But for now, I\u0027m just going to create a variable."},{"Start":"07:22.235 ","End":"07:25.460","Text":"Again, I\u0027m going to create an integer variable."},{"Start":"07:25.460 ","End":"07:27.575","Text":"I\u0027m going to call it myNum."},{"Start":"07:27.575 ","End":"07:31.890","Text":"I\u0027m going to give it an initial value by assigning it a value,"},{"Start":"07:31.890 ","End":"07:34.065","Text":"and I\u0027ll make that 1234."},{"Start":"07:34.065 ","End":"07:37.760","Text":"You\u0027ll notice that I\u0027ve got diagonal lines again in the background"},{"Start":"07:37.760 ","End":"07:41.535","Text":"here on this icon and that other view,"},{"Start":"07:41.535 ","End":"07:44.745","Text":"and they\u0027ll go away if I click on the Compile button."},{"Start":"07:44.745 ","End":"07:47.580","Text":"Now I can close this window."},{"Start":"07:47.580 ","End":"07:49.530","Text":"To run the program,"},{"Start":"07:49.530 ","End":"07:53.590","Text":"what I can do is I can make what\u0027s called an object from this class,"},{"Start":"07:53.590 ","End":"07:57.550","Text":"and by right-clicking on it and saying new MyApp,"},{"Start":"07:57.550 ","End":"07:59.140","Text":"MyApp being the name of the class."},{"Start":"07:59.140 ","End":"08:01.030","Text":"If I click on it,"},{"Start":"08:01.030 ","End":"08:04.510","Text":"it\u0027s asking me to give a name to"},{"Start":"08:04.510 ","End":"08:10.330","Text":"this instance just so I can identify this particular instance of it."},{"Start":"08:10.330 ","End":"08:12.710","Text":"I\u0027ll click on Okay now."},{"Start":"08:12.710 ","End":"08:16.225","Text":"There we go. We\u0027ve created what\u0027s called an object,"},{"Start":"08:16.225 ","End":"08:17.815","Text":"and it\u0027s in red."},{"Start":"08:17.815 ","End":"08:20.785","Text":"This area is called the object workbench."},{"Start":"08:20.785 ","End":"08:22.390","Text":"It\u0027s unique to BlueJ,"},{"Start":"08:22.390 ","End":"08:26.570","Text":"which allows you to create objects and interact with them."},{"Start":"08:26.570 ","End":"08:30.380","Text":"For the moment, we won\u0027t be getting too much into object-oriented programming."},{"Start":"08:30.380 ","End":"08:33.635","Text":"We\u0027re just going to learn the real basics."},{"Start":"08:33.635 ","End":"08:38.225","Text":"But I\u0027m going to use the terms class and object from time to time."},{"Start":"08:38.225 ","End":"08:43.355","Text":"All you need to know for the moment is an object is an instance of a class."},{"Start":"08:43.355 ","End":"08:46.250","Text":"If I double-click on this here,"},{"Start":"08:46.250 ","End":"08:49.940","Text":"I should be able to see the inside of the code."},{"Start":"08:49.940 ","End":"08:55.385","Text":"All it\u0027s showing me is that we\u0027ve got a variable called myNum,"},{"Start":"08:55.385 ","End":"08:57.050","Text":"which is an integer,"},{"Start":"08:57.050 ","End":"09:00.875","Text":"and it\u0027s been given the value 1234."},{"Start":"09:00.875 ","End":"09:03.820","Text":"Because there\u0027s no other code in here for me to run,"},{"Start":"09:03.820 ","End":"09:05.720","Text":"that\u0027s literally all I can do."},{"Start":"09:05.720 ","End":"09:08.465","Text":"I can\u0027t actually run any other lines of code."},{"Start":"09:08.465 ","End":"09:11.570","Text":"I\u0027ve simply created a variable and store the value in it."},{"Start":"09:11.570 ","End":"09:15.710","Text":"But it gives you the idea of the different areas and what they\u0027re"},{"Start":"09:15.710 ","End":"09:20.030","Text":"responsible for within the BlueJ environment,"},{"Start":"09:20.030 ","End":"09:21.860","Text":"so that\u0027s it for now."},{"Start":"09:21.860 ","End":"09:27.290","Text":"We\u0027ve just had a look at the basic displays within the BlueJ ID,"},{"Start":"09:27.290 ","End":"09:31.490","Text":"given the class and files here at the top,"},{"Start":"09:31.490 ","End":"09:33.020","Text":"the code pad here,"},{"Start":"09:33.020 ","End":"09:36.125","Text":"and the object workbench here where we can create"},{"Start":"09:36.125 ","End":"09:39.210","Text":"objects and we can run code, and obviously,"},{"Start":"09:39.210 ","End":"09:43.235","Text":"the main menus at the top here where we create our project"},{"Start":"09:43.235 ","End":"09:48.635","Text":"and load it should we need to if we open another project at some point."},{"Start":"09:48.635 ","End":"09:51.560","Text":"That\u0027s it for this video."},{"Start":"09:51.560 ","End":"09:54.740","Text":"In the next one, we\u0027ll look at how to create a structure for"},{"Start":"09:54.740 ","End":"09:59.705","Text":"a simple program and how to output to the display."},{"Start":"09:59.705 ","End":"10:02.190","Text":"I\u0027ll see you then."}],"ID":26346},{"Watched":false,"Name":"Program structure in Java","Duration":"10m 56s","ChapterTopicVideoID":26015,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.490","Text":"Hi everybody, welcome back."},{"Start":"00:02.490 ","End":"00:03.900","Text":"In the previous video,"},{"Start":"00:03.900 ","End":"00:06.570","Text":"we created a new project and interacted with"},{"Start":"00:06.570 ","End":"00:11.115","Text":"a BlueJ environment by typing code into the code pad down here,"},{"Start":"00:11.115 ","End":"00:16.710","Text":"and creating 1 line program which we compiled and inspected using the object workbench,"},{"Start":"00:16.710 ","End":"00:19.215","Text":"which is usually found here."},{"Start":"00:19.215 ","End":"00:21.150","Text":"We\u0027re now going to look at the structure of"},{"Start":"00:21.150 ","End":"00:24.705","Text":"a simple Java program that creates more than a single variable."},{"Start":"00:24.705 ","End":"00:28.360","Text":"Let\u0027s start by creating a new project."},{"Start":"00:28.790 ","End":"00:31.890","Text":"As we said before,"},{"Start":"00:31.890 ","End":"00:36.405","Text":"all code in Java must be contained in something called a class."},{"Start":"00:36.405 ","End":"00:39.330","Text":"We have to click on New Class up here."},{"Start":"00:39.330 ","End":"00:46.830","Text":"I\u0027m just going to call my class myvariables and apps comes,"},{"Start":"00:46.830 ","End":"00:48.764","Text":"the icon for the class."},{"Start":"00:48.764 ","End":"00:51.075","Text":"If I now double-click on this,"},{"Start":"00:51.075 ","End":"00:58.245","Text":"what I\u0027ll see is the editor view,"},{"Start":"00:58.245 ","End":"01:05.165","Text":"and the editor shows me some default code that BlueJ has helpfully put in for me,"},{"Start":"01:05.165 ","End":"01:07.790","Text":"but I\u0027m going to remove it all just to make it easier for you"},{"Start":"01:07.790 ","End":"01:11.540","Text":"to see the structure of the class itself."},{"Start":"01:11.540 ","End":"01:13.370","Text":"I\u0027ll take out everything except for"},{"Start":"01:13.370 ","End":"01:17.510","Text":"the first 2 lines and that last closing bracket there."},{"Start":"01:17.510 ","End":"01:19.700","Text":"If I press Enter a few times,"},{"Start":"01:19.700 ","End":"01:21.320","Text":"I\u0027ve got a bit of space to write my code,"},{"Start":"01:21.320 ","End":"01:22.900","Text":"and every time I press Enter,"},{"Start":"01:22.900 ","End":"01:24.585","Text":"it adds a new line in."},{"Start":"01:24.585 ","End":"01:26.780","Text":"If I want to indent the code,"},{"Start":"01:26.780 ","End":"01:29.150","Text":"I just press the Tab key, like I\u0027ve done there."},{"Start":"01:29.150 ","End":"01:31.325","Text":"Sometimes it will do it automatically for you,"},{"Start":"01:31.325 ","End":"01:33.365","Text":"on the end of the previous line."},{"Start":"01:33.365 ","End":"01:36.785","Text":"The variables I want to create first,"},{"Start":"01:36.785 ","End":"01:38.600","Text":"go on the first few lines."},{"Start":"01:38.600 ","End":"01:41.540","Text":"I\u0027m just going to create a couple of integer variables."},{"Start":"01:41.540 ","End":"01:44.690","Text":"I\u0027m going to call them num1 and num2."},{"Start":"01:44.690 ","End":"01:47.300","Text":"I\u0027ll give num1 the value 10,"},{"Start":"01:47.300 ","End":"01:51.860","Text":"and I\u0027ll give num2 the value 20."},{"Start":"01:51.860 ","End":"01:55.370","Text":"I\u0027ve got my variables now and that\u0027s no different than what we had before,"},{"Start":"01:55.370 ","End":"02:00.050","Text":"but I want to create some code now that is not just declaring variables."},{"Start":"02:00.050 ","End":"02:03.620","Text":"To do that, I have to create something called a method."},{"Start":"02:03.620 ","End":"02:06.470","Text":"It\u0027s a separate block in which the lines"},{"Start":"02:06.470 ","End":"02:10.380","Text":"of code that are going to be executed are stored."},{"Start":"02:10.570 ","End":"02:14.705","Text":"First thing I have to do is put a keyword void for now."},{"Start":"02:14.705 ","End":"02:18.320","Text":"Void basically tells the compiler that"},{"Start":"02:18.320 ","End":"02:21.800","Text":"nothing is going to be returned by this piece of code."},{"Start":"02:21.800 ","End":"02:25.100","Text":"Then I just give my piece of code a name,"},{"Start":"02:25.100 ","End":"02:26.510","Text":"I\u0027m going to call it test."},{"Start":"02:26.510 ","End":"02:30.590","Text":"I need a pair of empty round brackets here for the moment."},{"Start":"02:30.590 ","End":"02:31.940","Text":"I\u0027m going to do that,"},{"Start":"02:31.940 ","End":"02:34.520","Text":"and then everything that\u0027s going to go inside"},{"Start":"02:34.520 ","End":"02:41.660","Text":"my block is between this opening curly bracket here and the closing 1 there."},{"Start":"02:41.660 ","End":"02:44.840","Text":"You\u0027ll notice when you click on a bracket,"},{"Start":"02:44.840 ","End":"02:46.775","Text":"if it\u0027s been matched up to something,"},{"Start":"02:46.775 ","End":"02:48.785","Text":"it will be in gray."},{"Start":"02:48.785 ","End":"02:51.005","Text":"You can see those 2 are in gray,"},{"Start":"02:51.005 ","End":"02:54.065","Text":"and this pair is in gray, as well here."},{"Start":"02:54.065 ","End":"02:56.780","Text":"I click on that one, it shows these 2 in gray,"},{"Start":"02:56.780 ","End":"03:01.115","Text":"so you\u0027ve got matching of opening and closing brackets there."},{"Start":"03:01.115 ","End":"03:05.150","Text":"Back to my method here called test,"},{"Start":"03:05.150 ","End":"03:10.775","Text":"I\u0027m going to now put a line of code that will just output something to the screen."},{"Start":"03:10.775 ","End":"03:13.580","Text":"That looks like this,"},{"Start":"03:13.580 ","End":"03:20.315","Text":"it\u0027s called a print line method and it belongs to a package called system.out."},{"Start":"03:20.315 ","End":"03:25.745","Text":"I have to put system.out.printline in order to run this or it won\u0027t work or get an error."},{"Start":"03:25.745 ","End":"03:28.280","Text":"Traditionally, what we usually say in"},{"Start":"03:28.280 ","End":"03:31.145","Text":"a new program for the first time"},{"Start":"03:31.145 ","End":"03:34.355","Text":"when we\u0027ve written something in a new language or new environment,"},{"Start":"03:34.355 ","End":"03:36.350","Text":"just to test things out is Hello world."},{"Start":"03:36.350 ","End":"03:38.120","Text":"Let\u0027s go ahead and do that."},{"Start":"03:38.120 ","End":"03:42.950","Text":"Now, I can compile my program and I\u0027ll close the editor, there\u0027s no errors."},{"Start":"03:42.950 ","End":"03:48.125","Text":"You\u0027ll see that this icon has now changed so that it\u0027s not hashed anymore."},{"Start":"03:48.125 ","End":"03:53.045","Text":"Now, another thing I need to do is to make sure I can see the output from my code,"},{"Start":"03:53.045 ","End":"03:54.965","Text":"in something called the terminal,"},{"Start":"03:54.965 ","End":"03:58.575","Text":"so I\u0027ll turn the terminal on by saying View Terminal,"},{"Start":"03:58.575 ","End":"04:00.000","Text":"and up it comes."},{"Start":"04:00.000 ","End":"04:02.375","Text":"It\u0027s also useful to have that open"},{"Start":"04:02.375 ","End":"04:05.435","Text":"while I\u0027ve got the development of the environment on the left-hand side."},{"Start":"04:05.435 ","End":"04:07.490","Text":"I\u0027m just going to minimize this."},{"Start":"04:07.490 ","End":"04:10.115","Text":"I\u0027ve got the 2 windows side by side."},{"Start":"04:10.115 ","End":"04:14.600","Text":"Now I\u0027m going to run my code by creating an object as we did previously,"},{"Start":"04:14.600 ","End":"04:17.170","Text":"objects are created from classes,"},{"Start":"04:17.170 ","End":"04:19.430","Text":"and I just click on this menu item here."},{"Start":"04:19.430 ","End":"04:22.955","Text":"I accept the name that it\u0027s given the object by default."},{"Start":"04:22.955 ","End":"04:25.190","Text":"Here\u0027s our object, and now I can interact with"},{"Start":"04:25.190 ","End":"04:27.950","Text":"the object by inspecting the variables inside it."},{"Start":"04:27.950 ","End":"04:28.970","Text":"If I double-click on it,"},{"Start":"04:28.970 ","End":"04:30.575","Text":"it will show me those variables."},{"Start":"04:30.575 ","End":"04:33.499","Text":"We can see we\u0027ve got 2 variables, num1 and num2."},{"Start":"04:33.499 ","End":"04:36.530","Text":"That\u0027s really no further than where we were before,"},{"Start":"04:36.530 ","End":"04:42.710","Text":"but now what we will see if I right-click is a method called test also appears."},{"Start":"04:42.710 ","End":"04:44.495","Text":"If I left-click on this,"},{"Start":"04:44.495 ","End":"04:47.270","Text":"it will run the code inside test and"},{"Start":"04:47.270 ","End":"04:50.255","Text":"the output will be shown in the terminal window on the right."},{"Start":"04:50.255 ","End":"04:52.250","Text":"If I do that, there we go,"},{"Start":"04:52.250 ","End":"04:53.527","Text":"we see the words,"},{"Start":"04:53.527 ","End":"04:56.285","Text":"Hello World popup at the top of the screen."},{"Start":"04:56.285 ","End":"04:57.770","Text":"If I want to clear that message,"},{"Start":"04:57.770 ","End":"05:01.235","Text":"I can click on Clear or if I\u0027ve got this button,"},{"Start":"05:01.235 ","End":"05:03.980","Text":"this menu item here ticked,"},{"Start":"05:03.980 ","End":"05:05.720","Text":"Clear screen at method call,"},{"Start":"05:05.720 ","End":"05:07.880","Text":"then every time I call a method,"},{"Start":"05:07.880 ","End":"05:09.650","Text":"it will clear the screen."},{"Start":"05:09.650 ","End":"05:11.660","Text":"If I untick that, we\u0027ll see the effect,"},{"Start":"05:11.660 ","End":"05:13.235","Text":"I\u0027ll call test again,"},{"Start":"05:13.235 ","End":"05:18.365","Text":"and it will just display Hello world under the previous 1."},{"Start":"05:18.365 ","End":"05:22.385","Text":"But if I turn back on Clear screen at method call,"},{"Start":"05:22.385 ","End":"05:24.905","Text":"every time I call a method, any method,"},{"Start":"05:24.905 ","End":"05:28.790","Text":"it will clear whatever was in the terminal window before."},{"Start":"05:28.790 ","End":"05:33.530","Text":"There you go, and you see it\u0027s just 1 test message being output."},{"Start":"05:33.530 ","End":"05:36.980","Text":"There again, it\u0027s clear the screen and display the same message again."},{"Start":"05:36.980 ","End":"05:41.690","Text":"Let\u0027s go back to our program now and let\u0027s change the contents of 1 of these variables."},{"Start":"05:41.690 ","End":"05:44.060","Text":"We won\u0027t do it by changing up here."},{"Start":"05:44.060 ","End":"05:48.065","Text":"We\u0027ll actually do it inside this method."},{"Start":"05:48.065 ","End":"05:51.665","Text":"We\u0027ll also print out the value of the variable."},{"Start":"05:51.665 ","End":"05:58.805","Text":"If I change the inside of the brackets here and put the name of the variable, no,"},{"Start":"05:58.805 ","End":"06:00.860","Text":"I don\u0027t need any speech marks around this"},{"Start":"06:00.860 ","End":"06:04.402","Text":"because I don\u0027t want to print the literal characters,"},{"Start":"06:04.402 ","End":"06:10.460","Text":"num1, I want to print the contents of the variable that I\u0027ve called num1."},{"Start":"06:10.460 ","End":"06:12.080","Text":"If I run this,"},{"Start":"06:12.080 ","End":"06:15.980","Text":"I should see 10 appear on the screen because"},{"Start":"06:15.980 ","End":"06:20.555","Text":"num1 contains 10 and I\u0027ve never changed it anywhere in this program."},{"Start":"06:20.555 ","End":"06:22.790","Text":"Let\u0027s see if that indeed happens."},{"Start":"06:22.790 ","End":"06:27.305","Text":"Let\u0027s create a class again and run the method."},{"Start":"06:27.305 ","End":"06:31.295","Text":"There we see 10 appears on the screen as we expected."},{"Start":"06:31.295 ","End":"06:33.695","Text":"I\u0027ll go back into my code now."},{"Start":"06:33.695 ","End":"06:36.710","Text":"Let\u0027s do this more than once."},{"Start":"06:36.710 ","End":"06:41.540","Text":"I\u0027m going to copy this line and I\u0027m going to paste it below in-between,"},{"Start":"06:41.540 ","End":"06:42.770","Text":"press Enter in front of it."},{"Start":"06:42.770 ","End":"06:44.450","Text":"I\u0027ve got a gap of a line."},{"Start":"06:44.450 ","End":"06:50.400","Text":"I\u0027m going to change the value of num1 to 30,"},{"Start":"06:50.400 ","End":"06:52.485","Text":"so I\u0027m printing num1 here,"},{"Start":"06:52.485 ","End":"06:55.055","Text":"I\u0027m changing the value of num1 to 30,"},{"Start":"06:55.055 ","End":"06:56.450","Text":"and then I\u0027m printing it again."},{"Start":"06:56.450 ","End":"06:58.955","Text":"Let\u0027s see what the effect of that is."},{"Start":"06:58.955 ","End":"07:00.920","Text":"Create a new object,"},{"Start":"07:00.920 ","End":"07:03.695","Text":"run a test method from that object."},{"Start":"07:03.695 ","End":"07:06.335","Text":"There we go, we see 10 appears first,"},{"Start":"07:06.335 ","End":"07:08.765","Text":"and 30 appears afterwards,"},{"Start":"07:08.765 ","End":"07:10.370","Text":"just as we\u0027d expect."},{"Start":"07:10.370 ","End":"07:13.655","Text":"If obviously, I want to print the contents of this other variable,"},{"Start":"07:13.655 ","End":"07:17.535","Text":"I can change the name of the variable here."},{"Start":"07:17.535 ","End":"07:22.625","Text":"I would expect it to then print 10 first because that\u0027s what\u0027s in there,"},{"Start":"07:22.625 ","End":"07:25.070","Text":"and then 20 afterwards."},{"Start":"07:25.070 ","End":"07:28.415","Text":"Even though I\u0027ve changed num1 to 30,"},{"Start":"07:28.415 ","End":"07:34.230","Text":"it won\u0027t print that because I\u0027m specifying num2 here other than num1."},{"Start":"07:34.230 ","End":"07:39.320","Text":"What if you want to print some text and the contents of the variable on the same line?"},{"Start":"07:39.320 ","End":"07:44.959","Text":"You can do that by putting whatever the text is in speech marks."},{"Start":"07:44.959 ","End":"07:48.770","Text":"I\u0027ll say contents of num1 and a colon."},{"Start":"07:48.770 ","End":"07:52.610","Text":"Close the speech marks and then you put a plus afterwards."},{"Start":"07:52.610 ","End":"07:59.260","Text":"What this is doing is just joining this string to the contents of the num1 variable."},{"Start":"07:59.260 ","End":"08:03.785","Text":"This will also be a string because everything for print line is going to be a string."},{"Start":"08:03.785 ","End":"08:07.640","Text":"It actually does a job of converting this to a string for us when we print"},{"Start":"08:07.640 ","End":"08:11.390","Text":"it out and joining it to the end of this message here."},{"Start":"08:11.390 ","End":"08:15.259","Text":"I\u0027ll do the same for contents of num2."},{"Start":"08:15.259 ","End":"08:17.220","Text":"Just take this line out here,"},{"Start":"08:17.220 ","End":"08:19.145","Text":"because that seem unnecessary."},{"Start":"08:19.145 ","End":"08:23.090","Text":"Compile again, close the editor window,"},{"Start":"08:23.090 ","End":"08:27.950","Text":"New object, run the test method from that object, and there we go."},{"Start":"08:27.950 ","End":"08:30.110","Text":"Now, it prints a little message and the value of"},{"Start":"08:30.110 ","End":"08:34.700","Text":"num1 and another message and the value of num2."},{"Start":"08:34.700 ","End":"08:36.410","Text":"That\u0027s pretty much it."},{"Start":"08:36.410 ","End":"08:38.359","Text":"You can do this to your heart\u0027s content,"},{"Start":"08:38.359 ","End":"08:40.160","Text":"declare variables out here,"},{"Start":"08:40.160 ","End":"08:43.160","Text":"and then print their contents out and"},{"Start":"08:43.160 ","End":"08:47.345","Text":"change the values of the variables in here as you wish."},{"Start":"08:47.345 ","End":"08:50.240","Text":"I\u0027ll try and do a slightly different assignment now."},{"Start":"08:50.240 ","End":"08:52.849","Text":"Let\u0027s try a hex assignment."},{"Start":"08:52.849 ","End":"08:55.850","Text":"You remember that if you want to assign a hex value,"},{"Start":"08:55.850 ","End":"08:58.265","Text":"you put 0x in front of it."},{"Start":"08:58.265 ","End":"09:01.960","Text":"I\u0027m going to say 0xabcd,"},{"Start":"09:01.960 ","End":"09:03.420","Text":"and see if that works,"},{"Start":"09:03.420 ","End":"09:06.095","Text":"and num1 should print something very strange now,"},{"Start":"09:06.095 ","End":"09:09.245","Text":"abcd or it\u0027s decimal equivalent."},{"Start":"09:09.245 ","End":"09:10.835","Text":"I\u0027ll take that second line out."},{"Start":"09:10.835 ","End":"09:12.905","Text":"Just to prove that this works."},{"Start":"09:12.905 ","End":"09:16.125","Text":"Let\u0027s just have a quick look at that, and there we go,"},{"Start":"09:16.125 ","End":"09:25.200","Text":"43,981 is the decimal version of abcd in hexadecimal."},{"Start":"09:25.200 ","End":"09:27.020","Text":"Have a little play around with that."},{"Start":"09:27.020 ","End":"09:28.820","Text":"If you do make a mistake,"},{"Start":"09:28.820 ","End":"09:32.095","Text":"for example, a very common 1 is missing a semicolon,"},{"Start":"09:32.095 ","End":"09:34.070","Text":"when you try and compile,"},{"Start":"09:34.070 ","End":"09:37.775","Text":"you\u0027ll see that little red mark appears in the margin there."},{"Start":"09:37.775 ","End":"09:40.025","Text":"It says, errors found in class here."},{"Start":"09:40.025 ","End":"09:42.905","Text":"If you click on line where that red appears,"},{"Start":"09:42.905 ","End":"09:46.040","Text":"it tries to help you identify the error."},{"Start":"09:46.040 ","End":"09:47.360","Text":"This one is a simple 1,"},{"Start":"09:47.360 ","End":"09:52.160","Text":"the semicolon\u0027s missing, but some more strange ones."},{"Start":"09:52.160 ","End":"09:57.750","Text":"For example, you forget to capitalize the capital S here at the beginning of System,"},{"Start":"09:57.750 ","End":"09:59.940","Text":"and Java is a case-sensitive language,"},{"Start":"09:59.940 ","End":"10:01.610","Text":"so it will complain about that."},{"Start":"10:01.610 ","End":"10:05.015","Text":"Now, we\u0027ll give a slightly more obscure error."},{"Start":"10:05.015 ","End":"10:07.030","Text":"Let\u0027s see what that is."},{"Start":"10:07.030 ","End":"10:10.670","Text":"Let\u0027s compile it, and it\u0027s saying the package system does not"},{"Start":"10:10.670 ","End":"10:14.270","Text":"exist because System with a capital S exists,"},{"Start":"10:14.270 ","End":"10:17.565","Text":"but system with a lowercase s does not,"},{"Start":"10:17.565 ","End":"10:19.445","Text":"and that\u0027s what it\u0027s complaining about."},{"Start":"10:19.445 ","End":"10:21.730","Text":"If I restore that to a capital S,"},{"Start":"10:21.730 ","End":"10:26.120","Text":"it stops complaining and I don\u0027t get anymore syntax errors."},{"Start":"10:26.120 ","End":"10:28.450","Text":"Don\u0027t worry about making mistakes at this point,"},{"Start":"10:28.450 ","End":"10:30.385","Text":"that\u0027s an important part of learning."},{"Start":"10:30.385 ","End":"10:32.080","Text":"You\u0027re going to forget semi-colons,"},{"Start":"10:32.080 ","End":"10:34.850","Text":"you\u0027ll forget to close a bracket that you previously opened,"},{"Start":"10:34.850 ","End":"10:37.115","Text":"you\u0027ll forget to capitalize the letter and so on,"},{"Start":"10:37.115 ","End":"10:38.945","Text":"is absolutely fine right now."},{"Start":"10:38.945 ","End":"10:40.430","Text":"That\u0027s what we\u0027d expect,"},{"Start":"10:40.430 ","End":"10:43.310","Text":"and the key is to just manage your frustrations and"},{"Start":"10:43.310 ","End":"10:46.430","Text":"just work through the errors patiently 1 by 1."},{"Start":"10:46.430 ","End":"10:49.945","Text":"That\u0027s it for now, you should be ready to complete the exercises."},{"Start":"10:49.945 ","End":"10:54.440","Text":"Have a go, and refer back to this video and the previous ones if you need to."},{"Start":"10:54.440 ","End":"10:57.090","Text":"Thanks very much and see you soon."}],"ID":26823},{"Watched":false,"Name":"Exercise 1","Duration":"7m 22s","ChapterTopicVideoID":26436,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:06.555","Text":"Hello everyone, and welcome to this first exercise on variables and primitive datatypes."},{"Start":"00:06.555 ","End":"00:11.340","Text":"Here we\u0027ve been asked to create a new project firstly and then open the Code Pad in"},{"Start":"00:11.340 ","End":"00:15.900","Text":"BlueJ and then to do the following 4 steps in the Code Pad."},{"Start":"00:15.900 ","End":"00:18.450","Text":"Part A, we\u0027re asked to create a new variable"},{"Start":"00:18.450 ","End":"00:21.450","Text":"called found that only stores Boolean values."},{"Start":"00:21.450 ","End":"00:25.935","Text":"In Part B we\u0027re then asked to store a Boolean value in found."},{"Start":"00:25.935 ","End":"00:29.280","Text":"In Part C to check that that Boolean value is stored"},{"Start":"00:29.280 ","End":"00:33.015","Text":"correctly by typing in found followed by the Enter key."},{"Start":"00:33.015 ","End":"00:37.110","Text":"Then in Part D, we are asked to try to store an integer value into"},{"Start":"00:37.110 ","End":"00:42.325","Text":"found to see what would happen and then explain what we find."},{"Start":"00:42.325 ","End":"00:45.919","Text":"Hello everybody, welcome to this first question"},{"Start":"00:45.919 ","End":"00:49.420","Text":"in the topic on variables and primitive datatypes."},{"Start":"00:49.420 ","End":"00:53.645","Text":"In the question we\u0027ve been asked to create a new project and open the Code Pad in BlueJ."},{"Start":"00:53.645 ","End":"00:55.875","Text":"I\u0027ve got BlueJ up right now."},{"Start":"00:55.875 ","End":"00:58.160","Text":"What you\u0027ll see is that Code Pad is here in the corner,"},{"Start":"00:58.160 ","End":"01:00.920","Text":"but it\u0027s inactive and that\u0027s because you can\u0027t"},{"Start":"01:00.920 ","End":"01:04.935","Text":"use the Code Pad unless you\u0027ve got an active project."},{"Start":"01:04.935 ","End":"01:08.915","Text":"If we just go ahead and create a new project and give it a name,"},{"Start":"01:08.915 ","End":"01:15.620","Text":"I\u0027m just going to call mine Topic 3 and what you\u0027ll then see is that the Code Pad now"},{"Start":"01:15.620 ","End":"01:18.575","Text":"becomes active in the bottom and it\u0027s probably useful to make"},{"Start":"01:18.575 ","End":"01:22.775","Text":"the space available to the Code Pad bigger just by resizing,"},{"Start":"01:22.775 ","End":"01:24.740","Text":"dragging on these bars here."},{"Start":"01:24.740 ","End":"01:26.300","Text":"I\u0027ve got a bit more space to see"},{"Start":"01:26.300 ","End":"01:29.900","Text":"the response from any commands that I type into the Code Pad."},{"Start":"01:29.900 ","End":"01:35.728","Text":"Down here at the bottom is where I\u0027m seeing the prompt to type in my commands,"},{"Start":"01:35.728 ","End":"01:39.080","Text":"and the first thing I need to do is create a new variable."},{"Start":"01:39.080 ","End":"01:43.940","Text":"I\u0027ve been told to call it found and it should store only Boolean values."},{"Start":"01:43.940 ","End":"01:46.940","Text":"When you\u0027re creating a variable in Java,"},{"Start":"01:46.940 ","End":"01:49.385","Text":"you have to state the datatype."},{"Start":"01:49.385 ","End":"01:53.720","Text":"If this is a variable that only contains Boolean values,"},{"Start":"01:53.720 ","End":"01:57.080","Text":"obviously the datatype is going to be Boolean."},{"Start":"01:57.080 ","End":"01:59.045","Text":"That\u0027s how we got to start the line."},{"Start":"01:59.045 ","End":"02:01.879","Text":"Then we give the name of the variable."},{"Start":"02:01.879 ","End":"02:04.640","Text":"In this case, we\u0027ve been told to call it found,"},{"Start":"02:04.640 ","End":"02:06.290","Text":"and I can end it there."},{"Start":"02:06.290 ","End":"02:10.715","Text":"Now, if I was to write this in a Java program and not in the Code Pad,"},{"Start":"02:10.715 ","End":"02:13.970","Text":"I would be obliged to put a semicolon at the end of the line,"},{"Start":"02:13.970 ","End":"02:17.675","Text":"because lines in Java end with a semicolon."},{"Start":"02:17.675 ","End":"02:19.100","Text":"I\u0027ve gone ahead and done that."},{"Start":"02:19.100 ","End":"02:20.495","Text":"If I hadn\u0027t done that,"},{"Start":"02:20.495 ","End":"02:24.495","Text":"it would still have created it in the Code Pad and it would immediately"},{"Start":"02:24.495 ","End":"02:29.255","Text":"have echoed back to me the value stored in found."},{"Start":"02:29.255 ","End":"02:32.855","Text":"When you don\u0027t give a value to a variable when you create it,"},{"Start":"02:32.855 ","End":"02:36.530","Text":"it will get a default value and that\u0027s what this message"},{"Start":"02:36.530 ","End":"02:40.985","Text":"here is telling us that it\u0027s happened, is automatically initialized."},{"Start":"02:40.985 ","End":"02:44.660","Text":"We can see what the value is stored in that variable."},{"Start":"02:44.660 ","End":"02:46.295","Text":"I haven\u0027t stored anything into it,"},{"Start":"02:46.295 ","End":"02:49.310","Text":"but I can actually see it by just typing"},{"Start":"02:49.310 ","End":"02:52.770","Text":"the name of the variable and it will tell me what was stored in there."},{"Start":"02:52.770 ","End":"02:54.890","Text":"It seems that by default,"},{"Start":"02:54.890 ","End":"02:59.465","Text":"Boolean variables have the value false stored into them."},{"Start":"02:59.465 ","End":"03:03.800","Text":"Let\u0027s store a different value in found."},{"Start":"03:03.800 ","End":"03:07.370","Text":"Because that\u0027s what Part B of this question asks us to do."},{"Start":"03:07.370 ","End":"03:10.705","Text":"To do that, we just give the name of the variable which is"},{"Start":"03:10.705 ","End":"03:16.240","Text":"found and follow it with an equals and give it a different value."},{"Start":"03:16.240 ","End":"03:17.740","Text":"Let\u0027s give it true."},{"Start":"03:17.740 ","End":"03:22.560","Text":"Now we know that that\u0027s the other value that you can give to variables."},{"Start":"03:22.560 ","End":"03:24.030","Text":"I\u0027ve mistyped that."},{"Start":"03:24.030 ","End":"03:27.460","Text":"If you ever do that, up-arrow will bring"},{"Start":"03:27.460 ","End":"03:32.440","Text":"the previously typed thing in to the little white box at the bottom there,"},{"Start":"03:32.440 ","End":"03:35.605","Text":"and you can just delete anything that you want to change."},{"Start":"03:35.605 ","End":"03:39.490","Text":"I\u0027ve inadvertently typed the hash key when I was pressing \"Enter\" there."},{"Start":"03:39.490 ","End":"03:45.130","Text":"Press \"Enter\" again, and I\u0027ve now found that it\u0027s stored the variable value"},{"Start":"03:45.130 ","End":"03:50.260","Text":"true into the variable found and it\u0027s echoed that back to me as I said before,"},{"Start":"03:50.260 ","End":"03:53.880","Text":"because I didn\u0027t put a semicolon on the end of this line."},{"Start":"03:53.880 ","End":"03:58.445","Text":"If I had, it would still store true,"},{"Start":"03:58.445 ","End":"04:01.100","Text":"but it just wouldn\u0027t echo back a value to me."},{"Start":"04:01.100 ","End":"04:05.420","Text":"You\u0027ll see that the command is being repeated here in black but"},{"Start":"04:05.420 ","End":"04:07.610","Text":"it\u0027s not giving me a value in green as it"},{"Start":"04:07.610 ","End":"04:10.160","Text":"did previously because I\u0027ve missed out the semicolon."},{"Start":"04:10.160 ","End":"04:13.010","Text":"That\u0027s the first 2 bits done."},{"Start":"04:13.010 ","End":"04:18.065","Text":"I\u0027ve just created a variable and I had to state the datatype first."},{"Start":"04:18.065 ","End":"04:22.955","Text":"Then I\u0027ve had to change the value in the variable to true."},{"Start":"04:22.955 ","End":"04:28.805","Text":"The last part here, it asked me to store an integer value in found to see what happens."},{"Start":"04:28.805 ","End":"04:30.995","Text":"Let\u0027s go ahead and do that."},{"Start":"04:30.995 ","End":"04:35.570","Text":"If I put found equals and then just make up any old integer value of 1,"},{"Start":"04:35.570 ","End":"04:38.825","Text":"2, 3, 4 say, and press \"Enter\"."},{"Start":"04:38.825 ","End":"04:41.135","Text":"I get an error message."},{"Start":"04:41.135 ","End":"04:43.370","Text":"It says incompatible types,"},{"Start":"04:43.370 ","End":"04:46.235","Text":"int cannot be converted to Boolean."},{"Start":"04:46.235 ","End":"04:52.070","Text":"Error messages in programming languages can be quite cryptic sometimes."},{"Start":"04:52.070 ","End":"04:54.560","Text":"This one\u0027s not too bad as it goes."},{"Start":"04:54.560 ","End":"04:59.360","Text":"You can work out why it\u0027s complaining and what it\u0027s complaining about."},{"Start":"04:59.360 ","End":"05:04.625","Text":"It\u0027s saying something about int and Boolean types."},{"Start":"05:04.625 ","End":"05:11.225","Text":"As we\u0027ve tried to assign an integer value to a Boolean variable,"},{"Start":"05:11.225 ","End":"05:13.580","Text":"it\u0027s not allowing it."},{"Start":"05:13.580 ","End":"05:16.765","Text":"This really is the only point of this exercise,"},{"Start":"05:16.765 ","End":"05:20.140","Text":"which is to demonstrate the datatypes"},{"Start":"05:20.140 ","End":"05:24.369","Text":"constrain what you can do with a particular variable."},{"Start":"05:24.369 ","End":"05:28.525","Text":"In this case, we\u0027ve set the datatype to Boolean."},{"Start":"05:28.525 ","End":"05:31.195","Text":"It can only store Booleans."},{"Start":"05:31.195 ","End":"05:33.670","Text":"If I try to store another datatype,"},{"Start":"05:33.670 ","End":"05:37.750","Text":"it will give me an error message at compile time."},{"Start":"05:37.750 ","End":"05:40.810","Text":"I\u0027m not compiling my program because there is no program,"},{"Start":"05:40.810 ","End":"05:47.695","Text":"I\u0027m just messing around in the Code Pad just to experiment with the features in Java."},{"Start":"05:47.695 ","End":"05:52.000","Text":"But it would give me an error message if I put this in a line in a program because I\u0027m"},{"Start":"05:52.000 ","End":"05:56.685","Text":"trying to put an integer value into a Boolean variable and clearly,"},{"Start":"05:56.685 ","End":"05:58.220","Text":"it doesn\u0027t want me to do that."},{"Start":"05:58.220 ","End":"06:00.530","Text":"Interestingly, there are some languages that"},{"Start":"06:00.530 ","End":"06:03.260","Text":"don\u0027t really complain about this sort of stuff."},{"Start":"06:03.260 ","End":"06:05.585","Text":"They have what\u0027s called dynamic typing."},{"Start":"06:05.585 ","End":"06:11.795","Text":"That means really any variable can be any datatype and it can switch between them."},{"Start":"06:11.795 ","End":"06:15.260","Text":"But Java is a statically typed language."},{"Start":"06:15.260 ","End":"06:18.080","Text":"That means once you create a type,"},{"Start":"06:18.080 ","End":"06:23.105","Text":"you\u0027re always going to be in that datatype and you can\u0027t change its datatype."},{"Start":"06:23.105 ","End":"06:25.640","Text":"If you want a different variable to store an integer,"},{"Start":"06:25.640 ","End":"06:28.850","Text":"you\u0027re going to have to declare a different variable with a different datatype."},{"Start":"06:28.850 ","End":"06:33.770","Text":"That\u0027s why we get this particular error and that\u0027s the explanation for why this"},{"Start":"06:33.770 ","End":"06:39.200","Text":"happens that you\u0027ve been asked to give in Part D. That was a nice,"},{"Start":"06:39.200 ","End":"06:42.725","Text":"gentle introduction to these exercises."},{"Start":"06:42.725 ","End":"06:45.080","Text":"Nice and simple. We\u0027ve created a project"},{"Start":"06:45.080 ","End":"06:47.780","Text":"which we had to in order to open up the Code Pad,"},{"Start":"06:47.780 ","End":"06:49.355","Text":"resize the window,"},{"Start":"06:49.355 ","End":"06:52.250","Text":"then we created a variable and stored a value,"},{"Start":"06:52.250 ","End":"06:56.120","Text":"changed the value, revealed what value is in there by just typing the name."},{"Start":"06:56.120 ","End":"07:03.500","Text":"Then we tried to put in a value that wasn\u0027t allowed and we saw why it wasn\u0027t allowed."},{"Start":"07:03.500 ","End":"07:09.470","Text":"In that, we\u0027re really now discovering this idea of datatypes being a constraint,"},{"Start":"07:09.470 ","End":"07:12.050","Text":"as well as something that will determine how"},{"Start":"07:12.050 ","End":"07:14.855","Text":"much memory space something\u0027s going to take up."},{"Start":"07:14.855 ","End":"07:16.610","Text":"That\u0027s it for this one. I\u0027ll see you in"},{"Start":"07:16.610 ","End":"07:18.140","Text":"the next one where we\u0027ll do something a little bit"},{"Start":"07:18.140 ","End":"07:22.380","Text":"more involved with integers. See you then."}],"ID":27342},{"Watched":false,"Name":"Exercise 2","Duration":"11m 26s","ChapterTopicVideoID":26435,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.430","Text":"Hi, everybody. Welcome back."},{"Start":"00:02.430 ","End":"00:05.700","Text":"In this exercise, we\u0027re going to continue looking at variables"},{"Start":"00:05.700 ","End":"00:09.390","Text":"and primitive data types using the code pad as we did it before."},{"Start":"00:09.390 ","End":"00:12.930","Text":"This exercise is about storing values using decimal,"},{"Start":"00:12.930 ","End":"00:15.555","Text":"hexadecimal, and binary literals."},{"Start":"00:15.555 ","End":"00:19.605","Text":"In parts a to c we\u0027ll be dealing with decimals."},{"Start":"00:19.605 ","End":"00:24.000","Text":"We\u0027ve been asked in part a to create a new variable to store 7 bits"},{"Start":"00:24.000 ","End":"00:29.430","Text":"signed integer value using the byte data type and to choose a sensible name."},{"Start":"00:29.430 ","End":"00:33.990","Text":"Then we\u0027re asked to store the value 10 decimal into that variable."},{"Start":"00:33.990 ","End":"00:35.530","Text":"Then finally in part c,"},{"Start":"00:35.530 ","End":"00:38.210","Text":"to check that the value is stored correctly by"},{"Start":"00:38.210 ","End":"00:41.675","Text":"typing the variable name and followed by the enter key."},{"Start":"00:41.675 ","End":"00:45.875","Text":"Then in part d too we\u0027re dealing with a hex questions."},{"Start":"00:45.875 ","End":"00:49.940","Text":"The prefix 0x is used to store a hexadecimal value into"},{"Start":"00:49.940 ","End":"00:54.505","Text":"the variable when you use that rather than the decimal representation."},{"Start":"00:54.505 ","End":"00:59.645","Text":"We want you to store the hexadecimal value 5F into the variable we created"},{"Start":"00:59.645 ","End":"01:06.110","Text":"earlier in part d. Then in part e to check that that value is 95 decimal,"},{"Start":"01:06.110 ","End":"01:09.245","Text":"and that it has been successfully stored into the variable."},{"Start":"01:09.245 ","End":"01:10.910","Text":"Then finally in part f,"},{"Start":"01:10.910 ","End":"01:17.375","Text":"to try to put the hexadecimal value AF into the variable and explain what happens."},{"Start":"01:17.375 ","End":"01:21.845","Text":"Part g and h then are where we use binary literals."},{"Start":"01:21.845 ","End":"01:26.315","Text":"The prefix 0b can be used to store a binary value into a variable."},{"Start":"01:26.315 ","End":"01:33.000","Text":"We want to store that binary variable given here into the variable we created in part a,"},{"Start":"01:33.000 ","End":"01:39.020","Text":"and then confirm that the value decimal 92 has been stored."},{"Start":"01:39.020 ","End":"01:41.660","Text":"Then the last part is to store"},{"Start":"01:41.660 ","End":"01:46.505","Text":"this new binary value into the variable and explain what happens."},{"Start":"01:46.505 ","End":"01:51.500","Text":"You can stay open in the same project as you had before in the same code pad window."},{"Start":"01:51.500 ","End":"01:54.433","Text":"I\u0027ve closed down Bluej and reopened it,"},{"Start":"01:54.433 ","End":"01:57.155","Text":"and that\u0027s why this area is empty here."},{"Start":"01:57.155 ","End":"02:01.730","Text":"But you may well have some output here and that\u0027s absolutely fine."},{"Start":"02:01.730 ","End":"02:04.560","Text":"You can continue on as normal."},{"Start":"02:04.560 ","End":"02:06.680","Text":"Let\u0027s look at the first part, part a."},{"Start":"02:06.680 ","End":"02:09.620","Text":"It\u0027s asking us to create a new variable to store a 7 bits signed"},{"Start":"02:09.620 ","End":"02:13.410","Text":"integer using the byte datatype and a sensible name."},{"Start":"02:13.410 ","End":"02:16.520","Text":"This time we have been told what name to give it."},{"Start":"02:16.520 ","End":"02:21.265","Text":"Naming as we know, is a very important part of making our code readable,"},{"Start":"02:21.265 ","End":"02:24.320","Text":"understandable, choosing sensible names to store things."},{"Start":"02:24.320 ","End":"02:27.185","Text":"We don\u0027t know what this variable is going to store,"},{"Start":"02:27.185 ","End":"02:30.440","Text":"but we do know that it\u0027s a data type of byte."},{"Start":"02:30.440 ","End":"02:34.910","Text":"Sometimes the convention that programmers use is to put"},{"Start":"02:34.910 ","End":"02:40.310","Text":"a prefix ahead of the variable name to indicate what the datatype is,"},{"Start":"02:40.310 ","End":"02:42.395","Text":"so maybe I\u0027ll try that."},{"Start":"02:42.395 ","End":"02:45.500","Text":"The datatype itself comes first as before,"},{"Start":"02:45.500 ","End":"02:50.090","Text":"I need to type the name of the data type and it\u0027s a byte data type, all lowercase."},{"Start":"02:50.090 ","End":"02:51.665","Text":"Then I\u0027m going to give my name,"},{"Start":"02:51.665 ","End":"02:53.990","Text":"and I\u0027m going to put a lowercase b in front of it"},{"Start":"02:53.990 ","End":"02:56.450","Text":"just to indicate that it\u0027s a byte datatype."},{"Start":"02:56.450 ","End":"02:59.690","Text":"You don\u0027t have to do this, I\u0027m just using that convention."},{"Start":"02:59.690 ","End":"03:03.620","Text":"Then I\u0027m going to give it a name and I\u0027m going to call it,"},{"Start":"03:03.620 ","End":"03:05.165","Text":"let\u0027s say a mask."},{"Start":"03:05.165 ","End":"03:08.195","Text":"A mask is something that is used quite often."},{"Start":"03:08.195 ","End":"03:14.270","Text":"Mask out areas of a network and binary values are often used to do that."},{"Start":"03:14.270 ","End":"03:19.085","Text":"I could imagine a scenario where we\u0027d have a variable called mask."},{"Start":"03:19.085 ","End":"03:23.285","Text":"I\u0027m going to put b in front of it just to indicate that this data type is"},{"Start":"03:23.285 ","End":"03:28.535","Text":"a byte because some programs will use that convention. There we go."},{"Start":"03:28.535 ","End":"03:30.800","Text":"I\u0027m going to put a semicolon as you know,"},{"Start":"03:30.800 ","End":"03:34.520","Text":"what that does is it puts the variable into memory,"},{"Start":"03:34.520 ","End":"03:37.670","Text":"but it doesn\u0027t reflect back to me what the value of the variable is."},{"Start":"03:37.670 ","End":"03:40.250","Text":"If I had left off the semicolon, it would\u0027ve done."},{"Start":"03:40.250 ","End":"03:41.555","Text":"But if I want the value,"},{"Start":"03:41.555 ","End":"03:43.880","Text":"I can just type the name of the variable,"},{"Start":"03:43.880 ","End":"03:45.725","Text":"and it will give the value."},{"Start":"03:45.725 ","End":"03:49.040","Text":"We\u0027ll see that it has actually created a byte data type,"},{"Start":"03:49.040 ","End":"03:52.160","Text":"the name of my variable is bMask,"},{"Start":"03:52.160 ","End":"03:54.255","Text":"and it currently has a value of 0."},{"Start":"03:54.255 ","End":"03:59.315","Text":"It seems that when you don\u0027t give it an initial value to a byte data type,"},{"Start":"03:59.315 ","End":"04:03.620","Text":"in Java, it assigns a default value of 0."},{"Start":"04:03.620 ","End":"04:07.745","Text":"We\u0027ve been asked in part b to store the value 10 into the variable."},{"Start":"04:07.745 ","End":"04:10.655","Text":"That\u0027s 10 decimal. Sounds straightforward enough."},{"Start":"04:10.655 ","End":"04:12.320","Text":"We\u0027ve seen this before,"},{"Start":"04:12.320 ","End":"04:14.520","Text":"and we\u0027ll do that,"},{"Start":"04:14.520 ","End":"04:16.760","Text":"and there doesn\u0027t seem to be any complaints."},{"Start":"04:16.760 ","End":"04:20.390","Text":"I left the semicolon off the end there."},{"Start":"04:20.390 ","End":"04:23.120","Text":"It\u0027s reflected back the value to me immediately,"},{"Start":"04:23.120 ","End":"04:24.490","Text":"but if I had typed it,"},{"Start":"04:24.490 ","End":"04:26.540","Text":"it would\u0027ve done the same thing."},{"Start":"04:26.540 ","End":"04:31.310","Text":"Now we\u0027re on to part d. We\u0027re going to check that we can use"},{"Start":"04:31.310 ","End":"04:38.720","Text":"a prefix of 0x to store a hexadecimal value into the variable rather than a decimal."},{"Start":"04:38.720 ","End":"04:43.420","Text":"We tend to work with decimal values because humans are used to decimal."},{"Start":"04:43.420 ","End":"04:49.760","Text":"But it might be that it\u0027s more convenient to state a value in hexadecimal."},{"Start":"04:49.760 ","End":"04:53.060","Text":"Let\u0027s see if we are able to do that."},{"Start":"04:53.060 ","End":"04:56.630","Text":"We\u0027re going to put the name of the variable, the equal sign,"},{"Start":"04:56.630 ","End":"04:59.900","Text":"and then we give our value in hexadecimal,"},{"Start":"04:59.900 ","End":"05:03.890","Text":"but we have to prefix it with 0 and x."},{"Start":"05:03.890 ","End":"05:05.720","Text":"That tells it\u0027s hexadecimal,"},{"Start":"05:05.720 ","End":"05:07.145","Text":"there\u0027s no spaces,"},{"Start":"05:07.145 ","End":"05:11.074","Text":"and I\u0027ll put the value 5f in as I was requested,"},{"Start":"05:11.074 ","End":"05:14.055","Text":"and it gets stored."},{"Start":"05:14.055 ","End":"05:19.830","Text":"It does give me the value of 95 decimal because 5"},{"Start":"05:19.830 ","End":"05:25.875","Text":"times 16 plus 15 is 95,"},{"Start":"05:25.875 ","End":"05:27.904","Text":"so that\u0027s what we\u0027d expect."},{"Start":"05:27.904 ","End":"05:29.540","Text":"That looks good."},{"Start":"05:29.540 ","End":"05:37.050","Text":"Let\u0027s just check what would have happened if we didn\u0027t put the 0x in front of the number."},{"Start":"05:37.050 ","End":"05:39.610","Text":"We got an error."},{"Start":"05:40.430 ","End":"05:42.650","Text":"In this case, interestingly,"},{"Start":"05:42.650 ","End":"05:46.640","Text":"it thinks that it\u0027s a float because of the f. Very interesting."},{"Start":"05:46.640 ","End":"05:50.960","Text":"I\u0027m going to try another value of hexadecimal."},{"Start":"05:50.960 ","End":"05:57.525","Text":"Let\u0027s say a 5c that\u0027s slightly different since an error expected."},{"Start":"05:57.525 ","End":"05:59.190","Text":"Semicolon. It still give me,"},{"Start":"05:59.190 ","End":"06:00.810","Text":"it\u0027s a very strange error."},{"Start":"06:00.810 ","End":"06:03.110","Text":"Some quite odd things can happen."},{"Start":"06:03.110 ","End":"06:05.510","Text":"I can\u0027t even explain why that has happened."},{"Start":"06:05.510 ","End":"06:09.575","Text":"It thinks I haven\u0027t terminated the line properly."},{"Start":"06:09.575 ","End":"06:16.325","Text":"Clearly, I think the c is something different than a hexadecimal character."},{"Start":"06:16.325 ","End":"06:22.790","Text":"That\u0027s what happens if we don\u0027t put 0x in front of the hexadecimal value."},{"Start":"06:22.790 ","End":"06:25.820","Text":"You see that? Now it\u0027s absolutely happy with it."},{"Start":"06:25.820 ","End":"06:29.840","Text":"This illustrates you can get some quite strange error messages"},{"Start":"06:29.840 ","End":"06:32.030","Text":"that don\u0027t really give you a clue as"},{"Start":"06:32.030 ","End":"06:34.310","Text":"to what\u0027s gone wrong and that is what"},{"Start":"06:34.310 ","End":"06:38.285","Text":"a beginner programmer will often find a real frustration."},{"Start":"06:38.285 ","End":"06:42.080","Text":"We\u0027ve done now part d and we\u0027ve checked it,"},{"Start":"06:42.080 ","End":"06:44.210","Text":"which is part e. If I just"},{"Start":"06:44.210 ","End":"06:47.090","Text":"restore the original value that I was supposed to put in there,"},{"Start":"06:47.090 ","End":"06:50.135","Text":"5f, there it is."},{"Start":"06:50.135 ","End":"06:53.090","Text":"It\u0027s a value 95. Now it\u0027s asked me in"},{"Start":"06:53.090 ","End":"06:58.925","Text":"part f to try and put the hexadecimal value af into the variable."},{"Start":"06:58.925 ","End":"07:03.080","Text":"Let\u0027s try that. I get an error message."},{"Start":"07:03.080 ","End":"07:06.810","Text":"Cannot find symbol variable af."},{"Start":"07:06.810 ","End":"07:09.725","Text":"That\u0027s because I didn\u0027t put 0x in front of it."},{"Start":"07:09.725 ","End":"07:11.720","Text":"It thinks it\u0027s a variable name."},{"Start":"07:11.720 ","End":"07:15.365","Text":"The characters a and f form a variable name, which makes sense."},{"Start":"07:15.365 ","End":"07:17.585","Text":"Let\u0027s try and put Ox in front of it."},{"Start":"07:17.585 ","End":"07:24.200","Text":"Now another error and this one we might be able"},{"Start":"07:24.200 ","End":"07:31.160","Text":"to judge from the previous exercise is related to the problem we had previously."},{"Start":"07:31.160 ","End":"07:38.060","Text":"Incompatible types, possible lousy conversion from int to byte."},{"Start":"07:38.060 ","End":"07:41.435","Text":"Can we explain what\u0027s happening here?"},{"Start":"07:41.435 ","End":"07:45.110","Text":"Well, what is happening is"},{"Start":"07:45.110 ","End":"07:53.120","Text":"the number af is a larger number than can be stored in 7 bits."},{"Start":"07:53.120 ","End":"07:57.290","Text":"A you remember is 10 in hexadecimal."},{"Start":"07:57.290 ","End":"08:00.820","Text":"10 times 16 would be 160 plus 15,"},{"Start":"08:00.820 ","End":"08:07.235","Text":"which is f, 175 is a number that cannot be stored in 7 bits."},{"Start":"08:07.235 ","End":"08:11.995","Text":"The highest number you can store with 7 bits is 127,"},{"Start":"08:11.995 ","End":"08:18.020","Text":"so we can\u0027t store this number into bMask because it\u0027s basically too big."},{"Start":"08:18.020 ","End":"08:21.760","Text":"That\u0027s the error message that we\u0027ve been given."},{"Start":"08:21.760 ","End":"08:26.810","Text":"If we had stored an integer which is larger than a byte,"},{"Start":"08:26.810 ","End":"08:29.870","Text":"then it would have been absolutely fine."},{"Start":"08:29.870 ","End":"08:36.350","Text":"That is why we are seeing that error message and hope that makes sense just"},{"Start":"08:36.350 ","End":"08:42.230","Text":"to prove that we can get any value that\u0027s smaller than a 127 in here."},{"Start":"08:42.230 ","End":"08:44.405","Text":"We could try in decimal if we wanted to."},{"Start":"08:44.405 ","End":"08:46.480","Text":"Let\u0027s try 128."},{"Start":"08:46.480 ","End":"08:48.605","Text":"Again it gives me the same error."},{"Start":"08:48.605 ","End":"08:51.040","Text":"Let\u0027s put a 127 in there,"},{"Start":"08:51.040 ","End":"08:54.320","Text":"and it\u0027s absolutely happy with that."},{"Start":"08:54.320 ","End":"08:58.550","Text":"That\u0027s parts a to f done."},{"Start":"08:58.550 ","End":"09:01.220","Text":"Then we\u0027ve been told that you can actually put"},{"Start":"09:01.220 ","End":"09:05.210","Text":"binary values into byte variable or to any variable,"},{"Start":"09:05.210 ","End":"09:06.900","Text":"and it stores numbers,"},{"Start":"09:06.900 ","End":"09:08.270","Text":"so let\u0027s try that."},{"Start":"09:08.270 ","End":"09:12.810","Text":"Let\u0027s make bMask prefix sum equal to 0b."},{"Start":"09:12.810 ","End":"09:17.850","Text":"I\u0027ve been given a number here to store 01011100,"},{"Start":"09:19.040 ","End":"09:24.320","Text":"and it goes and I can confirm that 92 has been"},{"Start":"09:24.320 ","End":"09:29.880","Text":"stored in there because it\u0027s reflected back to me there in the code pad window."},{"Start":"09:30.320 ","End":"09:32.745","Text":"All good so far."},{"Start":"09:32.745 ","End":"09:35.085","Text":"Then let\u0027s just do the last part."},{"Start":"09:35.085 ","End":"09:42.315","Text":"The value 10000000 into the same variable."},{"Start":"09:42.315 ","End":"09:44.243","Text":"Let\u0027s give that a go,"},{"Start":"09:44.243 ","End":"09:47.220","Text":"0b and then 10000000."},{"Start":"09:47.600 ","End":"09:55.000","Text":"Again, I get the error message talking about loss aversion from int to byte."},{"Start":"09:55.000 ","End":"09:56.625","Text":"For the same reason,"},{"Start":"09:56.625 ","End":"09:59.005","Text":"as we saw before in part f,"},{"Start":"09:59.005 ","End":"10:02.750","Text":"I simply cannot store a number this big into a byte"},{"Start":"10:02.750 ","End":"10:06.580","Text":"because that is the binary value for a 128,"},{"Start":"10:06.580 ","End":"10:11.299","Text":"and we\u0027ve already proved that you can\u0027t store 128 into"},{"Start":"10:11.299 ","End":"10:17.230","Text":"the variable because we tried to do that here and it gave us an error message."},{"Start":"10:17.230 ","End":"10:24.365","Text":"There we go. We have been able to store various values into our byte datatype variable."},{"Start":"10:24.365 ","End":"10:29.555","Text":"We saw that you can\u0027t store values greater than a certain amount."},{"Start":"10:29.555 ","End":"10:34.055","Text":"Basically, 127 is the highest value you can put in."},{"Start":"10:34.055 ","End":"10:37.235","Text":"What we didn\u0027t do is store a negative value in."},{"Start":"10:37.235 ","End":"10:38.660","Text":"We can try that if we want."},{"Start":"10:38.660 ","End":"10:43.220","Text":"Let\u0027s put into bMask a value of minus 127,"},{"Start":"10:43.220 ","End":"10:44.530","Text":"see if it\u0027s happy with that."},{"Start":"10:44.530 ","End":"10:49.680","Text":"It is. This is what we mean by a signed data type."},{"Start":"10:49.680 ","End":"10:51.820","Text":"It\u0027s a signed integer, therefore,"},{"Start":"10:51.820 ","End":"10:54.050","Text":"we can have a positive or a negative number."},{"Start":"10:54.050 ","End":"10:56.990","Text":"In some languages, you can have unsigned integers,"},{"Start":"10:56.990 ","End":"11:01.910","Text":"which means you get to use the whole range of available bit values."},{"Start":"11:01.910 ","End":"11:05.824","Text":"But it will just be a positive number always."},{"Start":"11:05.824 ","End":"11:14.540","Text":"Java byte default is all variables are signed variables if they are to store numbers."},{"Start":"11:14.540 ","End":"11:17.985","Text":"That\u0027s it for this exercise,"},{"Start":"11:17.985 ","End":"11:22.355","Text":"we\u0027ll move on in the next one to slightly larger integers,"},{"Start":"11:22.355 ","End":"11:27.060","Text":"and I\u0027ll see you for that one soon. Take care."}],"ID":27343},{"Watched":false,"Name":"Exercise 3","Duration":"9m 18s","ChapterTopicVideoID":26439,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.140 ","End":"00:03.450","Text":"Hi, welcome back. In this exercise,"},{"Start":"00:03.450 ","End":"00:06.840","Text":"we\u0027ve been asked in the Code Pad once again to first of all"},{"Start":"00:06.840 ","End":"00:11.310","Text":"create a variable in Code Pad and to call it myInt,"},{"Start":"00:11.310 ","End":"00:13.110","Text":"and that should store an integer."},{"Start":"00:13.110 ","End":"00:16.560","Text":"In Part B, then we\u0027ve been asked to store into that variable"},{"Start":"00:16.560 ","End":"00:20.790","Text":"the maximum negative value that\u0027s possible."},{"Start":"00:20.790 ","End":"00:23.145","Text":"We\u0027ve been given a little hint here."},{"Start":"00:23.145 ","End":"00:26.745","Text":"In Part C, we\u0027re then being asked to type myInt,"},{"Start":"00:26.745 ","End":"00:29.010","Text":"the name of the variable, and to press \"Enter\" to check"},{"Start":"00:29.010 ","End":"00:31.875","Text":"that that intended value was stored."},{"Start":"00:31.875 ","End":"00:33.735","Text":"Then in Part D,"},{"Start":"00:33.735 ","End":"00:39.475","Text":"we\u0027re then asked to store the maximum positive value that was possible into myInt,"},{"Start":"00:39.475 ","End":"00:42.830","Text":"and then again, to check that that intended value was stored."},{"Start":"00:42.830 ","End":"00:44.750","Text":"In Part E,"},{"Start":"00:44.750 ","End":"00:48.170","Text":"we\u0027ve been asked to take the value that was stored,"},{"Start":"00:48.170 ","End":"00:50.210","Text":"the maximum positive value that was stored,"},{"Start":"00:50.210 ","End":"00:52.700","Text":"and to then type a following little fragment of"},{"Start":"00:52.700 ","End":"00:56.000","Text":"code which will add 1 to the contents of my variable."},{"Start":"00:56.000 ","End":"01:00.460","Text":"The fragment of code is myInt plus equals 1."},{"Start":"01:00.460 ","End":"01:04.820","Text":"Then finally, we\u0027ve been told that the results should be a negative number,"},{"Start":"01:04.820 ","End":"01:08.015","Text":"and to explain why that happens."},{"Start":"01:08.015 ","End":"01:13.175","Text":"It asked us initially to create another variable in Code Pad."},{"Start":"01:13.175 ","End":"01:15.685","Text":"This time, let\u0027s give it a name,"},{"Start":"01:15.685 ","End":"01:19.700","Text":"myInt, and we need to store an integer."},{"Start":"01:19.700 ","End":"01:22.760","Text":"Now, the first thing you might have been thinking here is,"},{"Start":"01:22.760 ","End":"01:27.470","Text":"well, I could have several different types of integer, and you\u0027re quite right."},{"Start":"01:27.470 ","End":"01:28.850","Text":"A bit after all,"},{"Start":"01:28.850 ","End":"01:30.410","Text":"is a type of integer,"},{"Start":"01:30.410 ","End":"01:33.995","Text":"meaning essentially a whole number with no fractional part,"},{"Start":"01:33.995 ","End":"01:36.424","Text":"but it\u0027s a particular size."},{"Start":"01:36.424 ","End":"01:38.900","Text":"If we have been just told an integer,"},{"Start":"01:38.900 ","End":"01:41.840","Text":"there is a datatype in Java called int,"},{"Start":"01:41.840 ","End":"01:43.688","Text":"which is an integer,"},{"Start":"01:43.688 ","End":"01:45.800","Text":"and it\u0027s actually 32 bits,"},{"Start":"01:45.800 ","End":"01:48.065","Text":"which it tells us in the next part of the question."},{"Start":"01:48.065 ","End":"01:50.555","Text":"But we don\u0027t type the full word, integer out,"},{"Start":"01:50.555 ","End":"01:53.645","Text":"it\u0027s just int on its own I-N-T."},{"Start":"01:53.645 ","End":"01:59.400","Text":"There is actually something called an integer in Java with a I,"},{"Start":"01:59.400 ","End":"02:03.380","Text":"but that\u0027s not something we\u0027re interested in at this point."},{"Start":"02:03.380 ","End":"02:07.250","Text":"We just want an int variable which will give us integer"},{"Start":"02:07.250 ","End":"02:12.855","Text":"datatype variable and I\u0027ve been given the name to use, which is myInt."},{"Start":"02:12.855 ","End":"02:15.110","Text":"There we go, create a variable."},{"Start":"02:15.110 ","End":"02:18.665","Text":"It goes ahead and does that for me."},{"Start":"02:18.665 ","End":"02:20.405","Text":"In Part B,"},{"Start":"02:20.405 ","End":"02:27.305","Text":"I\u0027ve now been asked to store the maximum negative value possible in an int."},{"Start":"02:27.305 ","End":"02:29.960","Text":"It does give me a hint here saying that"},{"Start":"02:29.960 ","End":"02:34.880","Text":"Java integer datatypes are signed and use 32 bits."},{"Start":"02:34.880 ","End":"02:37.115","Text":"There\u0027s a couple of ways I could do this."},{"Start":"02:37.115 ","End":"02:40.940","Text":"The easiest way is to use a calculator to work"},{"Start":"02:40.940 ","End":"02:46.400","Text":"out what the maximum negative number is that I can store in 32 bits."},{"Start":"02:46.400 ","End":"02:49.790","Text":"You\u0027ll recall that there is a formula for this,"},{"Start":"02:49.790 ","End":"02:59.505","Text":"2^n-1 will give us the largest negative value you can store in a variable."},{"Start":"02:59.505 ","End":"03:03.105","Text":"In this case, n will be 32,"},{"Start":"03:03.105 ","End":"03:06.040","Text":"n minus 1 is going to be 31,"},{"Start":"03:06.080 ","End":"03:13.535","Text":"2^31 gives us 2147483648."},{"Start":"03:13.535 ","End":"03:16.354","Text":"That\u0027s what I\u0027m going to need to store in my variable."},{"Start":"03:16.354 ","End":"03:24.000","Text":"Let\u0027s put that value in, 2147483648,"},{"Start":"03:24.430 ","End":"03:27.920","Text":"except I forgot it\u0027s supposed to be a negative value,"},{"Start":"03:27.920 ","End":"03:32.900","Text":"so I need to put p sign in front of it and if I don\u0027t put a semicolon in,"},{"Start":"03:32.900 ","End":"03:38.315","Text":"it will put the value in and it will reflect it back to me if it was successfully stored."},{"Start":"03:38.315 ","End":"03:41.300","Text":"It does, so that\u0027s great."},{"Start":"03:41.300 ","End":"03:46.390","Text":"I know I can store that very large number into an int datatype."},{"Start":"03:46.390 ","End":"03:48.550","Text":"My variable called myInt,"},{"Start":"03:48.550 ","End":"03:52.565","Text":"now has a very large negative number in it,"},{"Start":"03:52.565 ","End":"03:59.435","Text":"and that\u0027s the most negative number I can store in an int datatype."},{"Start":"03:59.435 ","End":"04:04.595","Text":"As I said, we saw the formula for this back in Topic 1,"},{"Start":"04:04.595 ","End":"04:07.940","Text":"for signed numbers and 2s complement,"},{"Start":"04:07.940 ","End":"04:10.910","Text":"2^n-1, gives us"},{"Start":"04:10.910 ","End":"04:13.910","Text":"the largest negative value I"},{"Start":"04:13.910 ","End":"04:17.210","Text":"can have given a particular number of bits, so that\u0027s great."},{"Start":"04:17.210 ","End":"04:20.390","Text":"That\u0027s Part A and B done,"},{"Start":"04:20.390 ","End":"04:23.000","Text":"and C as well because it\u0027s reflected back."},{"Start":"04:23.000 ","End":"04:27.275","Text":"But if you want, I can type it out and it will give me the value again."},{"Start":"04:27.275 ","End":"04:29.585","Text":"Now, in Part D,"},{"Start":"04:29.585 ","End":"04:36.180","Text":"it\u0027s asked me to store the maximum positive value in myInt and check that it was stored."},{"Start":"04:36.180 ","End":"04:39.725","Text":"Surely that\u0027s just the case of flipping a bit, isn\u0027t it?"},{"Start":"04:39.725 ","End":"04:42.450","Text":"Flipping the sign, I should say."},{"Start":"04:42.450 ","End":"04:45.765","Text":"However, what you\u0027ll find if you try that,"},{"Start":"04:45.765 ","End":"04:49.159","Text":"is it says integer number too large."},{"Start":"04:49.159 ","End":"04:56.840","Text":"The reason for this is that signed 2s complement numbers are actually not symmetrical."},{"Start":"04:56.840 ","End":"05:03.230","Text":"You can store slightly more negative values than you can positive values."},{"Start":"05:03.230 ","End":"05:04.940","Text":"The formula actually goes,"},{"Start":"05:04.940 ","End":"05:12.774","Text":"the range from negative to positive is 2^n-1 on the negative side,"},{"Start":"05:12.774 ","End":"05:16.610","Text":"but on the positive side it\u0027s 2^n-1,"},{"Start":"05:16.610 ","End":"05:20.480","Text":"and then we subtract 1 from that number."},{"Start":"05:20.480 ","End":"05:24.150","Text":"Actually, the largest positive number I can store,"},{"Start":"05:24.150 ","End":"05:27.725","Text":"is going to be what I just attempted to store in there,"},{"Start":"05:27.725 ","End":"05:30.720","Text":"but I\u0027m going to have to take 1 off it,"},{"Start":"05:30.720 ","End":"05:40.850","Text":"so 47483647 is the largest positive number"},{"Start":"05:40.850 ","End":"05:42.350","Text":"I can store into an int."},{"Start":"05:42.350 ","End":"05:44.705","Text":"Let\u0027s try that. Sure enough,"},{"Start":"05:44.705 ","End":"05:48.335","Text":"it\u0027s happy, and it\u0027s allowed me to store it,"},{"Start":"05:48.335 ","End":"05:54.420","Text":"so 242147483648 gave me an error,"},{"Start":"05:54.420 ","End":"05:57.529","Text":"the integer number is too large."},{"Start":"05:57.529 ","End":"05:59.570","Text":"But when I took 1 off it,"},{"Start":"05:59.570 ","End":"06:01.355","Text":"it did allow me to store that."},{"Start":"06:01.355 ","End":"06:06.725","Text":"As I said, the reason for that is the formula that we looked at in Topic 1,"},{"Start":"06:06.725 ","End":"06:12.035","Text":"which shows you the range of a 2s complement number,"},{"Start":"06:12.035 ","End":"06:15.185","Text":"and it\u0027s not symmetrical across 0,"},{"Start":"06:15.185 ","End":"06:19.825","Text":"and you can have slightly more negative numbers then positive numbers."},{"Start":"06:19.825 ","End":"06:21.715","Text":"That\u0027s great, that done."},{"Start":"06:21.715 ","End":"06:26.650","Text":"Now, in Part E it says with this maximum positive value stored,"},{"Start":"06:26.650 ","End":"06:30.670","Text":"type the following, which will add 1 to the contents of the variable."},{"Start":"06:30.670 ","End":"06:36.520","Text":"I\u0027m going to type exactly what we were asked to type in exactly the same order."},{"Start":"06:36.520 ","End":"06:39.250","Text":"Looks slightly strange, we haven\u0027t seen this before and we\u0027ll come"},{"Start":"06:39.250 ","End":"06:42.355","Text":"across the explanation for this in the next topic."},{"Start":"06:42.355 ","End":"06:49.068","Text":"But for now, we just want to see what the effect of this line will be on our variable."},{"Start":"06:49.068 ","End":"06:50.470","Text":"Off we go."},{"Start":"06:50.470 ","End":"06:56.130","Text":"Now, myInt has been reflected back to me and weirdly,"},{"Start":"06:56.130 ","End":"07:03.105","Text":"I\u0027ve added 1 to this positive number and what I\u0027ve got is a negative number,"},{"Start":"07:03.105 ","End":"07:07.030","Text":"and I\u0027m being asked to explain why that happens."},{"Start":"07:07.030 ","End":"07:14.905","Text":"Well, what happens when you try and increment a number that is already a maximum,"},{"Start":"07:14.905 ","End":"07:23.769","Text":"is it will wrap around to the largest negative value that\u0027s available in the datatype."},{"Start":"07:23.769 ","End":"07:29.305","Text":"When I added 1 onto 2147483647,"},{"Start":"07:29.305 ","End":"07:31.580","Text":"it made it overflow,"},{"Start":"07:31.580 ","End":"07:34.350","Text":"essentially the size of that variable,"},{"Start":"07:34.350 ","End":"07:39.199","Text":"and it went to the largest negative value that was possible."},{"Start":"07:39.199 ","End":"07:47.495","Text":"That\u0027s why I see minus 2147483648 stored."},{"Start":"07:47.495 ","End":"07:50.685","Text":"Very strange seeming results,"},{"Start":"07:50.685 ","End":"07:57.925","Text":"I\u0027m adding 1 to the largest possible number and I\u0027m getting the largest negative number."},{"Start":"07:57.925 ","End":"08:00.090","Text":"Very odd. If I kept on repeating that,"},{"Start":"08:00.090 ","End":"08:01.605","Text":"you could see what happens."},{"Start":"08:01.605 ","End":"08:03.150","Text":"That\u0027s working fine,"},{"Start":"08:03.150 ","End":"08:04.655","Text":"that makes sense, doesn\u0027t it?"},{"Start":"08:04.655 ","End":"08:10.055","Text":"The number is getting less negative as I keep adding 1 onto it."},{"Start":"08:10.055 ","End":"08:16.610","Text":"But when I had the large positive value and it was as big as it could possibly be,"},{"Start":"08:16.610 ","End":"08:19.085","Text":"when I tried to add 1 more,"},{"Start":"08:19.085 ","End":"08:21.360","Text":"it went to a negative value,"},{"Start":"08:21.360 ","End":"08:23.915","Text":"so this is something programmers need to be aware of."},{"Start":"08:23.915 ","End":"08:26.300","Text":"You can actually overflow the size of"},{"Start":"08:26.300 ","End":"08:30.350","Text":"a variable and you\u0027ll get some fairly strange things happening."},{"Start":"08:30.350 ","End":"08:32.765","Text":"Essentially, if once you go past"},{"Start":"08:32.765 ","End":"08:38.165","Text":"the highest positive number that can be stored in a certain size variable,"},{"Start":"08:38.165 ","End":"08:42.240","Text":"you will start going into the negative range and that will play"},{"Start":"08:42.240 ","End":"08:46.610","Text":"havoc with your calculations and your program in general."},{"Start":"08:46.610 ","End":"08:48.420","Text":"Just be aware of that issue,"},{"Start":"08:48.420 ","End":"08:53.060","Text":"that variables can only store data of a certain size,"},{"Start":"08:53.060 ","End":"08:57.335","Text":"and if you try and break that limit,"},{"Start":"08:57.335 ","End":"09:00.380","Text":"you\u0027re going to have some strange effects going on."},{"Start":"09:00.380 ","End":"09:04.785","Text":"That\u0027s really what this exercise was illustrating."},{"Start":"09:04.785 ","End":"09:08.770","Text":"That\u0027s us done for Question 3."},{"Start":"09:08.770 ","End":"09:10.600","Text":"I\u0027ll see you shortly,"},{"Start":"09:10.600 ","End":"09:18.180","Text":"and we\u0027ll move on to even bigger integers in the next question. See you then."}],"ID":27344},{"Watched":false,"Name":"Exercise 4","Duration":"8m 36s","ChapterTopicVideoID":26438,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:05.040","Text":"Hello, again. Welcome back to this next video where we\u0027ve been asked to continue on in"},{"Start":"00:05.040 ","End":"00:07.980","Text":"the code pad and to create a new variable called"},{"Start":"00:07.980 ","End":"00:11.595","Text":"myLong this time to store a long integer."},{"Start":"00:11.595 ","End":"00:16.657","Text":"Then in part b, we\u0027ve been asked to store into myLong the number 2,"},{"Start":"00:16.657 ","End":"00:18.725","Text":"147, 483,"},{"Start":"00:18.725 ","End":"00:21.945","Text":"648, and we\u0027ve been given a little hint here."},{"Start":"00:21.945 ","End":"00:25.260","Text":"Then in Part c, we\u0027ve been asked to check that the number"},{"Start":"00:25.260 ","End":"00:28.380","Text":"we expect is stored in myLong,"},{"Start":"00:28.380 ","End":"00:30.330","Text":"and in Part d,"},{"Start":"00:30.330 ","End":"00:36.060","Text":"then to store the maximum positive number that is possible into myLong."},{"Start":"00:36.060 ","End":"00:39.710","Text":"Then to speculate on what would happen in Part e,"},{"Start":"00:39.710 ","End":"00:43.280","Text":"if we were to add 1 to that value that we stored in Part d,"},{"Start":"00:43.280 ","End":"00:48.890","Text":"what would we expect to happen if we did add 1 to this maximum positive number possible?"},{"Start":"00:48.890 ","End":"00:51.695","Text":"We\u0027ve been asked in Part a to create"},{"Start":"00:51.695 ","End":"00:56.405","Text":"a new variable called myLong to store a long integer."},{"Start":"00:56.405 ","End":"00:59.765","Text":"That first part is pretty straightforward."},{"Start":"00:59.765 ","End":"01:02.389","Text":"Give the data type which is now going to be long,"},{"Start":"01:02.389 ","End":"01:06.215","Text":"not int or byte because it\u0027s a long integer,"},{"Start":"01:06.215 ","End":"01:09.360","Text":"which means it\u0027s got more memory,"},{"Start":"01:09.360 ","End":"01:11.850","Text":"so it can store a larger number."},{"Start":"01:11.850 ","End":"01:16.710","Text":"In Java, that will be 64 bits but it\u0027s a signed number,"},{"Start":"01:16.710 ","End":"01:19.880","Text":"so will be 63 bits."},{"Start":"01:19.880 ","End":"01:23.300","Text":"In terms of the size of the magnitude of"},{"Start":"01:23.300 ","End":"01:26.330","Text":"the number and one bit will be given up"},{"Start":"01:26.330 ","End":"01:30.215","Text":"to the fact that it\u0027s negative and positive numbers."},{"Start":"01:30.215 ","End":"01:34.655","Text":"Let\u0027s put my name identifier of this variable,"},{"Start":"01:34.655 ","End":"01:36.200","Text":"which I\u0027ve been asked to call it myLong."},{"Start":"01:36.200 ","End":"01:40.580","Text":"I\u0027m not going to put anything in there at the moment but it will"},{"Start":"01:40.580 ","End":"01:45.485","Text":"probably be initialized to 0 as before and so it is."},{"Start":"01:45.485 ","End":"01:47.150","Text":"Let\u0027s have a look at Part b,"},{"Start":"01:47.150 ","End":"01:51.180","Text":"which looks very straightforward and the same as what we\u0027ve seen before."},{"Start":"01:51.200 ","End":"01:59.670","Text":"Try and store into myLong 2147483648."},{"Start":"02:00.020 ","End":"02:02.755","Text":"Remember, we don\u0027t put any commas,"},{"Start":"02:02.755 ","End":"02:05.225","Text":"if we try to do that we\u0027d get an error."},{"Start":"02:05.225 ","End":"02:09.185","Text":"But obviously, when you\u0027re reading from worksheets and so on,"},{"Start":"02:09.185 ","End":"02:16.505","Text":"we find it easy to see the number or digits by separating them with commas and so on."},{"Start":"02:16.505 ","End":"02:19.100","Text":"Let\u0027s try that and see what happens."},{"Start":"02:19.100 ","End":"02:22.729","Text":"I get an error saying integer number too large."},{"Start":"02:22.729 ","End":"02:25.055","Text":"Now, why would that be the case?"},{"Start":"02:25.055 ","End":"02:29.449","Text":"When a long has much more bits"},{"Start":"02:29.449 ","End":"02:34.835","Text":"available and therefore should be able to store a much larger number than an int."},{"Start":"02:34.835 ","End":"02:42.515","Text":"You\u0027ll recall that we were able to store in an int 2147483647."},{"Start":"02:42.515 ","End":"02:47.645","Text":"Only very slightly smaller than this number that we\u0027ve been trying to make, one less."},{"Start":"02:47.645 ","End":"02:54.315","Text":"We\u0027ve just added 1 on and I\u0027ve got twice as much space to store in a long."},{"Start":"02:54.315 ","End":"02:56.300","Text":"Why would it be an error?"},{"Start":"02:56.300 ","End":"02:59.840","Text":"The answer is in the hint here for Part b."},{"Start":"02:59.840 ","End":"03:04.040","Text":"Because I\u0027ve typed in a number here,"},{"Start":"03:04.040 ","End":"03:07.430","Text":"it\u0027s assuming that I\u0027ve typed in an integer."},{"Start":"03:07.430 ","End":"03:12.470","Text":"Whenever you type a literal into the code pad and in fact,"},{"Start":"03:12.470 ","End":"03:13.970","Text":"in the Java system in general,"},{"Start":"03:13.970 ","End":"03:16.700","Text":"when I\u0027ve got that in a line of a program,"},{"Start":"03:16.700 ","End":"03:21.210","Text":"it assumes that literal is going to be an integer."},{"Start":"03:21.590 ","End":"03:23.840","Text":"It\u0027s basically saying, well,"},{"Start":"03:23.840 ","End":"03:30.230","Text":"I can\u0027t have an integer that big because integers can only be 31 bits long."},{"Start":"03:30.230 ","End":"03:33.649","Text":"What I have to do is I have to tell Java,"},{"Start":"03:33.649 ","End":"03:38.005","Text":"no, this literal is not an integer, it\u0027s a long."},{"Start":"03:38.005 ","End":"03:42.650","Text":"The thing that you need to do is simply stick an L"},{"Start":"03:42.650 ","End":"03:49.010","Text":"after the number and the L when it\u0027s picked up by the compiler or in the code pad,"},{"Start":"03:49.010 ","End":"03:55.385","Text":"in this instance, will indicate that this is a literal which is not an integer."},{"Start":"03:55.385 ","End":"03:57.215","Text":"It won\u0027t make that assumption anymore."},{"Start":"03:57.215 ","End":"04:04.585","Text":"It will say, this is still a literal but it\u0027s actually going to be interpreted as a long."},{"Start":"04:04.585 ","End":"04:06.815","Text":"If I press Enter now,"},{"Start":"04:06.815 ","End":"04:08.840","Text":"it\u0027s happy this time,"},{"Start":"04:08.840 ","End":"04:10.790","Text":"it doesn\u0027t give me an error message."},{"Start":"04:10.790 ","End":"04:14.345","Text":"It does successfully store this number."},{"Start":"04:14.345 ","End":"04:21.995","Text":"Literally, all I did was add the character L onto the end of this literal, L for long."},{"Start":"04:21.995 ","End":"04:24.860","Text":"It would work if it was a lowercase l as well,"},{"Start":"04:24.860 ","End":"04:27.380","Text":"by the way, but that looks a bit like a 1,"},{"Start":"04:27.380 ","End":"04:33.320","Text":"which is why I\u0027ve used the L. It\u0027s happy enough and it\u0027s stored this number,"},{"Start":"04:33.320 ","End":"04:38.450","Text":"which is only one larger than the maximum integer I could have stored in an integer."},{"Start":"04:38.450 ","End":"04:43.625","Text":"But it is larger and it is successfully stored into the variable."},{"Start":"04:43.625 ","End":"04:47.225","Text":"That\u0027s Part b, it looked deceptively simple."},{"Start":"04:47.225 ","End":"04:49.115","Text":"But for this little issue,"},{"Start":"04:49.115 ","End":"04:51.845","Text":"we\u0027ve explained why that happens."},{"Start":"04:51.845 ","End":"04:54.680","Text":"Essentially, all literals that you type"},{"Start":"04:54.680 ","End":"04:57.440","Text":"into a Java program are going to be assumed to be"},{"Start":"04:57.440 ","End":"05:04.200","Text":"integers unless you tell the system otherwise by sticking an L on the end."},{"Start":"05:04.200 ","End":"05:12.085","Text":"Great. What about the maximum positive number that we can store into myLong."},{"Start":"05:12.085 ","End":"05:13.620","Text":"Well, longs,"},{"Start":"05:13.620 ","End":"05:14.825","Text":"as we said before,"},{"Start":"05:14.825 ","End":"05:17.600","Text":"are stored in 64 bits."},{"Start":"05:17.600 ","End":"05:20.540","Text":"It\u0027s a 63-bit signed number,"},{"Start":"05:20.540 ","End":"05:29.243","Text":"so 2^63 is what I\u0027m looking for as the maximum number,"},{"Start":"05:29.243 ","End":"05:31.580","Text":"so let\u0027s think about what that might be."},{"Start":"05:31.580 ","End":"05:33.680","Text":"If I use the calculator,"},{"Start":"05:33.680 ","End":"05:36.470","Text":"I\u0027d find it\u0027s a huge number,"},{"Start":"05:36.470 ","End":"05:42.090","Text":"which I\u0027m going to type in, it\u0027ll be 9223372036854775808."},{"Start":"05:51.410 ","End":"05:55.730","Text":"That would have caused an error."},{"Start":"05:55.730 ","End":"05:57.500","Text":"I need to put the equal sign."},{"Start":"05:57.500 ","End":"06:02.720","Text":"However, remember that when we are dealing with a signed number and"},{"Start":"06:02.720 ","End":"06:08.390","Text":"the range in this complement is 2^n minus 1 on the negative side,"},{"Start":"06:08.390 ","End":"06:15.525","Text":"and 2^n minus 1 and that number should have 1 subtracted from it as well."},{"Start":"06:15.525 ","End":"06:19.785","Text":"I can\u0027t put 808 in but I can put 807 in."},{"Start":"06:19.785 ","End":"06:26.225","Text":"Again, I\u0027ve got to put an L on the end just to indicate that this is a long,"},{"Start":"06:26.225 ","End":"06:30.545","Text":"not an integer literal L, fantastic."},{"Start":"06:30.545 ","End":"06:33.000","Text":"It seems to have stored it."},{"Start":"06:33.000 ","End":"06:37.010","Text":"I\u0027ve got this incredibly a long series of digits,"},{"Start":"06:37.010 ","End":"06:38.540","Text":"hence the name long,"},{"Start":"06:38.540 ","End":"06:45.500","Text":"so I can store a much larger integer value into a long than I could into an integer."},{"Start":"06:45.500 ","End":"06:46.760","Text":"Remember in an integer,"},{"Start":"06:46.760 ","End":"06:54.070","Text":"the maximum positive value I could store was 2147483647,"},{"Start":"06:54.070 ","End":"06:56.255","Text":"1 less than this value."},{"Start":"06:56.255 ","End":"07:01.565","Text":"But now I\u0027ve got a massive number of digits that I\u0027ve been able to store."},{"Start":"07:01.565 ","End":"07:04.460","Text":"That is us done up to"},{"Start":"07:04.460 ","End":"07:11.015","Text":"Part d. We\u0027ve been asked the question if we add 1 to the value stored here,"},{"Start":"07:11.015 ","End":"07:13.955","Text":"what would we expect to happen?"},{"Start":"07:13.955 ","End":"07:17.330","Text":"Well, I hope you can guess what would happen but we could"},{"Start":"07:17.330 ","End":"07:21.485","Text":"actually try and add 1 to the value."},{"Start":"07:21.485 ","End":"07:24.860","Text":"If I put plus equal to 1 here,"},{"Start":"07:24.860 ","End":"07:30.030","Text":"I\u0027m going to add 1 to what is already stored in myLong and I\u0027m going to see what"},{"Start":"07:30.030 ","End":"07:35.000","Text":"happens and I assume the same thing is going to happen as what happened for integers,"},{"Start":"07:35.000 ","End":"07:37.340","Text":"and that they overflowed and we\u0027ve got"},{"Start":"07:37.340 ","End":"07:41.445","Text":"a large negative number and that\u0027s exactly what happened."},{"Start":"07:41.445 ","End":"07:45.920","Text":"I\u0027ve now seen the largest possible negative number that"},{"Start":"07:45.920 ","End":"07:50.210","Text":"can be stored in a long and it\u0027s that,"},{"Start":"07:50.210 ","End":"07:54.230","Text":"and the reason is exactly the same as the ones for integers."},{"Start":"07:54.230 ","End":"07:58.130","Text":"I\u0027ve overflowed the size I have available and"},{"Start":"07:58.130 ","End":"08:02.135","Text":"if I try and add 1 to the already highest value,"},{"Start":"08:02.135 ","End":"08:04.250","Text":"it goes into a negative value."},{"Start":"08:04.250 ","End":"08:06.275","Text":"The same thing happens with an integer."},{"Start":"08:06.275 ","End":"08:09.140","Text":"Even though a long can store a much larger number"},{"Start":"08:09.140 ","End":"08:12.525","Text":"even a long is eventually going to overflow,"},{"Start":"08:12.525 ","End":"08:15.710","Text":"so you always have to be aware of what"},{"Start":"08:15.710 ","End":"08:19.805","Text":"the maximum value is going to be stored in a variable."},{"Start":"08:19.805 ","End":"08:24.005","Text":"If you don\u0027t, you\u0027re going to have some strange effects on your program."},{"Start":"08:24.005 ","End":"08:29.420","Text":"That\u0027s us done with all of the different various types of integers."},{"Start":"08:29.420 ","End":"08:30.695","Text":"Actually, there\u0027s one missing,"},{"Start":"08:30.695 ","End":"08:34.055","Text":"but that will come up in the next video."},{"Start":"08:34.055 ","End":"08:37.590","Text":"I\u0027ll see you in that one. Thanks again."}],"ID":27345},{"Watched":false,"Name":"Exercise 5","Duration":"14m 4s","ChapterTopicVideoID":26437,"CourseChapterTopicPlaylistID":237669,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.400","Text":"Hey. Welcome back."},{"Start":"00:02.400 ","End":"00:06.735","Text":"We\u0027re going to work on a slightly more open-ended exercise this time."},{"Start":"00:06.735 ","End":"00:11.580","Text":"We\u0027ve been asked to create 4 more different variables using"},{"Start":"00:11.580 ","End":"00:13.995","Text":"the remaining primitives available in Java"},{"Start":"00:13.995 ","End":"00:17.280","Text":"that we haven\u0027t already used in the previous exercises."},{"Start":"00:17.280 ","End":"00:20.535","Text":"Then in part B, we\u0027ve been asked to give each variable"},{"Start":"00:20.535 ","End":"00:23.715","Text":"a sensible name and to use a mixture of styles."},{"Start":"00:23.715 ","End":"00:26.250","Text":"We know about camel case, snake case,"},{"Start":"00:26.250 ","End":"00:28.830","Text":"capital camel case, and capital snake case."},{"Start":"00:28.830 ","End":"00:31.980","Text":"We should try and use a mixture of those different styles"},{"Start":"00:31.980 ","End":"00:35.745","Text":"for each of those 4 different variables that we\u0027ll be creating."},{"Start":"00:35.745 ","End":"00:41.580","Text":"We\u0027ve also been asked to store values into each of those variables to see the effect."},{"Start":"00:41.580 ","End":"00:45.380","Text":"Then to try and cause an error by attempting to"},{"Start":"00:45.380 ","End":"00:49.700","Text":"store an illegal value in each of those variables."},{"Start":"00:49.700 ","End":"00:56.660","Text":"Let\u0027s start with 1 of the integer data types which we haven\u0027t used yet, which is short."},{"Start":"00:56.660 ","End":"00:59.105","Text":"The ones we have used are int,"},{"Start":"00:59.105 ","End":"01:00.860","Text":"which is 32 bits,"},{"Start":"01:00.860 ","End":"01:03.430","Text":"long, which is 64 bits,"},{"Start":"01:03.430 ","End":"01:05.535","Text":"byte, which is 8 bits,"},{"Start":"01:05.535 ","End":"01:08.855","Text":"short is between an integer and a byte,"},{"Start":"01:08.855 ","End":"01:10.835","Text":"so it\u0027s only 16 bits."},{"Start":"01:10.835 ","End":"01:14.035","Text":"The data type we need is short."},{"Start":"01:14.035 ","End":"01:16.050","Text":"Let\u0027s give it a name."},{"Start":"01:16.050 ","End":"01:20.240","Text":"I\u0027m going to use snake case, all lowercase."},{"Start":"01:20.240 ","End":"01:24.365","Text":"Remember, snake case is an underscore symbol used"},{"Start":"01:24.365 ","End":"01:29.670","Text":"to separate each word within the identifier of the variable name."},{"Start":"01:29.670 ","End":"01:32.310","Text":"For example, if I\u0027ve got a 2-player game,"},{"Start":"01:32.310 ","End":"01:34.440","Text":"I\u0027ve got Player 1 and Player 2,"},{"Start":"01:34.440 ","End":"01:36.750","Text":"I can call 1 of those variables,"},{"Start":"01:36.750 ","End":"01:41.045","Text":"player_one_score, if I need 2 variables to keep track of scores."},{"Start":"01:41.045 ","End":"01:45.350","Text":"There we go. That\u0027s creating the variable which is of"},{"Start":"01:45.350 ","End":"01:50.800","Text":"type short and has a identify a player_one_score."},{"Start":"01:51.710 ","End":"01:54.570","Text":"Let\u0027s give it some values."},{"Start":"01:54.570 ","End":"01:56.210","Text":"Because it\u0027s an integer,"},{"Start":"01:56.210 ","End":"01:58.450","Text":"I should be able to give it a number."},{"Start":"01:58.450 ","End":"02:03.090","Text":"I will need take out the short there first."},{"Start":"02:03.090 ","End":"02:07.760","Text":"There we go. Player_one_score is given a value of 1234, and it\u0027s quite happy with that."},{"Start":"02:07.760 ","End":"02:09.635","Text":"Let\u0027s try a bigger value."},{"Start":"02:09.635 ","End":"02:14.830","Text":"Straightaway, I hit an error because I\u0027ve presumably put"},{"Start":"02:14.830 ","End":"02:16.940","Text":"in a number that\u0027s too big and it is telling"},{"Start":"02:16.940 ","End":"02:19.520","Text":"us possible lossy conversion from int to short."},{"Start":"02:19.520 ","End":"02:20.750","Text":"As we saw before,"},{"Start":"02:20.750 ","End":"02:24.125","Text":"literals are assumed to be integers,"},{"Start":"02:24.125 ","End":"02:27.650","Text":"and that\u0027s why it always gives this type of error message when it\u0027s trying to convert"},{"Start":"02:27.650 ","End":"02:31.460","Text":"down the literal we\u0027ve typed in is assumed to be an int."},{"Start":"02:31.460 ","End":"02:37.415","Text":"In this case, we can\u0027t store an integer this large into 16 bits."},{"Start":"02:37.415 ","End":"02:40.085","Text":"Remember, it\u0027s 16 bits but it\u0027s signed,"},{"Start":"02:40.085 ","End":"02:46.455","Text":"so that means it\u0027s actually 15 bits and minus 1 in the positive direction."},{"Start":"02:46.455 ","End":"02:50.870","Text":"Remember, it\u0027s 2^n minus 1 on the negative side,"},{"Start":"02:50.870 ","End":"02:53.975","Text":"and it\u0027s 2^n minus 1 on the positive side."},{"Start":"02:53.975 ","End":"02:56.720","Text":"The biggest number I can actually represent"},{"Start":"02:56.720 ","End":"03:03.035","Text":"is the highest number I can store in 15 bits, which is 32767."},{"Start":"03:03.035 ","End":"03:05.910","Text":"Let\u0027s try that, and sure enough,"},{"Start":"03:05.910 ","End":"03:07.110","Text":"it\u0027s happy with that."},{"Start":"03:07.110 ","End":"03:11.250","Text":"Just to test it, I\u0027ll add 1 onto that to see if it complains,"},{"Start":"03:11.250 ","End":"03:12.585","Text":"and it does,"},{"Start":"03:12.585 ","End":"03:18.495","Text":"so I\u0027ve reached the limit of numbers I can store in a short."},{"Start":"03:18.495 ","End":"03:21.110","Text":"Let\u0027s try it in the negative direction."},{"Start":"03:21.110 ","End":"03:24.980","Text":"I should be out to store 32768 because remember I\u0027m allowed to"},{"Start":"03:24.980 ","End":"03:29.575","Text":"store 1 more in the negative direction than I can in the positive direction."},{"Start":"03:29.575 ","End":"03:31.340","Text":"It complains about that."},{"Start":"03:31.340 ","End":"03:33.530","Text":"Interesting because I\u0027ve got an extra,"},{"Start":"03:33.530 ","End":"03:37.205","Text":"extra digit in there that\u0027s better, 32768."},{"Start":"03:37.205 ","End":"03:41.120","Text":"There we go, 32768 on the negative side is fine."},{"Start":"03:41.120 ","End":"03:43.310","Text":"If I tried 32769,"},{"Start":"03:43.310 ","End":"03:47.225","Text":"it would complain, and it has."},{"Start":"03:47.225 ","End":"03:51.140","Text":"We\u0027ve done parts A to D for a short."},{"Start":"03:51.140 ","End":"03:54.460","Text":"Let\u0027s try for chars now."},{"Start":"03:54.460 ","End":"04:00.150","Text":"A char data type clearly starts with the data type which is called char."},{"Start":"04:00.150 ","End":"04:07.800","Text":"Now, let\u0027s use capital snake case for the variable name."},{"Start":"04:07.800 ","End":"04:13.235","Text":"It\u0027s all capitals, but I\u0027m still using under scores to separate the words."},{"Start":"04:13.235 ","End":"04:17.225","Text":"When you tend to use capitals snake case for constants,"},{"Start":"04:17.225 ","End":"04:19.985","Text":"something is not going to change in your program."},{"Start":"04:19.985 ","End":"04:23.060","Text":"Let\u0027s say we had a special char that we set up once at"},{"Start":"04:23.060 ","End":"04:26.300","Text":"the beginning of our program and it never changes again but I do"},{"Start":"04:26.300 ","End":"04:29.030","Text":"want it to store it in a variable just for"},{"Start":"04:29.030 ","End":"04:32.645","Text":"ease of reading my program and ease of maintaining it,"},{"Start":"04:32.645 ","End":"04:35.420","Text":"then it\u0027s a good convention to use."},{"Start":"04:35.420 ","End":"04:39.260","Text":"Most programs will do capital snake case in that."},{"Start":"04:39.260 ","End":"04:40.985","Text":"Here we go, special char,"},{"Start":"04:40.985 ","End":"04:42.170","Text":"and I can just put a char,"},{"Start":"04:42.170 ","End":"04:46.205","Text":"and note chars start with a single quote,"},{"Start":"04:46.205 ","End":"04:48.965","Text":"and then I can put the letter that I want to store."},{"Start":"04:48.965 ","End":"04:51.785","Text":"In fact, let me just define the variable first."},{"Start":"04:51.785 ","End":"04:53.660","Text":"There we go. There\u0027s my variable."},{"Start":"04:53.660 ","End":"04:58.100","Text":"Let us see what this default value is inside my variable. There we go."},{"Start":"04:58.100 ","End":"05:04.625","Text":"Is stored what\u0027s called a null character into special char by default in Java."},{"Start":"05:04.625 ","End":"05:09.681","Text":"In some languages, the null char is used to end the string,"},{"Start":"05:09.681 ","End":"05:12.260","Text":"so every string will end in a null char."},{"Start":"05:12.260 ","End":"05:16.925","Text":"That\u0027s just a character which has an integer value of 0."},{"Start":"05:16.925 ","End":"05:21.890","Text":"Now, let\u0027s actually store something in a variable. Here we go."},{"Start":"05:21.890 ","End":"05:23.090","Text":"I\u0027m going to store the letter a,"},{"Start":"05:23.090 ","End":"05:26.585","Text":"lowercase a, and it has no problem with that."},{"Start":"05:26.585 ","End":"05:28.370","Text":"Let\u0027s try A."},{"Start":"05:28.370 ","End":"05:29.930","Text":"No problem with that either."},{"Start":"05:29.930 ","End":"05:31.700","Text":"What if I put 2 letters?"},{"Start":"05:31.700 ","End":"05:34.490","Text":"Can\u0027t do that. It doesn\u0027t understand why I\u0027ve put"},{"Start":"05:34.490 ","End":"05:38.780","Text":"2 letters because obviously a char can only store 1 letter."},{"Start":"05:38.780 ","End":"05:41.915","Text":"It\u0027s a string that stores multiple letters."},{"Start":"05:41.915 ","End":"05:45.065","Text":"Then I go back to lowercase z, happy with that."},{"Start":"05:45.065 ","End":"05:47.740","Text":"Let\u0027s try another symbol like @,"},{"Start":"05:47.740 ","End":"05:49.370","Text":"it\u0027s happy with that as well."},{"Start":"05:49.370 ","End":"05:53.480","Text":"Even store non-printing symbols like newline,"},{"Start":"05:53.480 ","End":"05:58.170","Text":"which uses the escape code slash and then n. It\u0027s happy with that,"},{"Start":"05:58.170 ","End":"06:00.105","Text":"and t, it will do as well."},{"Start":"06:00.105 ","End":"06:02.960","Text":"Happy with that. I think I should be able to store"},{"Start":"06:02.960 ","End":"06:08.180","Text":"the null character like I had earlier, then that as well."},{"Start":"06:08.180 ","End":"06:11.180","Text":"Now, you\u0027ll notice here it\u0027s got a /u in front."},{"Start":"06:11.180 ","End":"06:14.690","Text":"That\u0027s the Unicode representation of a string."},{"Start":"06:14.690 ","End":"06:16.490","Text":"That\u0027s quite fun to play around with."},{"Start":"06:16.490 ","End":"06:19.445","Text":"If I try, it has to be /u,"},{"Start":"06:19.445 ","End":"06:23.060","Text":"and then what\u0027s going to follow is 4 hexadecimal digits,"},{"Start":"06:23.060 ","End":"06:27.140","Text":"and if I know a code for a particular character,"},{"Start":"06:27.140 ","End":"06:30.215","Text":"I can put in the Unicode value for that character."},{"Start":"06:30.215 ","End":"06:34.505","Text":"I happen to know that the UK pound symbol is"},{"Start":"06:34.505 ","End":"06:39.080","Text":"A3 in the Unicode character tables. Let\u0027s try that."},{"Start":"06:39.080 ","End":"06:43.220","Text":"Sure enough it\u0027s stored a pound symbol into special char."},{"Start":"06:43.220 ","End":"06:50.255","Text":"Now, you can obviously go up to very large 16-bit values here in this 4 characters."},{"Start":"06:50.255 ","End":"06:54.755","Text":"Let\u0027s try something a bit more esoteric."},{"Start":"06:54.755 ","End":"06:57.330","Text":"Let\u0027s try 266b,"},{"Start":"06:57.330 ","End":"07:00.025","Text":"happen to know is a special symbol."},{"Start":"07:00.025 ","End":"07:01.180","Text":"There we go."},{"Start":"07:01.180 ","End":"07:03.135","Text":"It\u0027s a musical symbol."},{"Start":"07:03.135 ","End":"07:05.805","Text":"Brilliant. That\u0027s char is done."},{"Start":"07:05.805 ","End":"07:09.440","Text":"I\u0027ve also managed to generate an error."},{"Start":"07:09.440 ","End":"07:12.605","Text":"Let me try 1 more. What if I put another symbol in here?"},{"Start":"07:12.605 ","End":"07:15.995","Text":"Rather than 4 hexadecimal characters,"},{"Start":"07:15.995 ","End":"07:19.890","Text":"let\u0027s put 5 hexadecimal characters and see what it says."},{"Start":"07:19.890 ","End":"07:21.915","Text":"Let\u0027s put 0 on the end of that."},{"Start":"07:21.915 ","End":"07:24.360","Text":"It basically doesn\u0027t understand it."},{"Start":"07:24.360 ","End":"07:27.665","Text":"It\u0027s saying that I think that\u0027s too long."},{"Start":"07:27.665 ","End":"07:34.800","Text":"When it says unclosed character literal here is expecting to see a closing quote,"},{"Start":"07:34.800 ","End":"07:37.950","Text":"but it sees a 0 instead basically saying,"},{"Start":"07:37.950 ","End":"07:39.900","Text":"I\u0027m getting too many characters."},{"Start":"07:39.900 ","End":"07:43.210","Text":"If I get rid of that one, it stops complaining."},{"Start":"07:43.210 ","End":"07:46.995","Text":"That\u0027s Part A-D done for a char."},{"Start":"07:46.995 ","End":"07:52.845","Text":"There\u0027s only 2 primitives left and they are the real number data types."},{"Start":"07:52.845 ","End":"07:57.750","Text":"In Java, those real number data types called float and double."},{"Start":"07:57.750 ","End":"08:02.145","Text":"Float uses 32 bits to store a floating point number,"},{"Start":"08:02.145 ","End":"08:06.945","Text":"and double uses 64 bits to store a floating point number."},{"Start":"08:06.945 ","End":"08:08.415","Text":"Let\u0027s go with that."},{"Start":"08:08.415 ","End":"08:10.560","Text":"Let\u0027s try float first."},{"Start":"08:10.560 ","End":"08:13.339","Text":"The datatype is float,"},{"Start":"08:13.339 ","End":"08:17.340","Text":"and let\u0027s give it a CamelCase name."},{"Start":"08:17.340 ","End":"08:21.270","Text":"CamelCase, remember is each new word starts"},{"Start":"08:21.270 ","End":"08:25.070","Text":"with a capital letter to separate the words out. There we go."},{"Start":"08:25.070 ","End":"08:27.575","Text":"I\u0027m going to call myFloat very boring,"},{"Start":"08:27.575 ","End":"08:28.985","Text":"not very descriptive names."},{"Start":"08:28.985 ","End":"08:31.355","Text":"I\u0027m not sure that\u0027s a great example, but there we go."},{"Start":"08:31.355 ","End":"08:35.220","Text":"myFloat, and I\u0027m going to give it a value now."},{"Start":"08:35.220 ","End":"08:36.975","Text":"Here we go with a value,"},{"Start":"08:36.975 ","End":"08:41.755","Text":"myFloat equals and let\u0027s give it this value."},{"Start":"08:41.755 ","End":"08:44.705","Text":"Immediately it complains, it\u0027s not happy."},{"Start":"08:44.705 ","End":"08:47.519","Text":"You might be a guest from the error message,"},{"Start":"08:47.519 ","End":"08:50.285","Text":"possible lossy conversion from double to float."},{"Start":"08:50.285 ","End":"08:52.440","Text":"We saw this with ints and shorts,"},{"Start":"08:52.440 ","End":"08:54.060","Text":"and ints and longs."},{"Start":"08:54.060 ","End":"08:56.345","Text":"So clearly it\u0027s assuming something,"},{"Start":"08:56.345 ","End":"09:01.015","Text":"is saying possible lossy conversion from double to float."},{"Start":"09:01.015 ","End":"09:07.775","Text":"The reason for that is I need to put an F after a literal,"},{"Start":"09:07.775 ","End":"09:09.325","Text":"if it\u0027s a floating point number,"},{"Start":"09:09.325 ","End":"09:12.935","Text":"or D, if it\u0027s a double precision number."},{"Start":"09:12.935 ","End":"09:17.680","Text":"It just needs to know because it can\u0027t tell unless I tell it whether this is"},{"Start":"09:17.680 ","End":"09:22.505","Text":"going to be a float or a double that you are typing in as a literal."},{"Start":"09:22.505 ","End":"09:25.695","Text":"Let\u0027s try that. Now it\u0027s perfectly happy."},{"Start":"09:25.695 ","End":"09:29.955","Text":"Let\u0027s just see how big we can go with this number."},{"Start":"09:29.955 ","End":"09:34.400","Text":"It seems to be able to store quite a few digits. Let\u0027s keep going."},{"Start":"09:34.400 ","End":"09:36.755","Text":"That seems to have stopped there."},{"Start":"09:36.755 ","End":"09:40.050","Text":"That might be something to do with the precision that\u0027s available."},{"Start":"09:40.050 ","End":"09:43.975","Text":"If you remember from the concepts video,"},{"Start":"09:43.975 ","End":"09:47.430","Text":"what we said was that there is a limit"},{"Start":"09:47.430 ","End":"09:51.420","Text":"to the smallest number that can be stored in a float,"},{"Start":"09:51.420 ","End":"09:57.930","Text":"and it\u0027s actually 1.4 times 10 to the minus 45, I think it was."},{"Start":"09:57.930 ","End":"09:59.650","Text":"So let\u0027s try that."},{"Start":"09:59.650 ","End":"10:02.220","Text":"Quite happy with 0.14."},{"Start":"10:02.220 ","End":"10:07.310","Text":"I can put 45 0s in front of this and it should be happy. Let\u0027s try that."},{"Start":"10:07.310 ","End":"10:09.590","Text":"Okay, brilliant, so it\u0027s happy with that."},{"Start":"10:09.590 ","End":"10:16.200","Text":"You\u0027ll see how the displays change to say 1.4E minus 45."},{"Start":"10:16.200 ","End":"10:19.915","Text":"That means 10 to the power minus 45."},{"Start":"10:19.915 ","End":"10:24.305","Text":"1.4 times 10 to the minus 45 is that number."},{"Start":"10:24.305 ","End":"10:27.020","Text":"If I try and put an extra 0 in,"},{"Start":"10:27.020 ","End":"10:29.315","Text":"I get this error message."},{"Start":"10:29.315 ","End":"10:33.885","Text":"It\u0027s a fairly clear one as error message go."},{"Start":"10:33.885 ","End":"10:39.770","Text":"It\u0027s basically saying, \"I can\u0027t store a number that small into a float.\""},{"Start":"10:39.770 ","End":"10:46.745","Text":"That we\u0027ve reached the limits of the smallest number that can be stored in a float."},{"Start":"10:46.745 ","End":"10:51.710","Text":"The final datatype then was a double."},{"Start":"10:51.710 ","End":"10:56.315","Text":"Let\u0027s create a variable for a double."},{"Start":"10:56.315 ","End":"11:00.090","Text":"We\u0027ll use capital camelCase this time."},{"Start":"11:00.090 ","End":"11:02.394","Text":"So I\u0027m going to call it MyDouble,"},{"Start":"11:02.394 ","End":"11:05.049","Text":"and you\u0027ll note the first letter has been capitalized."},{"Start":"11:05.049 ","End":"11:10.339","Text":"You tend not to use this in Java unless you\u0027re defining something called a class."},{"Start":"11:10.339 ","End":"11:12.675","Text":"But I\u0027m just doing it as an example here."},{"Start":"11:12.675 ","End":"11:14.603","Text":"There\u0027s my variable,"},{"Start":"11:14.603 ","End":"11:16.835","Text":"has been created now called MyDouble."},{"Start":"11:16.835 ","End":"11:19.865","Text":"Let\u0027s see what the value is and bet you can guess"},{"Start":"11:19.865 ","End":"11:22.890","Text":"what value is stored by default in there and"},{"Start":"11:22.890 ","End":"11:29.095","Text":"it\u0027s 0.0 because this is a floating point number with fractions."},{"Start":"11:29.095 ","End":"11:33.780","Text":"We should be able to happily store that very small number that we"},{"Start":"11:33.780 ","End":"11:39.090","Text":"saw before into MyDouble. Let\u0027s try that."},{"Start":"11:39.090 ","End":"11:41.940","Text":"Because I\u0027ve got an F on there, it\u0027s complaining."},{"Start":"11:41.940 ","End":"11:44.260","Text":"It\u0027s okay if I put a D. There we go."},{"Start":"11:44.260 ","End":"11:48.885","Text":"This time we are able to store 1.4 times 10 to the minus 46."},{"Start":"11:48.885 ","End":"11:50.830","Text":"Remember we couldn\u0027t do that in a float."},{"Start":"11:50.830 ","End":"11:55.930","Text":"We could get to 10 to the minus 45,"},{"Start":"11:55.930 ","End":"12:03.170","Text":"which we did up here successfully but we couldn\u0027t get an extra 0 in front there."},{"Start":"12:03.170 ","End":"12:06.720","Text":"However, we are able to do it when we store it in a double,"},{"Start":"12:06.720 ","End":"12:09.150","Text":"because we\u0027ve got way more digits,"},{"Start":"12:09.150 ","End":"12:12.070","Text":"we\u0027re using double the amount of space in memory to store"},{"Start":"12:12.070 ","End":"12:16.190","Text":"it but the actual number of 0s we can have in front is way more than double."},{"Start":"12:16.190 ","End":"12:21.060","Text":"In fact, I think it\u0027s 324."},{"Start":"12:21.060 ","End":"12:22.905","Text":"This is going to be interesting."},{"Start":"12:22.905 ","End":"12:26.100","Text":"We need 324 0s."},{"Start":"12:26.100 ","End":"12:29.695","Text":"So what I\u0027ll do is I\u0027ll copy and paste a lot of 0s from here."},{"Start":"12:29.695 ","End":"12:32.435","Text":"I\u0027ll do that,"},{"Start":"12:32.435 ","End":"12:36.170","Text":"let\u0027s do that maybe 20 times."},{"Start":"12:36.170 ","End":"12:37.805","Text":"See what we\u0027ve got now."},{"Start":"12:37.805 ","End":"12:41.755","Text":"Oops, so it is already complaining."},{"Start":"12:41.755 ","End":"12:44.000","Text":"Let\u0027s take some of those 0s out,"},{"Start":"12:44.000 ","End":"12:46.115","Text":"see what I can get away with."},{"Start":"12:46.115 ","End":"12:48.780","Text":"Still complaining. 32,"},{"Start":"12:48.780 ","End":"12:51.710","Text":"it\u0027s happy with, 79, it\u0027s happy with,"},{"Start":"12:51.710 ","End":"12:53.960","Text":"104, as I said,"},{"Start":"12:53.960 ","End":"12:59.480","Text":"it should be able to cope with 320 0s and more."},{"Start":"12:59.480 ","End":"13:05.235","Text":"199 now, 251, 94, 318."},{"Start":"13:05.235 ","End":"13:06.535","Text":"We\u0027re getting close to the limit now,"},{"Start":"13:06.535 ","End":"13:08.615","Text":"so let\u0027s count 19,"},{"Start":"13:08.615 ","End":"13:11.100","Text":"20, 21, 22,"},{"Start":"13:11.100 ","End":"13:13.945","Text":"23, was happy with that as well,"},{"Start":"13:13.945 ","End":"13:19.535","Text":"24, and we\u0027ve reached the limit there as we\u0027d expect."},{"Start":"13:19.535 ","End":"13:21.395","Text":"That\u0027s fantastic."},{"Start":"13:21.395 ","End":"13:23.700","Text":"We have now looked at"},{"Start":"13:23.700 ","End":"13:28.755","Text":"the 4 different datatypes that we hadn\u0027t used previously in the exercises."},{"Start":"13:28.755 ","End":"13:32.985","Text":"That was short, char, float, and double."},{"Start":"13:32.985 ","End":"13:36.280","Text":"We\u0027ve seen the values so we can store in there,"},{"Start":"13:36.280 ","End":"13:38.700","Text":"we can see the limits of the smallest values we can store"},{"Start":"13:38.700 ","End":"13:42.030","Text":"in to floats and doubles for example."},{"Start":"13:42.030 ","End":"13:44.795","Text":"Hopefully, that gives you an insight into"},{"Start":"13:44.795 ","End":"13:47.795","Text":"how we can make use of the different datatypes."},{"Start":"13:47.795 ","End":"13:50.615","Text":"If you wanted to play around a little bit longer in the code pad,"},{"Start":"13:50.615 ","End":"13:56.705","Text":"you might want to store some large values in floats and doubles to see the upper limits."},{"Start":"13:56.705 ","End":"13:58.580","Text":"That\u0027s it for this video."},{"Start":"13:58.580 ","End":"14:04.240","Text":"I\u0027ll see for the next set of exercises on Topic 4. See you then."}],"ID":27346}],"Thumbnail":null,"ID":237669},{"Name":"Assignment And Expressions","TopicPlaylistFirstVideoID":0,"Duration":null,"Videos":[{"Watched":false,"Name":"Assignment And Maths Operators","Duration":"8m 22s","ChapterTopicVideoID":26018,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.760","Text":"Hi everybody, welcome to this next video in which"},{"Start":"00:02.760 ","End":"00:06.120","Text":"we\u0027ll expand on our initial understanding of variables."},{"Start":"00:06.120 ","End":"00:07.710","Text":"By the end of this section,"},{"Start":"00:07.710 ","End":"00:11.475","Text":"you\u0027ll be able to understand the difference between declaration and assignment."},{"Start":"00:11.475 ","End":"00:15.600","Text":"Use the mathematical and comparison operators in an expression."},{"Start":"00:15.600 ","End":"00:19.500","Text":"Differentiate between the use of bitwise and logical operators."},{"Start":"00:19.500 ","End":"00:21.090","Text":"Describe the difference between"},{"Start":"00:21.090 ","End":"00:24.500","Text":"assignment and compound assignment operators and apply"},{"Start":"00:24.500 ","End":"00:28.249","Text":"your understanding of expressions and assignment in high-level languages."},{"Start":"00:28.249 ","End":"00:30.950","Text":"In the previous topic, we were introduced to the concept of"},{"Start":"00:30.950 ","End":"00:33.815","Text":"variables as a way of storing and retrieving data,"},{"Start":"00:33.815 ","End":"00:35.885","Text":"and the concept of a datatype,"},{"Start":"00:35.885 ","End":"00:39.230","Text":"which determines what can be done with a particular item of data."},{"Start":"00:39.230 ","End":"00:42.080","Text":"In a high-level language it is a formal process that"},{"Start":"00:42.080 ","End":"00:45.170","Text":"takes place when creating a variable and giving it a value."},{"Start":"00:45.170 ","End":"00:49.490","Text":"During variable declaration, we give a name more formerly known as"},{"Start":"00:49.490 ","End":"00:54.710","Text":"an identifier to the variable and we specify the datatype."},{"Start":"00:54.710 ","End":"00:57.005","Text":"Here the datatype shown in green,"},{"Start":"00:57.005 ","End":"00:59.134","Text":"and the identifier follows."},{"Start":"00:59.134 ","End":"01:03.500","Text":"Different datatypes as we know can have different memory requirements."},{"Start":"01:03.500 ","End":"01:05.920","Text":"These examples are in Java."},{"Start":"01:05.920 ","End":"01:09.920","Text":"Some languages don\u0027t require the datatype to be specified."},{"Start":"01:09.920 ","End":"01:12.290","Text":"Python being one example."},{"Start":"01:12.290 ","End":"01:14.434","Text":"Once a variable has been declared,"},{"Start":"01:14.434 ","End":"01:15.920","Text":"it can be given a value."},{"Start":"01:15.920 ","End":"01:19.535","Text":"This process is formerly known as variable assignment."},{"Start":"01:19.535 ","End":"01:22.625","Text":"In assignment, there are two halves of a statement,"},{"Start":"01:22.625 ","End":"01:29.194","Text":"with each half being separated by a symbol or symbols called an assignment operator."},{"Start":"01:29.194 ","End":"01:33.410","Text":"In most languages, this is a single equals sign."},{"Start":"01:33.410 ","End":"01:38.180","Text":"In some languages, it\u0027s a colon followed by an equal sign."},{"Start":"01:38.180 ","End":"01:40.445","Text":"The order is important."},{"Start":"01:40.445 ","End":"01:46.130","Text":"What you\u0027d expect is for the variable identifier to be on the left-hand side of"},{"Start":"01:46.130 ","End":"01:48.860","Text":"the assignment operator and the value to be"},{"Start":"01:48.860 ","End":"01:53.180","Text":"stored in the variable to be on the right-hand side of the assignment operator."},{"Start":"01:53.180 ","End":"01:55.025","Text":"In these two examples,"},{"Start":"01:55.025 ","End":"01:58.475","Text":"the variables have been assigned a value which is always the same"},{"Start":"01:58.475 ","End":"02:01.880","Text":"at the point it\u0027s encountered by the compiler or interpreter,"},{"Start":"02:01.880 ","End":"02:05.945","Text":"and hence we call this a literal constant assignment,"},{"Start":"02:05.945 ","End":"02:09.110","Text":"often abbreviated to just literal."},{"Start":"02:09.110 ","End":"02:12.380","Text":"We could instead put the name of a different variable on"},{"Start":"02:12.380 ","End":"02:15.805","Text":"the right-hand side of the assignment operator."},{"Start":"02:15.805 ","End":"02:20.330","Text":"What happens in this case is that the right-hand side is evaluated and"},{"Start":"02:20.330 ","End":"02:25.850","Text":"whatever value is returned goes into the variable on the left-hand side."},{"Start":"02:25.850 ","End":"02:31.324","Text":"Given that the right-hand side here is the identifier for a different variable,"},{"Start":"02:31.324 ","End":"02:35.270","Text":"evaluation is simply to return the contents of this variable."},{"Start":"02:35.270 ","End":"02:38.330","Text":"Running these two lines would result in the words input"},{"Start":"02:38.330 ","End":"02:41.930","Text":"your response being stored into both of the variables,"},{"Start":"02:41.930 ","End":"02:44.585","Text":"message 1 and message 2."},{"Start":"02:44.585 ","End":"02:47.240","Text":"In most languages, it\u0027s possible to combine"},{"Start":"02:47.240 ","End":"02:50.525","Text":"variable declaration and assignment in the same line."},{"Start":"02:50.525 ","End":"02:55.055","Text":"In fact, it\u0027s very common to give the variable an initial value when declaring it."},{"Start":"02:55.055 ","End":"02:57.800","Text":"We call that variable initialization."},{"Start":"02:57.800 ","End":"03:04.910","Text":"Here we declare the integer variable right left and giving it an initial value of 3."},{"Start":"03:04.910 ","End":"03:12.005","Text":"Likewise, the Boolean variable game completed is given an initial value of false."},{"Start":"03:12.005 ","End":"03:14.180","Text":"Once you\u0027ve declared this variable,"},{"Start":"03:14.180 ","End":"03:15.920","Text":"you don\u0027t need to declare it again,"},{"Start":"03:15.920 ","End":"03:19.370","Text":"but you can give it another variable with an assignment statement."},{"Start":"03:19.370 ","End":"03:23.360","Text":"In some languages, declaring a variable again could result in an error."},{"Start":"03:23.360 ","End":"03:25.010","Text":"In this example here,"},{"Start":"03:25.010 ","End":"03:29.240","Text":"we can see that tries has already been declared as an integer variable."},{"Start":"03:29.240 ","End":"03:31.655","Text":"We don\u0027t need to do that again and in fact,"},{"Start":"03:31.655 ","End":"03:33.455","Text":"if we did, we\u0027d probably get an error."},{"Start":"03:33.455 ","End":"03:36.770","Text":"To change the value of a variable already declared,"},{"Start":"03:36.770 ","End":"03:39.920","Text":"you drop the datatype before, in this case int,"},{"Start":"03:39.920 ","End":"03:44.865","Text":"and simply assign a new value using the operator assignment,"},{"Start":"03:44.865 ","End":"03:48.420","Text":"operator symbol, and the new value that you want to assign."},{"Start":"03:48.420 ","End":"03:52.675","Text":"Where assignments get more complex is when there\u0027s an expression involved."},{"Start":"03:52.675 ","End":"03:54.620","Text":"An expression is a statement that when"},{"Start":"03:54.620 ","End":"03:57.510","Text":"evaluated results in the computation of some value."},{"Start":"03:57.510 ","End":"04:00.050","Text":"We\u0027ve already come across the assignment operator,"},{"Start":"04:00.050 ","End":"04:02.014","Text":"which is equals in most languages,"},{"Start":"04:02.014 ","End":"04:04.895","Text":"expressions might use of other operators."},{"Start":"04:04.895 ","End":"04:13.265","Text":"For example, the most familiar basic maths operators are add, subtract, divide, multiply."},{"Start":"04:13.265 ","End":"04:16.040","Text":"The purpose of most of these operators are obvious although,"},{"Start":"04:16.040 ","End":"04:19.040","Text":"note the symbols are sometimes different."},{"Start":"04:19.040 ","End":"04:21.385","Text":"So divide is a forward slash,"},{"Start":"04:21.385 ","End":"04:24.900","Text":"multiply uses asterisk character,"},{"Start":"04:24.900 ","End":"04:27.005","Text":"which is shift and 8 on most keyboards."},{"Start":"04:27.005 ","End":"04:29.510","Text":"That\u0027s different to what we would do if we were writing"},{"Start":"04:29.510 ","End":"04:32.164","Text":"out a divide or a multiply operation."},{"Start":"04:32.164 ","End":"04:36.034","Text":"Modulo might be the only operator that\u0027s less obvious."},{"Start":"04:36.034 ","End":"04:40.325","Text":"It divides one integer by another and returns the remainder."},{"Start":"04:40.325 ","End":"04:43.189","Text":"In C#, Java, and Python,"},{"Start":"04:43.189 ","End":"04:46.490","Text":"the modulo operator is the percent symbol."},{"Start":"04:46.490 ","End":"04:51.500","Text":"The following examples are expressions that can be used in a program."},{"Start":"04:51.500 ","End":"04:56.210","Text":"If those expressions were assigned to a variable,"},{"Start":"04:56.210 ","End":"04:58.580","Text":"you\u0027d get a result of,"},{"Start":"04:58.580 ","End":"05:03.115","Text":"in this case, one being stored in the variable called result."},{"Start":"05:03.115 ","End":"05:09.540","Text":"In this example, 5 multiplied by 7 would store a result 35 into result,"},{"Start":"05:09.540 ","End":"05:13.290","Text":"15 divided by 3 would store 5 in results,"},{"Start":"05:13.290 ","End":"05:15.360","Text":"9 modulo 4,"},{"Start":"05:15.360 ","End":"05:22.485","Text":"would store 1 in result because 9 divided by 4 would give you 2 with a remainder of 1,"},{"Start":"05:22.485 ","End":"05:24.115","Text":"hence we store 1."},{"Start":"05:24.115 ","End":"05:26.915","Text":"That\u0027s what the modulo operator does."},{"Start":"05:26.915 ","End":"05:29.570","Text":"Expressions don\u0027t have to involve just literals,"},{"Start":"05:29.570 ","End":"05:31.475","Text":"they can also include variables."},{"Start":"05:31.475 ","End":"05:34.205","Text":"The first three lines here do involve literals,"},{"Start":"05:34.205 ","End":"05:36.274","Text":"but look at these last two lines."},{"Start":"05:36.274 ","End":"05:41.030","Text":"They use the expression on the right-hand side of the assignment operator to"},{"Start":"05:41.030 ","End":"05:46.220","Text":"evaluate a value which is then stored in the variable identified on the left-hand side."},{"Start":"05:46.220 ","End":"05:47.465","Text":"In the first case,"},{"Start":"05:47.465 ","End":"05:51.320","Text":"15 is stored into total because the value of"},{"Start":"05:51.320 ","End":"05:56.240","Text":"these 3 variables is computed by adding their content together."},{"Start":"05:56.240 ","End":"05:57.650","Text":"That currently 3, 5,"},{"Start":"05:57.650 ","End":"05:59.360","Text":"and 7 therefore,"},{"Start":"05:59.360 ","End":"06:01.940","Text":"15 would be stored into total."},{"Start":"06:01.940 ","End":"06:04.985","Text":"Average is assigned the value 5,"},{"Start":"06:04.985 ","End":"06:07.640","Text":"which is a contents of the total variable,"},{"Start":"06:07.640 ","End":"06:10.565","Text":"as we saw, is 15 divided by 3."},{"Start":"06:10.565 ","End":"06:13.250","Text":"Therefore, 5 is stored into average."},{"Start":"06:13.250 ","End":"06:16.400","Text":"These examples show one identifier on the left-hand"},{"Start":"06:16.400 ","End":"06:20.870","Text":"sided and one or more different identifies on the right-hand side."},{"Start":"06:20.870 ","End":"06:23.120","Text":"You could even use the same variable on"},{"Start":"06:23.120 ","End":"06:27.575","Text":"the left-hand side of the assignment operation and on the right-hand side."},{"Start":"06:27.575 ","End":"06:32.690","Text":"Here, we\u0027re referring to total on the left-hand side and on the right-hand side."},{"Start":"06:32.690 ","End":"06:37.745","Text":"So the expression is evaluated by adding to the current contents of total,"},{"Start":"06:37.745 ","End":"06:39.860","Text":"the literal value 1."},{"Start":"06:39.860 ","End":"06:44.075","Text":"If total already had 15 stored in it after this line runs,"},{"Start":"06:44.075 ","End":"06:49.385","Text":"total now store 16 due to this addition operation."},{"Start":"06:49.385 ","End":"06:55.559","Text":"The operators have an order of precedence similar to the standard mathematical order."},{"Start":"06:55.559 ","End":"06:57.050","Text":"Division, modulus,"},{"Start":"06:57.050 ","End":"06:59.405","Text":"and multiplication take place first,"},{"Start":"06:59.405 ","End":"07:01.865","Text":"followed by addition and subtraction."},{"Start":"07:01.865 ","End":"07:06.890","Text":"Here, division has a higher precedence than addition."},{"Start":"07:06.890 ","End":"07:10.115","Text":"So 15 will first be divided by 3,"},{"Start":"07:10.115 ","End":"07:13.360","Text":"then the results will be added to 15,"},{"Start":"07:13.360 ","End":"07:16.175","Text":"hence 20 is stored in the result."},{"Start":"07:16.175 ","End":"07:18.875","Text":"As brackets have the highest precedence,"},{"Start":"07:18.875 ","End":"07:21.260","Text":"they can be used in expressions to change"},{"Start":"07:21.260 ","End":"07:24.155","Text":"the exact order in which evaluation takes place."},{"Start":"07:24.155 ","End":"07:26.630","Text":"This line looks similar to the one above,"},{"Start":"07:26.630 ","End":"07:32.135","Text":"but forces 15 to be added to 15 before the division takes place,"},{"Start":"07:32.135 ","End":"07:36.465","Text":"hence result will have 10 stored in it in this case."},{"Start":"07:36.465 ","End":"07:41.735","Text":"Any operators that have equivalent precedence are evaluated from left to right."},{"Start":"07:41.735 ","End":"07:46.580","Text":"Here, divide and multiply are of the same order of precedence,"},{"Start":"07:46.580 ","End":"07:49.730","Text":"but divide is encountered by the compiler or"},{"Start":"07:49.730 ","End":"07:53.405","Text":"interpreter first so that operation happens first,"},{"Start":"07:53.405 ","End":"07:56.270","Text":"and the result is multiplied by 10,"},{"Start":"07:56.270 ","End":"07:58.085","Text":"giving the final result 50."},{"Start":"07:58.085 ","End":"08:02.480","Text":"Here subtraction and addition are also of equal precedence."},{"Start":"08:02.480 ","End":"08:08.150","Text":"Again, we proceed simply from left to right and 3 is subtracted from 15,"},{"Start":"08:08.150 ","End":"08:11.870","Text":"so 12 is then added to 4 and the result"},{"Start":"08:11.870 ","End":"08:15.905","Text":"ends up with a value 16 being assigned into result."},{"Start":"08:15.905 ","End":"08:19.730","Text":"We\u0027ll pause there now and in the next video we\u0027ll look at the comparison,"},{"Start":"08:19.730 ","End":"08:23.550","Text":"logical, and bitwise operators."}],"ID":26824},{"Watched":false,"Name":"Comparison Logical And Bitwise Operators","Duration":"13m 24s","ChapterTopicVideoID":26016,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:03.180","Text":"Hi, welcome back. In the previous video,"},{"Start":"00:03.180 ","End":"00:06.315","Text":"we looked at the assignment and mathematical operators."},{"Start":"00:06.315 ","End":"00:10.319","Text":"A different set of operators allow us to compare 2 values."},{"Start":"00:10.319 ","End":"00:13.080","Text":"Depending on the relationship between those 2 values,"},{"Start":"00:13.080 ","End":"00:16.860","Text":"the expression evaluates to true or false."},{"Start":"00:16.860 ","End":"00:21.105","Text":"Therefore, called comparison or relational operators."},{"Start":"00:21.105 ","End":"00:26.835","Text":"In most high-level languages the equal to comparison operator is a pair of equal signs,"},{"Start":"00:26.835 ","End":"00:28.850","Text":"not a single equal sign."},{"Start":"00:28.850 ","End":"00:34.220","Text":"This allows the compiler or interpreter to easily distinguish between an assignment,"},{"Start":"00:34.220 ","End":"00:35.795","Text":"which is a single equals,"},{"Start":"00:35.795 ","End":"00:37.190","Text":"and a comparison,"},{"Start":"00:37.190 ","End":"00:38.990","Text":"which is a double equals."},{"Start":"00:38.990 ","End":"00:42.770","Text":"Similarly, the not equals to operator is also a pair of"},{"Start":"00:42.770 ","End":"00:48.155","Text":"symbols with the exclamation mark followed by a single equal sign."},{"Start":"00:48.155 ","End":"00:51.035","Text":"Less than is a single symbol."},{"Start":"00:51.035 ","End":"00:55.354","Text":"The value on the left is compared to the value on the right."},{"Start":"00:55.354 ","End":"00:58.340","Text":"If the left-hand value is less,"},{"Start":"00:58.340 ","End":"01:00.185","Text":"it will return true."},{"Start":"01:00.185 ","End":"01:02.180","Text":"Less than or equals is the same,"},{"Start":"01:02.180 ","End":"01:05.060","Text":"but it will also return true if the 2 values being"},{"Start":"01:05.060 ","End":"01:09.390","Text":"compared either side of the operator are exactly equal."},{"Start":"01:09.390 ","End":"01:10.580","Text":"Greater than is similar."},{"Start":"01:10.580 ","End":"01:14.270","Text":"The value on the left is compared to the 1 on the right,"},{"Start":"01:14.270 ","End":"01:16.880","Text":"but this time the left side value has to be bigger"},{"Start":"01:16.880 ","End":"01:20.210","Text":"than the 1 on the right to return true."},{"Start":"01:20.210 ","End":"01:23.780","Text":"Greater than or equal to could be greater"},{"Start":"01:23.780 ","End":"01:27.560","Text":"than or exactly equal to the value on the right."},{"Start":"01:27.560 ","End":"01:31.265","Text":"Let\u0027s look at some examples where we compare 2 integers."},{"Start":"01:31.265 ","End":"01:36.830","Text":"We\u0027ll store the results of our expressions in a Boolean variable called result."},{"Start":"01:36.830 ","End":"01:40.849","Text":"Result will only ever contain the value true or false."},{"Start":"01:40.849 ","End":"01:43.820","Text":"In reality, we probably wouldn\u0027t do this in a real program."},{"Start":"01:43.820 ","End":"01:46.490","Text":"It\u0027d be more likely to be used as part of another statement."},{"Start":"01:46.490 ","End":"01:50.485","Text":"But we\u0027ll just do it this way to keep things simple for the moment."},{"Start":"01:50.485 ","End":"01:53.900","Text":"This next line looks a bit strange because we\u0027re"},{"Start":"01:53.900 ","End":"01:57.080","Text":"using a single equals for the assignment."},{"Start":"01:57.080 ","End":"02:00.620","Text":"Then a double equals for comparison."},{"Start":"02:00.620 ","End":"02:03.740","Text":"We\u0027ll get a value of false stored in result,"},{"Start":"02:03.740 ","End":"02:07.625","Text":"because the expression num1 equals num2"},{"Start":"02:07.625 ","End":"02:12.755","Text":"compares our 2 integer variables which are not equal."},{"Start":"02:12.755 ","End":"02:16.925","Text":"Therefore, the expression evaluates to false."},{"Start":"02:16.925 ","End":"02:22.790","Text":"The value false will be stored in variable results."},{"Start":"02:22.790 ","End":"02:24.440","Text":"In this next example,"},{"Start":"02:24.440 ","End":"02:27.980","Text":"the expression evaluates to true because the 2 integers"},{"Start":"02:27.980 ","End":"02:31.885","Text":"stored in num1 and num2 are not equal."},{"Start":"02:31.885 ","End":"02:35.570","Text":"If not true gets stored into result on this line."},{"Start":"02:35.570 ","End":"02:39.590","Text":"Now we\u0027re comparing 2 integers to see if 1 is greater than the other."},{"Start":"02:39.590 ","End":"02:44.465","Text":"In this case, num1 is storing a value greater than num2."},{"Start":"02:44.465 ","End":"02:46.730","Text":"What it\u0027s asking that question is it?"},{"Start":"02:46.730 ","End":"02:50.630","Text":"It isn\u0027t so because num1 is 3 and num2 is 5,"},{"Start":"02:50.630 ","End":"02:53.705","Text":"so this expression evaluates to false."},{"Start":"02:53.705 ","End":"03:00.485","Text":"However, if we do it the other way round and we say is num1 less than num2?"},{"Start":"03:00.485 ","End":"03:03.845","Text":"It will evaluate to true because in this case,"},{"Start":"03:03.845 ","End":"03:05.885","Text":"it obviously is true."},{"Start":"03:05.885 ","End":"03:12.200","Text":"Here we\u0027re comparing num2 to a literal value 5 to illustrate the point in"},{"Start":"03:12.200 ","End":"03:18.515","Text":"that greater than or equal to compares the values on the left and right of the operator,"},{"Start":"03:18.515 ","End":"03:22.295","Text":"and either 1 is bigger than the other or they\u0027re exactly equal."},{"Start":"03:22.295 ","End":"03:26.470","Text":"In this case they are equal so we\u0027ll get true."},{"Start":"03:26.470 ","End":"03:32.765","Text":"This expression will evaluate to true as well because although num1 is not less than 3,"},{"Start":"03:32.765 ","End":"03:36.170","Text":"it is exactly equal to 3."},{"Start":"03:36.170 ","End":"03:37.715","Text":"Hence, we\u0027ll get true."},{"Start":"03:37.715 ","End":"03:43.235","Text":"Another type of expression that evaluates to a Boolean result is the logical operation."},{"Start":"03:43.235 ","End":"03:48.275","Text":"In logical operations, Boolean inputs are used to generate a single Boolean output."},{"Start":"03:48.275 ","End":"03:53.570","Text":"In this case, logical AND expects both inputs to be true,"},{"Start":"03:53.570 ","End":"03:56.785","Text":"to return a result of true."},{"Start":"03:56.785 ","End":"04:05.430","Text":"Logical OR only expects 1 of the inputs to be true to return a value of true."},{"Start":"04:05.430 ","End":"04:12.005","Text":"Logical NOT just as the reverse of whatever the input was and compliments it."},{"Start":"04:12.005 ","End":"04:14.240","Text":"It\u0027s easy to understand with some examples."},{"Start":"04:14.240 ","End":"04:18.085","Text":"Let\u0027s say we have 2 Boolean variables, a and b."},{"Start":"04:18.085 ","End":"04:21.350","Text":"If we use the logical AND operator,"},{"Start":"04:21.350 ","End":"04:27.650","Text":"the result is false because AND wants both inputs to be true."},{"Start":"04:27.650 ","End":"04:30.590","Text":"In this case, only a is true."},{"Start":"04:30.590 ","End":"04:37.449","Text":"The evaluation will result in false being stored in result."},{"Start":"04:37.449 ","End":"04:39.465","Text":"However with OR,"},{"Start":"04:39.465 ","End":"04:43.085","Text":"only 1 or the other of the inputs needs to be true."},{"Start":"04:43.085 ","End":"04:45.515","Text":"In this case, a is true,"},{"Start":"04:45.515 ","End":"04:51.440","Text":"but b isn\u0027t, and that\u0027s fine with all so the results is true."},{"Start":"04:51.440 ","End":"04:55.400","Text":"Finally, note here there\u0027s only 1 value needed for"},{"Start":"04:55.400 ","End":"05:00.050","Text":"NOT in contrast the previous 2 which needed 2 values either side of the operator."},{"Start":"05:00.050 ","End":"05:05.090","Text":"The NOT operator flips the value that follows it to make it the opposite."},{"Start":"05:05.090 ","End":"05:08.450","Text":"In this case, b was false."},{"Start":"05:08.450 ","End":"05:11.545","Text":"But the NOT makes it true."},{"Start":"05:11.545 ","End":"05:14.600","Text":"That\u0027s what\u0027s stored in result here."},{"Start":"05:14.600 ","End":"05:17.540","Text":"What makes logical operations particularly useful is that"},{"Start":"05:17.540 ","End":"05:20.480","Text":"they can be used to evaluate multiple expressions,"},{"Start":"05:20.480 ","End":"05:23.720","Text":"so long as each expression evaluates to a Boolean."},{"Start":"05:23.720 ","End":"05:27.500","Text":"Here, we store the results of a comparison operation and"},{"Start":"05:27.500 ","End":"05:33.215","Text":"the variable result1 and another 1 in result2."},{"Start":"05:33.215 ","End":"05:39.140","Text":"The final outcome we\u0027re looking to determine is stored in a variable called outcome."},{"Start":"05:39.140 ","End":"05:44.779","Text":"It joins together the previous 2 expressions using the AND operator."},{"Start":"05:44.779 ","End":"05:48.125","Text":"Another way of writing that would be this."},{"Start":"05:48.125 ","End":"05:50.315","Text":"In both these lines,"},{"Start":"05:50.315 ","End":"05:55.050","Text":"num1 would have to be bigger than num2 and"},{"Start":"05:55.050 ","End":"05:56.960","Text":"num2 would have to be"},{"Start":"05:56.960 ","End":"06:02.365","Text":"smaller than 100 in order for a result of true to be stored in outcome."},{"Start":"06:02.365 ","End":"06:05.705","Text":"That\u0027s true of this line or this 1,"},{"Start":"06:05.705 ","End":"06:12.280","Text":"which simply uses these 2 expressions here in a third line."},{"Start":"06:12.280 ","End":"06:15.400","Text":"This is slightly more compact and you could"},{"Start":"06:15.400 ","End":"06:19.000","Text":"argue that maybe this is a little bit easier to read for a beginner."},{"Start":"06:19.000 ","End":"06:23.785","Text":"The conditional and logical operations always produce a Boolean output."},{"Start":"06:23.785 ","End":"06:27.925","Text":"A different type of operator can produce results on integers."},{"Start":"06:27.925 ","End":"06:34.540","Text":"The so-called bit-wise operators operate on 1 bit at a time when applied to 2 integers."},{"Start":"06:34.540 ","End":"06:39.730","Text":"The same operators exist as we previously saw for the logical operators."},{"Start":"06:39.730 ","End":"06:42.265","Text":"With the addition of a new 1."},{"Start":"06:42.265 ","End":"06:46.360","Text":"The bitwise exclusive OR works like an OR."},{"Start":"06:46.360 ","End":"06:50.980","Text":"But once exclusivity, if both the inputs are true,"},{"Start":"06:50.980 ","End":"06:52.915","Text":"it will give a false output."},{"Start":"06:52.915 ","End":"06:58.960","Text":"Unlike the regular OR which gives a true when both inputs are true."},{"Start":"06:58.960 ","End":"07:04.550","Text":"Here\u0027s an example of a variable assignment that uses a bitwise AND expression."},{"Start":"07:04.550 ","End":"07:08.840","Text":"It looks deceptively similar to the logical AND we saw earlier though,"},{"Start":"07:08.840 ","End":"07:12.020","Text":"note there\u0027s only 1 ampersand symbol here."},{"Start":"07:12.020 ","End":"07:16.120","Text":"But the bit-wise result also has a very different effect."},{"Start":"07:16.120 ","End":"07:20.375","Text":"It\u0027s easier to see when we look at 8 bit integers"},{"Start":"07:20.375 ","End":"07:24.425","Text":"expressed in binary when a bit wise AND is performed,"},{"Start":"07:24.425 ","End":"07:31.579","Text":"each respective bit in the 2 different integers is compared with an AND operation."},{"Start":"07:31.579 ","End":"07:34.790","Text":"The AND operation is performed on it and stored in"},{"Start":"07:34.790 ","End":"07:37.640","Text":"the result at the same position as we can see"},{"Start":"07:37.640 ","End":"07:44.940","Text":"here an AND requires 2 ones and the only place where we have 2 ones is in bit 8."},{"Start":"07:44.940 ","End":"07:48.055","Text":"Therefore the result, bit 8 is 1."},{"Start":"07:48.055 ","End":"07:53.929","Text":"Everywhere else has a 0 because nowhere do both of these 2 integer variables"},{"Start":"07:53.929 ","End":"08:00.510","Text":"have a 1 present at their equivalent bits except for bit 8."},{"Start":"08:00.510 ","End":"08:06.725","Text":"With bitwise OR any 1 of the 2 input bits can be a 1 to generate a 1 in the results,"},{"Start":"08:06.725 ","End":"08:09.680","Text":"or even both inputs can be 1 to generate a 1."},{"Start":"08:09.680 ","End":"08:13.910","Text":"The only combination that won\u0027t generate a 1 is 2 zeros,"},{"Start":"08:13.910 ","End":"08:15.815","Text":"which we see here in bit 5."},{"Start":"08:15.815 ","End":"08:17.690","Text":"But everywhere else, as you can see,"},{"Start":"08:17.690 ","End":"08:25.130","Text":"there\u0027s at least 1 1 in either int1 or int2 at every single bit position,"},{"Start":"08:25.130 ","End":"08:28.385","Text":"apart from, as we\u0027ve already said in bit 5."},{"Start":"08:28.385 ","End":"08:35.135","Text":"Contrast this with an exclusive OR which has the same result as an OR apart from when,"},{"Start":"08:35.135 ","End":"08:41.465","Text":"both inputs are 1 when the output is 0 and we see that here in a bit 8."},{"Start":"08:41.465 ","End":"08:46.040","Text":"We have a 1 here and a 1 here and exclusive OR doesn\u0027t like that."},{"Start":"08:46.040 ","End":"08:51.260","Text":"It makes it 0 here will also be a 0 because neither of the bits are 1."},{"Start":"08:51.260 ","End":"08:54.230","Text":"Everywhere else is fine because it has exclusivity."},{"Start":"08:54.230 ","End":"09:00.380","Text":"Only 1 of the bits at the relevant position is a 1, not both."},{"Start":"09:00.380 ","End":"09:04.145","Text":"The only places where that\u0027s not true is here where they\u0027re both 1,"},{"Start":"09:04.145 ","End":"09:06.650","Text":"therefore for exclusive OR it\u0027s a 0,"},{"Start":"09:06.650 ","End":"09:11.920","Text":"or they\u0027re both 0, which for OR and exclusive OR is always a 0."},{"Start":"09:11.920 ","End":"09:14.750","Text":"Finally, the bitwise complement operation flips"},{"Start":"09:14.750 ","End":"09:17.585","Text":"all the bits in the input so they\u0027re complimentary value."},{"Start":"09:17.585 ","End":"09:24.110","Text":"Everywhere where there was a 1 becomes a 0 as we see here."},{"Start":"09:24.110 ","End":"09:29.540","Text":"Everywhere where there was a 0 becomes a 1 as we see in these bits."},{"Start":"09:29.540 ","End":"09:32.300","Text":"The final type of operator commonly found in"},{"Start":"09:32.300 ","End":"09:35.795","Text":"high-level languages is the compound assignment operator."},{"Start":"09:35.795 ","End":"09:40.325","Text":"In this case, it takes the contents of variable num and adds"},{"Start":"09:40.325 ","End":"09:44.945","Text":"5 to it and then stores the result back into num."},{"Start":"09:44.945 ","End":"09:50.495","Text":"It\u0027s combining a mathematical operation with an assignment operation in 1 step."},{"Start":"09:50.495 ","End":"09:54.505","Text":"This is exactly equivalent to the following line,"},{"Start":"09:54.505 ","End":"09:57.850","Text":"where we have an expression on the right-hand side"},{"Start":"09:57.850 ","End":"10:01.705","Text":"saying add 5 to the current contents of num,"},{"Start":"10:01.705 ","End":"10:04.570","Text":"which is then stored back into num."},{"Start":"10:04.570 ","End":"10:09.280","Text":"As you can see, the compound assignment style is a little bit briefer."},{"Start":"10:09.280 ","End":"10:10.870","Text":"Although you could argue that"},{"Start":"10:10.870 ","End":"10:14.650","Text":"this longer version is a little bit easier to read for a beginner."},{"Start":"10:14.650 ","End":"10:17.470","Text":"In the most popular high-level languages,"},{"Start":"10:17.470 ","End":"10:19.600","Text":"all of the basic maths operators and"},{"Start":"10:19.600 ","End":"10:23.765","Text":"bitwise operators have a compound assignment equivalent."},{"Start":"10:23.765 ","End":"10:27.250","Text":"Here we will see some examples."},{"Start":"10:27.250 ","End":"10:29.980","Text":"There are also a pair of operators that you use to add or"},{"Start":"10:29.980 ","End":"10:33.039","Text":"subtract exactly 1 from variables."},{"Start":"10:33.039 ","End":"10:37.460","Text":"These are called the increment and decrement operators respectively."},{"Start":"10:37.460 ","End":"10:42.725","Text":"Here we are seeing num and the increment operator."},{"Start":"10:42.725 ","End":"10:48.215","Text":"The variable num will have 1 added to its current contents,"},{"Start":"10:48.215 ","End":"10:51.475","Text":"and then the result will be stored back into num."},{"Start":"10:51.475 ","End":"10:54.470","Text":"Decrement operator here would do the same thing,"},{"Start":"10:54.470 ","End":"11:00.500","Text":"but it would subtract 1 from num and store the value back into num."},{"Start":"11:00.500 ","End":"11:02.555","Text":"When you use an expression,"},{"Start":"11:02.555 ","End":"11:08.135","Text":"the increment and decrement operators can be used to pre-increment or post-increment."},{"Start":"11:08.135 ","End":"11:12.530","Text":"That means the value when used in the expression is changed before"},{"Start":"11:12.530 ","End":"11:17.240","Text":"the expression is evaluated or after the expression is evaluated."},{"Start":"11:17.240 ","End":"11:23.074","Text":"Here we\u0027re going to use the compound assignment operator and the increment operator."},{"Start":"11:23.074 ","End":"11:27.560","Text":"On the right-hand side of this compound assignment operation is"},{"Start":"11:27.560 ","End":"11:32.075","Text":"an expression which is evaluated first before the assignment takes place."},{"Start":"11:32.075 ","End":"11:40.365","Text":"What happens is that num1 is added to what is in int1 and stored back into int1."},{"Start":"11:40.365 ","End":"11:44.630","Text":"Int1 will have 15 stored into it after this line runs."},{"Start":"11:44.630 ","End":"11:48.110","Text":"With post-increment, after that evaluation"},{"Start":"11:48.110 ","End":"11:51.845","Text":"of the expression has happened, the increment happens."},{"Start":"11:51.845 ","End":"11:53.990","Text":"Once the line has finished,"},{"Start":"11:53.990 ","End":"11:57.295","Text":"num1 will contain 11."},{"Start":"11:57.295 ","End":"11:59.610","Text":"Previously it contained 10."},{"Start":"11:59.610 ","End":"12:01.609","Text":"When the expression was evaluated,"},{"Start":"12:01.609 ","End":"12:06.350","Text":"it would have been 10 hence 10 was added to 5,"},{"Start":"12:06.350 ","End":"12:09.200","Text":"and int1 had 15 stored in it."},{"Start":"12:09.200 ","End":"12:13.520","Text":"However, at the end of the line after the assignment had taken place,"},{"Start":"12:13.520 ","End":"12:16.820","Text":"num1 would have been incremented because this is a post-increment."},{"Start":"12:16.820 ","End":"12:22.145","Text":"Then for num1 would store 11 once the line has finished running."},{"Start":"12:22.145 ","End":"12:27.260","Text":"Contrast that with pre-increment where the increment happens first,"},{"Start":"12:27.260 ","End":"12:29.630","Text":"then the expression is evaluated."},{"Start":"12:29.630 ","End":"12:33.215","Text":"Here, num2 will be incremented first."},{"Start":"12:33.215 ","End":"12:39.365","Text":"Then the expression will be evaluated giving 11 as that\u0027s what\u0027s now stored in num2."},{"Start":"12:39.365 ","End":"12:41.855","Text":"Then the compound assignment happens,"},{"Start":"12:41.855 ","End":"12:49.480","Text":"which increases in 2 by 11 and stores the result 16 back into int2."},{"Start":"12:49.480 ","End":"12:54.485","Text":"In this section, we learned how to distinguish between declaration and assignment."},{"Start":"12:54.485 ","End":"12:58.024","Text":"Use a mathematical and comparison operators in an expression."},{"Start":"12:58.024 ","End":"13:02.015","Text":"Differentiate between the use of bitwise and logical operators."},{"Start":"13:02.015 ","End":"13:06.800","Text":"Describe the difference between assignment and compound assignment operators."},{"Start":"13:06.800 ","End":"13:11.195","Text":"Apply your understanding of expressions and assignment in high-level languages."},{"Start":"13:11.195 ","End":"13:15.500","Text":"That\u0027s it for now, be sure to try the exercises to apply what you\u0027ve learned."},{"Start":"13:15.500 ","End":"13:18.860","Text":"I\u0027ll see you in the next section where we\u0027ll look at how to control"},{"Start":"13:18.860 ","End":"13:22.520","Text":"the order in which instructions are executed."},{"Start":"13:22.520 ","End":"13:24.810","Text":"Thanks and see you soon.2"}],"ID":26825},{"Watched":false,"Name":"Exercise 1","Duration":"4m 54s","ChapterTopicVideoID":26432,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.760","Text":"Hello. Welcome to this first video where we work through"},{"Start":"00:02.760 ","End":"00:06.045","Text":"the first exercise on assignments and expressions,"},{"Start":"00:06.045 ","End":"00:09.990","Text":"aiming to build on our initial understanding of variables and data types."},{"Start":"00:09.990 ","End":"00:15.180","Text":"We, first of all, been asked to create a new project and open the Code Pad in Bluej,"},{"Start":"00:15.180 ","End":"00:17.925","Text":"and then to do the following activities in the Code Pad."},{"Start":"00:17.925 ","End":"00:22.230","Text":"In part A, we need to create a single line of code to create a Boolean variable,"},{"Start":"00:22.230 ","End":"00:24.510","Text":"and to call that variable is valid,"},{"Start":"00:24.510 ","End":"00:27.345","Text":"and to initialize it with the value true."},{"Start":"00:27.345 ","End":"00:32.040","Text":"Part B, we\u0027re asked to use the up arrow to retrieve the line we just typed in,"},{"Start":"00:32.040 ","End":"00:36.650","Text":"and to change the last part of the line so the value is false, not true,"},{"Start":"00:36.650 ","End":"00:42.495","Text":"and then explain why we get an error message when you press \"Enter\" to compile a line."},{"Start":"00:42.495 ","End":"00:44.210","Text":"Then finally in part C,"},{"Start":"00:44.210 ","End":"00:49.730","Text":"we\u0027re asked to correct that line to successfully change the value to false."},{"Start":"00:49.730 ","End":"00:52.250","Text":"Welcome to this first video where we work through"},{"Start":"00:52.250 ","End":"00:55.670","Text":"the exercise on expressions and assignments."},{"Start":"00:55.670 ","End":"00:59.150","Text":"Exercise 1 specifically with the aim of building on"},{"Start":"00:59.150 ","End":"01:02.660","Text":"our initial understanding of variables and data types."},{"Start":"01:02.660 ","End":"01:07.505","Text":"We\u0027ve been first asked in exercise 1 to create a new project."},{"Start":"01:07.505 ","End":"01:09.740","Text":"Open the Code Pad, as we know from before,"},{"Start":"01:09.740 ","End":"01:16.010","Text":"you cannot have a Code Pad unless you have a project to contain it within."},{"Start":"01:16.010 ","End":"01:20.600","Text":"We\u0027ll just give it a name and I can open up"},{"Start":"01:20.600 ","End":"01:26.210","Text":"the window here just to give myself a bit of space to see the responses, etc."},{"Start":"01:26.210 ","End":"01:30.500","Text":"What we\u0027ve been asked to do in part 1 is with a single line of code,"},{"Start":"01:30.500 ","End":"01:36.400","Text":"create a Boolean variable called is valid and to initialize it with the value true."},{"Start":"01:36.400 ","End":"01:38.840","Text":"As we know from previously,"},{"Start":"01:38.840 ","End":"01:41.390","Text":"to declare a variable in Java,"},{"Start":"01:41.390 ","End":"01:44.345","Text":"you need to state the data type first."},{"Start":"01:44.345 ","End":"01:46.190","Text":"In this case, it\u0027s Boolean,"},{"Start":"01:46.190 ","End":"01:48.997","Text":"then the identifier or the name,"},{"Start":"01:48.997 ","End":"01:53.075","Text":"in this case, we\u0027ve been asked to call it is valid in camel case."},{"Start":"01:53.075 ","End":"01:56.000","Text":"Then we\u0027ve been asked to initialize it with the value true."},{"Start":"01:56.000 ","End":"01:57.590","Text":"Now up until now,"},{"Start":"01:57.590 ","End":"02:01.565","Text":"we would\u0027ve ended this line with a semicolon or by pressing \"Enter\","},{"Start":"02:01.565 ","End":"02:03.320","Text":"and we wouldn\u0027t have given it a value."},{"Start":"02:03.320 ","End":"02:08.520","Text":"But now we\u0027ve been asked to assign a value whilst we are declaring the variables,"},{"Start":"02:08.520 ","End":"02:09.990","Text":"so we can go ahead and do that,"},{"Start":"02:09.990 ","End":"02:12.410","Text":"and we have been asked to give it valid true,"},{"Start":"02:12.410 ","End":"02:14.780","Text":"which in Java is all lowercase."},{"Start":"02:14.780 ","End":"02:17.990","Text":"Let\u0027s do that. I\u0027m going to put semicolon on the end as well,"},{"Start":"02:17.990 ","End":"02:20.850","Text":"because that\u0027s how lines should end."},{"Start":"02:21.290 ","End":"02:28.580","Text":"No problems there, it\u0027s created my variable and I can check if I want that the value"},{"Start":"02:28.580 ","End":"02:34.880","Text":"in there is what I expect and is indeed true and is all data type Boolean,"},{"Start":"02:34.880 ","End":"02:36.710","Text":"so it\u0027s done its job and I\u0027m going to expect"},{"Start":"02:36.710 ","End":"02:39.350","Text":"anything else because it\u0027s such a simple line of code."},{"Start":"02:39.350 ","End":"02:41.480","Text":"Now we\u0027ve been asked in part B to press"},{"Start":"02:41.480 ","End":"02:44.840","Text":"the up arrow key to true treat the line we just typed to."},{"Start":"02:44.840 ","End":"02:48.020","Text":"It would be this line that we just typed to and obviously,"},{"Start":"02:48.020 ","End":"02:49.670","Text":"you\u0027ve looked at a value if is valid as well,"},{"Start":"02:49.670 ","End":"02:50.780","Text":"so I\u0027ve skipped the overlap,"},{"Start":"02:50.780 ","End":"02:53.180","Text":"but here is the initial line and we\u0027ve just been"},{"Start":"02:53.180 ","End":"02:55.865","Text":"asked to change the value to false so I\u0027ll do that."},{"Start":"02:55.865 ","End":"03:00.590","Text":"Now we get an error message saying is valid is already defined."},{"Start":"03:00.590 ","End":"03:04.640","Text":"We\u0027ve been asked to explain why we get that error message."},{"Start":"03:04.640 ","End":"03:06.920","Text":"Was actually relatively straightforward."},{"Start":"03:06.920 ","End":"03:10.310","Text":"As we said, when you declare a variable in Java,"},{"Start":"03:10.310 ","End":"03:13.940","Text":"you need to give a data type and you can also assign a value."},{"Start":"03:13.940 ","End":"03:19.235","Text":"Now what we\u0027re trying to do is presumably assign a different value to this variable."},{"Start":"03:19.235 ","End":"03:22.940","Text":"What we cannot do is redefine the variable because"},{"Start":"03:22.940 ","End":"03:26.735","Text":"that\u0027s what we appear to be doing as far as Java is concerned."},{"Start":"03:26.735 ","End":"03:28.805","Text":"It\u0027s saying is valid is already defined"},{"Start":"03:28.805 ","End":"03:32.270","Text":"because we put the data type in front of is valid,"},{"Start":"03:32.270 ","End":"03:36.875","Text":"it assumes we\u0027re declaring a new variable called is valid,"},{"Start":"03:36.875 ","End":"03:39.755","Text":"but it already has a variable called is valid,"},{"Start":"03:39.755 ","End":"03:43.790","Text":"so refuses to let us do that and hence the error message."},{"Start":"03:43.790 ","End":"03:47.600","Text":"What I need to do to correct this for part C is I simply need to"},{"Start":"03:47.600 ","End":"03:51.455","Text":"remove the data type from the beginning."},{"Start":"03:51.455 ","End":"03:56.220","Text":"Now it understands that there is an existing variable called is valid,"},{"Start":"03:56.220 ","End":"03:58.480","Text":"is not declaring a new one and it just"},{"Start":"03:58.480 ","End":"04:01.495","Text":"wants to change the value of that existing variable."},{"Start":"04:01.495 ","End":"04:04.270","Text":"I\u0027ll go ahead and do that and no error this time"},{"Start":"04:04.270 ","End":"04:06.940","Text":"and if I look at the value of is valid again,"},{"Start":"04:06.940 ","End":"04:08.755","Text":"it is indeed false now,"},{"Start":"04:08.755 ","End":"04:10.405","Text":"whereas previously it was true."},{"Start":"04:10.405 ","End":"04:12.490","Text":"A very, very simple exercise,"},{"Start":"04:12.490 ","End":"04:16.330","Text":"but really just there to illustrate the difference between"},{"Start":"04:16.330 ","End":"04:20.320","Text":"declaring a variable and assigning a value to a variable."},{"Start":"04:20.320 ","End":"04:23.560","Text":"They\u0027re different things, although we can do both things on"},{"Start":"04:23.560 ","End":"04:28.180","Text":"one line as we did here and as we attempted to do here,"},{"Start":"04:28.180 ","End":"04:31.085","Text":"but we couldn\u0027t because the variable already existed so"},{"Start":"04:31.085 ","End":"04:34.165","Text":"this is an error that a beginner will quite often get."},{"Start":"04:34.165 ","End":"04:38.440","Text":"They\u0027ll forget to take the data type off the beginning when they\u0027re merely"},{"Start":"04:38.440 ","End":"04:43.495","Text":"assigning a new value to a variable that already exists."},{"Start":"04:43.495 ","End":"04:45.700","Text":"Hopefully, that makes sense now,"},{"Start":"04:45.700 ","End":"04:49.790","Text":"and I\u0027ll see you in the next exercise where we start working with"},{"Start":"04:49.790 ","End":"04:55.350","Text":"assignments of variables to other variables. I\u0027ll see you then."}],"ID":27334},{"Watched":false,"Name":"Exercise 2","Duration":"4m 29s","ChapterTopicVideoID":26433,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:01.725","Text":"Hello, welcome back."},{"Start":"00:01.725 ","End":"00:05.340","Text":"In this next exercise on assignment and expressions,"},{"Start":"00:05.340 ","End":"00:08.430","Text":"we\u0027ve been asked to within the same Code Pad as before,"},{"Start":"00:08.430 ","End":"00:10.395","Text":"create 2 integer variables,"},{"Start":"00:10.395 ","End":"00:13.260","Text":"num1 and num2 with no initial value given,"},{"Start":"00:13.260 ","End":"00:18.230","Text":"and then to assign the value 10 to num1."},{"Start":"00:18.230 ","End":"00:22.775","Text":"Then in part c, to assign the contents of num1 to num2."},{"Start":"00:22.775 ","End":"00:24.020","Text":"Then finally in part d,"},{"Start":"00:24.020 ","End":"00:28.775","Text":"to confirm the contents of num2 are what you would expect."},{"Start":"00:28.775 ","End":"00:32.360","Text":"We\u0027ve been asked to create 2 integer variables num1 and"},{"Start":"00:32.360 ","End":"00:36.495","Text":"num2 with no initial value given in part a."},{"Start":"00:36.495 ","End":"00:38.430","Text":"Let\u0027s go ahead and do that."},{"Start":"00:38.430 ","End":"00:41.130","Text":"It turns out there\u0027s a little trick you can do."},{"Start":"00:41.130 ","End":"00:44.000","Text":"If there are 2 variables that you want to declare,"},{"Start":"00:44.000 ","End":"00:45.905","Text":"you can declare them in 1 line,"},{"Start":"00:45.905 ","End":"00:48.350","Text":"so long as they are the same data type,"},{"Start":"00:48.350 ","End":"00:51.245","Text":"because both of these are int,"},{"Start":"00:51.245 ","End":"00:57.430","Text":"we can do that and you just simply separate the 2 variable names with a comma."},{"Start":"00:57.430 ","End":"01:02.160","Text":"It will happily declare both of those variables in 1 line,"},{"Start":"01:02.160 ","End":"01:03.740","Text":"I could do in 2 if I wanted to,"},{"Start":"01:03.740 ","End":"01:07.925","Text":"but I\u0027m just going to show you that it will work if you do it in 1 line."},{"Start":"01:07.925 ","End":"01:10.145","Text":"Just to prove that that\u0027s worked."},{"Start":"01:10.145 ","End":"01:16.430","Text":"Well, I just get num1\u0027s value is 0 and num2\u0027s value is also 0."},{"Start":"01:16.430 ","End":"01:18.740","Text":"That\u0027s what this message here is saying."},{"Start":"01:18.740 ","End":"01:21.995","Text":"By the way, it\u0027s always actually good practice to"},{"Start":"01:21.995 ","End":"01:25.700","Text":"assign a value to a variable when you declare it,"},{"Start":"01:25.700 ","End":"01:28.700","Text":"even if it will be given a default value,"},{"Start":"01:28.700 ","End":"01:33.275","Text":"you sometimes can\u0027t guarantee that on certain systems,"},{"Start":"01:33.275 ","End":"01:36.590","Text":"so its best practice is to actually always assign"},{"Start":"01:36.590 ","End":"01:41.285","Text":"a value to a variable when you\u0027re initially declaring it."},{"Start":"01:41.285 ","End":"01:43.760","Text":"That\u0027s the first part, part a."},{"Start":"01:43.760 ","End":"01:48.070","Text":"Then in part b, we\u0027ve been asked to assign the value 10 to num1."},{"Start":"01:48.070 ","End":"01:50.780","Text":"Remembering what we learned in the previous exercise,"},{"Start":"01:50.780 ","End":"01:52.865","Text":"I don\u0027t need to put the data type again."},{"Start":"01:52.865 ","End":"01:56.105","Text":"I simply need to write the variable name out."},{"Start":"01:56.105 ","End":"02:02.195","Text":"Num1 equals 10 is what I\u0027ve been asked to do and it\u0027s quite happy doing that."},{"Start":"02:02.195 ","End":"02:05.000","Text":"But part c is something we haven\u0027t seen before,"},{"Start":"02:05.000 ","End":"02:09.710","Text":"it\u0027s asking us to assign the contents of num1 to num2."},{"Start":"02:09.710 ","End":"02:14.630","Text":"Previously, we\u0027ve only ever assigned literal values to variables."},{"Start":"02:14.630 ","End":"02:19.500","Text":"Now, we\u0027re being asked to assign the contents of a variable to another variable so,"},{"Start":"02:19.500 ","End":"02:23.640","Text":"really, all we need to do here is understand which order we put things in."},{"Start":"02:23.640 ","End":"02:29.840","Text":"You\u0027ll remember from the video that we are supposed to put on the left-hand side,"},{"Start":"02:29.840 ","End":"02:33.904","Text":"the name of the variable that we wanted to store things into."},{"Start":"02:33.904 ","End":"02:38.465","Text":"Here, we\u0027ve been asked to assign the contents of num1 to num2."},{"Start":"02:38.465 ","End":"02:42.235","Text":"Num2 should go on the left-hand side here,"},{"Start":"02:42.235 ","End":"02:44.390","Text":"then follows the assignment operator,"},{"Start":"02:44.390 ","End":"02:47.705","Text":"which in Java is a single equals,"},{"Start":"02:47.705 ","End":"02:52.915","Text":"and then num1 is the value we want to assign to num2."},{"Start":"02:52.915 ","End":"02:55.500","Text":"I\u0027ll go ahead and do that, and it\u0027s done."},{"Start":"02:55.500 ","End":"02:58.790","Text":"It reflects back to me 10 I\u0027m not sure what is 10,"},{"Start":"02:58.790 ","End":"03:00.050","Text":"is it num1 or is it num2?"},{"Start":"03:00.050 ","End":"03:01.925","Text":"Let\u0027s have a look at the value of num2."},{"Start":"03:01.925 ","End":"03:03.375","Text":"Num2 is 10,"},{"Start":"03:03.375 ","End":"03:09.480","Text":"and we already know that num1 is 10 because we set its value over here."},{"Start":"03:09.480 ","End":"03:12.885","Text":"Now, num2 and num1 are 10."},{"Start":"03:12.885 ","End":"03:15.630","Text":"That\u0027s pretty much what we expect."},{"Start":"03:15.630 ","End":"03:22.715","Text":"All we\u0027ve really learned here is when you put the contents of 1 variable into another,"},{"Start":"03:22.715 ","End":"03:27.655","Text":"you get a copy of the variable value."},{"Start":"03:27.655 ","End":"03:31.060","Text":"It does not affect the value you\u0027re copying in."},{"Start":"03:31.060 ","End":"03:35.050","Text":"In this case, we were copying num1 into num2."},{"Start":"03:35.050 ","End":"03:37.165","Text":"Num2 got num1 value,"},{"Start":"03:37.165 ","End":"03:39.430","Text":"but num1 didn\u0027t change itself."},{"Start":"03:39.430 ","End":"03:43.720","Text":"You might think that when you\u0027re assigning a value from 1 variable to another,"},{"Start":"03:43.720 ","End":"03:45.655","Text":"you\u0027re removing the value somehow,"},{"Start":"03:45.655 ","End":"03:46.840","Text":"but you\u0027re not doing that."},{"Start":"03:46.840 ","End":"03:51.280","Text":"You\u0027re just producing a copy of the value and the copy of that value goes"},{"Start":"03:51.280 ","End":"03:57.175","Text":"into the variable on the left-hand side of the assignment operator."},{"Start":"03:57.175 ","End":"04:00.700","Text":"We\u0027ll do some more complex operations later on."},{"Start":"04:00.700 ","End":"04:04.645","Text":"But that\u0027s the most basic type of assignment of 1 variable to another."},{"Start":"04:04.645 ","End":"04:08.290","Text":"Essentially, we\u0027re evaluating an expression on the right-hand side"},{"Start":"04:08.290 ","End":"04:12.530","Text":"and because the expression simply contains the name of a variable,"},{"Start":"04:12.530 ","End":"04:16.815","Text":"the evaluation is just to give us the contents of that variable."},{"Start":"04:16.815 ","End":"04:22.355","Text":"Then the assignment then happens and it\u0027s stored into the variable on the left-hand side."},{"Start":"04:22.355 ","End":"04:24.545","Text":"Nice and simple for exercise 2."},{"Start":"04:24.545 ","End":"04:30.240","Text":"I\u0027ll see you in the next one where we work with another pair of variables. See you then."}],"ID":27335},{"Watched":false,"Name":"Exercise 3","Duration":"9m 44s","ChapterTopicVideoID":26434,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.580","Text":"Hello, welcome back again."},{"Start":"00:02.580 ","End":"00:04.890","Text":"In this exercise, we\u0027ve been asked to create"},{"Start":"00:04.890 ","End":"00:07.875","Text":"another pair of variables in the Code Pad once again,"},{"Start":"00:07.875 ","End":"00:13.455","Text":"this time to create a char variable and assign it the value a,"},{"Start":"00:13.455 ","End":"00:17.775","Text":"then to create a short variable with no initial value."},{"Start":"00:17.775 ","End":"00:20.580","Text":"Then in part c, we\u0027ve been asked to assign the contents of"},{"Start":"00:20.580 ","End":"00:25.620","Text":"the char variable to the short variable and explain what happens."},{"Start":"00:25.620 ","End":"00:30.405","Text":"In part d we\u0027re asked to do part c again,"},{"Start":"00:30.405 ","End":"00:34.770","Text":"but in front of the char variable name put the following characters exactly"},{"Start":"00:34.770 ","End":"00:39.240","Text":"as they appear so (short)."},{"Start":"00:39.240 ","End":"00:41.990","Text":"In part e, we\u0027re asked to look at the contents of"},{"Start":"00:41.990 ","End":"00:47.275","Text":"the short variable and explain why it contains the particular value that it contains."},{"Start":"00:47.275 ","End":"00:49.370","Text":"Moving on into part f,"},{"Start":"00:49.370 ","End":"00:51.110","Text":"we move on to Unicode characters."},{"Start":"00:51.110 ","End":"00:55.380","Text":"We\u0027re asked to assign a Unicode character \u0027\\u9000\u0027,"},{"Start":"00:56.650 ","End":"00:59.180","Text":"to the char variable."},{"Start":"00:59.180 ","End":"01:01.430","Text":"Then in part g, once again,"},{"Start":"01:01.430 ","End":"01:04.130","Text":"to assign the value of that char variable to"},{"Start":"01:04.130 ","End":"01:09.875","Text":"the short variable with short in brackets in front of the char variable name."},{"Start":"01:09.875 ","End":"01:14.690","Text":"Then in the final part to look at the contents of the short variable again, and again,"},{"Start":"01:14.690 ","End":"01:19.805","Text":"explain why it contains the particular value it contains and what has gone wrong."},{"Start":"01:19.805 ","End":"01:26.690","Text":"We first have been asked to create a char variable and assign it with the value a."},{"Start":"01:26.690 ","End":"01:28.490","Text":"Let\u0027s go ahead and do that."},{"Start":"01:28.490 ","End":"01:31.370","Text":"We haven\u0027t been told a identifier,"},{"Start":"01:31.370 ","End":"01:33.800","Text":"so I\u0027m going to call mine my char,"},{"Start":"01:33.800 ","End":"01:38.830","Text":"not particularly descriptive, but it\u0027ll do for purposes of this exercise."},{"Start":"01:38.830 ","End":"01:41.870","Text":"Note that when you\u0027re assigning a char value,"},{"Start":"01:41.870 ","End":"01:43.714","Text":"it\u0027s a single quote,"},{"Start":"01:43.714 ","End":"01:46.730","Text":"and it\u0027s closed with a single quote as well,"},{"Start":"01:46.730 ","End":"01:49.655","Text":"not speech marks, which is double-quotes,"},{"Start":"01:49.655 ","End":"01:52.220","Text":"which would be shifted to on most keyboards."},{"Start":"01:52.220 ","End":"01:56.180","Text":"It\u0027s just a single quote that\u0027s needed for a char. There we go."},{"Start":"01:56.180 ","End":"02:01.880","Text":"I\u0027ve defined my variable and it has a value just to check that value and sure enough,"},{"Start":"02:01.880 ","End":"02:05.795","Text":"it\u0027s a data type of char and it contains the value a."},{"Start":"02:05.795 ","End":"02:07.130","Text":"Then in the second part,"},{"Start":"02:07.130 ","End":"02:10.460","Text":"we\u0027ve been asked to create a short variable with no initial value."},{"Start":"02:10.460 ","End":"02:14.130","Text":"Fair enough, call it my short,"},{"Start":"02:14.130 ","End":"02:18.290","Text":"I\u0027ll be consistent and no initial value,"},{"Start":"02:18.290 ","End":"02:22.265","Text":"so I\u0027ll just end it with a semicolon just to prove It will"},{"Start":"02:22.265 ","End":"02:31.550","Text":"have an initial value and it\u0027s initialized to 0 by default by the Java system."},{"Start":"02:31.550 ","End":"02:34.880","Text":"That\u0027s fine. Now I\u0027m asked to assign"},{"Start":"02:34.880 ","End":"02:39.410","Text":"the contents of the char variable to the short variable."},{"Start":"02:39.410 ","End":"02:44.495","Text":"Assign the contents of the my char variable to the my short variables."},{"Start":"02:44.495 ","End":"02:50.720","Text":"My short comes first because it\u0027s the thing that I want to receive the value into,"},{"Start":"02:50.720 ","End":"02:55.970","Text":"and my char is on the right-hand side of the assignment operator."},{"Start":"02:55.970 ","End":"02:58.280","Text":"Let\u0027s see what happens if I try that."},{"Start":"02:58.280 ","End":"03:00.965","Text":"Unsurprisingly hopefully to you,"},{"Start":"03:00.965 ","End":"03:04.790","Text":"I get an error message and it says, incompatible types."},{"Start":"03:04.790 ","End":"03:07.414","Text":"However, what\u0027s interesting about this error message."},{"Start":"03:07.414 ","End":"03:12.710","Text":"It doesn\u0027t seem to be a closed book and it looks very similar to"},{"Start":"03:12.710 ","End":"03:15.890","Text":"some similar messages we had before when we were dealing with"},{"Start":"03:15.890 ","End":"03:19.450","Text":"floats and different sizes of integer and so on."},{"Start":"03:19.450 ","End":"03:24.670","Text":"It almost seems that it\u0027s possible to do this but we\u0027re not quite"},{"Start":"03:24.670 ","End":"03:26.680","Text":"going about it the right way because it\u0027s saying"},{"Start":"03:26.680 ","End":"03:30.175","Text":"possible lossy conversion from char to short."},{"Start":"03:30.175 ","End":"03:33.430","Text":"We will see that in the next part,"},{"Start":"03:33.430 ","End":"03:34.840","Text":"in part d,"},{"Start":"03:34.840 ","End":"03:38.350","Text":"where I\u0027ve been asked to take exactly what I had before,"},{"Start":"03:38.350 ","End":"03:48.435","Text":"but put the following characters (short) in front of my char and see what happens."},{"Start":"03:48.435 ","End":"03:55.545","Text":"Strangely, the error message goes away and I\u0027m reflected back the value 97."},{"Start":"03:55.545 ","End":"03:59.770","Text":"What we\u0027re seeing here is something called casting or it\u0027s also called"},{"Start":"03:59.770 ","End":"04:04.370","Text":"coercion where we\u0027re saying to the system,"},{"Start":"04:04.370 ","End":"04:11.025","Text":"I know that one of these things is a short data type and one is a char data type"},{"Start":"04:11.025 ","End":"04:14.420","Text":"and normally you cannot assign a variable"},{"Start":"04:14.420 ","End":"04:17.810","Text":"of one data type to a different data type but just,"},{"Start":"04:17.810 ","End":"04:25.160","Text":"for now, I\u0027d like you to pretend essentially that my Char is not a char, it\u0027s a short."},{"Start":"04:25.160 ","End":"04:28.250","Text":"If it can do it, the system will actually go ahead and try and"},{"Start":"04:28.250 ","End":"04:31.340","Text":"do it and this will work in C and other languages as well."},{"Start":"04:31.340 ","End":"04:34.625","Text":"What we\u0027ve done here is we\u0027ve cast my char,"},{"Start":"04:34.625 ","End":"04:36.650","Text":"which is a char into a short,"},{"Start":"04:36.650 ","End":"04:40.385","Text":"and then we\u0027ve been able to assign it into my short."},{"Start":"04:40.385 ","End":"04:43.325","Text":"The value 97 we\u0027re being asked,"},{"Start":"04:43.325 ","End":"04:46.940","Text":"why does it contain this value in part e?"},{"Start":"04:46.940 ","End":"04:54.770","Text":"We might be able to guess that the letter a actually has a value in the ASCII table,"},{"Start":"04:54.770 ","End":"04:58.295","Text":"and it happens to be a is 97."},{"Start":"04:58.295 ","End":"05:01.445","Text":"What has happened here is the system has said, all right,"},{"Start":"05:01.445 ","End":"05:05.330","Text":"I know this is a char and my char is not changed,"},{"Start":"05:05.330 ","End":"05:06.830","Text":"by the way, if I look at my chart,"},{"Start":"05:06.830 ","End":"05:13.400","Text":"it still contains a character a but my short now contains not 0 but 97,"},{"Start":"05:13.400 ","End":"05:19.385","Text":"which happens to be the ASCII value of the character that\u0027s stored in my chart."},{"Start":"05:19.385 ","End":"05:23.090","Text":"This statement here has basically said, \"Yes,"},{"Start":"05:23.090 ","End":"05:26.825","Text":"I know you can assign a char to a short,"},{"Start":"05:26.825 ","End":"05:33.350","Text":"but can you just pretend the char is a short and store it into my short variable\"."},{"Start":"05:33.350 ","End":"05:35.225","Text":"It has done, and it\u0027s worked."},{"Start":"05:35.225 ","End":"05:38.195","Text":"That could be useful in some situations."},{"Start":"05:38.195 ","End":"05:40.460","Text":"It does allow you to do it,"},{"Start":"05:40.460 ","End":"05:44.810","Text":"but there could be some issues and we\u0027ll see that in the subsequent parts."},{"Start":"05:44.810 ","End":"05:47.425","Text":"If we look at Part f,"},{"Start":"05:47.425 ","End":"05:50.105","Text":"it asks us to assign a Unicode character,"},{"Start":"05:50.105 ","End":"05:53.675","Text":"\\u9000 to a char variable. Let\u0027s go ahead and do that."},{"Start":"05:53.675 ","End":"05:58.910","Text":"The variable is called my char and we put a single quote, backslash,"},{"Start":"05:58.910 ","End":"06:06.720","Text":"not a forward slash u and then 9,000 has to be 4 digits, hexadecimal digits."},{"Start":"06:06.720 ","End":"06:11.870","Text":"There we go. Assign the value and I get a symbol from"},{"Start":"06:11.870 ","End":"06:17.600","Text":"the Unicode character space that is a symbol in the Chinese alphabet."},{"Start":"06:17.600 ","End":"06:19.895","Text":"We wouldn\u0027t call it an alphabet, I guess it\u0027s a symbol."},{"Start":"06:19.895 ","End":"06:21.440","Text":"There are thousands of symbols,"},{"Start":"06:21.440 ","End":"06:26.464","Text":"which is why they\u0027re so high up in the Chinese symbols range,"},{"Start":"06:26.464 ","End":"06:28.340","Text":"and we call this symbol C, J, K by the way,"},{"Start":"06:28.340 ","End":"06:32.420","Text":"because Japanese and Korean also fall into the same range."},{"Start":"06:32.420 ","End":"06:37.125","Text":"There\u0027s a C, J, K symbol in my char now,"},{"Start":"06:37.125 ","End":"06:40.790","Text":"and correct me now I can do stuff with that, I can display it,"},{"Start":"06:40.790 ","End":"06:44.750","Text":"or I can search for it because it\u0027s in a variable now in a char variable."},{"Start":"06:44.750 ","End":"06:52.395","Text":"But let\u0027s try and do what we did before and assign this value into my short."},{"Start":"06:52.395 ","End":"06:54.830","Text":"My char now has a different value in it,"},{"Start":"06:54.830 ","End":"07:01.355","Text":"which is that character represented by the Unicode value 9,000 hex."},{"Start":"07:01.355 ","End":"07:04.640","Text":"Let\u0027s try and do what we did before and we know it worked before I got"},{"Start":"07:04.640 ","End":"07:09.710","Text":"97 into my short when I had the letter a in there."},{"Start":"07:09.710 ","End":"07:11.665","Text":"Let\u0027s see what happens now."},{"Start":"07:11.665 ","End":"07:16.265","Text":"I get a negative number, very strange."},{"Start":"07:16.265 ","End":"07:20.210","Text":"Now, why would I have got a negative number?"},{"Start":"07:20.210 ","End":"07:25.415","Text":"Why does short contain that value I\u0027m being asked in part h?"},{"Start":"07:25.415 ","End":"07:29.000","Text":"Well the reason is the size of short,"},{"Start":"07:29.000 ","End":"07:32.540","Text":"short remember is a 16-bit number,"},{"Start":"07:32.540 ","End":"07:35.705","Text":"but it\u0027s a signed 16-bit number so actually,"},{"Start":"07:35.705 ","End":"07:39.965","Text":"the maximum value you can have is a 15-bit number,"},{"Start":"07:39.965 ","End":"07:42.710","Text":"which is 3, 2, 7, 6, 7."},{"Start":"07:42.710 ","End":"07:47.390","Text":"It just so happens that 9,000 hex is a bigger number than 3,"},{"Start":"07:47.390 ","End":"07:52.025","Text":"2, 7, 6, 7, it\u0027s actually 36,864."},{"Start":"07:52.025 ","End":"07:56.225","Text":"What\u0027s happening here is I\u0027m going outside the range that can"},{"Start":"07:56.225 ","End":"08:00.740","Text":"be displayed in 15 bits or can be encoded in 15 bits."},{"Start":"08:00.740 ","End":"08:04.130","Text":"It\u0027s wrapped around through a negative value."},{"Start":"08:04.130 ","End":"08:10.760","Text":"I think really all this illustrates is although we can sometimes convert"},{"Start":"08:10.760 ","End":"08:14.420","Text":"one data type into another temporarily for the purposes"},{"Start":"08:14.420 ","End":"08:18.170","Text":"of an assignment by using this costing syntax,"},{"Start":"08:18.170 ","End":"08:22.075","Text":"which is to put a data type in brackets ahead of your variable name,"},{"Start":"08:22.075 ","End":"08:25.520","Text":"it can sometimes have unexpected effects"},{"Start":"08:25.520 ","End":"08:28.910","Text":"so you\u0027ve got to be very careful if you\u0027re doing this."},{"Start":"08:28.910 ","End":"08:30.829","Text":"If you\u0027re using, for example,"},{"Start":"08:30.829 ","End":"08:33.740","Text":"7-bit ASCII characters, no problem,"},{"Start":"08:33.740 ","End":"08:37.280","Text":"you can convert an integer that is values from 0 to"},{"Start":"08:37.280 ","End":"08:41.690","Text":"127 into an ASCII value from 0 to 127."},{"Start":"08:41.690 ","End":"08:44.900","Text":"No problem. But if it\u0027s anything else,"},{"Start":"08:44.900 ","End":"08:46.805","Text":"you\u0027ve got to be very careful."},{"Start":"08:46.805 ","End":"08:52.505","Text":"This short might, on the surface seem okay because it\u0027s 16 bits and so is Unicode,"},{"Start":"08:52.505 ","End":"08:59.810","Text":"but actually the short is 15 bits in the positive direction and negative direction,"},{"Start":"08:59.810 ","End":"09:02.075","Text":"and one bit is used for the sign so"},{"Start":"09:02.075 ","End":"09:06.210","Text":"it\u0027s potentially an area where you can have a problem."},{"Start":"09:06.210 ","End":"09:10.010","Text":"This exercise has shown you that you can\u0027t"},{"Start":"09:10.010 ","End":"09:16.145","Text":"normally put a variable of one data type into another variable of a different data type"},{"Start":"09:16.145 ","End":"09:21.560","Text":"but you can coerce one variable to temporarily pretend it\u0027s"},{"Start":"09:21.560 ","End":"09:24.560","Text":"a different type but that may or may not"},{"Start":"09:24.560 ","End":"09:27.825","Text":"cause problems and it\u0027s just something to be aware of."},{"Start":"09:27.825 ","End":"09:32.120","Text":"Generally, remember that data types are there to enforce"},{"Start":"09:32.120 ","End":"09:37.700","Text":"some constraints on the variable so they\u0027re there for a reason and it can be overwritten,"},{"Start":"09:37.700 ","End":"09:40.670","Text":"but just need to be very careful if you\u0027re going to do that."},{"Start":"09:40.670 ","End":"09:42.500","Text":"That\u0027s it for this exercise."},{"Start":"09:42.500 ","End":"09:44.970","Text":"I\u0027ll see for the next one."}],"ID":27336},{"Watched":false,"Name":"Exercise 4","Duration":"6m 39s","ChapterTopicVideoID":26427,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:05.415","Text":"Hello. Welcome back to the next video on the exercises on assignments and expressions."},{"Start":"00:05.415 ","End":"00:09.450","Text":"Here we\u0027ve been asked to create a 3rd integer variable in Code Pad called"},{"Start":"00:09.450 ","End":"00:14.910","Text":"num3 to complement the 2 integer variables we created in an earlier exercise."},{"Start":"00:14.910 ","End":"00:19.200","Text":"In part a, we\u0027ve been asked to assign the value 10 to num1,"},{"Start":"00:19.200 ","End":"00:21.120","Text":"20 to num2,"},{"Start":"00:21.120 ","End":"00:23.055","Text":"and 4 to num3,"},{"Start":"00:23.055 ","End":"00:26.250","Text":"and then check the contents of all 3 of those variables."},{"Start":"00:26.250 ","End":"00:31.980","Text":"In part b, we\u0027ve been asked to create a single expression involving all 3 of"},{"Start":"00:31.980 ","End":"00:38.210","Text":"those variables that adds num1 to num2 divided by num3,"},{"Start":"00:38.210 ","End":"00:41.830","Text":"and then note results of that evaluation."},{"Start":"00:41.830 ","End":"00:45.410","Text":"In part c, we\u0027ve been asked to take that same expression,"},{"Start":"00:45.410 ","End":"00:48.470","Text":"but put brackets around the addition of num1 and"},{"Start":"00:48.470 ","End":"00:52.495","Text":"num2 and then explain the resulting evaluation."},{"Start":"00:52.495 ","End":"00:54.325","Text":"Then finally, in part d,"},{"Start":"00:54.325 ","End":"00:59.270","Text":"I\u0027ve been asked to use the same expression again as part c,"},{"Start":"00:59.270 ","End":"01:02.660","Text":"but to use the modulo operation this time instead of"},{"Start":"01:02.660 ","End":"01:06.950","Text":"the divide operation and to explain the resulting evaluation."},{"Start":"01:06.950 ","End":"01:13.070","Text":"In question 4, we\u0027ve been asked to create a 3rd integer variable in co bad num3."},{"Start":"01:13.070 ","End":"01:16.250","Text":"We already created num1 and 2 in exercise 2."},{"Start":"01:16.250 ","End":"01:19.145","Text":"I\u0027ve actually got rid of mine because I\u0027ve started a new session."},{"Start":"01:19.145 ","End":"01:22.130","Text":"But you only need to put all of these in."},{"Start":"01:22.130 ","End":"01:24.800","Text":"I\u0027m going to create all 3 variables again."},{"Start":"01:24.800 ","End":"01:28.505","Text":"As I said, if you already still have num1 and num2,"},{"Start":"01:28.505 ","End":"01:30.304","Text":"you just need to create num3."},{"Start":"01:30.304 ","End":"01:36.430","Text":"Now, I have my 3 variables and part a asks me to assign the value 10 to num1,"},{"Start":"01:36.430 ","End":"01:38.980","Text":"20 to num2,"},{"Start":"01:39.170 ","End":"01:42.300","Text":"and 4 to num3."},{"Start":"01:42.300 ","End":"01:46.565","Text":"In part b, it now ask me to create a single expression involving"},{"Start":"01:46.565 ","End":"01:51.795","Text":"all 3 variables that adds num1 to num2 divided by num3."},{"Start":"01:51.795 ","End":"01:55.310","Text":"I haven\u0027t been told to store those values anywhere."},{"Start":"01:55.310 ","End":"01:59.660","Text":"I\u0027ve simply been asked to create an expression involving those 3 variables."},{"Start":"01:59.660 ","End":"02:01.580","Text":"That sounds straightforward enough."},{"Start":"02:01.580 ","End":"02:10.065","Text":"Num1 gets added to num2 divided by num3."},{"Start":"02:10.065 ","End":"02:12.825","Text":"It will evaluate to 15."},{"Start":"02:12.825 ","End":"02:14.305","Text":"Then part c,"},{"Start":"02:14.305 ","End":"02:18.260","Text":"I have been asked to put brackets around the addition of num1 and"},{"Start":"02:18.260 ","End":"02:23.240","Text":"2 and explain the evaluation that results from that."},{"Start":"02:23.240 ","End":"02:27.230","Text":"I\u0027ll just do our power to get back what I\u0027ve just typed."},{"Start":"02:27.230 ","End":"02:28.820","Text":"I\u0027ll do as I\u0027ve been asked,"},{"Start":"02:28.820 ","End":"02:36.015","Text":"which is to put brackets around num1 plus num2 and the value I get is 7."},{"Start":"02:36.015 ","End":"02:40.550","Text":"How can I explain the difference between those 2 evaluations?"},{"Start":"02:40.550 ","End":"02:42.350","Text":"Well, the first one here,"},{"Start":"02:42.350 ","End":"02:46.010","Text":"as we know the order of precedence comes in here."},{"Start":"02:46.010 ","End":"02:49.415","Text":"Normally we\u0027d evaluate from left to right, however,"},{"Start":"02:49.415 ","End":"02:55.415","Text":"some operations have a greater precedence than others and division and multiplication"},{"Start":"02:55.415 ","End":"03:02.089","Text":"would be an example of something that has a higher precedence than plus and minus."},{"Start":"03:02.089 ","End":"03:04.655","Text":"The division will happen first."},{"Start":"03:04.655 ","End":"03:11.045","Text":"Therefore, num2 will be divided by num3 and the result of that will be added to num1."},{"Start":"03:11.045 ","End":"03:12.950","Text":"That\u0027s exactly what we saw."},{"Start":"03:12.950 ","End":"03:18.485","Text":"Num2 was 20, num3 was 4."},{"Start":"03:18.485 ","End":"03:22.455","Text":"So 20 was divided by 4,"},{"Start":"03:22.455 ","End":"03:24.615","Text":"which will give us 5, of course,"},{"Start":"03:24.615 ","End":"03:28.235","Text":"and then it was added to num1 because num1 had 10 in it,"},{"Start":"03:28.235 ","End":"03:32.045","Text":"the result was 15 as we would expect."},{"Start":"03:32.045 ","End":"03:37.700","Text":"The result of putting brackets around num1 and num2,"},{"Start":"03:37.700 ","End":"03:40.750","Text":"brackets have the highest order of precedence of all."},{"Start":"03:40.750 ","End":"03:43.415","Text":"So they will be evaluated first,"},{"Start":"03:43.415 ","End":"03:44.750","Text":"and then the division,"},{"Start":"03:44.750 ","End":"03:47.015","Text":"although it has a higher precedence, now,"},{"Start":"03:47.015 ","End":"03:49.550","Text":"will be overridden by the brackets."},{"Start":"03:49.550 ","End":"03:52.010","Text":"It has a higher precedence than plus that is to say,"},{"Start":"03:52.010 ","End":"03:56.390","Text":"as it did here, the brackets now will be evaluated first."},{"Start":"03:56.390 ","End":"03:59.395","Text":"Num1 will be added to num2."},{"Start":"03:59.395 ","End":"04:05.455","Text":"Therefore, we\u0027d have 30 and then 30 is divided by num3, which is 4."},{"Start":"04:05.455 ","End":"04:07.120","Text":"Now, why do we get 7?"},{"Start":"04:07.120 ","End":"04:13.180","Text":"Because 30 divided by 4 is 28 with a remainder and"},{"Start":"04:13.180 ","End":"04:15.820","Text":"we only ask to give the integer part"},{"Start":"04:15.820 ","End":"04:19.404","Text":"because all these variables involved are integer variables."},{"Start":"04:19.404 ","End":"04:22.630","Text":"Therefore, the result of the expression would also be an integer,"},{"Start":"04:22.630 ","End":"04:26.140","Text":"and it\u0027s evaluated to the value 7."},{"Start":"04:26.140 ","End":"04:28.690","Text":"In part d, we\u0027ve been asked to use"},{"Start":"04:28.690 ","End":"04:32.095","Text":"exactly the same expression as part c, which was this one,"},{"Start":"04:32.095 ","End":"04:37.894","Text":"but to change the divide operator to the percent operator,"},{"Start":"04:37.894 ","End":"04:42.800","Text":"which means modulo and to explain the results of the evaluation."},{"Start":"04:42.800 ","End":"04:44.450","Text":"Now, we get 2."},{"Start":"04:44.450 ","End":"04:46.622","Text":"Going through those numbers again,"},{"Start":"04:46.622 ","End":"04:50.330","Text":"what we\u0027re seeing is num1 plus num2,"},{"Start":"04:50.330 ","End":"04:54.760","Text":"as we said, was 30 divided by 4."},{"Start":"04:54.760 ","End":"04:58.070","Text":"We are asked to give the remainder when we divide by 4."},{"Start":"04:58.070 ","End":"05:00.545","Text":"Not the quotient, but the remainder."},{"Start":"05:00.545 ","End":"05:03.870","Text":"The remainder when we divide 30 by 4,"},{"Start":"05:03.870 ","End":"05:08.645","Text":"we get 28 and then the remainder of 2,"},{"Start":"05:08.645 ","End":"05:11.165","Text":"so the result is 2."},{"Start":"05:11.165 ","End":"05:15.980","Text":"It\u0027s showing really the difference between the division and the modulo operators,"},{"Start":"05:15.980 ","End":"05:17.315","Text":"they\u0027re obviously related,"},{"Start":"05:17.315 ","End":"05:19.790","Text":"and how that applies to integers."},{"Start":"05:19.790 ","End":"05:25.125","Text":"We also saw how precedence is affected by brackets."},{"Start":"05:25.125 ","End":"05:28.730","Text":"This was a very straightforward expression involving"},{"Start":"05:28.730 ","End":"05:32.239","Text":"just a couple of numbers, 3 different variables."},{"Start":"05:32.239 ","End":"05:35.660","Text":"In fact, we can have a play around with this till our heart is"},{"Start":"05:35.660 ","End":"05:39.170","Text":"content by just typing in values and seeing how they\u0027re evaluated."},{"Start":"05:39.170 ","End":"05:41.660","Text":"These were variables, but if we wanted to,"},{"Start":"05:41.660 ","End":"05:46.940","Text":"we could put literals in here if we wanted to see what the effect would"},{"Start":"05:46.940 ","End":"05:53.855","Text":"be and how a set of brackets could be used to affect the order evaluation."},{"Start":"05:53.855 ","End":"05:56.750","Text":"You might be able to predict what you\u0027d get from this value."},{"Start":"05:56.750 ","End":"06:01.834","Text":"For example, what we\u0027ve got is 12 times 3 is going to happen first,"},{"Start":"06:01.834 ","End":"06:05.160","Text":"and that would give us 36."},{"Start":"06:05.160 ","End":"06:08.190","Text":"Then we minus 3 plus 4,"},{"Start":"06:08.190 ","End":"06:09.475","Text":"which is 7,"},{"Start":"06:09.475 ","End":"06:11.378","Text":"and that, obviously, gives us 29."},{"Start":"06:11.378 ","End":"06:12.950","Text":"Have a play around with this."},{"Start":"06:12.950 ","End":"06:16.730","Text":"The expressions can involve a variable or they can involve literals,"},{"Start":"06:16.730 ","End":"06:20.345","Text":"but they eventually will be evaluated and return a value."},{"Start":"06:20.345 ","End":"06:23.240","Text":"Of course that value could be stored into a variable."},{"Start":"06:23.240 ","End":"06:24.770","Text":"We haven\u0027t done that here."},{"Start":"06:24.770 ","End":"06:29.735","Text":"We weren\u0027t asked to, but it\u0027s probably going to happen in a real program."},{"Start":"06:29.735 ","End":"06:34.220","Text":"That\u0027s it for very simple expressions using some of"},{"Start":"06:34.220 ","End":"06:39.990","Text":"the mathematical operators and we\u0027re done for question 4."}],"ID":27337},{"Watched":false,"Name":"Exercise 5","Duration":"12m 57s","ChapterTopicVideoID":26428,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.220","Text":"Hello, welcome back. In this exercise,"},{"Start":"00:02.220 ","End":"00:05.280","Text":"we\u0027ve been asked to use the same variables as in the previous exercise,"},{"Start":"00:05.280 ","End":"00:08.085","Text":"integer variables from num1 to num3."},{"Start":"00:08.085 ","End":"00:10.830","Text":"In part a, we\u0027ve been asked to assign the value 7"},{"Start":"00:10.830 ","End":"00:13.980","Text":"to variable num1 and 8 to variable num2."},{"Start":"00:13.980 ","End":"00:18.000","Text":"Then in part b, which has got some sub-questions we\u0027ve been asked,"},{"Start":"00:18.000 ","End":"00:20.040","Text":"without using any other variables,"},{"Start":"00:20.040 ","End":"00:22.980","Text":"to use the comparison or relational operators."},{"Start":"00:22.980 ","End":"00:26.820","Text":"As they are also known in the Code Pad to test first of all,"},{"Start":"00:26.820 ","End":"00:29.115","Text":"if num1 and num2 are equal."},{"Start":"00:29.115 ","End":"00:30.810","Text":"Then in part 2,"},{"Start":"00:30.810 ","End":"00:34.245","Text":"if num1 and num2 are not equal,"},{"Start":"00:34.245 ","End":"00:39.000","Text":"in part b iii is num1 greater than num2,"},{"Start":"00:39.000 ","End":"00:43.589","Text":"and in part b iv is num1 less than num2."},{"Start":"00:43.589 ","End":"00:49.310","Text":"Then in part c, we\u0027ve been asked to change the value of num2 to 7 and then retest to"},{"Start":"00:49.310 ","End":"00:55.100","Text":"see if in part c1 num1 is greater than or equal to num2."},{"Start":"00:55.100 ","End":"01:00.145","Text":"In part c2, if num1 is less than or equal to num2."},{"Start":"01:00.145 ","End":"01:02.360","Text":"In the next part of the exercise,"},{"Start":"01:02.360 ","End":"01:04.325","Text":"we use the logical operators."},{"Start":"01:04.325 ","End":"01:09.360","Text":"Part d asks us to assign the value 9 to num3."},{"Start":"01:09.360 ","End":"01:14.180","Text":"Then we use the logical and operator to create a single expression that"},{"Start":"01:14.180 ","End":"01:20.305","Text":"evaluates whether num2 is greater than 5 and less than 10."},{"Start":"01:20.305 ","End":"01:23.905","Text":"In part f, we\u0027re asked to change the value of num2 to 5,"},{"Start":"01:23.905 ","End":"01:27.775","Text":"then run the expression above again, in part g,"},{"Start":"01:27.775 ","End":"01:33.530","Text":"we\u0027re asked to use the logical or operator instead to create a single expression that"},{"Start":"01:33.530 ","End":"01:40.585","Text":"evaluates whether num1 is less than num2 or num3 is equal to 11."},{"Start":"01:40.585 ","End":"01:41.870","Text":"In part h,"},{"Start":"01:41.870 ","End":"01:45.440","Text":"we\u0027re asked to change the value of num3 to 11 and run"},{"Start":"01:45.440 ","End":"01:50.125","Text":"the expression from part f again to see if the evaluation changes."},{"Start":"01:50.125 ","End":"01:55.550","Text":"Then finally, we\u0027re asked to create our own expression using a combination of"},{"Start":"01:55.550 ","End":"01:59.030","Text":"logical and comparison operators and to include"},{"Start":"01:59.030 ","End":"02:02.890","Text":"the not operator and brackets to change the order of evaluation."},{"Start":"02:02.890 ","End":"02:05.210","Text":"We\u0027re asked to change the value of at least one of"},{"Start":"02:05.210 ","End":"02:09.635","Text":"our variables and to see the effect on the evaluation."},{"Start":"02:09.635 ","End":"02:12.440","Text":"In this exercise number 5,"},{"Start":"02:12.440 ","End":"02:16.340","Text":"we\u0027ve been asked to use the same variables as in Exercise 4."},{"Start":"02:16.340 ","End":"02:20.075","Text":"We add num1 to num3 or integer variables,"},{"Start":"02:20.075 ","End":"02:24.455","Text":"and to perform various steps in the code patterns before."},{"Start":"02:24.455 ","End":"02:28.820","Text":"The first step in part a is to assign num1,"},{"Start":"02:28.820 ","End":"02:30.495","Text":"the value 7,"},{"Start":"02:30.495 ","End":"02:34.080","Text":"and num2, the value 8."},{"Start":"02:34.080 ","End":"02:35.835","Text":"Let\u0027s go ahead and do that."},{"Start":"02:35.835 ","End":"02:37.960","Text":"Then in part b,"},{"Start":"02:37.960 ","End":"02:42.230","Text":"we\u0027re being asked to not use any other variables but to use the comparison,"},{"Start":"02:42.230 ","End":"02:46.220","Text":"also known as relational operators in Code Pad to test"},{"Start":"02:46.220 ","End":"02:52.340","Text":"various logical tests using comparison operators."},{"Start":"02:52.340 ","End":"02:54.980","Text":"The first one b part 1,"},{"Start":"02:54.980 ","End":"02:59.830","Text":"is asking to see if num1 and num2 are equal."},{"Start":"02:59.830 ","End":"03:05.000","Text":"First trap you could follow in here is to use a single equal sign."},{"Start":"03:05.000 ","End":"03:09.230","Text":"Remember the single equal sign means, assign a value."},{"Start":"03:09.230 ","End":"03:14.465","Text":"Double equals sign is the comparison operator in Java."},{"Start":"03:14.465 ","End":"03:17.465","Text":"We\u0027re comparing one value to another."},{"Start":"03:17.465 ","End":"03:19.465","Text":"In this expression we\u0027re saying,"},{"Start":"03:19.465 ","End":"03:21.905","Text":"is num1 equal to num2?"},{"Start":"03:21.905 ","End":"03:27.200","Text":"Does it contain the same value as num2? Let\u0027s see if it does."},{"Start":"03:27.200 ","End":"03:31.220","Text":"I get a response which is a Boolean response."},{"Start":"03:31.220 ","End":"03:35.330","Text":"These operators all return a Boolean response."},{"Start":"03:35.330 ","End":"03:37.160","Text":"In this case, it\u0027s false."},{"Start":"03:37.160 ","End":"03:39.635","Text":"Because num1 contains 7,"},{"Start":"03:39.635 ","End":"03:41.355","Text":"as you\u0027ve seen here,"},{"Start":"03:41.355 ","End":"03:42.990","Text":"and num2 contains 8."},{"Start":"03:42.990 ","End":"03:44.625","Text":"Clearly, they\u0027re not the same."},{"Start":"03:44.625 ","End":"03:49.145","Text":"We would expect therefore the evaluation to return false."},{"Start":"03:49.145 ","End":"03:53.540","Text":"In b2, we\u0027re asked to see if num1 and num2 are not"},{"Start":"03:53.540 ","End":"03:58.175","Text":"equal and just to test that we remember what the operator is."},{"Start":"03:58.175 ","End":"04:01.670","Text":"It is the not sign,"},{"Start":"04:01.670 ","End":"04:05.899","Text":"which is an exclamation mark followed by equals, no spaces."},{"Start":"04:05.899 ","End":"04:10.160","Text":"We\u0027re saying it\u0027s not equal to num2."},{"Start":"04:10.160 ","End":"04:13.985","Text":"As we know, 7 and 8 are not equal."},{"Start":"04:13.985 ","End":"04:18.590","Text":"The expression here generates a result of true,"},{"Start":"04:18.590 ","End":"04:25.670","Text":"num1 not equal to num2 returns the evaluation of true."},{"Start":"04:25.670 ","End":"04:32.224","Text":"In b3, we\u0027re asked to see if num1 is greater than num2."},{"Start":"04:32.224 ","End":"04:36.890","Text":"This is simple case of remembering your greater than and less than symbols."},{"Start":"04:36.890 ","End":"04:40.085","Text":"Num1 is greater than num2."},{"Start":"04:40.085 ","End":"04:41.870","Text":"We know that that\u0027s not true,"},{"Start":"04:41.870 ","End":"04:46.040","Text":"so we expect a false because 7 is not greater than 8."},{"Start":"04:46.040 ","End":"04:48.185","Text":"Let\u0027s try it the other way round then,"},{"Start":"04:48.185 ","End":"04:50.600","Text":"which is b4,"},{"Start":"04:50.600 ","End":"04:53.630","Text":"num1 is less than num2."},{"Start":"04:53.630 ","End":"04:56.030","Text":"Here\u0027s the less than operator."},{"Start":"04:56.030 ","End":"05:00.770","Text":"We would expect that to be true because 7 is less than 8."},{"Start":"05:00.770 ","End":"05:03.080","Text":"We are given a value true,"},{"Start":"05:03.080 ","End":"05:05.075","Text":"which is just what we\u0027d expect."},{"Start":"05:05.075 ","End":"05:12.180","Text":"We\u0027ve used the basic operators now in terms of comparison or relational operators."},{"Start":"05:12.180 ","End":"05:15.000","Text":"They will operate, as you would expect."},{"Start":"05:15.000 ","End":"05:18.695","Text":"Something\u0027s either equal to something else or it\u0027s not equal to something else."},{"Start":"05:18.695 ","End":"05:22.475","Text":"It\u0027s greater than something else or it\u0027s less than something else."},{"Start":"05:22.475 ","End":"05:27.365","Text":"We\u0027re now in part c. We\u0027ve asked to change the value of num2 to 7."},{"Start":"05:27.365 ","End":"05:28.850","Text":"Let\u0027s go ahead and do that."},{"Start":"05:28.850 ","End":"05:32.970","Text":"Remember, num1 is also 7 and then in"},{"Start":"05:32.970 ","End":"05:37.655","Text":"c1 we\u0027ve been asked to test if num1 is greater than or equal to num2."},{"Start":"05:37.655 ","End":"05:43.160","Text":"This is really just so that we get the idea of the greater than or equal to operator,"},{"Start":"05:43.160 ","End":"05:44.780","Text":"which is 2 symbols."},{"Start":"05:44.780 ","End":"05:49.129","Text":"The greater than comes first and the equals comes second."},{"Start":"05:49.129 ","End":"05:55.040","Text":"We\u0027re saying is num1 either greater than or exactly equal to num2."},{"Start":"05:55.040 ","End":"06:00.275","Text":"Of course, it is exactly equal to num2."},{"Start":"06:00.275 ","End":"06:04.785","Text":"Remember before, num1 greater than num2 return to false."},{"Start":"06:04.785 ","End":"06:07.730","Text":"This time because we\u0027ve changed it to greater than or"},{"Start":"06:07.730 ","End":"06:10.955","Text":"equal to and we\u0027ve changed the value of num2 to 7."},{"Start":"06:10.955 ","End":"06:16.009","Text":"We\u0027re getting a true instead of false."},{"Start":"06:16.009 ","End":"06:19.190","Text":"Let\u0027s try it the other way round or not the other way around."},{"Start":"06:19.190 ","End":"06:22.520","Text":"But let\u0027s try the less than or equal to operator,"},{"Start":"06:22.520 ","End":"06:25.055","Text":"which is part c2."},{"Start":"06:25.055 ","End":"06:34.610","Text":"We would expect that also to return true and it does because num1 is not less than num2."},{"Start":"06:34.610 ","End":"06:38.180","Text":"But it is exactly equal to num2 for the same reasons as we said above."},{"Start":"06:38.180 ","End":"06:44.150","Text":"Great. We\u0027ve used all of the basic operators for comparison and relationships."},{"Start":"06:44.150 ","End":"06:51.485","Text":"That\u0027s all straightforward and we\u0027ll see there\u0027s an awful lot in the next topic."},{"Start":"06:51.485 ","End":"06:55.190","Text":"It\u0027s really important that you\u0027ve understood this and by all means,"},{"Start":"06:55.190 ","End":"06:57.710","Text":"spend a little bit of extra time working"},{"Start":"06:57.710 ","End":"07:02.225","Text":"through some of your own examples to just drum that home."},{"Start":"07:02.225 ","End":"07:07.370","Text":"Now, part d, we\u0027ve been asked to assign the value 9 to num3."},{"Start":"07:07.370 ","End":"07:09.430","Text":"Let\u0027s go ahead and do that."},{"Start":"07:09.430 ","End":"07:14.450","Text":"Then use the logical and operator to create a single expression that"},{"Start":"07:14.450 ","End":"07:19.730","Text":"evaluates whether num2 is greater than 5 and less than 10."},{"Start":"07:19.730 ","End":"07:23.720","Text":"You\u0027ll remember that and requires two things to"},{"Start":"07:23.720 ","End":"07:27.920","Text":"be true in order to generate a true result."},{"Start":"07:27.920 ","End":"07:33.290","Text":"What we\u0027ve been asked to do here is num2 greater than 5 and less than 10?"},{"Start":"07:33.290 ","End":"07:34.760","Text":"We\u0027re going to ask two questions."},{"Start":"07:34.760 ","End":"07:38.010","Text":"We\u0027re going to say num2 greater than 5,"},{"Start":"07:38.010 ","End":"07:39.890","Text":"and we\u0027re going to ask another question,"},{"Start":"07:39.890 ","End":"07:44.905","Text":"num2 less than 10."},{"Start":"07:44.905 ","End":"07:48.605","Text":"But what we\u0027re going to do is we have to join those with an and,"},{"Start":"07:48.605 ","End":"07:50.330","Text":"and the keyword is not and."},{"Start":"07:50.330 ","End":"07:53.345","Text":"It would be in Python and Java and C,"},{"Start":"07:53.345 ","End":"07:55.070","Text":"it\u0027s a double ampersand,"},{"Start":"07:55.070 ","End":"07:59.150","Text":"2 ampersands would be a logical and."},{"Start":"07:59.150 ","End":"08:07.110","Text":"As we know, num2 contains 7."},{"Start":"08:07.110 ","End":"08:14.075","Text":"We would expect therefore because num2 is greater than 5 and num2 is less than 10."},{"Start":"08:14.075 ","End":"08:17.150","Text":"Both of those things are true either side of the logical and."},{"Start":"08:17.150 ","End":"08:19.970","Text":"We would expect the result to be true as well."},{"Start":"08:19.970 ","End":"08:24.310","Text":"We do indeed get a value of true."},{"Start":"08:24.310 ","End":"08:26.560","Text":"Now in part f,"},{"Start":"08:26.560 ","End":"08:32.135","Text":"we\u0027ve been asked to change the value of num2 to 5 and run that expression again."},{"Start":"08:32.135 ","End":"08:34.220","Text":"Let\u0027s do that."},{"Start":"08:34.220 ","End":"08:38.300","Text":"num2 equals 5. Let\u0027s run the expression again."},{"Start":"08:38.300 ","End":"08:40.490","Text":"Now this time we get a false."},{"Start":"08:40.490 ","End":"08:42.780","Text":"Exactly the same expression, but we get a false."},{"Start":"08:42.780 ","End":"08:44.750","Text":"I hope you\u0027ll realize why."},{"Start":"08:44.750 ","End":"08:49.340","Text":"It\u0027s because it\u0027s exactly equal to 5 but not greater than 5."},{"Start":"08:49.340 ","End":"08:54.395","Text":"Now num2, this part of the expression would evaluate to false."},{"Start":"08:54.395 ","End":"08:59.105","Text":"This one will be true because 5 is less than 10 still."},{"Start":"08:59.105 ","End":"09:01.670","Text":"But both parts have to be true for"},{"Start":"09:01.670 ","End":"09:05.975","Text":"the overall evaluation to come out true because that\u0027s what and expects."},{"Start":"09:05.975 ","End":"09:10.330","Text":"Hence we\u0027ve got this result of false."},{"Start":"09:10.330 ","End":"09:12.525","Text":"In part g,"},{"Start":"09:12.525 ","End":"09:15.395","Text":"we\u0027ve been asked to use the logical or operator"},{"Start":"09:15.395 ","End":"09:17.870","Text":"to create a single expression that evaluates"},{"Start":"09:17.870 ","End":"09:24.375","Text":"whether num1 is less than num2 or number 3 is equal to 11."},{"Start":"09:24.375 ","End":"09:32.255","Text":"What we want to do here then is say num1 is less than num2."},{"Start":"09:32.255 ","End":"09:37.710","Text":"Then we want the or and we say num3 equals 11."},{"Start":"09:37.710 ","End":"09:42.425","Text":"Now, or in Python is just or but in Java,"},{"Start":"09:42.425 ","End":"09:45.125","Text":"it\u0027s what we call the pipe character and it\u0027s two of them."},{"Start":"09:45.125 ","End":"09:46.850","Text":"It\u0027s like a vertical bar,"},{"Start":"09:46.850 ","End":"09:50.825","Text":"but we need two of those to do a logical or."},{"Start":"09:50.825 ","End":"09:54.680","Text":"What this is doing is it\u0027s joining two expressions together"},{"Start":"09:54.680 ","End":"09:58.730","Text":"and either of them can be true to generate a result of true."},{"Start":"09:58.730 ","End":"10:05.270","Text":"Either num1 is less than num2 or num3 is exactly equal to,"},{"Start":"10:05.270 ","End":"10:08.225","Text":"not 1, I\u0027ve been asked to do 11."},{"Start":"10:08.225 ","End":"10:12.875","Text":"Num3 is exactly equal to 11. Let\u0027s run that."},{"Start":"10:12.875 ","End":"10:20.120","Text":"I get a false because num1 is not less than num2."},{"Start":"10:20.120 ","End":"10:23.585","Text":"If we just remind ourselves what num1 has is 7."},{"Start":"10:23.585 ","End":"10:26.760","Text":"Num2 is 5."},{"Start":"10:26.760 ","End":"10:30.005","Text":"Num1 is actually greater than num2."},{"Start":"10:30.005 ","End":"10:32.374","Text":"Hence this part, it\u0027s going to be false."},{"Start":"10:32.374 ","End":"10:35.410","Text":"Num3 is not 11."},{"Start":"10:35.410 ","End":"10:39.005","Text":"Remind ourselves what num3 contains. It\u0027s got 9."},{"Start":"10:39.005 ","End":"10:41.720","Text":"Neither parts of this expression are true."},{"Start":"10:41.720 ","End":"10:43.550","Text":"That\u0027s false and that\u0027s false."},{"Start":"10:43.550 ","End":"10:47.555","Text":"Therefore, it cannot generate a true value, it generates false."},{"Start":"10:47.555 ","End":"10:50.300","Text":"However, now, if I change the values,"},{"Start":"10:50.300 ","End":"10:56.765","Text":"I\u0027ve been asked in part h of num3 to 11 and run that expression again,"},{"Start":"10:56.765 ","End":"10:59.255","Text":"what I see is true."},{"Start":"10:59.255 ","End":"11:02.330","Text":"Because even though num1 is not"},{"Start":"11:02.330 ","End":"11:05.679","Text":"less than num2 still because we didn\u0027t change their values,"},{"Start":"11:05.679 ","End":"11:08.195","Text":"7 is still not less than 5."},{"Start":"11:08.195 ","End":"11:13.790","Text":"This next part of the expression is num3 equal to 11 is now true."},{"Start":"11:13.790 ","End":"11:17.300","Text":"Only one part of this expression needs to be true with"},{"Start":"11:17.300 ","End":"11:22.175","Text":"all to generate a true as the output."},{"Start":"11:22.175 ","End":"11:26.085","Text":"That\u0027s great, that\u0027s part h done."},{"Start":"11:26.085 ","End":"11:29.510","Text":"In part i, we\u0027ve just been asked to use any combination of"},{"Start":"11:29.510 ","End":"11:32.360","Text":"logical and comparison operators and maybe use"},{"Start":"11:32.360 ","End":"11:36.950","Text":"the not operator as well and brackets to change the order of evaluation."},{"Start":"11:36.950 ","End":"11:38.435","Text":"Do have a play around with that."},{"Start":"11:38.435 ","End":"11:41.030","Text":"I\u0027ll show you an example of what I mean."},{"Start":"11:41.030 ","End":"11:45.825","Text":"For example, I could put a not around the whole thing."},{"Start":"11:45.825 ","End":"11:47.595","Text":"Brackets, first of all,"},{"Start":"11:47.595 ","End":"11:49.680","Text":"all of this will be evaluated."},{"Start":"11:49.680 ","End":"11:51.485","Text":"Whatever the result is."},{"Start":"11:51.485 ","End":"11:54.800","Text":"I will flip the results to the opposite."},{"Start":"11:54.800 ","End":"11:57.065","Text":"You see I was getting true before."},{"Start":"11:57.065 ","End":"11:59.735","Text":"It should flip back to false and it has."},{"Start":"11:59.735 ","End":"12:02.615","Text":"By taking the not out again,"},{"Start":"12:02.615 ","End":"12:04.760","Text":"you\u0027ll see it goes back to true."},{"Start":"12:04.760 ","End":"12:12.045","Text":"Note, the logical not operation just flips the output to the opposite Boolean value."},{"Start":"12:12.045 ","End":"12:13.670","Text":"The brackets, as you see,"},{"Start":"12:13.670 ","End":"12:15.545","Text":"it\u0027s evaluating this whole thing."},{"Start":"12:15.545 ","End":"12:18.335","Text":"Here is one. You can use that in any way you want."},{"Start":"12:18.335 ","End":"12:21.200","Text":"I can have another set of brackets inside the brackets if I wanted to,"},{"Start":"12:21.200 ","End":"12:23.690","Text":"it wouldn\u0027t make any difference in this particular example."},{"Start":"12:23.690 ","End":"12:28.205","Text":"But do have a play around with that and see the effect of brackets"},{"Start":"12:28.205 ","End":"12:33.350","Text":"on the way that things will be evaluated in a logical comparison."},{"Start":"12:33.350 ","End":"12:35.270","Text":"That\u0027s great. In these questions,"},{"Start":"12:35.270 ","End":"12:37.850","Text":"we\u0027ve looked at the logical operators,"},{"Start":"12:37.850 ","End":"12:40.350","Text":"the basic ones were and and or,"},{"Start":"12:40.350 ","End":"12:42.860","Text":"and then we also have not and we also looked at"},{"Start":"12:42.860 ","End":"12:46.475","Text":"the comparison and relational operators of equal to,"},{"Start":"12:46.475 ","End":"12:49.340","Text":"not equal to, greater than, less than,"},{"Start":"12:49.340 ","End":"12:53.690","Text":"and then greater than or equals to and less than or equal to."},{"Start":"12:53.690 ","End":"12:57.600","Text":"I\u0027ll see you in the next exercise."}],"ID":27338},{"Watched":false,"Name":"Exercise 6","Duration":"10m 22s","ChapterTopicVideoID":26429,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:04.770","Text":"Welcome. In this exercise we\u0027re going to explore the bitwise operators."},{"Start":"00:04.770 ","End":"00:06.540","Text":"In the code pad, as usual,"},{"Start":"00:06.540 ","End":"00:12.465","Text":"we\u0027re going to create a variable using the byte datatype and assign it the value 65."},{"Start":"00:12.465 ","End":"00:13.890","Text":"Then n part b,"},{"Start":"00:13.890 ","End":"00:17.895","Text":"we\u0027re going to perform a bitwise and operation on the variable."},{"Start":"00:17.895 ","End":"00:21.675","Text":"We\u0027re going to use this binary value to do that bitwise."},{"Start":"00:21.675 ","End":"00:26.690","Text":"In part c, we\u0027re asked to explain why you get the resulting value."},{"Start":"00:26.690 ","End":"00:32.525","Text":"In part d, we\u0027re asked to perform a bitwise or operation on the variable,"},{"Start":"00:32.525 ","End":"00:35.990","Text":"but this time using the decimal value 32."},{"Start":"00:35.990 ","End":"00:39.590","Text":"Then again to explain why we get this new value."},{"Start":"00:39.590 ","End":"00:43.970","Text":"In part f, we assign the value 17 to the byte variable,"},{"Start":"00:43.970 ","End":"00:47.450","Text":"then perform a bitwise exclusive or"},{"Start":"00:47.450 ","End":"00:51.920","Text":"operation on the variable using this binary value here."},{"Start":"00:51.920 ","End":"00:55.490","Text":"Once again, we\u0027re asked to explain the resulting evaluation."},{"Start":"00:55.490 ","End":"01:00.065","Text":"Then finally, we assign the value 1 to the byte variable,"},{"Start":"01:00.065 ","End":"01:03.950","Text":"and then perform a complement operation on the variable,"},{"Start":"01:03.950 ","End":"01:08.840","Text":"and we\u0027re asked to explain the value that we get and we\u0027re given a little hint."},{"Start":"01:08.840 ","End":"01:16.730","Text":"We\u0027ll start by creating the variable as he\u0027s asked us in part a. Typing the datatype,"},{"Start":"01:16.730 ","End":"01:18.500","Text":"give it a name,"},{"Start":"01:18.500 ","End":"01:24.340","Text":"and then assign the value 65 as it\u0027s asks us to complete that with a semicolon."},{"Start":"01:24.340 ","End":"01:28.070","Text":"Now in part b, we\u0027ve been asked to perform a bitwise and"},{"Start":"01:28.070 ","End":"01:32.225","Text":"operation on the variable using the given value."},{"Start":"01:32.225 ","End":"01:39.710","Text":"A variable name comes first the bitwise and operation is a single ampersand symbol."},{"Start":"01:39.710 ","End":"01:44.430","Text":"The value we\u0027ve been asked to and width is 0b01000000."},{"Start":"01:46.850 ","End":"01:49.715","Text":"Lets go and see what that does."},{"Start":"01:49.715 ","End":"01:53.135","Text":"The value we get back is 64."},{"Start":"01:53.135 ","End":"01:56.510","Text":"As we know with an and we have to have a"},{"Start":"01:56.510 ","End":"02:01.909","Text":"1 in both bytes in order to get a 1 at the output."},{"Start":"02:01.909 ","End":"02:04.640","Text":"Maybe it\u0027s easier to see this if we have two literals."},{"Start":"02:04.640 ","End":"02:10.745","Text":"If I put 0b01000000 as we\u0027ve started with,"},{"Start":"02:10.745 ","End":"02:15.770","Text":"and the value that we\u0027re ending with is 65,"},{"Start":"02:15.770 ","End":"02:19.255","Text":"which is actually a same bit pattern,"},{"Start":"02:19.255 ","End":"02:21.500","Text":"but with a 1 at the end."},{"Start":"02:21.500 ","End":"02:23.150","Text":"If we add those together,"},{"Start":"02:23.150 ","End":"02:26.570","Text":"we should get the same results, and we do."},{"Start":"02:26.570 ","End":"02:31.250","Text":"It\u0027s much easier to see obviously with the binary representation because"},{"Start":"02:31.250 ","End":"02:36.730","Text":"65 here has a 1 and 64 only has a 1."},{"Start":"02:36.730 ","End":"02:39.470","Text":"Therefore, the output is also going to be"},{"Start":"02:39.470 ","End":"02:42.730","Text":"64 because the only places where there are 2 1s,"},{"Start":"02:42.730 ","End":"02:45.465","Text":"are these 2 bit positions here."},{"Start":"02:45.465 ","End":"02:49.550","Text":"That explains and the value we get from parts a and b,"},{"Start":"02:49.550 ","End":"02:51.545","Text":"so part c is done."},{"Start":"02:51.545 ","End":"02:54.260","Text":"Now we are asked to perform a bitwise or"},{"Start":"02:54.260 ","End":"02:57.470","Text":"operation on the same variable with the same content Susan,"},{"Start":"02:57.470 ","End":"02:59.455","Text":"the decimal value 32."},{"Start":"02:59.455 ","End":"03:03.280","Text":"This just involves us using again a variable name,"},{"Start":"03:03.280 ","End":"03:09.395","Text":"and this time the bitwise or operation is the vertical bar or pipe character,"},{"Start":"03:09.395 ","End":"03:11.120","Text":"and only one of those is needed."},{"Start":"03:11.120 ","End":"03:13.385","Text":"A logical order would have two of them"},{"Start":"03:13.385 ","End":"03:16.930","Text":"because this is a bit wise or we only need one of them."},{"Start":"03:16.930 ","End":"03:19.850","Text":"Then we\u0027ve been asked to use the value 32."},{"Start":"03:19.850 ","End":"03:22.475","Text":"What\u0027s the value we get back?"},{"Start":"03:22.475 ","End":"03:25.760","Text":"We get 97 this time."},{"Start":"03:25.760 ","End":"03:31.940","Text":"Let\u0027s try and explain that value is it\u0027s asked us to in part e. Well,"},{"Start":"03:31.940 ","End":"03:34.700","Text":"if we do the same thing again and go from"},{"Start":"03:34.700 ","End":"03:38.345","Text":"the binary versions and the binary representations."},{"Start":"03:38.345 ","End":"03:43.460","Text":"We know already that 65 is 0b01000001"},{"Start":"03:43.460 ","End":"03:50.590","Text":", so that\u0027s 65."},{"Start":"03:50.590 ","End":"03:56.090","Text":"If we do a bit wise or with 32 is represented"},{"Start":"03:56.090 ","End":"04:01.545","Text":"by 0b00100000,or the first bit there will be 1 to 8,"},{"Start":"04:01.545 ","End":"04:04.995","Text":"then 64, then 32 there."},{"Start":"04:04.995 ","End":"04:08.685","Text":"Then all the other 4 bits will be 0s."},{"Start":"04:08.685 ","End":"04:12.570","Text":"Let\u0027s see what we get there and we do indeed get 97."},{"Start":"04:12.570 ","End":"04:16.865","Text":"We can see again more clearly when we do it with binary values"},{"Start":"04:16.865 ","End":"04:22.025","Text":"that the bitwise or will take each individual bit and,"},{"Start":"04:22.025 ","End":"04:26.010","Text":"or a bit in the respective position."},{"Start":"04:26.110 ","End":"04:31.715","Text":"Here, because we\u0027ve got an extra bit being set here,"},{"Start":"04:31.715 ","End":"04:35.410","Text":"the result will also have an extra bit set."},{"Start":"04:35.410 ","End":"04:37.115","Text":"It will be set here,"},{"Start":"04:37.115 ","End":"04:43.730","Text":"and the result. We\u0027ll have 01100001."},{"Start":"04:43.730 ","End":"04:49.805","Text":"If we want to prove that to send a look at the value of 97 in binary"},{"Start":"04:49.805 ","End":"04:58.590","Text":"should be 01100001 if we\u0027ve assumed,"},{"Start":"04:58.590 ","End":"04:59.910","Text":"right and it is."},{"Start":"04:59.910 ","End":"05:01.800","Text":"You can see that very clearly,"},{"Start":"05:01.800 ","End":"05:03.260","Text":"got a 1 set there,"},{"Start":"05:03.260 ","End":"05:05.540","Text":"but we\u0027ve also got at 1 set there,"},{"Start":"05:05.540 ","End":"05:08.195","Text":"which is what we see appearing here."},{"Start":"05:08.195 ","End":"05:13.520","Text":"The rest of it is all 0s apart from this bit here, which has a1."},{"Start":"05:13.520 ","End":"05:20.224","Text":"That explains part e. Moving on to part f,"},{"Start":"05:20.224 ","End":"05:23.675","Text":"we assign the value 17 to the variables."},{"Start":"05:23.675 ","End":"05:25.580","Text":"Let\u0027s go ahead and do that."},{"Start":"05:25.580 ","End":"05:28.280","Text":"Now we\u0027ve got 17 decimal in there."},{"Start":"05:28.280 ","End":"05:32.375","Text":"Now we\u0027ve been asked to perform a bitwise exclusive or"},{"Start":"05:32.375 ","End":"05:37.040","Text":"operation on that variable using a given binary value."},{"Start":"05:37.040 ","End":"05:42.425","Text":"Bitwise exclusive or we don\u0027t see a logical equivalent,"},{"Start":"05:42.425 ","End":"05:46.745","Text":"but that\u0027s the symbol for the operator to do a bitwise exclusive"},{"Start":"05:46.745 ","End":"05:51.230","Text":"or remember exclusive or means, not both bits."},{"Start":"05:51.230 ","End":"05:58.190","Text":"If 2 bits are set to operate in the 2 data items that were exclusive oriented together,"},{"Start":"05:58.190 ","End":"06:04.655","Text":"we ignore that bit once only one of them to have a 1 at the output."},{"Start":"06:04.655 ","End":"06:09.450","Text":"The value had been asked to put in 0b00010001."},{"Start":"06:12.670 ","End":"06:16.860","Text":"Let us see what result we get,"},{"Start":"06:16.860 ","End":"06:19.730","Text":"and 0 shortly, There we go."},{"Start":"06:19.730 ","End":"06:22.805","Text":"The result I get is 0."},{"Start":"06:22.805 ","End":"06:25.550","Text":"Now why do I get 0?"},{"Start":"06:25.550 ","End":"06:27.710","Text":"Well, the reason is,"},{"Start":"06:27.710 ","End":"06:31.025","Text":"if we were to put this again in binary,"},{"Start":"06:31.025 ","End":"06:35.435","Text":"actually what we\u0027ll find is the binary value that we were"},{"Start":"06:35.435 ","End":"06:40.655","Text":"oring with exclusive or in width is actually 17."},{"Start":"06:40.655 ","End":"06:46.010","Text":"We were doing 17 and exclusive oring with 17."},{"Start":"06:46.010 ","End":"06:54.229","Text":"Because both of these patterns have 1s in exactly the same place and nowhere else,"},{"Start":"06:54.229 ","End":"06:59.440","Text":"the result is going to be 0 and hopefully you can see that."},{"Start":"06:59.440 ","End":"07:04.700","Text":"Let\u0027s just prove that we\u0027ve got a 1 in this position and in"},{"Start":"07:04.700 ","End":"07:06.830","Text":"this position and we\u0027ve got a 1 in this position and"},{"Start":"07:06.830 ","End":"07:09.290","Text":"that position of course we have because they have the same number,"},{"Start":"07:09.290 ","End":"07:13.055","Text":"although we didn\u0027t make that obvious by putting it in decimal initially."},{"Start":"07:13.055 ","End":"07:18.440","Text":"The reason the output is 0 is because there is nowhere in either of these"},{"Start":"07:18.440 ","End":"07:23.810","Text":"2 where there is a 1 and it isn\u0027t already present in the other side."},{"Start":"07:23.810 ","End":"07:29.915","Text":"Hence, we get the result of 0 and that\u0027s why exclusive or is doing its job."},{"Start":"07:29.915 ","End":"07:32.359","Text":"It\u0027s only putting a 1 at the output."},{"Start":"07:32.359 ","End":"07:37.050","Text":"If the relative position doesn\u0027t have 2 1s."},{"Start":"07:37.050 ","End":"07:38.445","Text":"If there\u0027s a single 1,"},{"Start":"07:38.445 ","End":"07:40.245","Text":"then the output will have a 1."},{"Start":"07:40.245 ","End":"07:41.600","Text":"There\u0027s 2 0s,"},{"Start":"07:41.600 ","End":"07:43.535","Text":"then obviously it will have a 0 there."},{"Start":"07:43.535 ","End":"07:45.875","Text":"Let\u0027s do the last part,"},{"Start":"07:45.875 ","End":"07:53.535","Text":"which is part h. We\u0027ve been told to assign the value 1 to the variable,"},{"Start":"07:53.535 ","End":"07:56.075","Text":"and then to perform a complement."},{"Start":"07:56.075 ","End":"07:58.880","Text":"A complement operator is different than the one\u0027s we\u0027ve"},{"Start":"07:58.880 ","End":"08:01.805","Text":"just been using because it\u0027s what\u0027s called a unitary operator,"},{"Start":"08:01.805 ","End":"08:05.435","Text":"only needs 1 thing to operate on."},{"Start":"08:05.435 ","End":"08:09.650","Text":"The symbol itself is a tilde character."},{"Start":"08:09.650 ","End":"08:12.320","Text":"It\u0027s quite tricky to find on keyboards often,"},{"Start":"08:12.320 ","End":"08:16.250","Text":"minds next to the Enter key above the hash."},{"Start":"08:16.250 ","End":"08:18.035","Text":"It could be anywhere on your keyboard,"},{"Start":"08:18.035 ","End":"08:22.445","Text":"but it\u0027s usually in a fairly hard to find positions is not typed very often."},{"Start":"08:22.445 ","End":"08:26.540","Text":"That\u0027s the tilde character and that\u0027s what does the complement."},{"Start":"08:26.540 ","End":"08:29.300","Text":"We simply put the name of our variable and we\u0027ll"},{"Start":"08:29.300 ","End":"08:32.510","Text":"get a compliment of the value that\u0027s in the variable."},{"Start":"08:32.510 ","End":"08:34.265","Text":"I get -2,"},{"Start":"08:34.265 ","End":"08:36.575","Text":"now note I get int back."},{"Start":"08:36.575 ","End":"08:39.965","Text":"I really should be looking to get a bite back."},{"Start":"08:39.965 ","End":"08:42.920","Text":"I could do cast on this to see the result."},{"Start":"08:42.920 ","End":"08:46.880","Text":"But let\u0027s have a look at why it\u0027s -2. first of all,"},{"Start":"08:46.880 ","End":"08:49.940","Text":"because it\u0027s a signed number."},{"Start":"08:49.940 ","End":"08:53.930","Text":"If I were to do this as a byte literal,"},{"Start":"08:53.930 ","End":"08:59.610","Text":"I\u0027d get 1 is obviously all 0s in the upper level and"},{"Start":"08:59.610 ","End":"09:06.005","Text":"then 0001 that is 1 in binary."},{"Start":"09:06.005 ","End":"09:08.345","Text":"Now if I was to do a complement,"},{"Start":"09:08.345 ","End":"09:14.270","Text":"remember the complement turns every single bit to the opposite of what it currently is."},{"Start":"09:14.270 ","End":"09:21.895","Text":"All of these would be a 1 and this would be a 0."},{"Start":"09:21.895 ","End":"09:24.620","Text":"That\u0027s what the complement operation is doing."},{"Start":"09:24.620 ","End":"09:27.155","Text":"If you look at that again,"},{"Start":"09:27.155 ","End":"09:35.700","Text":"and if I actually type this out and flip it manually, 11111110."},{"Start":"09:35.810 ","End":"09:40.280","Text":"This is what the complemented version of that would look like."},{"Start":"09:40.280 ","End":"09:41.890","Text":"What\u0027s the value I get?"},{"Start":"09:41.890 ","End":"09:48.095","Text":"It\u0027s -2,and the only reason I\u0027m having to bite in front of it is when I put literals in,"},{"Start":"09:48.095 ","End":"09:51.020","Text":"in blue jay, it will assume they\u0027re integers always."},{"Start":"09:51.020 ","End":"09:53.990","Text":"A sign bit will be way over here"},{"Start":"09:53.990 ","End":"09:57.800","Text":"somewhere because it\u0027s a 32-bit number, obviously an integer."},{"Start":"09:57.800 ","End":"10:05.105","Text":"That\u0027s the explanation for part h. We get -2 because we\u0027ve complemented this pattern"},{"Start":"10:05.105 ","End":"10:08.750","Text":"when we\u0027re complimenting a bite that contains 1"},{"Start":"10:08.750 ","End":"10:12.455","Text":"and the complement will return this value here,"},{"Start":"10:12.455 ","End":"10:15.250","Text":"which I\u0027ve typed out as binary search easier for you to see,"},{"Start":"10:15.250 ","End":"10:16.880","Text":"and that binary value,"},{"Start":"10:16.880 ","End":"10:19.925","Text":"if it\u0027s a byte, is worth -2."},{"Start":"10:19.925 ","End":"10:23.580","Text":"That\u0027s it for this one. I\u0027ll see you in the next one."}],"ID":27339},{"Watched":false,"Name":"Exercise 7","Duration":"9m 3s","ChapterTopicVideoID":26430,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.910","Text":"Hi, again. In this video we\u0027re going to look at"},{"Start":"00:02.910 ","End":"00:05.550","Text":"the exercise in which we explore the increment,"},{"Start":"00:05.550 ","End":"00:08.880","Text":"decrement, and compound assignment operators."},{"Start":"00:08.880 ","End":"00:12.630","Text":"We have first been asked to create a variable of int datatype,"},{"Start":"00:12.630 ","End":"00:15.810","Text":"and to assign to it the initial value 10 decimal."},{"Start":"00:15.810 ","End":"00:20.070","Text":"In part a then, we\u0027re asked to use the post increment operator"},{"Start":"00:20.070 ","End":"00:23.910","Text":"on the variable and to not put a semicolon on the end of the line."},{"Start":"00:23.910 ","End":"00:26.160","Text":"In part b, we\u0027re asked the question,"},{"Start":"00:26.160 ","End":"00:31.290","Text":"why does that value reflected back by Bluej not appear to change?"},{"Start":"00:31.290 ","End":"00:33.450","Text":"Then we use in Part C,"},{"Start":"00:33.450 ","End":"00:36.615","Text":"the pre increment operator on the same variable."},{"Start":"00:36.615 ","End":"00:40.770","Text":"Once again, not to put a semicolon on the end of the line."},{"Start":"00:40.770 ","End":"00:42.500","Text":"In Part d,"},{"Start":"00:42.500 ","End":"00:47.990","Text":"we\u0027re asked what difference we observe between post and pre increment."},{"Start":"00:47.990 ","End":"00:50.330","Text":"Moving on to part e,"},{"Start":"00:50.330 ","End":"00:55.575","Text":"we are using now the pre decrement operator on the variable."},{"Start":"00:55.575 ","End":"01:00.110","Text":"In part f, we use the post decrement operator on the variable."},{"Start":"01:00.110 ","End":"01:03.980","Text":"Then, we use a compound assignment to multiply the variable"},{"Start":"01:03.980 ","End":"01:08.355","Text":"by 10 and store the result back into the variable."},{"Start":"01:08.355 ","End":"01:11.630","Text":"In part h, we use another compound assignment to"},{"Start":"01:11.630 ","End":"01:15.175","Text":"add 28 to the variable and store the result back in."},{"Start":"01:15.175 ","End":"01:17.260","Text":"Finally in part i,"},{"Start":"01:17.260 ","End":"01:25.150","Text":"we\u0027re asked to use a compound assignment to do a bitwise exclusive or with a value 129."},{"Start":"01:25.150 ","End":"01:30.875","Text":"We\u0027ve been first starts to create a variable of int datatype."},{"Start":"01:30.875 ","End":"01:33.870","Text":"Let\u0027s go ahead and do that."},{"Start":"01:34.460 ","End":"01:41.405","Text":"We are asked to give it the initial value of 10 in decimal."},{"Start":"01:41.405 ","End":"01:44.060","Text":"Then in part a, we\u0027re asked to use"},{"Start":"01:44.060 ","End":"01:46.320","Text":"the post increment operator on"},{"Start":"01:46.320 ","End":"01:49.505","Text":"the variable and to not put a semicolon on the end of the line."},{"Start":"01:49.505 ","End":"01:52.195","Text":"We get a value straight back."},{"Start":"01:52.195 ","End":"01:56.390","Text":"The increment and decrement operators are unitary."},{"Start":"01:56.390 ","End":"01:58.895","Text":"Once again, they only need one thing to operate on."},{"Start":"01:58.895 ","End":"02:01.160","Text":"If it\u0027s a post increment operator,"},{"Start":"02:01.160 ","End":"02:03.365","Text":"it follows the name of the variable."},{"Start":"02:03.365 ","End":"02:08.835","Text":"We\u0027ll put myVar, and then two pluses that will increment myVar by one."},{"Start":"02:08.835 ","End":"02:10.980","Text":"Let\u0027s see the value."},{"Start":"02:10.980 ","End":"02:14.205","Text":"Now, I had 10 in there originally."},{"Start":"02:14.205 ","End":"02:19.580","Text":"It does not seem to have changed as part b seems to suggest."},{"Start":"02:19.580 ","End":"02:23.400","Text":"It\u0027s asking, why it doesn\u0027t appear to change?"},{"Start":"02:23.400 ","End":"02:24.890","Text":"There is a clue there,"},{"Start":"02:24.890 ","End":"02:26.540","Text":"and it says appear to change."},{"Start":"02:26.540 ","End":"02:30.405","Text":"The value reflected back was 10."},{"Start":"02:30.405 ","End":"02:32.764","Text":"But what does myVar actually contain?"},{"Start":"02:32.764 ","End":"02:35.660","Text":"It actually contains 11."},{"Start":"02:35.660 ","End":"02:38.750","Text":"What we\u0027re seeing here is the difference between the post increment"},{"Start":"02:38.750 ","End":"02:42.215","Text":"and a pre increment when it\u0027s used in an expression."},{"Start":"02:42.215 ","End":"02:43.910","Text":"Although it doesn\u0027t look like it,"},{"Start":"02:43.910 ","End":"02:49.010","Text":"this is an expression and could be used in an expression if we wanted it to"},{"Start":"02:49.010 ","End":"02:54.950","Text":"but what it\u0027s doing is it\u0027s giving us the value back before it increments it."},{"Start":"02:54.950 ","End":"03:00.015","Text":"Hence, the name post increment because it will return a value."},{"Start":"03:00.015 ","End":"03:04.490","Text":"Then after post the return of the value, equal increment it."},{"Start":"03:04.490 ","End":"03:06.260","Text":"That\u0027s exactly what\u0027s happened here."},{"Start":"03:06.260 ","End":"03:07.595","Text":"We started with 10,"},{"Start":"03:07.595 ","End":"03:09.170","Text":"myVar had 10 in it,"},{"Start":"03:09.170 ","End":"03:11.975","Text":"and when we executed myVar plus, plus."},{"Start":"03:11.975 ","End":"03:16.325","Text":"It gave us back the value before the increment,"},{"Start":"03:16.325 ","End":"03:19.715","Text":"which we see here, but when we display the value,"},{"Start":"03:19.715 ","End":"03:23.820","Text":"we\u0027ve seen them, it\u0027s actually got 11 and then now."},{"Start":"03:23.820 ","End":"03:27.320","Text":"Let\u0027s see it should be fairly obvious what happens in part"},{"Start":"03:27.320 ","End":"03:32.030","Text":"c. Use the pre increment operator on the variable,"},{"Start":"03:32.030 ","End":"03:35.010","Text":"and don\u0027t put a semicolon on the end."},{"Start":"03:35.010 ","End":"03:36.829","Text":"We see the value back straightaway."},{"Start":"03:36.829 ","End":"03:39.170","Text":"If I do plus plus MyVar,"},{"Start":"03:39.170 ","End":"03:41.525","Text":"that\u0027s the pre increment."},{"Start":"03:41.525 ","End":"03:44.150","Text":"Increment because it\u0027s plus, double plus,"},{"Start":"03:44.150 ","End":"03:48.095","Text":"and pre because it comes before the variable name."},{"Start":"03:48.095 ","End":"03:52.850","Text":"It reflects back the value straight away in the expression."},{"Start":"03:52.850 ","End":"03:56.000","Text":"Obviously, there\u0027s no other parts to this expression here."},{"Start":"03:56.000 ","End":"04:00.250","Text":"But it\u0027s giving me the value back straightaway of the incremented value."},{"Start":"04:00.250 ","End":"04:03.845","Text":"It was 11, and it immediately gives me 12 back."},{"Start":"04:03.845 ","End":"04:07.340","Text":"It shows me the value 12,"},{"Start":"04:07.340 ","End":"04:11.495","Text":"and it\u0027s also got stored in it 12, you\u0027ll find there."},{"Start":"04:11.495 ","End":"04:17.145","Text":"You see the contrast now between the post increment and the pre increment."},{"Start":"04:17.145 ","End":"04:20.325","Text":"Basically, they both add 1 but 1,"},{"Start":"04:20.325 ","End":"04:25.130","Text":"if it\u0027s involved in expression will return the value before it\u0027s incremented."},{"Start":"04:25.130 ","End":"04:28.805","Text":"The other one will show you the increments straight away,"},{"Start":"04:28.805 ","End":"04:32.225","Text":"as we see in these examples here."},{"Start":"04:32.225 ","End":"04:40.010","Text":"That\u0027s us done from parts a to d. Now we\u0027ve been asked to use the pre decrement operator."},{"Start":"04:40.010 ","End":"04:43.560","Text":"Presumably, that is going to be straightforward,"},{"Start":"04:43.560 ","End":"04:45.165","Text":"and follow the same pattern."},{"Start":"04:45.165 ","End":"04:50.625","Text":"Pre decrement, decrement is minus minus."},{"Start":"04:50.625 ","End":"04:53.140","Text":"This is pre decrement."},{"Start":"04:53.140 ","End":"04:56.630","Text":"It\u0027s going to give me the value back straight away when I get it"},{"Start":"04:56.630 ","End":"05:00.285","Text":"reflected back because it\u0027s used in an expression here and it\u0027s 11."},{"Start":"05:00.285 ","End":"05:01.430","Text":"Which is what I expect,"},{"Start":"05:01.430 ","End":"05:04.605","Text":"and it will contain 11, which it does."},{"Start":"05:04.605 ","End":"05:08.840","Text":"Now I\u0027m asked to use the post decrement operator."},{"Start":"05:08.840 ","End":"05:14.360","Text":"With F^F, that\u0027ll be myVar minus, minus."},{"Start":"05:14.360 ","End":"05:16.760","Text":"What do you expect to happen here?"},{"Start":"05:16.760 ","End":"05:18.800","Text":"Because it\u0027s a post decrement,"},{"Start":"05:18.800 ","End":"05:22.310","Text":"we should see 11 reflected back because that\u0027s"},{"Start":"05:22.310 ","End":"05:26.600","Text":"the value that we expect before we take away 1."},{"Start":"05:26.600 ","End":"05:29.520","Text":"But it then should subsequently contain 10."},{"Start":"05:29.520 ","End":"05:32.790","Text":"We do indeed see 11 reflected back."},{"Start":"05:32.790 ","End":"05:35.040","Text":"If we look at myVar,"},{"Start":"05:35.040 ","End":"05:38.070","Text":"it does indeed contain 10."},{"Start":"05:38.070 ","End":"05:41.990","Text":"That\u0027s us done from parts a to f. Now"},{"Start":"05:41.990 ","End":"05:47.330","Text":"the last couple of parts to this exercise asks us to do some compound assignments."},{"Start":"05:47.330 ","End":"05:52.340","Text":"In part g says user compound assignment to multiply the variable by 10,"},{"Start":"05:52.340 ","End":"05:54.955","Text":"and store the result back into the variable."},{"Start":"05:54.955 ","End":"06:00.065","Text":"Well at compound assignment is a very lean syntax."},{"Start":"06:00.065 ","End":"06:03.200","Text":"What it will do is do some operation,"},{"Start":"06:03.200 ","End":"06:08.300","Text":"and store immediately back the value into the variable."},{"Start":"06:08.300 ","End":"06:14.215","Text":"What we want to do is say, myVar times equals 10."},{"Start":"06:14.215 ","End":"06:17.910","Text":"What we\u0027re saying, is multiplied by 10,"},{"Start":"06:17.910 ","End":"06:21.220","Text":"and store it back into myVar."},{"Start":"06:21.220 ","End":"06:29.470","Text":"We should see a 100 stored back into myVar if we\u0027ve got the syntax right, and we do."},{"Start":"06:29.470 ","End":"06:32.960","Text":"It\u0027s not just reflecting back the current value of myVar,"},{"Start":"06:32.960 ","End":"06:35.330","Text":"it\u0027s actually stored that in MyVar as well."},{"Start":"06:35.330 ","End":"06:37.055","Text":"Just to prove it, I\u0027ll do that."},{"Start":"06:37.055 ","End":"06:43.660","Text":"The expression results in 10 being multiplied by 10 because that\u0027s what myVar had in it,"},{"Start":"06:43.660 ","End":"06:45.590","Text":"and that\u0027s what we see reflected back here."},{"Start":"06:45.590 ","End":"06:51.650","Text":"But it also results in the assignment of a new value to myVar."},{"Start":"06:51.650 ","End":"06:54.320","Text":"We\u0027re doing two things that we\u0027re doing a multiplication,"},{"Start":"06:54.320 ","End":"06:57.635","Text":"and then we\u0027re storing it back into the original variables."},{"Start":"06:57.635 ","End":"07:01.880","Text":"The equivalent way of doing this in slightly longer syntax would"},{"Start":"07:01.880 ","End":"07:05.900","Text":"have been this myVar equals myVar times 10 would have"},{"Start":"07:05.900 ","End":"07:07.880","Text":"had exactly the same result but it\u0027s"},{"Start":"07:07.880 ","End":"07:13.985","Text":"a slightly more compact form to do it with the compound assignment."},{"Start":"07:13.985 ","End":"07:16.820","Text":"That\u0027s part g. Now it\u0027s saying use"},{"Start":"07:16.820 ","End":"07:21.035","Text":"a compound assignment to add 28 to the variable and store the results."},{"Start":"07:21.035 ","End":"07:22.760","Text":"That\u0027s exactly the same."},{"Start":"07:22.760 ","End":"07:25.655","Text":"We just obviously going to use a different symbol."},{"Start":"07:25.655 ","End":"07:27.950","Text":"A plus comes first,"},{"Start":"07:27.950 ","End":"07:31.520","Text":"then the equals, and then whatever the value is,"},{"Start":"07:31.520 ","End":"07:33.365","Text":"what we want to work with."},{"Start":"07:33.365 ","End":"07:39.080","Text":"It\u0027s added 28 to what was already in there and stored it back into myVar."},{"Start":"07:39.080 ","End":"07:43.815","Text":"Myvar contains 128, nice and easy."},{"Start":"07:43.815 ","End":"07:46.940","Text":"Then the last one is to use a compound assignment to do"},{"Start":"07:46.940 ","End":"07:50.315","Text":"a bitwise exclusive or with your variable,"},{"Start":"07:50.315 ","End":"07:51.668","Text":"and the value 1, 2,"},{"Start":"07:51.668 ","End":"07:53.880","Text":"9, install them only back."},{"Start":"07:53.880 ","End":"08:02.340","Text":"That is going to be myVar bitwise exclusive or is the current symbols,"},{"Start":"08:02.340 ","End":"08:05.734","Text":"is usually shift, and, followed by equals."},{"Start":"08:05.734 ","End":"08:06.980","Text":"We just did that on its own."},{"Start":"08:06.980 ","End":"08:11.015","Text":"It would do the bitwise exclusive or but it wouldn\u0027t store it back into myVar."},{"Start":"08:11.015 ","End":"08:15.485","Text":"We put the equals to store it back into myVar."},{"Start":"08:15.485 ","End":"08:18.432","Text":"Then we will use the value 1,"},{"Start":"08:18.432 ","End":"08:20.520","Text":"2, 9, and see what we get back."},{"Start":"08:20.520 ","End":"08:22.095","Text":"We get 1 back."},{"Start":"08:22.095 ","End":"08:25.725","Text":"Because remember the bitwise exclusive or,"},{"Start":"08:25.725 ","End":"08:29.415","Text":"doesn\u0027t want to see two 1s\u0027 in any bit position,"},{"Start":"08:29.415 ","End":"08:30.942","Text":"1, 2, 8, and 1, 2,"},{"Start":"08:30.942 ","End":"08:36.500","Text":"9 are exactly the same number with the least significant bit set in 1, 2, 9."},{"Start":"08:36.500 ","End":"08:39.845","Text":"It\u0027s the same as doing this, for example."},{"Start":"08:39.845 ","End":"08:42.105","Text":"This will be 1, 2, 8."},{"Start":"08:42.105 ","End":"08:46.220","Text":"If we do a bitwise exclusive or,"},{"Start":"08:46.220 ","End":"08:47.720","Text":"with 1, 2, 9,"},{"Start":"08:47.720 ","End":"08:50.705","Text":"it\u0027ll learn this. Hence, we get 1."},{"Start":"08:50.705 ","End":"08:54.749","Text":"Because we did an compound assignment,"},{"Start":"08:54.749 ","End":"08:56.940","Text":"that value in myVar will now be stored away."},{"Start":"08:56.940 ","End":"08:58.695","Text":"MyVar will contain 1."},{"Start":"08:58.695 ","End":"09:01.305","Text":"That\u0027s it for Exercise 7."},{"Start":"09:01.305 ","End":"09:03.940","Text":"I\u0027ll see you in the next one."}],"ID":27340},{"Watched":false,"Name":"Exercise 8","Duration":"9m 11s","ChapterTopicVideoID":26431,"CourseChapterTopicPlaylistID":246357,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.940","Text":"Hey, welcome back. In this final exercise,"},{"Start":"00:02.940 ","End":"00:05.340","Text":"we\u0027re going to move away from the code pad and"},{"Start":"00:05.340 ","End":"00:08.520","Text":"instead create a program in the BlueJ editor."},{"Start":"00:08.520 ","End":"00:12.090","Text":"We\u0027ve eventually been asked to create a class in this project that we\u0027ve already"},{"Start":"00:12.090 ","End":"00:15.480","Text":"been working in code MyTempConverterApp."},{"Start":"00:15.480 ","End":"00:19.740","Text":"Then in Part A to declare a variable of an appropriate type to hold"},{"Start":"00:19.740 ","End":"00:27.600","Text":"an input temperature and to give it an initial value of 37.77778."},{"Start":"00:27.600 ","End":"00:30.750","Text":"Then in Part B, to declare a variable of an appropriate type,"},{"Start":"00:30.750 ","End":"00:33.615","Text":"again, to hold an output temperature."},{"Start":"00:33.615 ","End":"00:38.770","Text":"Then in Part C, we\u0027re asked to create a method inside the class called Convert."},{"Start":"00:38.770 ","End":"00:41.660","Text":"Then in Part D, within the Convert method,"},{"Start":"00:41.660 ","End":"00:44.540","Text":"we are asked to add a line that uses whatever operators are"},{"Start":"00:44.540 ","End":"00:47.720","Text":"needed to convert the input temperature from"},{"Start":"00:47.720 ","End":"00:51.050","Text":"Celsius to Fahrenheit and to assign"},{"Start":"00:51.050 ","End":"00:54.855","Text":"the evaluated value to the output temperature variable."},{"Start":"00:54.855 ","End":"00:56.335","Text":"Then in Part E,"},{"Start":"00:56.335 ","End":"00:59.390","Text":"we\u0027re asked to add a second line in that method which will print"},{"Start":"00:59.390 ","End":"01:03.700","Text":"the output temperature to the screen using system out print line."},{"Start":"01:03.700 ","End":"01:06.830","Text":"Then in Part F, we are asked to compile the program and test"},{"Start":"01:06.830 ","End":"01:10.324","Text":"it correct any errors that have been signaled by the compiler."},{"Start":"01:10.324 ","End":"01:16.010","Text":"In Part G, create an object from the class to finally test the code and"},{"Start":"01:16.010 ","End":"01:22.375","Text":"run the Convert method in Part H and check that the result is a 100."},{"Start":"01:22.375 ","End":"01:28.265","Text":"The first thing we need to do is to create a class within our project."},{"Start":"01:28.265 ","End":"01:30.530","Text":"Up until now, we\u0027ve been using the codePad for everything."},{"Start":"01:30.530 ","End":"01:33.410","Text":"Generally, you would have a project which will contain"},{"Start":"01:33.410 ","End":"01:36.470","Text":"all your code and that will be made up of multiple classes,"},{"Start":"01:36.470 ","End":"01:38.720","Text":"which will appear here in this exercise."},{"Start":"01:38.720 ","End":"01:42.980","Text":"We only need 1 class and we\u0027ll do for many of the initial exercises."},{"Start":"01:42.980 ","End":"01:46.190","Text":"Let\u0027s go ahead and create the new class by clicking on the button"},{"Start":"01:46.190 ","End":"01:50.630","Text":"here and giving it the name we\u0027ve been asked to give,"},{"Start":"01:50.630 ","End":"01:58.235","Text":"which is MyTempConverterApp that we are given"},{"Start":"01:58.235 ","End":"02:02.750","Text":"the class and we will have code in which BlueJ just helpfully"},{"Start":"02:02.750 ","End":"02:07.545","Text":"puts in for you while I wanted to take it out just to make it clear what we\u0027re adding."},{"Start":"02:07.545 ","End":"02:11.405","Text":"We\u0027ll just keep the opening line and the braces."},{"Start":"02:11.405 ","End":"02:14.720","Text":"In Part A, we\u0027ve been asked to declare a variable of"},{"Start":"02:14.720 ","End":"02:19.100","Text":"an appropriate type to hold an input temperature and to give it an initial value."},{"Start":"02:19.100 ","End":"02:22.370","Text":"37 point several 7, and an 8."},{"Start":"02:22.370 ","End":"02:26.740","Text":"What would be an appropriate data type for this data?"},{"Start":"02:26.740 ","End":"02:29.255","Text":"Well, it\u0027s a real number,"},{"Start":"02:29.255 ","End":"02:31.625","Text":"so our choice is a float or a double."},{"Start":"02:31.625 ","End":"02:35.270","Text":"Double would probably be overkill for this number."},{"Start":"02:35.270 ","End":"02:37.940","Text":"There\u0027s not many digits in the decimal places,"},{"Start":"02:37.940 ","End":"02:40.560","Text":"so float will suffice."},{"Start":"02:40.560 ","End":"02:42.560","Text":"If we put the data type float,"},{"Start":"02:42.560 ","End":"02:47.225","Text":"give it a name I\u0027m going to call mine input t rather than writing out temperature."},{"Start":"02:47.225 ","End":"02:51.005","Text":"But I could write temperature or even temp perhaps would be a little bit better."},{"Start":"02:51.005 ","End":"02:52.910","Text":"Input temp for temperature."},{"Start":"02:52.910 ","End":"03:02.400","Text":"I\u0027ll give it an initial value 37.77778 and a semicolon."},{"Start":"03:02.400 ","End":"03:05.090","Text":"Then I\u0027ve been asked to declare in Part B"},{"Start":"03:05.090 ","End":"03:09.395","Text":"another variable to hold an output temperature again, of an appropriate type."},{"Start":"03:09.395 ","End":"03:11.180","Text":"Well, if the input was a float,"},{"Start":"03:11.180 ","End":"03:15.900","Text":"it would make sense for the output to be a float as well."},{"Start":"03:15.900 ","End":"03:19.415","Text":"I don\u0027t need to give it an initial value, haven\u0027t been asked to."},{"Start":"03:19.415 ","End":"03:22.280","Text":"I\u0027ll just end the line with a semicolon."},{"Start":"03:22.280 ","End":"03:23.510","Text":"We\u0027re on Part C now,"},{"Start":"03:23.510 ","End":"03:28.460","Text":"so we\u0027re asked to create a method inside the class called converts."},{"Start":"03:28.460 ","End":"03:31.085","Text":"Our method is where the code belongs."},{"Start":"03:31.085 ","End":"03:33.320","Text":"We saw when we did an initial exercise what"},{"Start":"03:33.320 ","End":"03:36.350","Text":"this looks like the structure of a Java program."},{"Start":"03:36.350 ","End":"03:39.065","Text":"Without going into too much detail,"},{"Start":"03:39.065 ","End":"03:43.625","Text":"you\u0027ll need to put in front of the name of the method a keyword void,"},{"Start":"03:43.625 ","End":"03:45.590","Text":"basically saying to the compiler,"},{"Start":"03:45.590 ","End":"03:48.350","Text":"don\u0027t expect anything to come back from this program."},{"Start":"03:48.350 ","End":"03:53.210","Text":"Then we put the name of the method and you put a pair of empty brackets for the moment."},{"Start":"03:53.210 ","End":"03:54.350","Text":"Later on in the course,"},{"Start":"03:54.350 ","End":"03:56.525","Text":"we\u0027ll find out what goes in those brackets."},{"Start":"03:56.525 ","End":"04:01.250","Text":"I\u0027ll close off my method with a closing brace here."},{"Start":"04:01.250 ","End":"04:06.380","Text":"It seems to be happy and you\u0027ll see in BlueJ highlights in yellow here,"},{"Start":"04:06.380 ","End":"04:11.275","Text":"to say that it\u0027s a method and the block is complete essentially."},{"Start":"04:11.275 ","End":"04:14.930","Text":"Code inside it should be indented it\u0027s good practice."},{"Start":"04:14.930 ","End":"04:17.120","Text":"It will still work if it doesn\u0027t but should"},{"Start":"04:17.120 ","End":"04:19.745","Text":"indent it just to make your code look a bit more readable."},{"Start":"04:19.745 ","End":"04:22.490","Text":"Now when I\u0027ve been asked to do in"},{"Start":"04:22.490 ","End":"04:27.020","Text":"Part D is to add a line that uses whatever operators are needed to"},{"Start":"04:27.020 ","End":"04:29.810","Text":"convert the imprint temperature from Celsius to"},{"Start":"04:29.810 ","End":"04:34.610","Text":"Fahrenheit and to assign the evaluated value to the output temperature value."},{"Start":"04:34.610 ","End":"04:41.300","Text":"Here I need to come up with a formula for this and we do a Google search for this."},{"Start":"04:41.300 ","End":"04:47.240","Text":"But what I\u0027m doing is I\u0027m trying to put a value into the output temp variable."},{"Start":"04:47.240 ","End":"04:50.675","Text":"That\u0027s where my expression will start output temp."},{"Start":"04:50.675 ","End":"04:52.805","Text":"Then the assignment operator,"},{"Start":"04:52.805 ","End":"04:55.700","Text":"because I want a value to go into output temp."},{"Start":"04:55.700 ","End":"04:59.960","Text":"Then the rest of the expression we\u0027ll do the calculation which calculates"},{"Start":"04:59.960 ","End":"05:07.130","Text":"a temperature in Fahrenheit when given a value in centigrade or degrees Celsius."},{"Start":"05:07.130 ","End":"05:09.050","Text":"If we have it,"},{"Start":"05:09.050 ","End":"05:12.515","Text":"the value that we want an input temp,"},{"Start":"05:12.515 ","End":"05:15.245","Text":"then that\u0027s how our expression is going to start off."},{"Start":"05:15.245 ","End":"05:19.355","Text":"If you were to look up what the conversion is,"},{"Start":"05:19.355 ","End":"05:21.710","Text":"do a web search for that."},{"Start":"05:21.710 ","End":"05:26.090","Text":"You\u0027ll find that the formula is the input temperature multiplied"},{"Start":"05:26.090 ","End":"05:31.775","Text":"by 9/5 and added to that should be 32,"},{"Start":"05:31.775 ","End":"05:33.935","Text":"and that should give you the results."},{"Start":"05:33.935 ","End":"05:37.550","Text":"Now, we won\u0027t get the correct result if we do"},{"Start":"05:37.550 ","End":"05:41.615","Text":"this and you might scratch your head and think of why wouldn\u0027t get the correct result."},{"Start":"05:41.615 ","End":"05:45.035","Text":"But actually, it comes down to this little bit here,"},{"Start":"05:45.035 ","End":"05:48.570","Text":"because this is a literal fraction"},{"Start":"05:48.570 ","End":"05:53.135","Text":"and by default what will happen is this will do an integer division."},{"Start":"05:53.135 ","End":"05:57.980","Text":"What you want to do is to force the compiler to consider this as a"},{"Start":"05:57.980 ","End":"06:03.110","Text":"fractional literal and it will work nicely."},{"Start":"06:03.110 ","End":"06:06.020","Text":"You could also work out what 9/5 is actually"},{"Start":"06:06.020 ","End":"06:10.895","Text":"1.8 and put 1.8 in there instead and that would do the job as well."},{"Start":"06:10.895 ","End":"06:12.110","Text":"If you don\u0027t do that,"},{"Start":"06:12.110 ","End":"06:16.385","Text":"you\u0027ll get an incorrect result and that will be the first little hurdle for you."},{"Start":"06:16.385 ","End":"06:21.890","Text":"Let\u0027s try and do the final part which says system out,"},{"Start":"06:21.890 ","End":"06:25.590","Text":"print line, and print the results basically."},{"Start":"06:25.590 ","End":"06:27.140","Text":"What is the result going to be?"},{"Start":"06:27.140 ","End":"06:29.975","Text":"Well, it\u0027s been stored into output temp."},{"Start":"06:29.975 ","End":"06:34.585","Text":"That is what we\u0027re looking to see."},{"Start":"06:34.585 ","End":"06:42.140","Text":"We\u0027ve done all the steps now from A to E. We probably written a few too many lines here."},{"Start":"06:42.140 ","End":"06:44.555","Text":"You should really, when you\u0027re writing a couple of lines,"},{"Start":"06:44.555 ","End":"06:47.555","Text":"test by compiling them as you\u0027re going along."},{"Start":"06:47.555 ","End":"06:49.130","Text":"If we click on compile here,"},{"Start":"06:49.130 ","End":"06:51.695","Text":"you\u0027ll see already it\u0027s found an error."},{"Start":"06:51.695 ","End":"06:55.930","Text":"Highlights in the margin here where the error is."},{"Start":"06:55.930 ","End":"06:57.350","Text":"If I click on the line,"},{"Start":"06:57.350 ","End":"07:02.539","Text":"it tells me incompatible types possible lossy conversion from double to float."},{"Start":"07:02.539 ","End":"07:04.160","Text":"What it\u0027s saying here is,"},{"Start":"07:04.160 ","End":"07:07.505","Text":"it\u0027s always assuming that if you put a fractional number,"},{"Start":"07:07.505 ","End":"07:10.820","Text":"that it\u0027s a double and it\u0027s trying to convert it from a"},{"Start":"07:10.820 ","End":"07:15.425","Text":"double to a float because it knows that that\u0027s what we want to put it into."},{"Start":"07:15.425 ","End":"07:18.020","Text":"We already saw this once before."},{"Start":"07:18.020 ","End":"07:22.820","Text":"We know that the trick here is just to put an f on the end to tell it that this"},{"Start":"07:22.820 ","End":"07:28.160","Text":"is a floating-point number and it should make the error go away."},{"Start":"07:28.160 ","End":"07:31.760","Text":"Let\u0027s compile and indeed the error does go away."},{"Start":"07:31.760 ","End":"07:35.675","Text":"We\u0027ve got a literal here which is assuming is a double."},{"Start":"07:35.675 ","End":"07:37.070","Text":"I\u0027m telling it no,"},{"Start":"07:37.070 ","End":"07:38.915","Text":"it\u0027s not double, it\u0027s a float."},{"Start":"07:38.915 ","End":"07:44.630","Text":"Therefore, I can assign it to a float without getting that warning error message."},{"Start":"07:44.630 ","End":"07:48.470","Text":"That now compiles with no syntax errors."},{"Start":"07:48.470 ","End":"07:52.715","Text":"What I\u0027m able to do now is I can close the editor."},{"Start":"07:52.715 ","End":"07:55.580","Text":"As it is asked me to do in"},{"Start":"07:55.580 ","End":"08:00.380","Text":"Part F while I\u0027ve actually compiled it and done Part F. Now I need to do Part G,"},{"Start":"08:00.380 ","End":"08:03.305","Text":"test it by creating an object from the class which you remember,"},{"Start":"08:03.305 ","End":"08:07.010","Text":"you right-click say new temperature converter app."},{"Start":"08:07.010 ","End":"08:10.340","Text":"It gives me a default name, I\u0027ll just accept."},{"Start":"08:10.340 ","End":"08:12.739","Text":"Then down here on the object workbench,"},{"Start":"08:12.739 ","End":"08:16.625","Text":"I\u0027ve got the object which I can run code on."},{"Start":"08:16.625 ","End":"08:22.940","Text":"I right-click now I select the name of the method that I wanted to run."},{"Start":"08:22.940 ","End":"08:25.130","Text":"I only have 1 method and it\u0027s called convert."},{"Start":"08:25.130 ","End":"08:31.305","Text":"I run it and it should print on the terminal the results and up pops my Terminal Window."},{"Start":"08:31.305 ","End":"08:34.385","Text":"The result is indeed what I was expecting,"},{"Start":"08:34.385 ","End":"08:36.410","Text":"which is a 100."},{"Start":"08:36.410 ","End":"08:39.290","Text":"Nice and simple program,"},{"Start":"08:39.290 ","End":"08:45.860","Text":"first useful program that we\u0027ve written really that converts a temperature from degrees"},{"Start":"08:45.860 ","End":"08:49.190","Text":"Celsius into Fahrenheit and displays the result on"},{"Start":"08:49.190 ","End":"08:53.540","Text":"the screen and only took a few lines of code to do that."},{"Start":"08:53.540 ","End":"08:56.675","Text":"But the key to it was this expression here,"},{"Start":"08:56.675 ","End":"09:04.415","Text":"which evaluated what this calculation is and then store the result into output temp,"},{"Start":"09:04.415 ","End":"09:07.400","Text":"which we then displayed on the screen."},{"Start":"09:07.400 ","End":"09:11.940","Text":"Thanks very much, and I\u0027ll see you in the next video."}],"ID":27341}],"Thumbnail":null,"ID":246357},{"Name":"Conditional Control Structures","TopicPlaylistFirstVideoID":0,"Duration":null,"Videos":[{"Watched":false,"Name":"If Structure","Duration":"6m 59s","ChapterTopicVideoID":26021,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:04.064","Text":"Hello everybody. By the end of this section on control structures,"},{"Start":"00:04.064 ","End":"00:06.690","Text":"you\u0027ll be able to explain the significance of"},{"Start":"00:06.690 ","End":"00:10.350","Text":"instructions being running sequence in imperative languages,"},{"Start":"00:10.350 ","End":"00:14.205","Text":"describe how high-level constructs allow code to be skipped,"},{"Start":"00:14.205 ","End":"00:17.925","Text":"and evaluate which control structures suit a particular problem."},{"Start":"00:17.925 ","End":"00:22.065","Text":"So far as simple programs we\u0027ve built stored values in variables,"},{"Start":"00:22.065 ","End":"00:27.255","Text":"perform mathematical operations, and output the contents of variables to the screen."},{"Start":"00:27.255 ","End":"00:30.480","Text":"In these programs, every instruction is executed by"},{"Start":"00:30.480 ","End":"00:33.750","Text":"the CPU 1 after the other in sequence."},{"Start":"00:33.750 ","End":"00:37.995","Text":"Instructions are fetched from memory and carried out one at a time."},{"Start":"00:37.995 ","End":"00:41.985","Text":"The program ends when there are no more instructions to execute."},{"Start":"00:41.985 ","End":"00:45.890","Text":"This idea of instructions running in sequence 1 after the other is"},{"Start":"00:45.890 ","End":"00:49.610","Text":"one of the fundamental building blocks of imperative programming languages."},{"Start":"00:49.610 ","End":"00:54.605","Text":"As a programmer, we write out instructions in the order we want them to be executed."},{"Start":"00:54.605 ","End":"00:58.295","Text":"Sometimes the order of 2 particular lines may not be important."},{"Start":"00:58.295 ","End":"01:00.740","Text":"At other times, a completely different outcome would"},{"Start":"01:00.740 ","End":"01:03.800","Text":"occur if 2 lines are in a different sequence."},{"Start":"01:03.800 ","End":"01:09.350","Text":"In this example, the program will output a message saying that the total is 16."},{"Start":"01:09.350 ","End":"01:11.210","Text":"If we did it another way,"},{"Start":"01:11.210 ","End":"01:14.330","Text":"swapping the order in which we add numbers to the total,"},{"Start":"01:14.330 ","End":"01:16.500","Text":"we\u0027d get exactly the same outcome,"},{"Start":"01:16.500 ","End":"01:19.595","Text":"a message saying the total is 16."},{"Start":"01:19.595 ","End":"01:24.005","Text":"In this example, we\u0027d see 21 output to the screen,"},{"Start":"01:24.005 ","End":"01:29.285","Text":"because 11 is in total by the time we get to line 3,"},{"Start":"01:29.285 ","End":"01:34.279","Text":"and then we add on 10 and the message would say the total is 21."},{"Start":"01:34.279 ","End":"01:38.675","Text":"But swapping the second and third lines over it gives us a different result."},{"Start":"01:38.675 ","End":"01:46.235","Text":"Total plus 10 will give us 10 and then we replace the contents of total with 6 plus 5."},{"Start":"01:46.235 ","End":"01:48.530","Text":"The message output will be different,"},{"Start":"01:48.530 ","End":"01:50.710","Text":"the total is 11."},{"Start":"01:50.710 ","End":"01:54.080","Text":"Even though lines 2 and 3 are identical"},{"Start":"01:54.080 ","End":"01:57.515","Text":"to the example above and all we did was swap the order,"},{"Start":"01:57.515 ","End":"01:59.600","Text":"the output is different."},{"Start":"01:59.600 ","End":"02:02.420","Text":"This trivial example illustrates the fact that sequence is"},{"Start":"02:02.420 ","End":"02:06.725","Text":"a fundamentally important idea in writing programs in imperative languages."},{"Start":"02:06.725 ","End":"02:09.140","Text":"It\u0027s up to the programmer to take account of the order"},{"Start":"02:09.140 ","End":"02:11.645","Text":"in which instructions are going to be executed."},{"Start":"02:11.645 ","End":"02:13.550","Text":"Well, what if you wanted to skip a line or"},{"Start":"02:13.550 ","End":"02:16.610","Text":"multiple lines of code depending on the circumstances?"},{"Start":"02:16.610 ","End":"02:20.375","Text":"This is exactly what conditional control structures are intended for."},{"Start":"02:20.375 ","End":"02:25.330","Text":"A conditional structure is a high-level programming language feature where execution"},{"Start":"02:25.330 ","End":"02:30.575","Text":"takes 1 of 2 possible paths depending on the value returned from a Boolean expression."},{"Start":"02:30.575 ","End":"02:34.310","Text":"Conditional structures allow us to choose whether a particular line or block of"},{"Start":"02:34.310 ","End":"02:38.705","Text":"code runs or not and use Boolean expressions to make the decision."},{"Start":"02:38.705 ","End":"02:42.665","Text":"You may have seen flowcharts used outside the context of programming,"},{"Start":"02:42.665 ","End":"02:45.920","Text":"where they used to show the steps that a process follows."},{"Start":"02:45.920 ","End":"02:51.245","Text":"Conditional statements are represented in flowcharts by a diamond symbol."},{"Start":"02:51.245 ","End":"02:55.040","Text":"Here we can see a Boolean expression where the value is stored in"},{"Start":"02:55.040 ","End":"02:59.575","Text":"variable A is being compared to the literal value 10."},{"Start":"02:59.575 ","End":"03:01.765","Text":"If A contains 10,"},{"Start":"03:01.765 ","End":"03:06.560","Text":"the expression evaluates to true and we follow the true path."},{"Start":"03:06.560 ","End":"03:08.525","Text":"If it doesn\u0027t contain 10,"},{"Start":"03:08.525 ","End":"03:14.420","Text":"the expression will evaluate to false and we follow the false path."},{"Start":"03:14.420 ","End":"03:17.150","Text":"Remember, a Boolean expression is one that results in"},{"Start":"03:17.150 ","End":"03:19.865","Text":"a value which is either true or false."},{"Start":"03:19.865 ","End":"03:24.810","Text":"Other examples would be tries is less than 6,"},{"Start":"03:24.810 ","End":"03:28.598","Text":"any value of tries less than 6 will evaluate to true,"},{"Start":"03:28.598 ","End":"03:30.994","Text":"any other values will give false."},{"Start":"03:30.994 ","End":"03:33.655","Text":"This expression uses and,"},{"Start":"03:33.655 ","End":"03:39.185","Text":"so will only give true for values above 7 and below 13,"},{"Start":"03:39.185 ","End":"03:41.480","Text":"so 8, 9, 10, 11,"},{"Start":"03:41.480 ","End":"03:43.243","Text":"12 give true,"},{"Start":"03:43.243 ","End":"03:45.640","Text":"anything else gives false."},{"Start":"03:45.640 ","End":"03:51.425","Text":"3 variables are being used in this expression with all joining 2 comparisons."},{"Start":"03:51.425 ","End":"03:56.960","Text":"This will evaluate to true if i is less than length or choice contains Q."},{"Start":"03:56.960 ","End":"04:02.179","Text":"Any other values for i and choice will result in an evaluation of false."},{"Start":"04:02.179 ","End":"04:04.385","Text":"There\u0027s lots going on in this example."},{"Start":"04:04.385 ","End":"04:09.380","Text":"We\u0027ve got 2 expressions joined by an and inside the brackets,"},{"Start":"04:09.380 ","End":"04:12.390","Text":"but as a not outside the brackets as well,"},{"Start":"04:12.390 ","End":"04:14.600","Text":"so that result will be flipped."},{"Start":"04:14.600 ","End":"04:21.769","Text":"You\u0027ll only get false here if tries is not 5 and password correct is not false."},{"Start":"04:21.769 ","End":"04:28.195","Text":"Any other values for tries and password correct in any combination will evaluate to true."},{"Start":"04:28.195 ","End":"04:32.900","Text":"Boolean variables can only be compared to the value true or false, like this example."},{"Start":"04:32.900 ","End":"04:38.945","Text":"However, you rarely see programs comparing a Boolean variable to true."},{"Start":"04:38.945 ","End":"04:43.025","Text":"Because just giving the name of the variable in an expression will give you a Boolean."},{"Start":"04:43.025 ","End":"04:45.140","Text":"If the variable contains true,"},{"Start":"04:45.140 ","End":"04:46.790","Text":"it evaluates to true."},{"Start":"04:46.790 ","End":"04:48.275","Text":"If it contains false,"},{"Start":"04:48.275 ","End":"04:50.000","Text":"it will evaluate to false."},{"Start":"04:50.000 ","End":"04:54.425","Text":"These last 3 lines are actually identical."},{"Start":"04:54.425 ","End":"04:57.800","Text":"The syntax for a conditional control structure starts with"},{"Start":"04:57.800 ","End":"05:01.570","Text":"the keyword if in most high-level languages."},{"Start":"05:01.570 ","End":"05:04.640","Text":"The keywords then followed with a Boolean expression,"},{"Start":"05:04.640 ","End":"05:07.775","Text":"which is to be evaluated and compared to true."},{"Start":"05:07.775 ","End":"05:10.220","Text":"If the evaluated value is true,"},{"Start":"05:10.220 ","End":"05:14.635","Text":"then the line or lines of code that follow will be executed."},{"Start":"05:14.635 ","End":"05:16.515","Text":"In C and Java,"},{"Start":"05:16.515 ","End":"05:20.090","Text":"the open brace more commonly called a curly bracket symbol,"},{"Start":"05:20.090 ","End":"05:24.470","Text":"starts the block and the closing one ends it."},{"Start":"05:24.470 ","End":"05:27.890","Text":"Everything within that block will be executed or"},{"Start":"05:27.890 ","End":"05:32.150","Text":"skipped depending on what the Boolean expression evaluated to."},{"Start":"05:32.150 ","End":"05:34.055","Text":"If it evaluated to true,"},{"Start":"05:34.055 ","End":"05:36.245","Text":"the lines in the block will be executed."},{"Start":"05:36.245 ","End":"05:39.140","Text":"If it evaluated to false, they\u0027ll be skipped."},{"Start":"05:39.140 ","End":"05:42.440","Text":"In Python, curly brackets aren\u0027t needed and the block is defined"},{"Start":"05:42.440 ","End":"05:46.000","Text":"mainly by indenting the statements inside the block."},{"Start":"05:46.000 ","End":"05:47.930","Text":"Here the green lines are indented,"},{"Start":"05:47.930 ","End":"05:50.345","Text":"which indicates they are part of the if block."},{"Start":"05:50.345 ","End":"05:53.240","Text":"It\u0027s not necessary to indent in C and Java,"},{"Start":"05:53.240 ","End":"05:54.560","Text":"the program will work,"},{"Start":"05:54.560 ","End":"05:58.355","Text":"but it\u0027s good practice to indent to make your code more readable."},{"Start":"05:58.355 ","End":"06:01.535","Text":"In Python, the indent is part of the syntax,"},{"Start":"06:01.535 ","End":"06:03.305","Text":"so it\u0027s not optional."},{"Start":"06:03.305 ","End":"06:05.839","Text":"Once the Boolean expression has been evaluated"},{"Start":"06:05.839 ","End":"06:08.525","Text":"and the block of code is executed or skipped,"},{"Start":"06:08.525 ","End":"06:13.430","Text":"execution then continues on from the end of the block."},{"Start":"06:13.430 ","End":"06:15.170","Text":"In this example in Java,"},{"Start":"06:15.170 ","End":"06:18.185","Text":"which will be almost identical in C and C Plus Plus,"},{"Start":"06:18.185 ","End":"06:21.680","Text":"a variable called tries might be used to keep"},{"Start":"06:21.680 ","End":"06:26.245","Text":"track of how many times a user has entered their password incorrectly."},{"Start":"06:26.245 ","End":"06:28.280","Text":"If we want to warn the user when they\u0027ve had"},{"Start":"06:28.280 ","End":"06:31.340","Text":"4 tries and therefore on their fifth and last try,"},{"Start":"06:31.340 ","End":"06:34.460","Text":"we could use this code which prints a message,"},{"Start":"06:34.460 ","End":"06:37.535","Text":"but only when you\u0027ve had your fourth try."},{"Start":"06:37.535 ","End":"06:45.030","Text":"The tries variable will always be incremented because that line\u0027s outside the if block."},{"Start":"06:45.030 ","End":"06:47.420","Text":"Whether tries contains 4 or not,"},{"Start":"06:47.420 ","End":"06:49.085","Text":"it will always run."},{"Start":"06:49.085 ","End":"06:51.080","Text":"We\u0027ll pause there for a moment."},{"Start":"06:51.080 ","End":"06:56.525","Text":"In the next video, we\u0027ll look at an extension of this if structure called an if-else."},{"Start":"06:56.525 ","End":"06:59.550","Text":"See you for that one in a moment."}],"ID":26827},{"Watched":false,"Name":"If Else Structure","Duration":"6m 38s","ChapterTopicVideoID":26019,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:01.905","Text":"Hello, welcome back."},{"Start":"00:01.905 ","End":"00:06.330","Text":"In the previous video, we saw how lines of code in a program can be run or skipped"},{"Start":"00:06.330 ","End":"00:11.880","Text":"depending on a Boolean expression using some encoder conditional control structure."},{"Start":"00:11.880 ","End":"00:15.465","Text":"We looked at an example using the keyword if."},{"Start":"00:15.465 ","End":"00:20.385","Text":"A slightly more powerful control structure is the so-called if else structure."},{"Start":"00:20.385 ","End":"00:23.910","Text":"Here we are again presented with a Boolean evaluation."},{"Start":"00:23.910 ","End":"00:27.810","Text":"But this time, rather than executing a block or skipping it,"},{"Start":"00:27.810 ","End":"00:31.230","Text":"we\u0027re able to choose between two alternative blocks."},{"Start":"00:31.230 ","End":"00:34.850","Text":"One or the other will be executed, but never both."},{"Start":"00:34.850 ","End":"00:36.980","Text":"Whichever one is executed,"},{"Start":"00:36.980 ","End":"00:40.049","Text":"execution continues on after the end of the whole if"},{"Start":"00:40.049 ","End":"00:43.535","Text":"else structure from the blue lines onward here."},{"Start":"00:43.535 ","End":"00:47.090","Text":"In this example, the Boolean expression being"},{"Start":"00:47.090 ","End":"00:50.840","Text":"evaluated will give true only when passwordLen"},{"Start":"00:50.840 ","End":"00:54.260","Text":"contains a value between 8 and 12 because it"},{"Start":"00:54.260 ","End":"00:58.879","Text":"must be greater than 7 and it must be less than 13."},{"Start":"00:58.879 ","End":"01:01.820","Text":"Anything else will give the value false."},{"Start":"01:01.820 ","End":"01:07.990","Text":"The first block following the if runs only if passwordLen contains values 8,"},{"Start":"01:07.990 ","End":"01:10.100","Text":"9, 10, 11, or 12."},{"Start":"01:10.100 ","End":"01:13.190","Text":"Otherwise, the else block will run."},{"Start":"01:13.190 ","End":"01:18.251","Text":"In either case, execution continues on from the end of the else block."},{"Start":"01:18.251 ","End":"01:22.099","Text":"In this case, outputting the message checks complete."},{"Start":"01:22.099 ","End":"01:25.340","Text":"A really important point to make here is that the else block"},{"Start":"01:25.340 ","End":"01:28.715","Text":"doesn\u0027t involve another Boolean evaluation."},{"Start":"01:28.715 ","End":"01:33.020","Text":"It\u0027s tied to the evaluation in the if statement."},{"Start":"01:33.020 ","End":"01:36.950","Text":"However, it is possible to have one if block tied to another if"},{"Start":"01:36.950 ","End":"01:40.655","Text":"block with both of them then tied to a final else."},{"Start":"01:40.655 ","End":"01:43.180","Text":"The first part here is just as before."},{"Start":"01:43.180 ","End":"01:47.945","Text":"But the last line doesn\u0027t say if on its own or else on its own."},{"Start":"01:47.945 ","End":"01:51.158","Text":"The two are combined together into an else"},{"Start":"01:51.158 ","End":"01:55.475","Text":"if and another Boolean expression is evaluated."},{"Start":"01:55.475 ","End":"02:00.320","Text":"This else if block then has its own statements inside the block,"},{"Start":"02:00.320 ","End":"02:05.705","Text":"and at the end of the block there follows an else with its own instructions."},{"Start":"02:05.705 ","End":"02:10.445","Text":"Notice that for else there\u0027s no Boolean expression to evaluate."},{"Start":"02:10.445 ","End":"02:14.660","Text":"Unlike above with the else if and the if,"},{"Start":"02:14.660 ","End":"02:17.795","Text":"both of which do have a Boolean expression."},{"Start":"02:17.795 ","End":"02:21.110","Text":"Here, if the first expression evaluates to true,"},{"Start":"02:21.110 ","End":"02:24.080","Text":"the green lines will run and everything else will be skipped,"},{"Start":"02:24.080 ","End":"02:26.360","Text":"and we continue on from the blue lines."},{"Start":"02:26.360 ","End":"02:29.630","Text":"If the first expression evaluated to false,"},{"Start":"02:29.630 ","End":"02:32.360","Text":"then expression 2 is evaluated."},{"Start":"02:32.360 ","End":"02:33.530","Text":"If that is true,"},{"Start":"02:33.530 ","End":"02:37.295","Text":"the red lines run and we continue on from the blue lines."},{"Start":"02:37.295 ","End":"02:42.365","Text":"If neither expression 1 was true or expression 2 was true,"},{"Start":"02:42.365 ","End":"02:46.460","Text":"then this else block comes into play and it would run"},{"Start":"02:46.460 ","End":"02:51.185","Text":"these lines in orange followed again by the lines in blue."},{"Start":"02:51.185 ","End":"02:54.024","Text":"Let\u0027s have a look at another example."},{"Start":"02:54.024 ","End":"02:57.935","Text":"Here the evaluations involve a variable called age,"},{"Start":"02:57.935 ","End":"03:02.060","Text":"which contains the age of someone trying to sign up for some service."},{"Start":"03:02.060 ","End":"03:05.180","Text":"If age contains a number less than 13,"},{"Start":"03:05.180 ","End":"03:07.650","Text":"the green lines will run."},{"Start":"03:07.650 ","End":"03:10.160","Text":"Then the message initial age checks"},{"Start":"03:10.160 ","End":"03:14.270","Text":"completed will be displayed as all the other blocks will be skipped."},{"Start":"03:14.270 ","End":"03:17.210","Text":"If the age is not less than 13,"},{"Start":"03:17.210 ","End":"03:24.140","Text":"then a second evaluation takes place to see if the age is less than 18."},{"Start":"03:24.140 ","End":"03:28.265","Text":"If it is, the red lines will run and again,"},{"Start":"03:28.265 ","End":"03:33.245","Text":"the message initial age checks will be completed at the end."},{"Start":"03:33.245 ","End":"03:38.870","Text":"If the age is not less than 13 and not less than 18,"},{"Start":"03:38.870 ","End":"03:43.025","Text":"then the else block comes into play and the lines in"},{"Start":"03:43.025 ","End":"03:47.180","Text":"orange will run before again the blue lines run."},{"Start":"03:47.180 ","End":"03:50.330","Text":"Note that no matter what value age contains,"},{"Start":"03:50.330 ","End":"03:54.320","Text":"only one of these 3 blocks is going to run,"},{"Start":"03:54.320 ","End":"03:56.605","Text":"and the other 2 will be skipped."},{"Start":"03:56.605 ","End":"04:00.575","Text":"We\u0027ll only have 1 else if in this example,"},{"Start":"04:00.575 ","End":"04:02.750","Text":"but you could have as many as you want."},{"Start":"04:02.750 ","End":"04:08.725","Text":"They must always follow the initial if and come before the final else block."},{"Start":"04:08.725 ","End":"04:11.475","Text":"Here\u0027s the same code in Python."},{"Start":"04:11.475 ","End":"04:13.625","Text":"There\u0027s no curly brackets here,"},{"Start":"04:13.625 ","End":"04:18.275","Text":"but you do see a colon which starts a block,"},{"Start":"04:18.275 ","End":"04:23.105","Text":"and the indents then determine what belongs inside a block."},{"Start":"04:23.105 ","End":"04:31.085","Text":"Also notice the keywords else and if are contracted into one word here, elif."},{"Start":"04:31.085 ","End":"04:35.770","Text":"Apart from that, it\u0027s very similar to the Java and C version."},{"Start":"04:35.770 ","End":"04:39.980","Text":"An alternative to else if is the use of a technique called nesting,"},{"Start":"04:39.980 ","End":"04:44.390","Text":"where one if else block is nestled inside another."},{"Start":"04:44.390 ","End":"04:48.890","Text":"Here we can see that a whole if else structure in green and blue"},{"Start":"04:48.890 ","End":"04:53.435","Text":"is inside the if block of another if else structure."},{"Start":"04:53.435 ","End":"05:00.995","Text":"We refer to these as an inner if else block and an outer if else block."},{"Start":"05:00.995 ","End":"05:03.140","Text":"The crucial visual cue here is"},{"Start":"05:03.140 ","End":"05:07.415","Text":"the further indentation of the blue and green statements here,"},{"Start":"05:07.415 ","End":"05:11.825","Text":"further in from the side of the screen within this inner if else block."},{"Start":"05:11.825 ","End":"05:15.895","Text":"What happens here is that Boolean expression 1 is evaluated,"},{"Start":"05:15.895 ","End":"05:18.000","Text":"and if it evaluates to true,"},{"Start":"05:18.000 ","End":"05:21.689","Text":"then the second expression is evaluated."},{"Start":"05:21.689 ","End":"05:27.890","Text":"The second expression will decide here whether the green block or the blue block runs."},{"Start":"05:27.890 ","End":"05:31.065","Text":"If expression 1 evaluated to false,"},{"Start":"05:31.065 ","End":"05:33.555","Text":"the if block of course will be skipped,"},{"Start":"05:33.555 ","End":"05:36.740","Text":"and so the outer else block will run."},{"Start":"05:36.740 ","End":"05:40.040","Text":"Hence, these orange lines are executed."},{"Start":"05:40.040 ","End":"05:42.710","Text":"Let\u0027s have a look at another example in Java."},{"Start":"05:42.710 ","End":"05:47.900","Text":"Here the variable month is check to see if it contains the value 2."},{"Start":"05:47.900 ","End":"05:51.460","Text":"If it is, then the inner if else structure runs,"},{"Start":"05:51.460 ","End":"05:57.140","Text":"otherwise the else structure and the overall outer else block runs."},{"Start":"05:57.140 ","End":"06:04.370","Text":"The nested if is checking a variable called leap year to see if it contains true."},{"Start":"06:04.370 ","End":"06:09.105","Text":"If it does, it will output the month has 29 days."},{"Start":"06:09.105 ","End":"06:10.425","Text":"If it\u0027s not true,"},{"Start":"06:10.425 ","End":"06:14.220","Text":"the else of the inner if else structure will run,"},{"Start":"06:14.220 ","End":"06:19.325","Text":"and then the month has 28 days will be output."},{"Start":"06:19.325 ","End":"06:22.310","Text":"It\u0027s possible to have multiple levels of nesting."},{"Start":"06:22.310 ","End":"06:24.785","Text":"We can have another one inside here if we wanted,"},{"Start":"06:24.785 ","End":"06:27.965","Text":"but the code then becomes quite hard to follow."},{"Start":"06:27.965 ","End":"06:29.960","Text":"In this final video in this section,"},{"Start":"06:29.960 ","End":"06:32.630","Text":"we\u0027ll look at an alternative called switch,"},{"Start":"06:32.630 ","End":"06:38.800","Text":"which may be more suited for some situations. I\u0027ll see you then."}],"ID":26828},{"Watched":false,"Name":"Switch Structure","Duration":"9m 9s","ChapterTopicVideoID":26020,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.475","Text":"Hello, everyone. Welcome back."},{"Start":"00:02.475 ","End":"00:06.510","Text":"We saw in the previous videos that conditional structures allow us to skip blocks"},{"Start":"00:06.510 ","End":"00:10.350","Text":"of code or run 1 block out of 2 alternatives,"},{"Start":"00:10.350 ","End":"00:12.405","Text":"the if block and the else block."},{"Start":"00:12.405 ","End":"00:17.145","Text":"We can also chain multiple if and else statements together using else-if."},{"Start":"00:17.145 ","End":"00:22.065","Text":"Nesting was the idea that 1 conditional structure can be embedded inside another one."},{"Start":"00:22.065 ","End":"00:28.020","Text":"Here we can see the if-else structure in blue is nested inside the outer if block."},{"Start":"00:28.020 ","End":"00:32.070","Text":"Whilst nesting allows us to have more complex and flexible code,"},{"Start":"00:32.070 ","End":"00:34.880","Text":"it\u0027s possible to have even more levels of nesting"},{"Start":"00:34.880 ","End":"00:37.700","Text":"than the one shown here in the example and if that\u0027s the case,"},{"Start":"00:37.700 ","End":"00:39.785","Text":"the code can be quite hard to follow."},{"Start":"00:39.785 ","End":"00:41.180","Text":"For this and other reasons,"},{"Start":"00:41.180 ","End":"00:46.130","Text":"some high-level languages provide an alternative mechanism called a switch structure."},{"Start":"00:46.130 ","End":"00:47.810","Text":"In a switch structure,"},{"Start":"00:47.810 ","End":"00:53.015","Text":"a value determines where the program should jump to an a list of possible statements."},{"Start":"00:53.015 ","End":"00:55.385","Text":"These are called cases."},{"Start":"00:55.385 ","End":"00:58.330","Text":"Another difference is that unlike if statements,"},{"Start":"00:58.330 ","End":"01:00.530","Text":"this is not a Boolean comparison."},{"Start":"01:00.530 ","End":"01:04.775","Text":"Remember true means an if block runs and false means it doesn\u0027t."},{"Start":"01:04.775 ","End":"01:06.380","Text":"With a switch statement,"},{"Start":"01:06.380 ","End":"01:07.850","Text":"it\u0027s an integer, char,"},{"Start":"01:07.850 ","End":"01:08.960","Text":"or in the case of Java,"},{"Start":"01:08.960 ","End":"01:14.530","Text":"a string that\u0027s being compared to a series of different values in each case block."},{"Start":"01:14.530 ","End":"01:17.530","Text":"If value contain the integer 1 in this example,"},{"Start":"01:17.530 ","End":"01:18.995","Text":"there would be a match,"},{"Start":"01:18.995 ","End":"01:22.060","Text":"an execution will continue from the first block."},{"Start":"01:22.060 ","End":"01:23.790","Text":"If it contain 2,"},{"Start":"01:23.790 ","End":"01:27.405","Text":"the second block and 3, the final block."},{"Start":"01:27.405 ","End":"01:33.335","Text":"In this example, a character contained inside the variable price code,"},{"Start":"01:33.335 ","End":"01:37.550","Text":"is being compared with 3 specific values, a, b,"},{"Start":"01:37.550 ","End":"01:42.470","Text":"and c. The relevant case block is executed for each particular value."},{"Start":"01:42.470 ","End":"01:46.055","Text":"For example, if price code contain b,"},{"Start":"01:46.055 ","End":"01:49.100","Text":"headphones would be output to the screen."},{"Start":"01:49.100 ","End":"01:51.455","Text":"If price code contained a,"},{"Start":"01:51.455 ","End":"01:55.100","Text":"cuddly toy would be output and if it contained c,"},{"Start":"01:55.100 ","End":"01:57.010","Text":"game would be output."},{"Start":"01:57.010 ","End":"02:00.330","Text":"For any other value than a, b, or c,"},{"Start":"02:00.330 ","End":"02:07.810","Text":"the default block will be executed in a similar way to else in the if-else construct."},{"Start":"02:07.810 ","End":"02:12.610","Text":"There\u0027s a keyword we\u0027ve not come across before here, break."},{"Start":"02:12.610 ","End":"02:17.980","Text":"What it does is break out of the surrounding overall control structure."},{"Start":"02:17.980 ","End":"02:21.205","Text":"An x it\u0027s the end of this overall block."},{"Start":"02:21.205 ","End":"02:24.880","Text":"With a switch statement is used to break out of the switch block once"},{"Start":"02:24.880 ","End":"02:30.760","Text":"a particular case has been found and the code inside that block has been executed."},{"Start":"02:30.760 ","End":"02:34.615","Text":"In this example, once it\u0027s printed, say cuddly toy,"},{"Start":"02:34.615 ","End":"02:40.605","Text":"we don\u0027t want it to print headphones and game as well hence the break."},{"Start":"02:40.605 ","End":"02:44.080","Text":"Note how there\u0027s no braces or curly brackets"},{"Start":"02:44.080 ","End":"02:47.365","Text":"around each case as they would be with an if and else."},{"Start":"02:47.365 ","End":"02:52.510","Text":"In a way the break is like a closing brace in an if or an else statement."},{"Start":"02:52.510 ","End":"02:56.665","Text":"But unlike a closing brace with if and else, which is compulsory,"},{"Start":"02:56.665 ","End":"02:58.990","Text":"the break statement is actually optional and"},{"Start":"02:58.990 ","End":"03:02.169","Text":"this can be seen better with another example."},{"Start":"03:02.169 ","End":"03:04.720","Text":"In this program, we\u0027re going to use an integer to"},{"Start":"03:04.720 ","End":"03:07.645","Text":"decide what to output when a game has ended."},{"Start":"03:07.645 ","End":"03:10.240","Text":"We want to print different messages depending on"},{"Start":"03:10.240 ","End":"03:13.015","Text":"what level of the game has been completed."},{"Start":"03:13.015 ","End":"03:14.740","Text":"Looking at the code,"},{"Start":"03:14.740 ","End":"03:17.274","Text":"you\u0027ll notice a couple of things have changed."},{"Start":"03:17.274 ","End":"03:23.180","Text":"Firstly, there are no break statements apart from the first case here."},{"Start":"03:23.180 ","End":"03:26.525","Text":"Secondly, there is no defaults option."},{"Start":"03:26.525 ","End":"03:28.910","Text":"This code, if we ran it,"},{"Start":"03:28.910 ","End":"03:31.790","Text":"would actually print several messages to the screen."},{"Start":"03:31.790 ","End":"03:37.535","Text":"Your experience is showing basic level completed and training level completed."},{"Start":"03:37.535 ","End":"03:41.870","Text":"The absence of a break statement means that the instructions keep on being"},{"Start":"03:41.870 ","End":"03:46.430","Text":"executed in sequence until the last line is reached."},{"Start":"03:46.430 ","End":"03:48.140","Text":"Although the variable level,"},{"Start":"03:48.140 ","End":"03:52.175","Text":"which is being used to select which case is executed,"},{"Start":"03:52.175 ","End":"03:56.120","Text":"contains 4 on entry to the switch statement,"},{"Start":"03:56.120 ","End":"04:00.133","Text":"there\u0027s no statement following case 4."},{"Start":"04:00.133 ","End":"04:04.610","Text":"So it continues on for the case statement for 3."},{"Start":"04:04.610 ","End":"04:07.820","Text":"Whether you\u0027ve reached level 4 or level 3 in this game,"},{"Start":"04:07.820 ","End":"04:10.145","Text":"the same messages will be displayed."},{"Start":"04:10.145 ","End":"04:14.750","Text":"The code then falls through into the cases for 2 and 1."},{"Start":"04:14.750 ","End":"04:18.260","Text":"Those lines will be executed and display those messages,"},{"Start":"04:18.260 ","End":"04:21.590","Text":"basic level completed and training level completed."},{"Start":"04:21.590 ","End":"04:23.825","Text":"Because there\u0027s no default case,"},{"Start":"04:23.825 ","End":"04:28.925","Text":"if a value less than 1 or greater than 5 is in the variable level,"},{"Start":"04:28.925 ","End":"04:35.480","Text":"nothing inside the block is executed so only game over will be printed."},{"Start":"04:35.480 ","End":"04:38.330","Text":"Not all languages support switch,"},{"Start":"04:38.330 ","End":"04:41.345","Text":"with Python being a notable example of one that doesn\u0027t."},{"Start":"04:41.345 ","End":"04:43.020","Text":"But if it is available to you,"},{"Start":"04:43.020 ","End":"04:47.075","Text":"you may be wondering when to use switch and when to use if-else."},{"Start":"04:47.075 ","End":"04:49.715","Text":"Here\u0027s a quick summary of the differences."},{"Start":"04:49.715 ","End":"04:53.030","Text":"Remember the way an if statement works is different to a switch"},{"Start":"04:53.030 ","End":"04:56.765","Text":"because if statements are based on Boolean evaluation,"},{"Start":"04:56.765 ","End":"05:01.685","Text":"for example, is the contents of 1 variable greater than the contents of another."},{"Start":"05:01.685 ","End":"05:05.270","Text":"With switch, execution jumps to a particular place in"},{"Start":"05:05.270 ","End":"05:09.845","Text":"the program depending on what value is in this specified variable."},{"Start":"05:09.845 ","End":"05:15.080","Text":"If statements organize the alternative blocks of code within else or"},{"Start":"05:15.080 ","End":"05:20.930","Text":"else-if where a switch uses case in an if-else structure,"},{"Start":"05:20.930 ","End":"05:24.950","Text":"only 1 block can be executed and the other one is skipped."},{"Start":"05:24.950 ","End":"05:29.135","Text":"This is also true of an if-else if chain of blocks."},{"Start":"05:29.135 ","End":"05:34.335","Text":"Only 1 block will run no matter how many else-if blocks exist."},{"Start":"05:34.335 ","End":"05:40.040","Text":"Switch is different because the case statement marks a starting point of execution and"},{"Start":"05:40.040 ","End":"05:42.380","Text":"code could continue on executing through"},{"Start":"05:42.380 ","End":"05:46.310","Text":"other cases until it encounters a break statement."},{"Start":"05:46.310 ","End":"05:52.310","Text":"In this way, the switch and case syntax is a little more flexible than the if-else."},{"Start":"05:52.310 ","End":"05:54.800","Text":"Because of the 1st point we made,"},{"Start":"05:54.800 ","End":"05:58.550","Text":"the if statement is a little bit more flexible in terms of choosing when"},{"Start":"05:58.550 ","End":"06:00.530","Text":"a particular block runs whereas"},{"Start":"06:00.530 ","End":"06:03.755","Text":"a switch statement is a little bit more limited than an if-else,"},{"Start":"06:03.755 ","End":"06:06.230","Text":"as the case is just a list of constants that"},{"Start":"06:06.230 ","End":"06:09.695","Text":"compared to the value being evaluated in the switch."},{"Start":"06:09.695 ","End":"06:13.340","Text":"This means more complex conditions like a range of values being"},{"Start":"06:13.340 ","End":"06:16.978","Text":"evaluated is possible within if combined with an and,"},{"Start":"06:16.978 ","End":"06:20.165","Text":"and that has no simple equivalent with a switch."},{"Start":"06:20.165 ","End":"06:25.970","Text":"The downside of the if statement\u0027s flexibility is that code can be harder to follow,"},{"Start":"06:25.970 ","End":"06:27.890","Text":"especially with nested ifs,"},{"Start":"06:27.890 ","End":"06:31.910","Text":"and there\u0027s a higher chance of introducing errors into our code as we develop it."},{"Start":"06:31.910 ","End":"06:33.680","Text":"In contrast, switch statements,"},{"Start":"06:33.680 ","End":"06:35.720","Text":"given they\u0027re slightly easier to read,"},{"Start":"06:35.720 ","End":"06:38.885","Text":"can be more straightforward to change and develop."},{"Start":"06:38.885 ","End":"06:44.885","Text":"Finally, there could be a slight speed penalty in using multiple if statements."},{"Start":"06:44.885 ","End":"06:46.760","Text":"Each time an if is encountered,"},{"Start":"06:46.760 ","End":"06:51.305","Text":"there needs to be a comparison made that results in a Boolean evaluation."},{"Start":"06:51.305 ","End":"06:53.870","Text":"With a long chain of if-else-if"},{"Start":"06:53.870 ","End":"06:57.890","Text":"statements or when there are multiple nested comparisons,"},{"Start":"06:57.890 ","End":"07:00.965","Text":"many comparisons may have to be made,"},{"Start":"07:00.965 ","End":"07:04.655","Text":"even if the code inside the block is going to be skipped."},{"Start":"07:04.655 ","End":"07:09.770","Text":"A switch statement doesn\u0027t have that disadvantage because a single comparison is made at"},{"Start":"07:09.770 ","End":"07:12.680","Text":"the beginning and the execution then continues"},{"Start":"07:12.680 ","End":"07:16.280","Text":"on from the relevant case until a break is encountered."},{"Start":"07:16.280 ","End":"07:20.240","Text":"Although it\u0027s dependent on how well the compiler or interpreter does its job,"},{"Start":"07:20.240 ","End":"07:23.045","Text":"you\u0027d expect a switch to be more efficient"},{"Start":"07:23.045 ","End":"07:26.690","Text":"than a series of if statements trying to do the same task."},{"Start":"07:26.690 ","End":"07:30.230","Text":"You can see here that the if structure is a little more"},{"Start":"07:30.230 ","End":"07:33.650","Text":"elegant than the equivalent switch because of the power of"},{"Start":"07:33.650 ","End":"07:36.140","Text":"Boolean expressions and the fact that"},{"Start":"07:36.140 ","End":"07:40.600","Text":"multiple conditions can be joined together with a logical and."},{"Start":"07:40.600 ","End":"07:44.900","Text":"In this example, if the range was wider than from 16-21,"},{"Start":"07:44.900 ","End":"07:49.760","Text":"say 16-41, the number of cases will become unmanageable."},{"Start":"07:49.760 ","End":"07:51.530","Text":"The if statement, by contrast,"},{"Start":"07:51.530 ","End":"07:54.335","Text":"just needs a single number to change."},{"Start":"07:54.335 ","End":"07:58.880","Text":"In general situations where there\u0027s a finite list of discrete values to be matched,"},{"Start":"07:58.880 ","End":"08:01.550","Text":"suggest a switch statement will be more useful."},{"Start":"08:01.550 ","End":"08:04.970","Text":"Anything that involves more complexity suggests an if statement"},{"Start":"08:04.970 ","End":"08:08.570","Text":"with a logical and comparison operators."},{"Start":"08:08.570 ","End":"08:12.800","Text":"There is, of course, nothing to stop you using both control structures together."},{"Start":"08:12.800 ","End":"08:17.375","Text":"The previous example could have used a default with an if-else inside it."},{"Start":"08:17.375 ","End":"08:22.340","Text":"The code will print a message if age contains a value less than 16 and"},{"Start":"08:22.340 ","End":"08:28.840","Text":"a different one if the age is over 21 because none of the cases above have been matched."},{"Start":"08:28.840 ","End":"08:34.895","Text":"There\u0027s also nothing to stop you putting a switch structure inside an if or else."},{"Start":"08:34.895 ","End":"08:38.270","Text":"In this way, we can have the best of both worlds allowing"},{"Start":"08:38.270 ","End":"08:41.870","Text":"code that\u0027s more readable, maintainable, and efficient."},{"Start":"08:41.870 ","End":"08:45.140","Text":"That\u0027s it on control structures."},{"Start":"08:45.140 ","End":"08:48.380","Text":"In this section, we learned how to explain the significance of"},{"Start":"08:48.380 ","End":"08:51.620","Text":"instructions being run in sequence in imperative languages,"},{"Start":"08:51.620 ","End":"08:55.685","Text":"to describe how high-level constructs allow code to be skipped,"},{"Start":"08:55.685 ","End":"09:01.070","Text":"and to evaluate which control structures suit a particular problem."},{"Start":"09:01.070 ","End":"09:04.100","Text":"I\u0027ll see you in the next topic which builds on this one to see"},{"Start":"09:04.100 ","End":"09:10.170","Text":"the high-level constructs available that allow us to repeat blocks of code. See you then."}],"ID":26829},{"Watched":false,"Name":"Exercise 1","Duration":"6m 50s","ChapterTopicVideoID":26447,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.760","Text":"Hello. Welcome to this first video where we work through"},{"Start":"00:02.760 ","End":"00:06.045","Text":"the first exercise on assignments and expressions,"},{"Start":"00:06.045 ","End":"00:09.990","Text":"aiming to build on our initial understanding of variables and data types."},{"Start":"00:09.990 ","End":"00:15.180","Text":"We, first of all, been asked to create a new project and open the Code Pad in Bluej,"},{"Start":"00:15.180 ","End":"00:17.925","Text":"and then to do the following activities in the Code Pad."},{"Start":"00:17.925 ","End":"00:22.230","Text":"In part A, we need to create a single line of code to create a Boolean variable,"},{"Start":"00:22.230 ","End":"00:24.510","Text":"and to call that variable is valid,"},{"Start":"00:24.510 ","End":"00:27.345","Text":"and to initialize it with the value true."},{"Start":"00:27.345 ","End":"00:32.040","Text":"Part B, we\u0027re asked to use the up arrow to retrieve the line we just typed in,"},{"Start":"00:32.040 ","End":"00:36.650","Text":"and to change the last part of the line so the value is false, not true,"},{"Start":"00:36.650 ","End":"00:42.495","Text":"and then explain why we get an error message when you press \"Enter\" to compile a line."},{"Start":"00:42.495 ","End":"00:44.210","Text":"Then finally in part C,"},{"Start":"00:44.210 ","End":"00:49.730","Text":"we\u0027re asked to correct that line to successfully change the value to false."},{"Start":"00:49.730 ","End":"00:52.250","Text":"Welcome to this first video where we work through"},{"Start":"00:52.250 ","End":"00:55.670","Text":"the exercise on expressions and assignments."},{"Start":"00:55.670 ","End":"00:59.150","Text":"Exercise 1 specifically with the aim of building on"},{"Start":"00:59.150 ","End":"01:02.660","Text":"our initial understanding of variables and data types."},{"Start":"01:02.660 ","End":"01:07.505","Text":"We\u0027ve been first asked in exercise 1 to create a new project."},{"Start":"01:07.505 ","End":"01:09.740","Text":"Open the Code Pad, as we know from before,"},{"Start":"01:09.740 ","End":"01:16.010","Text":"you cannot have a Code Pad unless you have a project to contain it within."},{"Start":"01:16.010 ","End":"01:20.600","Text":"We\u0027ll just give it a name and I can open up"},{"Start":"01:20.600 ","End":"01:26.210","Text":"the window here just to give myself a bit of space to see the responses, etc."},{"Start":"01:26.210 ","End":"01:30.500","Text":"What we\u0027ve been asked to do in part 1 is with a single line of code,"},{"Start":"01:30.500 ","End":"01:36.400","Text":"create a Boolean variable called is valid and to initialize it with the value true."},{"Start":"01:36.400 ","End":"01:38.840","Text":"As we know from previously,"},{"Start":"01:38.840 ","End":"01:41.390","Text":"to declare a variable in Java,"},{"Start":"01:41.390 ","End":"01:44.345","Text":"you need to state the data type first."},{"Start":"01:44.345 ","End":"01:46.190","Text":"In this case, it\u0027s Boolean,"},{"Start":"01:46.190 ","End":"01:48.997","Text":"then the identifier or the name,"},{"Start":"01:48.997 ","End":"01:53.075","Text":"in this case, we\u0027ve been asked to call it is valid in camel case."},{"Start":"01:53.075 ","End":"01:56.000","Text":"Then we\u0027ve been asked to initialize it with the value true."},{"Start":"01:56.000 ","End":"01:57.590","Text":"Now up until now,"},{"Start":"01:57.590 ","End":"02:01.565","Text":"we would\u0027ve ended this line with a semicolon or by pressing \"Enter\","},{"Start":"02:01.565 ","End":"02:03.320","Text":"and we wouldn\u0027t have given it a value."},{"Start":"02:03.320 ","End":"02:08.520","Text":"But now we\u0027ve been asked to assign a value whilst we are declaring the variables,"},{"Start":"02:08.520 ","End":"02:09.990","Text":"so we can go ahead and do that,"},{"Start":"02:09.990 ","End":"02:12.410","Text":"and we have been asked to give it valid true,"},{"Start":"02:12.410 ","End":"02:14.780","Text":"which in Java is all lowercase."},{"Start":"02:14.780 ","End":"02:17.990","Text":"Let\u0027s do that. I\u0027m going to put semicolon on the end as well,"},{"Start":"02:17.990 ","End":"02:20.850","Text":"because that\u0027s how lines should end."},{"Start":"02:21.290 ","End":"02:28.580","Text":"No problems there, it\u0027s created my variable and I can check if I want that the value"},{"Start":"02:28.580 ","End":"02:34.880","Text":"in there is what I expect and is indeed true and is all data type Boolean,"},{"Start":"02:34.880 ","End":"02:36.710","Text":"so it\u0027s done its job and I\u0027m going to expect"},{"Start":"02:36.710 ","End":"02:39.350","Text":"anything else because it\u0027s such a simple line of code."},{"Start":"02:39.350 ","End":"02:41.480","Text":"Now we\u0027ve been asked in part B to press"},{"Start":"02:41.480 ","End":"02:44.840","Text":"the up arrow key to true treat the line we just typed to."},{"Start":"02:44.840 ","End":"02:48.020","Text":"It would be this line that we just typed to and obviously,"},{"Start":"02:48.020 ","End":"02:49.670","Text":"you\u0027ve looked at a value if is valid as well,"},{"Start":"02:49.670 ","End":"02:50.780","Text":"so I\u0027ve skipped the overlap,"},{"Start":"02:50.780 ","End":"02:53.180","Text":"but here is the initial line and we\u0027ve just been"},{"Start":"02:53.180 ","End":"02:55.865","Text":"asked to change the value to false so I\u0027ll do that."},{"Start":"02:55.865 ","End":"03:00.590","Text":"Now we get an error message saying is valid is already defined."},{"Start":"03:00.590 ","End":"03:04.640","Text":"We\u0027ve been asked to explain why we get that error message."},{"Start":"03:04.640 ","End":"03:06.920","Text":"Was actually relatively straightforward."},{"Start":"03:06.920 ","End":"03:10.310","Text":"As we said, when you declare a variable in Java,"},{"Start":"03:10.310 ","End":"03:13.940","Text":"you need to give a data type and you can also assign a value."},{"Start":"03:13.940 ","End":"03:19.235","Text":"Now what we\u0027re trying to do is presumably assign a different value to this variable."},{"Start":"03:19.235 ","End":"03:22.940","Text":"What we cannot do is redefine the variable because"},{"Start":"03:22.940 ","End":"03:26.735","Text":"that\u0027s what we appear to be doing as far as Java is concerned."},{"Start":"03:26.735 ","End":"03:28.805","Text":"It\u0027s saying is valid is already defined"},{"Start":"03:28.805 ","End":"03:32.270","Text":"because we put the data type in front of is valid,"},{"Start":"03:32.270 ","End":"03:36.875","Text":"it assumes we\u0027re declaring a new variable called is valid,"},{"Start":"03:36.875 ","End":"03:39.755","Text":"but it already has a variable called is valid,"},{"Start":"03:39.755 ","End":"03:43.790","Text":"so refuses to let us do that and hence the error message."},{"Start":"03:43.790 ","End":"03:47.600","Text":"What I need to do to correct this for part C is I simply need to"},{"Start":"03:47.600 ","End":"03:51.455","Text":"remove the data type from the beginning."},{"Start":"03:51.455 ","End":"03:56.220","Text":"Now it understands that there is an existing variable called is valid,"},{"Start":"03:56.220 ","End":"03:58.480","Text":"is not declaring a new one and it just"},{"Start":"03:58.480 ","End":"04:01.495","Text":"wants to change the value of that existing variable."},{"Start":"04:01.495 ","End":"04:04.270","Text":"I\u0027ll go ahead and do that and no error this time"},{"Start":"04:04.270 ","End":"04:06.940","Text":"and if I look at the value of is valid again,"},{"Start":"04:06.940 ","End":"04:08.755","Text":"it is indeed false now,"},{"Start":"04:08.755 ","End":"04:10.405","Text":"whereas previously it was true."},{"Start":"04:10.405 ","End":"04:12.490","Text":"A very, very simple exercise,"},{"Start":"04:12.490 ","End":"04:16.330","Text":"but really just there to illustrate the difference between"},{"Start":"04:16.330 ","End":"04:20.320","Text":"declaring a variable and assigning a value to a variable."},{"Start":"04:20.320 ","End":"04:23.560","Text":"They\u0027re different things, although we can do both things on"},{"Start":"04:23.560 ","End":"04:28.180","Text":"one line as we did here and as we attempted to do here,"},{"Start":"04:28.180 ","End":"04:31.085","Text":"but we couldn\u0027t because the variable already existed so"},{"Start":"04:31.085 ","End":"04:34.165","Text":"this is an error that a beginner will quite often get."},{"Start":"04:34.165 ","End":"04:38.440","Text":"They\u0027ll forget to take the data type off the beginning when they\u0027re merely"},{"Start":"04:38.440 ","End":"04:43.495","Text":"assigning a new value to a variable that already exists."},{"Start":"04:43.495 ","End":"04:45.700","Text":"Hopefully, that makes sense now,"},{"Start":"04:45.700 ","End":"04:49.790","Text":"and I\u0027ll see you in the next exercise where we start working with"},{"Start":"04:49.790 ","End":"04:55.350","Text":"assignments of variables to other variables. I\u0027ll see you then."}],"ID":27350},{"Watched":false,"Name":"Exercise 2","Duration":"8m 2s","ChapterTopicVideoID":26448,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:01.725","Text":"Hello, welcome back."},{"Start":"00:01.725 ","End":"00:05.340","Text":"In this next exercise on assignment and expressions,"},{"Start":"00:05.340 ","End":"00:08.430","Text":"we\u0027ve been asked to within the same Code Pad as before,"},{"Start":"00:08.430 ","End":"00:10.395","Text":"create 2 integer variables,"},{"Start":"00:10.395 ","End":"00:13.260","Text":"num1 and num2 with no initial value given,"},{"Start":"00:13.260 ","End":"00:18.230","Text":"and then to assign the value 10 to num1."},{"Start":"00:18.230 ","End":"00:22.775","Text":"Then in part c, to assign the contents of num1 to num2."},{"Start":"00:22.775 ","End":"00:24.020","Text":"Then finally in part d,"},{"Start":"00:24.020 ","End":"00:28.775","Text":"to confirm the contents of num2 are what you would expect."},{"Start":"00:28.775 ","End":"00:32.360","Text":"We\u0027ve been asked to create 2 integer variables num1 and"},{"Start":"00:32.360 ","End":"00:36.495","Text":"num2 with no initial value given in part a."},{"Start":"00:36.495 ","End":"00:38.430","Text":"Let\u0027s go ahead and do that."},{"Start":"00:38.430 ","End":"00:41.130","Text":"It turns out there\u0027s a little trick you can do."},{"Start":"00:41.130 ","End":"00:44.000","Text":"If there are 2 variables that you want to declare,"},{"Start":"00:44.000 ","End":"00:45.905","Text":"you can declare them in 1 line,"},{"Start":"00:45.905 ","End":"00:48.350","Text":"so long as they are the same data type,"},{"Start":"00:48.350 ","End":"00:51.245","Text":"because both of these are int,"},{"Start":"00:51.245 ","End":"00:57.430","Text":"we can do that and you just simply separate the 2 variable names with a comma."},{"Start":"00:57.430 ","End":"01:02.160","Text":"It will happily declare both of those variables in 1 line,"},{"Start":"01:02.160 ","End":"01:03.740","Text":"I could do in 2 if I wanted to,"},{"Start":"01:03.740 ","End":"01:07.925","Text":"but I\u0027m just going to show you that it will work if you do it in 1 line."},{"Start":"01:07.925 ","End":"01:10.145","Text":"Just to prove that that\u0027s worked."},{"Start":"01:10.145 ","End":"01:16.430","Text":"Well, I just get num1\u0027s value is 0 and num2\u0027s value is also 0."},{"Start":"01:16.430 ","End":"01:18.740","Text":"That\u0027s what this message here is saying."},{"Start":"01:18.740 ","End":"01:21.995","Text":"By the way, it\u0027s always actually good practice to"},{"Start":"01:21.995 ","End":"01:25.700","Text":"assign a value to a variable when you declare it,"},{"Start":"01:25.700 ","End":"01:28.700","Text":"even if it will be given a default value,"},{"Start":"01:28.700 ","End":"01:33.275","Text":"you sometimes can\u0027t guarantee that on certain systems,"},{"Start":"01:33.275 ","End":"01:36.590","Text":"so its best practice is to actually always assign"},{"Start":"01:36.590 ","End":"01:41.285","Text":"a value to a variable when you\u0027re initially declaring it."},{"Start":"01:41.285 ","End":"01:43.760","Text":"That\u0027s the first part, part a."},{"Start":"01:43.760 ","End":"01:48.070","Text":"Then in part b, we\u0027ve been asked to assign the value 10 to num1."},{"Start":"01:48.070 ","End":"01:50.780","Text":"Remembering what we learned in the previous exercise,"},{"Start":"01:50.780 ","End":"01:52.865","Text":"I don\u0027t need to put the data type again."},{"Start":"01:52.865 ","End":"01:56.105","Text":"I simply need to write the variable name out."},{"Start":"01:56.105 ","End":"02:02.195","Text":"Num1 equals 10 is what I\u0027ve been asked to do and it\u0027s quite happy doing that."},{"Start":"02:02.195 ","End":"02:05.000","Text":"But part c is something we haven\u0027t seen before,"},{"Start":"02:05.000 ","End":"02:09.710","Text":"it\u0027s asking us to assign the contents of num1 to num2."},{"Start":"02:09.710 ","End":"02:14.630","Text":"Previously, we\u0027ve only ever assigned literal values to variables."},{"Start":"02:14.630 ","End":"02:19.500","Text":"Now, we\u0027re being asked to assign the contents of a variable to another variable so,"},{"Start":"02:19.500 ","End":"02:23.640","Text":"really, all we need to do here is understand which order we put things in."},{"Start":"02:23.640 ","End":"02:29.840","Text":"You\u0027ll remember from the video that we are supposed to put on the left-hand side,"},{"Start":"02:29.840 ","End":"02:33.904","Text":"the name of the variable that we wanted to store things into."},{"Start":"02:33.904 ","End":"02:38.465","Text":"Here, we\u0027ve been asked to assign the contents of num1 to num2."},{"Start":"02:38.465 ","End":"02:42.235","Text":"Num2 should go on the left-hand side here,"},{"Start":"02:42.235 ","End":"02:44.390","Text":"then follows the assignment operator,"},{"Start":"02:44.390 ","End":"02:47.705","Text":"which in Java is a single equals,"},{"Start":"02:47.705 ","End":"02:52.915","Text":"and then num1 is the value we want to assign to num2."},{"Start":"02:52.915 ","End":"02:55.500","Text":"I\u0027ll go ahead and do that, and it\u0027s done."},{"Start":"02:55.500 ","End":"02:58.790","Text":"It reflects back to me 10 I\u0027m not sure what is 10,"},{"Start":"02:58.790 ","End":"03:00.050","Text":"is it num1 or is it num2?"},{"Start":"03:00.050 ","End":"03:01.925","Text":"Let\u0027s have a look at the value of num2."},{"Start":"03:01.925 ","End":"03:03.375","Text":"Num2 is 10,"},{"Start":"03:03.375 ","End":"03:09.480","Text":"and we already know that num1 is 10 because we set its value over here."},{"Start":"03:09.480 ","End":"03:12.885","Text":"Now, num2 and num1 are 10."},{"Start":"03:12.885 ","End":"03:15.630","Text":"That\u0027s pretty much what we expect."},{"Start":"03:15.630 ","End":"03:22.715","Text":"All we\u0027ve really learned here is when you put the contents of 1 variable into another,"},{"Start":"03:22.715 ","End":"03:27.655","Text":"you get a copy of the variable value."},{"Start":"03:27.655 ","End":"03:31.060","Text":"It does not affect the value you\u0027re copying in."},{"Start":"03:31.060 ","End":"03:35.050","Text":"In this case, we were copying num1 into num2."},{"Start":"03:35.050 ","End":"03:37.165","Text":"Num2 got num1 value,"},{"Start":"03:37.165 ","End":"03:39.430","Text":"but num1 didn\u0027t change itself."},{"Start":"03:39.430 ","End":"03:43.720","Text":"You might think that when you\u0027re assigning a value from 1 variable to another,"},{"Start":"03:43.720 ","End":"03:45.655","Text":"you\u0027re removing the value somehow,"},{"Start":"03:45.655 ","End":"03:46.840","Text":"but you\u0027re not doing that."},{"Start":"03:46.840 ","End":"03:51.280","Text":"You\u0027re just producing a copy of the value and the copy of that value goes"},{"Start":"03:51.280 ","End":"03:57.175","Text":"into the variable on the left-hand side of the assignment operator."},{"Start":"03:57.175 ","End":"04:00.700","Text":"We\u0027ll do some more complex operations later on."},{"Start":"04:00.700 ","End":"04:04.645","Text":"But that\u0027s the most basic type of assignment of 1 variable to another."},{"Start":"04:04.645 ","End":"04:08.290","Text":"Essentially, we\u0027re evaluating an expression on the right-hand side"},{"Start":"04:08.290 ","End":"04:12.530","Text":"and because the expression simply contains the name of a variable,"},{"Start":"04:12.530 ","End":"04:16.815","Text":"the evaluation is just to give us the contents of that variable."},{"Start":"04:16.815 ","End":"04:22.355","Text":"Then the assignment then happens and it\u0027s stored into the variable on the left-hand side."},{"Start":"04:22.355 ","End":"04:24.545","Text":"Nice and simple for exercise 2."},{"Start":"04:24.545 ","End":"04:30.240","Text":"I\u0027ll see you in the next one where we work with another pair of variables. See you then."}],"ID":27351},{"Watched":false,"Name":"Exercise 3","Duration":"8m 12s","ChapterTopicVideoID":26449,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.580","Text":"Hello, welcome back again."},{"Start":"00:02.580 ","End":"00:04.890","Text":"In this exercise, we\u0027ve been asked to create"},{"Start":"00:04.890 ","End":"00:07.875","Text":"another pair of variables in the Code Pad once again,"},{"Start":"00:07.875 ","End":"00:13.455","Text":"this time to create a char variable and assign it the value a,"},{"Start":"00:13.455 ","End":"00:17.775","Text":"then to create a short variable with no initial value."},{"Start":"00:17.775 ","End":"00:20.580","Text":"Then in part c, we\u0027ve been asked to assign the contents of"},{"Start":"00:20.580 ","End":"00:25.620","Text":"the char variable to the short variable and explain what happens."},{"Start":"00:25.620 ","End":"00:30.405","Text":"In part d we\u0027re asked to do part c again,"},{"Start":"00:30.405 ","End":"00:34.770","Text":"but in front of the char variable name put the following characters exactly"},{"Start":"00:34.770 ","End":"00:39.240","Text":"as they appear so (short)."},{"Start":"00:39.240 ","End":"00:41.990","Text":"In part e, we\u0027re asked to look at the contents of"},{"Start":"00:41.990 ","End":"00:47.275","Text":"the short variable and explain why it contains the particular value that it contains."},{"Start":"00:47.275 ","End":"00:49.370","Text":"Moving on into part f,"},{"Start":"00:49.370 ","End":"00:51.110","Text":"we move on to Unicode characters."},{"Start":"00:51.110 ","End":"00:55.380","Text":"We\u0027re asked to assign a Unicode character \u0027\\u9000\u0027,"},{"Start":"00:56.650 ","End":"00:59.180","Text":"to the char variable."},{"Start":"00:59.180 ","End":"01:01.430","Text":"Then in part g, once again,"},{"Start":"01:01.430 ","End":"01:04.130","Text":"to assign the value of that char variable to"},{"Start":"01:04.130 ","End":"01:09.875","Text":"the short variable with short in brackets in front of the char variable name."},{"Start":"01:09.875 ","End":"01:14.690","Text":"Then in the final part to look at the contents of the short variable again, and again,"},{"Start":"01:14.690 ","End":"01:19.805","Text":"explain why it contains the particular value it contains and what has gone wrong."},{"Start":"01:19.805 ","End":"01:26.690","Text":"We first have been asked to create a char variable and assign it with the value a."},{"Start":"01:26.690 ","End":"01:28.490","Text":"Let\u0027s go ahead and do that."},{"Start":"01:28.490 ","End":"01:31.370","Text":"We haven\u0027t been told a identifier,"},{"Start":"01:31.370 ","End":"01:33.800","Text":"so I\u0027m going to call mine my char,"},{"Start":"01:33.800 ","End":"01:38.830","Text":"not particularly descriptive, but it\u0027ll do for purposes of this exercise."},{"Start":"01:38.830 ","End":"01:41.870","Text":"Note that when you\u0027re assigning a char value,"},{"Start":"01:41.870 ","End":"01:43.714","Text":"it\u0027s a single quote,"},{"Start":"01:43.714 ","End":"01:46.730","Text":"and it\u0027s closed with a single quote as well,"},{"Start":"01:46.730 ","End":"01:49.655","Text":"not speech marks, which is double-quotes,"},{"Start":"01:49.655 ","End":"01:52.220","Text":"which would be shifted to on most keyboards."},{"Start":"01:52.220 ","End":"01:56.180","Text":"It\u0027s just a single quote that\u0027s needed for a char. There we go."},{"Start":"01:56.180 ","End":"02:01.880","Text":"I\u0027ve defined my variable and it has a value just to check that value and sure enough,"},{"Start":"02:01.880 ","End":"02:05.795","Text":"it\u0027s a data type of char and it contains the value a."},{"Start":"02:05.795 ","End":"02:07.130","Text":"Then in the second part,"},{"Start":"02:07.130 ","End":"02:10.460","Text":"we\u0027ve been asked to create a short variable with no initial value."},{"Start":"02:10.460 ","End":"02:14.130","Text":"Fair enough, call it my short,"},{"Start":"02:14.130 ","End":"02:18.290","Text":"I\u0027ll be consistent and no initial value,"},{"Start":"02:18.290 ","End":"02:22.265","Text":"so I\u0027ll just end it with a semicolon just to prove It will"},{"Start":"02:22.265 ","End":"02:31.550","Text":"have an initial value and it\u0027s initialized to 0 by default by the Java system."},{"Start":"02:31.550 ","End":"02:34.880","Text":"That\u0027s fine. Now I\u0027m asked to assign"},{"Start":"02:34.880 ","End":"02:39.410","Text":"the contents of the char variable to the short variable."},{"Start":"02:39.410 ","End":"02:44.495","Text":"Assign the contents of the my char variable to the my short variables."},{"Start":"02:44.495 ","End":"02:50.720","Text":"My short comes first because it\u0027s the thing that I want to receive the value into,"},{"Start":"02:50.720 ","End":"02:55.970","Text":"and my char is on the right-hand side of the assignment operator."},{"Start":"02:55.970 ","End":"02:58.280","Text":"Let\u0027s see what happens if I try that."},{"Start":"02:58.280 ","End":"03:00.965","Text":"Unsurprisingly hopefully to you,"},{"Start":"03:00.965 ","End":"03:04.790","Text":"I get an error message and it says, incompatible types."},{"Start":"03:04.790 ","End":"03:07.414","Text":"However, what\u0027s interesting about this error message."},{"Start":"03:07.414 ","End":"03:12.710","Text":"It doesn\u0027t seem to be a closed book and it looks very similar to"},{"Start":"03:12.710 ","End":"03:15.890","Text":"some similar messages we had before when we were dealing with"},{"Start":"03:15.890 ","End":"03:19.450","Text":"floats and different sizes of integer and so on."},{"Start":"03:19.450 ","End":"03:24.670","Text":"It almost seems that it\u0027s possible to do this but we\u0027re not quite"},{"Start":"03:24.670 ","End":"03:26.680","Text":"going about it the right way because it\u0027s saying"},{"Start":"03:26.680 ","End":"03:30.175","Text":"possible lossy conversion from char to short."},{"Start":"03:30.175 ","End":"03:33.430","Text":"We will see that in the next part,"},{"Start":"03:33.430 ","End":"03:34.840","Text":"in part d,"},{"Start":"03:34.840 ","End":"03:38.350","Text":"where I\u0027ve been asked to take exactly what I had before,"},{"Start":"03:38.350 ","End":"03:48.435","Text":"but put the following characters (short) in front of my char and see what happens."},{"Start":"03:48.435 ","End":"03:55.545","Text":"Strangely, the error message goes away and I\u0027m reflected back the value 97."},{"Start":"03:55.545 ","End":"03:59.770","Text":"What we\u0027re seeing here is something called casting or it\u0027s also called"},{"Start":"03:59.770 ","End":"04:04.370","Text":"coercion where we\u0027re saying to the system,"},{"Start":"04:04.370 ","End":"04:11.025","Text":"I know that one of these things is a short data type and one is a char data type"},{"Start":"04:11.025 ","End":"04:14.420","Text":"and normally you cannot assign a variable"},{"Start":"04:14.420 ","End":"04:17.810","Text":"of one data type to a different data type but just,"},{"Start":"04:17.810 ","End":"04:25.160","Text":"for now, I\u0027d like you to pretend essentially that my Char is not a char, it\u0027s a short."},{"Start":"04:25.160 ","End":"04:28.250","Text":"If it can do it, the system will actually go ahead and try and"},{"Start":"04:28.250 ","End":"04:31.340","Text":"do it and this will work in C and other languages as well."},{"Start":"04:31.340 ","End":"04:34.625","Text":"What we\u0027ve done here is we\u0027ve cast my char,"},{"Start":"04:34.625 ","End":"04:36.650","Text":"which is a char into a short,"},{"Start":"04:36.650 ","End":"04:40.385","Text":"and then we\u0027ve been able to assign it into my short."},{"Start":"04:40.385 ","End":"04:43.325","Text":"The value 97 we\u0027re being asked,"},{"Start":"04:43.325 ","End":"04:46.940","Text":"why does it contain this value in part e?"},{"Start":"04:46.940 ","End":"04:54.770","Text":"We might be able to guess that the letter a actually has a value in the ASCII table,"},{"Start":"04:54.770 ","End":"04:58.295","Text":"and it happens to be a is 97."},{"Start":"04:58.295 ","End":"05:01.445","Text":"What has happened here is the system has said, all right,"},{"Start":"05:01.445 ","End":"05:05.330","Text":"I know this is a char and my char is not changed,"},{"Start":"05:05.330 ","End":"05:06.830","Text":"by the way, if I look at my chart,"},{"Start":"05:06.830 ","End":"05:13.400","Text":"it still contains a character a but my short now contains not 0 but 97,"},{"Start":"05:13.400 ","End":"05:19.385","Text":"which happens to be the ASCII value of the character that\u0027s stored in my chart."},{"Start":"05:19.385 ","End":"05:23.090","Text":"This statement here has basically said, \"Yes,"},{"Start":"05:23.090 ","End":"05:26.825","Text":"I know you can assign a char to a short,"},{"Start":"05:26.825 ","End":"05:33.350","Text":"but can you just pretend the char is a short and store it into my short variable\"."},{"Start":"05:33.350 ","End":"05:35.225","Text":"It has done, and it\u0027s worked."},{"Start":"05:35.225 ","End":"05:38.195","Text":"That could be useful in some situations."},{"Start":"05:38.195 ","End":"05:40.460","Text":"It does allow you to do it,"},{"Start":"05:40.460 ","End":"05:44.810","Text":"but there could be some issues and we\u0027ll see that in the subsequent parts."},{"Start":"05:44.810 ","End":"05:47.425","Text":"If we look at Part f,"},{"Start":"05:47.425 ","End":"05:50.105","Text":"it asks us to assign a Unicode character,"},{"Start":"05:50.105 ","End":"05:53.675","Text":"\\u9000 to a char variable. Let\u0027s go ahead and do that."},{"Start":"05:53.675 ","End":"05:58.910","Text":"The variable is called my char and we put a single quote, backslash,"},{"Start":"05:58.910 ","End":"06:06.720","Text":"not a forward slash u and then 9,000 has to be 4 digits, hexadecimal digits."},{"Start":"06:06.720 ","End":"06:11.870","Text":"There we go. Assign the value and I get a symbol from"},{"Start":"06:11.870 ","End":"06:17.600","Text":"the Unicode character space that is a symbol in the Chinese alphabet."},{"Start":"06:17.600 ","End":"06:19.895","Text":"We wouldn\u0027t call it an alphabet, I guess it\u0027s a symbol."},{"Start":"06:19.895 ","End":"06:21.440","Text":"There are thousands of symbols,"},{"Start":"06:21.440 ","End":"06:26.464","Text":"which is why they\u0027re so high up in the Chinese symbols range,"},{"Start":"06:26.464 ","End":"06:28.340","Text":"and we call this symbol C, J, K by the way,"},{"Start":"06:28.340 ","End":"06:32.420","Text":"because Japanese and Korean also fall into the same range."},{"Start":"06:32.420 ","End":"06:37.125","Text":"There\u0027s a C, J, K symbol in my char now,"},{"Start":"06:37.125 ","End":"06:40.790","Text":"and correct me now I can do stuff with that, I can display it,"},{"Start":"06:40.790 ","End":"06:44.750","Text":"or I can search for it because it\u0027s in a variable now in a char variable."},{"Start":"06:44.750 ","End":"06:52.395","Text":"But let\u0027s try and do what we did before and assign this value into my short."},{"Start":"06:52.395 ","End":"06:54.830","Text":"My char now has a different value in it,"},{"Start":"06:54.830 ","End":"07:01.355","Text":"which is that character represented by the Unicode value 9,000 hex."},{"Start":"07:01.355 ","End":"07:04.640","Text":"Let\u0027s try and do what we did before and we know it worked before I got"},{"Start":"07:04.640 ","End":"07:09.710","Text":"97 into my short when I had the letter a in there."},{"Start":"07:09.710 ","End":"07:11.665","Text":"Let\u0027s see what happens now."},{"Start":"07:11.665 ","End":"07:16.265","Text":"I get a negative number, very strange."},{"Start":"07:16.265 ","End":"07:20.210","Text":"Now, why would I have got a negative number?"},{"Start":"07:20.210 ","End":"07:25.415","Text":"Why does short contain that value I\u0027m being asked in part h?"},{"Start":"07:25.415 ","End":"07:29.000","Text":"Well the reason is the size of short,"},{"Start":"07:29.000 ","End":"07:32.540","Text":"short remember is a 16-bit number,"},{"Start":"07:32.540 ","End":"07:35.705","Text":"but it\u0027s a signed 16-bit number so actually,"},{"Start":"07:35.705 ","End":"07:39.965","Text":"the maximum value you can have is a 15-bit number,"},{"Start":"07:39.965 ","End":"07:42.710","Text":"which is 3, 2, 7, 6, 7."},{"Start":"07:42.710 ","End":"07:47.390","Text":"It just so happens that 9,000 hex is a bigger number than 3,"},{"Start":"07:47.390 ","End":"07:52.025","Text":"2, 7, 6, 7, it\u0027s actually 36,864."},{"Start":"07:52.025 ","End":"07:56.225","Text":"What\u0027s happening here is I\u0027m going outside the range that can"},{"Start":"07:56.225 ","End":"08:00.740","Text":"be displayed in 15 bits or can be encoded in 15 bits."},{"Start":"08:00.740 ","End":"08:04.130","Text":"It\u0027s wrapped around through a negative value."},{"Start":"08:04.130 ","End":"08:10.760","Text":"I think really all this illustrates is although we can sometimes convert"},{"Start":"08:10.760 ","End":"08:14.420","Text":"one data type into another temporarily for the purposes"},{"Start":"08:14.420 ","End":"08:18.170","Text":"of an assignment by using this costing syntax,"},{"Start":"08:18.170 ","End":"08:22.075","Text":"which is to put a data type in brackets ahead of your variable name,"},{"Start":"08:22.075 ","End":"08:25.520","Text":"it can sometimes have unexpected effects"},{"Start":"08:25.520 ","End":"08:28.910","Text":"so you\u0027ve got to be very careful if you\u0027re doing this."},{"Start":"08:28.910 ","End":"08:30.829","Text":"If you\u0027re using, for example,"},{"Start":"08:30.829 ","End":"08:33.740","Text":"7-bit ASCII characters, no problem,"},{"Start":"08:33.740 ","End":"08:37.280","Text":"you can convert an integer that is values from 0 to"},{"Start":"08:37.280 ","End":"08:41.690","Text":"127 into an ASCII value from 0 to 127."},{"Start":"08:41.690 ","End":"08:44.900","Text":"No problem. But if it\u0027s anything else,"},{"Start":"08:44.900 ","End":"08:46.805","Text":"you\u0027ve got to be very careful."},{"Start":"08:46.805 ","End":"08:52.505","Text":"This short might, on the surface seem okay because it\u0027s 16 bits and so is Unicode,"},{"Start":"08:52.505 ","End":"08:59.810","Text":"but actually the short is 15 bits in the positive direction and negative direction,"},{"Start":"08:59.810 ","End":"09:02.075","Text":"and one bit is used for the sign so"},{"Start":"09:02.075 ","End":"09:06.210","Text":"it\u0027s potentially an area where you can have a problem."},{"Start":"09:06.210 ","End":"09:10.010","Text":"This exercise has shown you that you can\u0027t"},{"Start":"09:10.010 ","End":"09:16.145","Text":"normally put a variable of one data type into another variable of a different data type"},{"Start":"09:16.145 ","End":"09:21.560","Text":"but you can coerce one variable to temporarily pretend it\u0027s"},{"Start":"09:21.560 ","End":"09:24.560","Text":"a different type but that may or may not"},{"Start":"09:24.560 ","End":"09:27.825","Text":"cause problems and it\u0027s just something to be aware of."},{"Start":"09:27.825 ","End":"09:32.120","Text":"Generally, remember that data types are there to enforce"},{"Start":"09:32.120 ","End":"09:37.700","Text":"some constraints on the variable so they\u0027re there for a reason and it can be overwritten,"},{"Start":"09:37.700 ","End":"09:40.670","Text":"but just need to be very careful if you\u0027re going to do that."},{"Start":"09:40.670 ","End":"09:42.500","Text":"That\u0027s it for this exercise."},{"Start":"09:42.500 ","End":"09:44.970","Text":"I\u0027ll see for the next one."}],"ID":27352},{"Watched":false,"Name":"Exercise 4","Duration":"11m 13s","ChapterTopicVideoID":26443,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:05.415","Text":"Hello. Welcome back to the next video on the exercises on assignments and expressions."},{"Start":"00:05.415 ","End":"00:09.450","Text":"Here we\u0027ve been asked to create a 3rd integer variable in Code Pad called"},{"Start":"00:09.450 ","End":"00:14.910","Text":"num3 to complement the 2 integer variables we created in an earlier exercise."},{"Start":"00:14.910 ","End":"00:19.200","Text":"In part a, we\u0027ve been asked to assign the value 10 to num1,"},{"Start":"00:19.200 ","End":"00:21.120","Text":"20 to num2,"},{"Start":"00:21.120 ","End":"00:23.055","Text":"and 4 to num3,"},{"Start":"00:23.055 ","End":"00:26.250","Text":"and then check the contents of all 3 of those variables."},{"Start":"00:26.250 ","End":"00:31.980","Text":"In part b, we\u0027ve been asked to create a single expression involving all 3 of"},{"Start":"00:31.980 ","End":"00:38.210","Text":"those variables that adds num1 to num2 divided by num3,"},{"Start":"00:38.210 ","End":"00:41.830","Text":"and then note results of that evaluation."},{"Start":"00:41.830 ","End":"00:45.410","Text":"In part c, we\u0027ve been asked to take that same expression,"},{"Start":"00:45.410 ","End":"00:48.470","Text":"but put brackets around the addition of num1 and"},{"Start":"00:48.470 ","End":"00:52.495","Text":"num2 and then explain the resulting evaluation."},{"Start":"00:52.495 ","End":"00:54.325","Text":"Then finally, in part d,"},{"Start":"00:54.325 ","End":"00:59.270","Text":"I\u0027ve been asked to use the same expression again as part c,"},{"Start":"00:59.270 ","End":"01:02.660","Text":"but to use the modulo operation this time instead of"},{"Start":"01:02.660 ","End":"01:06.950","Text":"the divide operation and to explain the resulting evaluation."},{"Start":"01:06.950 ","End":"01:13.070","Text":"In question 4, we\u0027ve been asked to create a 3rd integer variable in co bad num3."},{"Start":"01:13.070 ","End":"01:16.250","Text":"We already created num1 and 2 in exercise 2."},{"Start":"01:16.250 ","End":"01:19.145","Text":"I\u0027ve actually got rid of mine because I\u0027ve started a new session."},{"Start":"01:19.145 ","End":"01:22.130","Text":"But you only need to put all of these in."},{"Start":"01:22.130 ","End":"01:24.800","Text":"I\u0027m going to create all 3 variables again."},{"Start":"01:24.800 ","End":"01:28.505","Text":"As I said, if you already still have num1 and num2,"},{"Start":"01:28.505 ","End":"01:30.304","Text":"you just need to create num3."},{"Start":"01:30.304 ","End":"01:36.430","Text":"Now, I have my 3 variables and part a asks me to assign the value 10 to num1,"},{"Start":"01:36.430 ","End":"01:38.980","Text":"20 to num2,"},{"Start":"01:39.170 ","End":"01:42.300","Text":"and 4 to num3."},{"Start":"01:42.300 ","End":"01:46.565","Text":"In part b, it now ask me to create a single expression involving"},{"Start":"01:46.565 ","End":"01:51.795","Text":"all 3 variables that adds num1 to num2 divided by num3."},{"Start":"01:51.795 ","End":"01:55.310","Text":"I haven\u0027t been told to store those values anywhere."},{"Start":"01:55.310 ","End":"01:59.660","Text":"I\u0027ve simply been asked to create an expression involving those 3 variables."},{"Start":"01:59.660 ","End":"02:01.580","Text":"That sounds straightforward enough."},{"Start":"02:01.580 ","End":"02:10.065","Text":"Num1 gets added to num2 divided by num3."},{"Start":"02:10.065 ","End":"02:12.825","Text":"It will evaluate to 15."},{"Start":"02:12.825 ","End":"02:14.305","Text":"Then part c,"},{"Start":"02:14.305 ","End":"02:18.260","Text":"I have been asked to put brackets around the addition of num1 and"},{"Start":"02:18.260 ","End":"02:23.240","Text":"2 and explain the evaluation that results from that."},{"Start":"02:23.240 ","End":"02:27.230","Text":"I\u0027ll just do our power to get back what I\u0027ve just typed."},{"Start":"02:27.230 ","End":"02:28.820","Text":"I\u0027ll do as I\u0027ve been asked,"},{"Start":"02:28.820 ","End":"02:36.015","Text":"which is to put brackets around num1 plus num2 and the value I get is 7."},{"Start":"02:36.015 ","End":"02:40.550","Text":"How can I explain the difference between those 2 evaluations?"},{"Start":"02:40.550 ","End":"02:42.350","Text":"Well, the first one here,"},{"Start":"02:42.350 ","End":"02:46.010","Text":"as we know the order of precedence comes in here."},{"Start":"02:46.010 ","End":"02:49.415","Text":"Normally we\u0027d evaluate from left to right, however,"},{"Start":"02:49.415 ","End":"02:55.415","Text":"some operations have a greater precedence than others and division and multiplication"},{"Start":"02:55.415 ","End":"03:02.089","Text":"would be an example of something that has a higher precedence than plus and minus."},{"Start":"03:02.089 ","End":"03:04.655","Text":"The division will happen first."},{"Start":"03:04.655 ","End":"03:11.045","Text":"Therefore, num2 will be divided by num3 and the result of that will be added to num1."},{"Start":"03:11.045 ","End":"03:12.950","Text":"That\u0027s exactly what we saw."},{"Start":"03:12.950 ","End":"03:18.485","Text":"Num2 was 20, num3 was 4."},{"Start":"03:18.485 ","End":"03:22.455","Text":"So 20 was divided by 4,"},{"Start":"03:22.455 ","End":"03:24.615","Text":"which will give us 5, of course,"},{"Start":"03:24.615 ","End":"03:28.235","Text":"and then it was added to num1 because num1 had 10 in it,"},{"Start":"03:28.235 ","End":"03:32.045","Text":"the result was 15 as we would expect."},{"Start":"03:32.045 ","End":"03:37.700","Text":"The result of putting brackets around num1 and num2,"},{"Start":"03:37.700 ","End":"03:40.750","Text":"brackets have the highest order of precedence of all."},{"Start":"03:40.750 ","End":"03:43.415","Text":"So they will be evaluated first,"},{"Start":"03:43.415 ","End":"03:44.750","Text":"and then the division,"},{"Start":"03:44.750 ","End":"03:47.015","Text":"although it has a higher precedence, now,"},{"Start":"03:47.015 ","End":"03:49.550","Text":"will be overridden by the brackets."},{"Start":"03:49.550 ","End":"03:52.010","Text":"It has a higher precedence than plus that is to say,"},{"Start":"03:52.010 ","End":"03:56.390","Text":"as it did here, the brackets now will be evaluated first."},{"Start":"03:56.390 ","End":"03:59.395","Text":"Num1 will be added to num2."},{"Start":"03:59.395 ","End":"04:05.455","Text":"Therefore, we\u0027d have 30 and then 30 is divided by num3, which is 4."},{"Start":"04:05.455 ","End":"04:07.120","Text":"Now, why do we get 7?"},{"Start":"04:07.120 ","End":"04:13.180","Text":"Because 30 divided by 4 is 28 with a remainder and"},{"Start":"04:13.180 ","End":"04:15.820","Text":"we only ask to give the integer part"},{"Start":"04:15.820 ","End":"04:19.404","Text":"because all these variables involved are integer variables."},{"Start":"04:19.404 ","End":"04:22.630","Text":"Therefore, the result of the expression would also be an integer,"},{"Start":"04:22.630 ","End":"04:26.140","Text":"and it\u0027s evaluated to the value 7."},{"Start":"04:26.140 ","End":"04:28.690","Text":"In part d, we\u0027ve been asked to use"},{"Start":"04:28.690 ","End":"04:32.095","Text":"exactly the same expression as part c, which was this one,"},{"Start":"04:32.095 ","End":"04:37.894","Text":"but to change the divide operator to the percent operator,"},{"Start":"04:37.894 ","End":"04:42.800","Text":"which means modulo and to explain the results of the evaluation."},{"Start":"04:42.800 ","End":"04:44.450","Text":"Now, we get 2."},{"Start":"04:44.450 ","End":"04:46.622","Text":"Going through those numbers again,"},{"Start":"04:46.622 ","End":"04:50.330","Text":"what we\u0027re seeing is num1 plus num2,"},{"Start":"04:50.330 ","End":"04:54.760","Text":"as we said, was 30 divided by 4."},{"Start":"04:54.760 ","End":"04:58.070","Text":"We are asked to give the remainder when we divide by 4."},{"Start":"04:58.070 ","End":"05:00.545","Text":"Not the quotient, but the remainder."},{"Start":"05:00.545 ","End":"05:03.870","Text":"The remainder when we divide 30 by 4,"},{"Start":"05:03.870 ","End":"05:08.645","Text":"we get 28 and then the remainder of 2,"},{"Start":"05:08.645 ","End":"05:11.165","Text":"so the result is 2."},{"Start":"05:11.165 ","End":"05:15.980","Text":"It\u0027s showing really the difference between the division and the modulo operators,"},{"Start":"05:15.980 ","End":"05:17.315","Text":"they\u0027re obviously related,"},{"Start":"05:17.315 ","End":"05:19.790","Text":"and how that applies to integers."},{"Start":"05:19.790 ","End":"05:25.125","Text":"We also saw how precedence is affected by brackets."},{"Start":"05:25.125 ","End":"05:28.730","Text":"This was a very straightforward expression involving"},{"Start":"05:28.730 ","End":"05:32.239","Text":"just a couple of numbers, 3 different variables."},{"Start":"05:32.239 ","End":"05:35.660","Text":"In fact, we can have a play around with this till our heart is"},{"Start":"05:35.660 ","End":"05:39.170","Text":"content by just typing in values and seeing how they\u0027re evaluated."},{"Start":"05:39.170 ","End":"05:41.660","Text":"These were variables, but if we wanted to,"},{"Start":"05:41.660 ","End":"05:46.940","Text":"we could put literals in here if we wanted to see what the effect would"},{"Start":"05:46.940 ","End":"05:53.855","Text":"be and how a set of brackets could be used to affect the order evaluation."},{"Start":"05:53.855 ","End":"05:56.750","Text":"You might be able to predict what you\u0027d get from this value."},{"Start":"05:56.750 ","End":"06:01.834","Text":"For example, what we\u0027ve got is 12 times 3 is going to happen first,"},{"Start":"06:01.834 ","End":"06:05.160","Text":"and that would give us 36."},{"Start":"06:05.160 ","End":"06:08.190","Text":"Then we minus 3 plus 4,"},{"Start":"06:08.190 ","End":"06:09.475","Text":"which is 7,"},{"Start":"06:09.475 ","End":"06:11.378","Text":"and that, obviously, gives us 29."},{"Start":"06:11.378 ","End":"06:12.950","Text":"Have a play around with this."},{"Start":"06:12.950 ","End":"06:16.730","Text":"The expressions can involve a variable or they can involve literals,"},{"Start":"06:16.730 ","End":"06:20.345","Text":"but they eventually will be evaluated and return a value."},{"Start":"06:20.345 ","End":"06:23.240","Text":"Of course that value could be stored into a variable."},{"Start":"06:23.240 ","End":"06:24.770","Text":"We haven\u0027t done that here."},{"Start":"06:24.770 ","End":"06:29.735","Text":"We weren\u0027t asked to, but it\u0027s probably going to happen in a real program."},{"Start":"06:29.735 ","End":"06:34.220","Text":"That\u0027s it for very simple expressions using some of"},{"Start":"06:34.220 ","End":"06:39.990","Text":"the mathematical operators and we\u0027re done for question 4."}],"ID":27353},{"Watched":false,"Name":"Exercise 5","Duration":"12m 49s","ChapterTopicVideoID":26444,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.220","Text":"Hello, welcome back. In this exercise,"},{"Start":"00:02.220 ","End":"00:05.280","Text":"we\u0027ve been asked to use the same variables as in the previous exercise,"},{"Start":"00:05.280 ","End":"00:08.085","Text":"integer variables from num1 to num3."},{"Start":"00:08.085 ","End":"00:10.830","Text":"In part a, we\u0027ve been asked to assign the value 7"},{"Start":"00:10.830 ","End":"00:13.980","Text":"to variable num1 and 8 to variable num2."},{"Start":"00:13.980 ","End":"00:18.000","Text":"Then in part b, which has got some sub-questions we\u0027ve been asked,"},{"Start":"00:18.000 ","End":"00:20.040","Text":"without using any other variables,"},{"Start":"00:20.040 ","End":"00:22.980","Text":"to use the comparison or relational operators."},{"Start":"00:22.980 ","End":"00:26.820","Text":"As they are also known in the Code Pad to test first of all,"},{"Start":"00:26.820 ","End":"00:29.115","Text":"if num1 and num2 are equal."},{"Start":"00:29.115 ","End":"00:30.810","Text":"Then in part 2,"},{"Start":"00:30.810 ","End":"00:34.245","Text":"if num1 and num2 are not equal,"},{"Start":"00:34.245 ","End":"00:39.000","Text":"in part b iii is num1 greater than num2,"},{"Start":"00:39.000 ","End":"00:43.589","Text":"and in part b iv is num1 less than num2."},{"Start":"00:43.589 ","End":"00:49.310","Text":"Then in part c, we\u0027ve been asked to change the value of num2 to 7 and then retest to"},{"Start":"00:49.310 ","End":"00:55.100","Text":"see if in part c1 num1 is greater than or equal to num2."},{"Start":"00:55.100 ","End":"01:00.145","Text":"In part c2, if num1 is less than or equal to num2."},{"Start":"01:00.145 ","End":"01:02.360","Text":"In the next part of the exercise,"},{"Start":"01:02.360 ","End":"01:04.325","Text":"we use the logical operators."},{"Start":"01:04.325 ","End":"01:09.360","Text":"Part d asks us to assign the value 9 to num3."},{"Start":"01:09.360 ","End":"01:14.180","Text":"Then we use the logical and operator to create a single expression that"},{"Start":"01:14.180 ","End":"01:20.305","Text":"evaluates whether num2 is greater than 5 and less than 10."},{"Start":"01:20.305 ","End":"01:23.905","Text":"In part f, we\u0027re asked to change the value of num2 to 5,"},{"Start":"01:23.905 ","End":"01:27.775","Text":"then run the expression above again, in part g,"},{"Start":"01:27.775 ","End":"01:33.530","Text":"we\u0027re asked to use the logical or operator instead to create a single expression that"},{"Start":"01:33.530 ","End":"01:40.585","Text":"evaluates whether num1 is less than num2 or num3 is equal to 11."},{"Start":"01:40.585 ","End":"01:41.870","Text":"In part h,"},{"Start":"01:41.870 ","End":"01:45.440","Text":"we\u0027re asked to change the value of num3 to 11 and run"},{"Start":"01:45.440 ","End":"01:50.125","Text":"the expression from part f again to see if the evaluation changes."},{"Start":"01:50.125 ","End":"01:55.550","Text":"Then finally, we\u0027re asked to create our own expression using a combination of"},{"Start":"01:55.550 ","End":"01:59.030","Text":"logical and comparison operators and to include"},{"Start":"01:59.030 ","End":"02:02.890","Text":"the not operator and brackets to change the order of evaluation."},{"Start":"02:02.890 ","End":"02:05.210","Text":"We\u0027re asked to change the value of at least one of"},{"Start":"02:05.210 ","End":"02:09.635","Text":"our variables and to see the effect on the evaluation."},{"Start":"02:09.635 ","End":"02:12.440","Text":"In this exercise number 5,"},{"Start":"02:12.440 ","End":"02:16.340","Text":"we\u0027ve been asked to use the same variables as in Exercise 4."},{"Start":"02:16.340 ","End":"02:20.075","Text":"We add num1 to num3 or integer variables,"},{"Start":"02:20.075 ","End":"02:24.455","Text":"and to perform various steps in the code patterns before."},{"Start":"02:24.455 ","End":"02:28.820","Text":"The first step in part a is to assign num1,"},{"Start":"02:28.820 ","End":"02:30.495","Text":"the value 7,"},{"Start":"02:30.495 ","End":"02:34.080","Text":"and num2, the value 8."},{"Start":"02:34.080 ","End":"02:35.835","Text":"Let\u0027s go ahead and do that."},{"Start":"02:35.835 ","End":"02:37.960","Text":"Then in part b,"},{"Start":"02:37.960 ","End":"02:42.230","Text":"we\u0027re being asked to not use any other variables but to use the comparison,"},{"Start":"02:42.230 ","End":"02:46.220","Text":"also known as relational operators in Code Pad to test"},{"Start":"02:46.220 ","End":"02:52.340","Text":"various logical tests using comparison operators."},{"Start":"02:52.340 ","End":"02:54.980","Text":"The first one b part 1,"},{"Start":"02:54.980 ","End":"02:59.830","Text":"is asking to see if num1 and num2 are equal."},{"Start":"02:59.830 ","End":"03:05.000","Text":"First trap you could follow in here is to use a single equal sign."},{"Start":"03:05.000 ","End":"03:09.230","Text":"Remember the single equal sign means, assign a value."},{"Start":"03:09.230 ","End":"03:14.465","Text":"Double equals sign is the comparison operator in Java."},{"Start":"03:14.465 ","End":"03:17.465","Text":"We\u0027re comparing one value to another."},{"Start":"03:17.465 ","End":"03:19.465","Text":"In this expression we\u0027re saying,"},{"Start":"03:19.465 ","End":"03:21.905","Text":"is num1 equal to num2?"},{"Start":"03:21.905 ","End":"03:27.200","Text":"Does it contain the same value as num2? Let\u0027s see if it does."},{"Start":"03:27.200 ","End":"03:31.220","Text":"I get a response which is a Boolean response."},{"Start":"03:31.220 ","End":"03:35.330","Text":"These operators all return a Boolean response."},{"Start":"03:35.330 ","End":"03:37.160","Text":"In this case, it\u0027s false."},{"Start":"03:37.160 ","End":"03:39.635","Text":"Because num1 contains 7,"},{"Start":"03:39.635 ","End":"03:41.355","Text":"as you\u0027ve seen here,"},{"Start":"03:41.355 ","End":"03:42.990","Text":"and num2 contains 8."},{"Start":"03:42.990 ","End":"03:44.625","Text":"Clearly, they\u0027re not the same."},{"Start":"03:44.625 ","End":"03:49.145","Text":"We would expect therefore the evaluation to return false."},{"Start":"03:49.145 ","End":"03:53.540","Text":"In b2, we\u0027re asked to see if num1 and num2 are not"},{"Start":"03:53.540 ","End":"03:58.175","Text":"equal and just to test that we remember what the operator is."},{"Start":"03:58.175 ","End":"04:01.670","Text":"It is the not sign,"},{"Start":"04:01.670 ","End":"04:05.899","Text":"which is an exclamation mark followed by equals, no spaces."},{"Start":"04:05.899 ","End":"04:10.160","Text":"We\u0027re saying it\u0027s not equal to num2."},{"Start":"04:10.160 ","End":"04:13.985","Text":"As we know, 7 and 8 are not equal."},{"Start":"04:13.985 ","End":"04:18.590","Text":"The expression here generates a result of true,"},{"Start":"04:18.590 ","End":"04:25.670","Text":"num1 not equal to num2 returns the evaluation of true."},{"Start":"04:25.670 ","End":"04:32.224","Text":"In b3, we\u0027re asked to see if num1 is greater than num2."},{"Start":"04:32.224 ","End":"04:36.890","Text":"This is simple case of remembering your greater than and less than symbols."},{"Start":"04:36.890 ","End":"04:40.085","Text":"Num1 is greater than num2."},{"Start":"04:40.085 ","End":"04:41.870","Text":"We know that that\u0027s not true,"},{"Start":"04:41.870 ","End":"04:46.040","Text":"so we expect a false because 7 is not greater than 8."},{"Start":"04:46.040 ","End":"04:48.185","Text":"Let\u0027s try it the other way round then,"},{"Start":"04:48.185 ","End":"04:50.600","Text":"which is b4,"},{"Start":"04:50.600 ","End":"04:53.630","Text":"num1 is less than num2."},{"Start":"04:53.630 ","End":"04:56.030","Text":"Here\u0027s the less than operator."},{"Start":"04:56.030 ","End":"05:00.770","Text":"We would expect that to be true because 7 is less than 8."},{"Start":"05:00.770 ","End":"05:03.080","Text":"We are given a value true,"},{"Start":"05:03.080 ","End":"05:05.075","Text":"which is just what we\u0027d expect."},{"Start":"05:05.075 ","End":"05:12.180","Text":"We\u0027ve used the basic operators now in terms of comparison or relational operators."},{"Start":"05:12.180 ","End":"05:15.000","Text":"They will operate, as you would expect."},{"Start":"05:15.000 ","End":"05:18.695","Text":"Something\u0027s either equal to something else or it\u0027s not equal to something else."},{"Start":"05:18.695 ","End":"05:22.475","Text":"It\u0027s greater than something else or it\u0027s less than something else."},{"Start":"05:22.475 ","End":"05:27.365","Text":"We\u0027re now in part c. We\u0027ve asked to change the value of num2 to 7."},{"Start":"05:27.365 ","End":"05:28.850","Text":"Let\u0027s go ahead and do that."},{"Start":"05:28.850 ","End":"05:32.970","Text":"Remember, num1 is also 7 and then in"},{"Start":"05:32.970 ","End":"05:37.655","Text":"c1 we\u0027ve been asked to test if num1 is greater than or equal to num2."},{"Start":"05:37.655 ","End":"05:43.160","Text":"This is really just so that we get the idea of the greater than or equal to operator,"},{"Start":"05:43.160 ","End":"05:44.780","Text":"which is 2 symbols."},{"Start":"05:44.780 ","End":"05:49.129","Text":"The greater than comes first and the equals comes second."},{"Start":"05:49.129 ","End":"05:55.040","Text":"We\u0027re saying is num1 either greater than or exactly equal to num2."},{"Start":"05:55.040 ","End":"06:00.275","Text":"Of course, it is exactly equal to num2."},{"Start":"06:00.275 ","End":"06:04.785","Text":"Remember before, num1 greater than num2 return to false."},{"Start":"06:04.785 ","End":"06:07.730","Text":"This time because we\u0027ve changed it to greater than or"},{"Start":"06:07.730 ","End":"06:10.955","Text":"equal to and we\u0027ve changed the value of num2 to 7."},{"Start":"06:10.955 ","End":"06:16.009","Text":"We\u0027re getting a true instead of false."},{"Start":"06:16.009 ","End":"06:19.190","Text":"Let\u0027s try it the other way round or not the other way around."},{"Start":"06:19.190 ","End":"06:22.520","Text":"But let\u0027s try the less than or equal to operator,"},{"Start":"06:22.520 ","End":"06:25.055","Text":"which is part c2."},{"Start":"06:25.055 ","End":"06:34.610","Text":"We would expect that also to return true and it does because num1 is not less than num2."},{"Start":"06:34.610 ","End":"06:38.180","Text":"But it is exactly equal to num2 for the same reasons as we said above."},{"Start":"06:38.180 ","End":"06:44.150","Text":"Great. We\u0027ve used all of the basic operators for comparison and relationships."},{"Start":"06:44.150 ","End":"06:51.485","Text":"That\u0027s all straightforward and we\u0027ll see there\u0027s an awful lot in the next topic."},{"Start":"06:51.485 ","End":"06:55.190","Text":"It\u0027s really important that you\u0027ve understood this and by all means,"},{"Start":"06:55.190 ","End":"06:57.710","Text":"spend a little bit of extra time working"},{"Start":"06:57.710 ","End":"07:02.225","Text":"through some of your own examples to just drum that home."},{"Start":"07:02.225 ","End":"07:07.370","Text":"Now, part d, we\u0027ve been asked to assign the value 9 to num3."},{"Start":"07:07.370 ","End":"07:09.430","Text":"Let\u0027s go ahead and do that."},{"Start":"07:09.430 ","End":"07:14.450","Text":"Then use the logical and operator to create a single expression that"},{"Start":"07:14.450 ","End":"07:19.730","Text":"evaluates whether num2 is greater than 5 and less than 10."},{"Start":"07:19.730 ","End":"07:23.720","Text":"You\u0027ll remember that and requires two things to"},{"Start":"07:23.720 ","End":"07:27.920","Text":"be true in order to generate a true result."},{"Start":"07:27.920 ","End":"07:33.290","Text":"What we\u0027ve been asked to do here is num2 greater than 5 and less than 10?"},{"Start":"07:33.290 ","End":"07:34.760","Text":"We\u0027re going to ask two questions."},{"Start":"07:34.760 ","End":"07:38.010","Text":"We\u0027re going to say num2 greater than 5,"},{"Start":"07:38.010 ","End":"07:39.890","Text":"and we\u0027re going to ask another question,"},{"Start":"07:39.890 ","End":"07:44.905","Text":"num2 less than 10."},{"Start":"07:44.905 ","End":"07:48.605","Text":"But what we\u0027re going to do is we have to join those with an and,"},{"Start":"07:48.605 ","End":"07:50.330","Text":"and the keyword is not and."},{"Start":"07:50.330 ","End":"07:53.345","Text":"It would be in Python and Java and C,"},{"Start":"07:53.345 ","End":"07:55.070","Text":"it\u0027s a double ampersand,"},{"Start":"07:55.070 ","End":"07:59.150","Text":"2 ampersands would be a logical and."},{"Start":"07:59.150 ","End":"08:07.110","Text":"As we know, num2 contains 7."},{"Start":"08:07.110 ","End":"08:14.075","Text":"We would expect therefore because num2 is greater than 5 and num2 is less than 10."},{"Start":"08:14.075 ","End":"08:17.150","Text":"Both of those things are true either side of the logical and."},{"Start":"08:17.150 ","End":"08:19.970","Text":"We would expect the result to be true as well."},{"Start":"08:19.970 ","End":"08:24.310","Text":"We do indeed get a value of true."},{"Start":"08:24.310 ","End":"08:26.560","Text":"Now in part f,"},{"Start":"08:26.560 ","End":"08:32.135","Text":"we\u0027ve been asked to change the value of num2 to 5 and run that expression again."},{"Start":"08:32.135 ","End":"08:34.220","Text":"Let\u0027s do that."},{"Start":"08:34.220 ","End":"08:38.300","Text":"num2 equals 5. Let\u0027s run the expression again."},{"Start":"08:38.300 ","End":"08:40.490","Text":"Now this time we get a false."},{"Start":"08:40.490 ","End":"08:42.780","Text":"Exactly the same expression, but we get a false."},{"Start":"08:42.780 ","End":"08:44.750","Text":"I hope you\u0027ll realize why."},{"Start":"08:44.750 ","End":"08:49.340","Text":"It\u0027s because it\u0027s exactly equal to 5 but not greater than 5."},{"Start":"08:49.340 ","End":"08:54.395","Text":"Now num2, this part of the expression would evaluate to false."},{"Start":"08:54.395 ","End":"08:59.105","Text":"This one will be true because 5 is less than 10 still."},{"Start":"08:59.105 ","End":"09:01.670","Text":"But both parts have to be true for"},{"Start":"09:01.670 ","End":"09:05.975","Text":"the overall evaluation to come out true because that\u0027s what and expects."},{"Start":"09:05.975 ","End":"09:10.330","Text":"Hence we\u0027ve got this result of false."},{"Start":"09:10.330 ","End":"09:12.525","Text":"In part g,"},{"Start":"09:12.525 ","End":"09:15.395","Text":"we\u0027ve been asked to use the logical or operator"},{"Start":"09:15.395 ","End":"09:17.870","Text":"to create a single expression that evaluates"},{"Start":"09:17.870 ","End":"09:24.375","Text":"whether num1 is less than num2 or number 3 is equal to 11."},{"Start":"09:24.375 ","End":"09:32.255","Text":"What we want to do here then is say num1 is less than num2."},{"Start":"09:32.255 ","End":"09:37.710","Text":"Then we want the or and we say num3 equals 11."},{"Start":"09:37.710 ","End":"09:42.425","Text":"Now, or in Python is just or but in Java,"},{"Start":"09:42.425 ","End":"09:45.125","Text":"it\u0027s what we call the pipe character and it\u0027s two of them."},{"Start":"09:45.125 ","End":"09:46.850","Text":"It\u0027s like a vertical bar,"},{"Start":"09:46.850 ","End":"09:50.825","Text":"but we need two of those to do a logical or."},{"Start":"09:50.825 ","End":"09:54.680","Text":"What this is doing is it\u0027s joining two expressions together"},{"Start":"09:54.680 ","End":"09:58.730","Text":"and either of them can be true to generate a result of true."},{"Start":"09:58.730 ","End":"10:05.270","Text":"Either num1 is less than num2 or num3 is exactly equal to,"},{"Start":"10:05.270 ","End":"10:08.225","Text":"not 1, I\u0027ve been asked to do 11."},{"Start":"10:08.225 ","End":"10:12.875","Text":"Num3 is exactly equal to 11. Let\u0027s run that."},{"Start":"10:12.875 ","End":"10:20.120","Text":"I get a false because num1 is not less than num2."},{"Start":"10:20.120 ","End":"10:23.585","Text":"If we just remind ourselves what num1 has is 7."},{"Start":"10:23.585 ","End":"10:26.760","Text":"Num2 is 5."},{"Start":"10:26.760 ","End":"10:30.005","Text":"Num1 is actually greater than num2."},{"Start":"10:30.005 ","End":"10:32.374","Text":"Hence this part, it\u0027s going to be false."},{"Start":"10:32.374 ","End":"10:35.410","Text":"Num3 is not 11."},{"Start":"10:35.410 ","End":"10:39.005","Text":"Remind ourselves what num3 contains. It\u0027s got 9."},{"Start":"10:39.005 ","End":"10:41.720","Text":"Neither parts of this expression are true."},{"Start":"10:41.720 ","End":"10:43.550","Text":"That\u0027s false and that\u0027s false."},{"Start":"10:43.550 ","End":"10:47.555","Text":"Therefore, it cannot generate a true value, it generates false."},{"Start":"10:47.555 ","End":"10:50.300","Text":"However, now, if I change the values,"},{"Start":"10:50.300 ","End":"10:56.765","Text":"I\u0027ve been asked in part h of num3 to 11 and run that expression again,"},{"Start":"10:56.765 ","End":"10:59.255","Text":"what I see is true."},{"Start":"10:59.255 ","End":"11:02.330","Text":"Because even though num1 is not"},{"Start":"11:02.330 ","End":"11:05.679","Text":"less than num2 still because we didn\u0027t change their values,"},{"Start":"11:05.679 ","End":"11:08.195","Text":"7 is still not less than 5."},{"Start":"11:08.195 ","End":"11:13.790","Text":"This next part of the expression is num3 equal to 11 is now true."},{"Start":"11:13.790 ","End":"11:17.300","Text":"Only one part of this expression needs to be true with"},{"Start":"11:17.300 ","End":"11:22.175","Text":"all to generate a true as the output."},{"Start":"11:22.175 ","End":"11:26.085","Text":"That\u0027s great, that\u0027s part h done."},{"Start":"11:26.085 ","End":"11:29.510","Text":"In part i, we\u0027ve just been asked to use any combination of"},{"Start":"11:29.510 ","End":"11:32.360","Text":"logical and comparison operators and maybe use"},{"Start":"11:32.360 ","End":"11:36.950","Text":"the not operator as well and brackets to change the order of evaluation."},{"Start":"11:36.950 ","End":"11:38.435","Text":"Do have a play around with that."},{"Start":"11:38.435 ","End":"11:41.030","Text":"I\u0027ll show you an example of what I mean."},{"Start":"11:41.030 ","End":"11:45.825","Text":"For example, I could put a not around the whole thing."},{"Start":"11:45.825 ","End":"11:47.595","Text":"Brackets, first of all,"},{"Start":"11:47.595 ","End":"11:49.680","Text":"all of this will be evaluated."},{"Start":"11:49.680 ","End":"11:51.485","Text":"Whatever the result is."},{"Start":"11:51.485 ","End":"11:54.800","Text":"I will flip the results to the opposite."},{"Start":"11:54.800 ","End":"11:57.065","Text":"You see I was getting true before."},{"Start":"11:57.065 ","End":"11:59.735","Text":"It should flip back to false and it has."},{"Start":"11:59.735 ","End":"12:02.615","Text":"By taking the not out again,"},{"Start":"12:02.615 ","End":"12:04.760","Text":"you\u0027ll see it goes back to true."},{"Start":"12:04.760 ","End":"12:12.045","Text":"Note, the logical not operation just flips the output to the opposite Boolean value."},{"Start":"12:12.045 ","End":"12:13.670","Text":"The brackets, as you see,"},{"Start":"12:13.670 ","End":"12:15.545","Text":"it\u0027s evaluating this whole thing."},{"Start":"12:15.545 ","End":"12:18.335","Text":"Here is one. You can use that in any way you want."},{"Start":"12:18.335 ","End":"12:21.200","Text":"I can have another set of brackets inside the brackets if I wanted to,"},{"Start":"12:21.200 ","End":"12:23.690","Text":"it wouldn\u0027t make any difference in this particular example."},{"Start":"12:23.690 ","End":"12:28.205","Text":"But do have a play around with that and see the effect of brackets"},{"Start":"12:28.205 ","End":"12:33.350","Text":"on the way that things will be evaluated in a logical comparison."},{"Start":"12:33.350 ","End":"12:35.270","Text":"That\u0027s great. In these questions,"},{"Start":"12:35.270 ","End":"12:37.850","Text":"we\u0027ve looked at the logical operators,"},{"Start":"12:37.850 ","End":"12:40.350","Text":"the basic ones were and and or,"},{"Start":"12:40.350 ","End":"12:42.860","Text":"and then we also have not and we also looked at"},{"Start":"12:42.860 ","End":"12:46.475","Text":"the comparison and relational operators of equal to,"},{"Start":"12:46.475 ","End":"12:49.340","Text":"not equal to, greater than, less than,"},{"Start":"12:49.340 ","End":"12:53.690","Text":"and then greater than or equals to and less than or equal to."},{"Start":"12:53.690 ","End":"12:57.600","Text":"I\u0027ll see you in the next exercise."}],"ID":27354},{"Watched":false,"Name":"Exercise 6","Duration":"2m 6s","ChapterTopicVideoID":26445,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:04.770","Text":"Welcome. In this exercise we\u0027re going to explore the bitwise operators."},{"Start":"00:04.770 ","End":"00:06.540","Text":"In the code pad, as usual,"},{"Start":"00:06.540 ","End":"00:12.465","Text":"we\u0027re going to create a variable using the byte datatype and assign it the value 65."},{"Start":"00:12.465 ","End":"00:13.890","Text":"Then n part b,"},{"Start":"00:13.890 ","End":"00:17.895","Text":"we\u0027re going to perform a bitwise and operation on the variable."},{"Start":"00:17.895 ","End":"00:21.675","Text":"We\u0027re going to use this binary value to do that bitwise."},{"Start":"00:21.675 ","End":"00:26.690","Text":"In part c, we\u0027re asked to explain why you get the resulting value."},{"Start":"00:26.690 ","End":"00:32.525","Text":"In part d, we\u0027re asked to perform a bitwise or operation on the variable,"},{"Start":"00:32.525 ","End":"00:35.990","Text":"but this time using the decimal value 32."},{"Start":"00:35.990 ","End":"00:39.590","Text":"Then again to explain why we get this new value."},{"Start":"00:39.590 ","End":"00:43.970","Text":"In part f, we assign the value 17 to the byte variable,"},{"Start":"00:43.970 ","End":"00:47.450","Text":"then perform a bitwise exclusive or"},{"Start":"00:47.450 ","End":"00:51.920","Text":"operation on the variable using this binary value here."},{"Start":"00:51.920 ","End":"00:55.490","Text":"Once again, we\u0027re asked to explain the resulting evaluation."},{"Start":"00:55.490 ","End":"01:00.065","Text":"Then finally, we assign the value 1 to the byte variable,"},{"Start":"01:00.065 ","End":"01:03.950","Text":"and then perform a complement operation on the variable,"},{"Start":"01:03.950 ","End":"01:08.840","Text":"and we\u0027re asked to explain the value that we get and we\u0027re given a little hint."},{"Start":"01:08.840 ","End":"01:16.730","Text":"We\u0027ll start by creating the variable as he\u0027s asked us in part a. Typing the datatype,"},{"Start":"01:16.730 ","End":"01:18.500","Text":"give it a name,"},{"Start":"01:18.500 ","End":"01:24.340","Text":"and then assign the value 65 as it\u0027s asks us to complete that with a semicolon."},{"Start":"01:24.340 ","End":"01:28.070","Text":"Now in part b, we\u0027ve been asked to perform a bitwise and"},{"Start":"01:28.070 ","End":"01:32.225","Text":"operation on the variable using the given value."},{"Start":"01:32.225 ","End":"01:39.710","Text":"A variable name comes first the bitwise and operation is a single ampersand symbol."},{"Start":"01:39.710 ","End":"01:44.430","Text":"The value we\u0027ve been asked to and width is 0b01000000."},{"Start":"01:46.850 ","End":"01:49.715","Text":"Lets go and see what that does."},{"Start":"01:49.715 ","End":"01:53.135","Text":"The value we get back is 64."},{"Start":"01:53.135 ","End":"01:56.510","Text":"As we know with an and we have to have a"},{"Start":"01:56.510 ","End":"02:01.909","Text":"1 in both bytes in order to get a 1 at the output."},{"Start":"02:01.909 ","End":"02:04.640","Text":"Maybe it\u0027s easier to see this if we have two literals."},{"Start":"02:04.640 ","End":"02:10.745","Text":"If I put 0b01000000 as we\u0027ve started with,"},{"Start":"02:10.745 ","End":"02:15.770","Text":"and the value that we\u0027re ending with is 65,"},{"Start":"02:15.770 ","End":"02:19.255","Text":"which is actually a same bit pattern,"},{"Start":"02:19.255 ","End":"02:21.500","Text":"but with a 1 at the end."},{"Start":"02:21.500 ","End":"02:23.150","Text":"If we add those together,"},{"Start":"02:23.150 ","End":"02:26.570","Text":"we should get the same results, and we do."},{"Start":"02:26.570 ","End":"02:31.250","Text":"It\u0027s much easier to see obviously with the binary representation because"},{"Start":"02:31.250 ","End":"02:36.730","Text":"65 here has a 1 and 64 only has a 1."},{"Start":"02:36.730 ","End":"02:39.470","Text":"Therefore, the output is also going to be"},{"Start":"02:39.470 ","End":"02:42.730","Text":"64 because the only places where there are 2 1s,"},{"Start":"02:42.730 ","End":"02:45.465","Text":"are these 2 bit positions here."},{"Start":"02:45.465 ","End":"02:49.550","Text":"That explains and the value we get from parts a and b,"},{"Start":"02:49.550 ","End":"02:51.545","Text":"so part c is done."},{"Start":"02:51.545 ","End":"02:54.260","Text":"Now we are asked to perform a bitwise or"},{"Start":"02:54.260 ","End":"02:57.470","Text":"operation on the same variable with the same content Susan,"},{"Start":"02:57.470 ","End":"02:59.455","Text":"the decimal value 32."},{"Start":"02:59.455 ","End":"03:03.280","Text":"This just involves us using again a variable name,"},{"Start":"03:03.280 ","End":"03:09.395","Text":"and this time the bitwise or operation is the vertical bar or pipe character,"},{"Start":"03:09.395 ","End":"03:11.120","Text":"and only one of those is needed."},{"Start":"03:11.120 ","End":"03:13.385","Text":"A logical order would have two of them"},{"Start":"03:13.385 ","End":"03:16.930","Text":"because this is a bit wise or we only need one of them."},{"Start":"03:16.930 ","End":"03:19.850","Text":"Then we\u0027ve been asked to use the value 32."},{"Start":"03:19.850 ","End":"03:22.475","Text":"What\u0027s the value we get back?"},{"Start":"03:22.475 ","End":"03:25.760","Text":"We get 97 this time."},{"Start":"03:25.760 ","End":"03:31.940","Text":"Let\u0027s try and explain that value is it\u0027s asked us to in part e. Well,"},{"Start":"03:31.940 ","End":"03:34.700","Text":"if we do the same thing again and go from"},{"Start":"03:34.700 ","End":"03:38.345","Text":"the binary versions and the binary representations."},{"Start":"03:38.345 ","End":"03:43.460","Text":"We know already that 65 is 0b01000001"},{"Start":"03:43.460 ","End":"03:50.590","Text":", so that\u0027s 65."},{"Start":"03:50.590 ","End":"03:56.090","Text":"If we do a bit wise or with 32 is represented"},{"Start":"03:56.090 ","End":"04:01.545","Text":"by 0b00100000,or the first bit there will be 1 to 8,"},{"Start":"04:01.545 ","End":"04:04.995","Text":"then 64, then 32 there."},{"Start":"04:04.995 ","End":"04:08.685","Text":"Then all the other 4 bits will be 0s."},{"Start":"04:08.685 ","End":"04:12.570","Text":"Let\u0027s see what we get there and we do indeed get 97."},{"Start":"04:12.570 ","End":"04:16.865","Text":"We can see again more clearly when we do it with binary values"},{"Start":"04:16.865 ","End":"04:22.025","Text":"that the bitwise or will take each individual bit and,"},{"Start":"04:22.025 ","End":"04:26.010","Text":"or a bit in the respective position."},{"Start":"04:26.110 ","End":"04:31.715","Text":"Here, because we\u0027ve got an extra bit being set here,"},{"Start":"04:31.715 ","End":"04:35.410","Text":"the result will also have an extra bit set."},{"Start":"04:35.410 ","End":"04:37.115","Text":"It will be set here,"},{"Start":"04:37.115 ","End":"04:43.730","Text":"and the result. We\u0027ll have 01100001."},{"Start":"04:43.730 ","End":"04:49.805","Text":"If we want to prove that to send a look at the value of 97 in binary"},{"Start":"04:49.805 ","End":"04:58.590","Text":"should be 01100001 if we\u0027ve assumed,"},{"Start":"04:58.590 ","End":"04:59.910","Text":"right and it is."},{"Start":"04:59.910 ","End":"05:01.800","Text":"You can see that very clearly,"},{"Start":"05:01.800 ","End":"05:03.260","Text":"got a 1 set there,"},{"Start":"05:03.260 ","End":"05:05.540","Text":"but we\u0027ve also got at 1 set there,"},{"Start":"05:05.540 ","End":"05:08.195","Text":"which is what we see appearing here."},{"Start":"05:08.195 ","End":"05:13.520","Text":"The rest of it is all 0s apart from this bit here, which has a1."},{"Start":"05:13.520 ","End":"05:20.224","Text":"That explains part e. Moving on to part f,"},{"Start":"05:20.224 ","End":"05:23.675","Text":"we assign the value 17 to the variables."},{"Start":"05:23.675 ","End":"05:25.580","Text":"Let\u0027s go ahead and do that."},{"Start":"05:25.580 ","End":"05:28.280","Text":"Now we\u0027ve got 17 decimal in there."},{"Start":"05:28.280 ","End":"05:32.375","Text":"Now we\u0027ve been asked to perform a bitwise exclusive or"},{"Start":"05:32.375 ","End":"05:37.040","Text":"operation on that variable using a given binary value."},{"Start":"05:37.040 ","End":"05:42.425","Text":"Bitwise exclusive or we don\u0027t see a logical equivalent,"},{"Start":"05:42.425 ","End":"05:46.745","Text":"but that\u0027s the symbol for the operator to do a bitwise exclusive"},{"Start":"05:46.745 ","End":"05:51.230","Text":"or remember exclusive or means, not both bits."},{"Start":"05:51.230 ","End":"05:58.190","Text":"If 2 bits are set to operate in the 2 data items that were exclusive oriented together,"},{"Start":"05:58.190 ","End":"06:04.655","Text":"we ignore that bit once only one of them to have a 1 at the output."},{"Start":"06:04.655 ","End":"06:09.450","Text":"The value had been asked to put in 0b00010001."},{"Start":"06:12.670 ","End":"06:16.860","Text":"Let us see what result we get,"},{"Start":"06:16.860 ","End":"06:19.730","Text":"and 0 shortly, There we go."},{"Start":"06:19.730 ","End":"06:22.805","Text":"The result I get is 0."},{"Start":"06:22.805 ","End":"06:25.550","Text":"Now why do I get 0?"},{"Start":"06:25.550 ","End":"06:27.710","Text":"Well, the reason is,"},{"Start":"06:27.710 ","End":"06:31.025","Text":"if we were to put this again in binary,"},{"Start":"06:31.025 ","End":"06:35.435","Text":"actually what we\u0027ll find is the binary value that we were"},{"Start":"06:35.435 ","End":"06:40.655","Text":"oring with exclusive or in width is actually 17."},{"Start":"06:40.655 ","End":"06:46.010","Text":"We were doing 17 and exclusive oring with 17."},{"Start":"06:46.010 ","End":"06:54.229","Text":"Because both of these patterns have 1s in exactly the same place and nowhere else,"},{"Start":"06:54.229 ","End":"06:59.440","Text":"the result is going to be 0 and hopefully you can see that."},{"Start":"06:59.440 ","End":"07:04.700","Text":"Let\u0027s just prove that we\u0027ve got a 1 in this position and in"},{"Start":"07:04.700 ","End":"07:06.830","Text":"this position and we\u0027ve got a 1 in this position and"},{"Start":"07:06.830 ","End":"07:09.290","Text":"that position of course we have because they have the same number,"},{"Start":"07:09.290 ","End":"07:13.055","Text":"although we didn\u0027t make that obvious by putting it in decimal initially."},{"Start":"07:13.055 ","End":"07:18.440","Text":"The reason the output is 0 is because there is nowhere in either of these"},{"Start":"07:18.440 ","End":"07:23.810","Text":"2 where there is a 1 and it isn\u0027t already present in the other side."},{"Start":"07:23.810 ","End":"07:29.915","Text":"Hence, we get the result of 0 and that\u0027s why exclusive or is doing its job."},{"Start":"07:29.915 ","End":"07:32.359","Text":"It\u0027s only putting a 1 at the output."},{"Start":"07:32.359 ","End":"07:37.050","Text":"If the relative position doesn\u0027t have 2 1s."},{"Start":"07:37.050 ","End":"07:38.445","Text":"If there\u0027s a single 1,"},{"Start":"07:38.445 ","End":"07:40.245","Text":"then the output will have a 1."},{"Start":"07:40.245 ","End":"07:41.600","Text":"There\u0027s 2 0s,"},{"Start":"07:41.600 ","End":"07:43.535","Text":"then obviously it will have a 0 there."},{"Start":"07:43.535 ","End":"07:45.875","Text":"Let\u0027s do the last part,"},{"Start":"07:45.875 ","End":"07:53.535","Text":"which is part h. We\u0027ve been told to assign the value 1 to the variable,"},{"Start":"07:53.535 ","End":"07:56.075","Text":"and then to perform a complement."},{"Start":"07:56.075 ","End":"07:58.880","Text":"A complement operator is different than the one\u0027s we\u0027ve"},{"Start":"07:58.880 ","End":"08:01.805","Text":"just been using because it\u0027s what\u0027s called a unitary operator,"},{"Start":"08:01.805 ","End":"08:05.435","Text":"only needs 1 thing to operate on."},{"Start":"08:05.435 ","End":"08:09.650","Text":"The symbol itself is a tilde character."},{"Start":"08:09.650 ","End":"08:12.320","Text":"It\u0027s quite tricky to find on keyboards often,"},{"Start":"08:12.320 ","End":"08:16.250","Text":"minds next to the Enter key above the hash."},{"Start":"08:16.250 ","End":"08:18.035","Text":"It could be anywhere on your keyboard,"},{"Start":"08:18.035 ","End":"08:22.445","Text":"but it\u0027s usually in a fairly hard to find positions is not typed very often."},{"Start":"08:22.445 ","End":"08:26.540","Text":"That\u0027s the tilde character and that\u0027s what does the complement."},{"Start":"08:26.540 ","End":"08:29.300","Text":"We simply put the name of our variable and we\u0027ll"},{"Start":"08:29.300 ","End":"08:32.510","Text":"get a compliment of the value that\u0027s in the variable."},{"Start":"08:32.510 ","End":"08:34.265","Text":"I get -2,"},{"Start":"08:34.265 ","End":"08:36.575","Text":"now note I get int back."},{"Start":"08:36.575 ","End":"08:39.965","Text":"I really should be looking to get a bite back."},{"Start":"08:39.965 ","End":"08:42.920","Text":"I could do cast on this to see the result."},{"Start":"08:42.920 ","End":"08:46.880","Text":"But let\u0027s have a look at why it\u0027s -2. first of all,"},{"Start":"08:46.880 ","End":"08:49.940","Text":"because it\u0027s a signed number."},{"Start":"08:49.940 ","End":"08:53.930","Text":"If I were to do this as a byte literal,"},{"Start":"08:53.930 ","End":"08:59.610","Text":"I\u0027d get 1 is obviously all 0s in the upper level and"},{"Start":"08:59.610 ","End":"09:06.005","Text":"then 0001 that is 1 in binary."},{"Start":"09:06.005 ","End":"09:08.345","Text":"Now if I was to do a complement,"},{"Start":"09:08.345 ","End":"09:14.270","Text":"remember the complement turns every single bit to the opposite of what it currently is."},{"Start":"09:14.270 ","End":"09:21.895","Text":"All of these would be a 1 and this would be a 0."},{"Start":"09:21.895 ","End":"09:24.620","Text":"That\u0027s what the complement operation is doing."},{"Start":"09:24.620 ","End":"09:27.155","Text":"If you look at that again,"},{"Start":"09:27.155 ","End":"09:35.700","Text":"and if I actually type this out and flip it manually, 11111110."},{"Start":"09:35.810 ","End":"09:40.280","Text":"This is what the complemented version of that would look like."},{"Start":"09:40.280 ","End":"09:41.890","Text":"What\u0027s the value I get?"},{"Start":"09:41.890 ","End":"09:48.095","Text":"It\u0027s -2,and the only reason I\u0027m having to bite in front of it is when I put literals in,"},{"Start":"09:48.095 ","End":"09:51.020","Text":"in blue jay, it will assume they\u0027re integers always."},{"Start":"09:51.020 ","End":"09:53.990","Text":"A sign bit will be way over here"},{"Start":"09:53.990 ","End":"09:57.800","Text":"somewhere because it\u0027s a 32-bit number, obviously an integer."},{"Start":"09:57.800 ","End":"10:05.105","Text":"That\u0027s the explanation for part h. We get -2 because we\u0027ve complemented this pattern"},{"Start":"10:05.105 ","End":"10:08.750","Text":"when we\u0027re complimenting a bite that contains 1"},{"Start":"10:08.750 ","End":"10:12.455","Text":"and the complement will return this value here,"},{"Start":"10:12.455 ","End":"10:15.250","Text":"which I\u0027ve typed out as binary search easier for you to see,"},{"Start":"10:15.250 ","End":"10:16.880","Text":"and that binary value,"},{"Start":"10:16.880 ","End":"10:19.925","Text":"if it\u0027s a byte, is worth -2."},{"Start":"10:19.925 ","End":"10:23.580","Text":"That\u0027s it for this one. I\u0027ll see you in the next one."}],"ID":27355},{"Watched":false,"Name":"Exercise 7","Duration":"6m 1s","ChapterTopicVideoID":26446,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.910","Text":"Hi, again. In this video we\u0027re going to look at"},{"Start":"00:02.910 ","End":"00:05.550","Text":"the exercise in which we explore the increment,"},{"Start":"00:05.550 ","End":"00:08.880","Text":"decrement, and compound assignment operators."},{"Start":"00:08.880 ","End":"00:12.630","Text":"We have first been asked to create a variable of int datatype,"},{"Start":"00:12.630 ","End":"00:15.810","Text":"and to assign to it the initial value 10 decimal."},{"Start":"00:15.810 ","End":"00:20.070","Text":"In part a then, we\u0027re asked to use the post increment operator"},{"Start":"00:20.070 ","End":"00:23.910","Text":"on the variable and to not put a semicolon on the end of the line."},{"Start":"00:23.910 ","End":"00:26.160","Text":"In part b, we\u0027re asked the question,"},{"Start":"00:26.160 ","End":"00:31.290","Text":"why does that value reflected back by Bluej not appear to change?"},{"Start":"00:31.290 ","End":"00:33.450","Text":"Then we use in Part C,"},{"Start":"00:33.450 ","End":"00:36.615","Text":"the pre increment operator on the same variable."},{"Start":"00:36.615 ","End":"00:40.770","Text":"Once again, not to put a semicolon on the end of the line."},{"Start":"00:40.770 ","End":"00:42.500","Text":"In Part d,"},{"Start":"00:42.500 ","End":"00:47.990","Text":"we\u0027re asked what difference we observe between post and pre increment."},{"Start":"00:47.990 ","End":"00:50.330","Text":"Moving on to part e,"},{"Start":"00:50.330 ","End":"00:55.575","Text":"we are using now the pre decrement operator on the variable."},{"Start":"00:55.575 ","End":"01:00.110","Text":"In part f, we use the post decrement operator on the variable."},{"Start":"01:00.110 ","End":"01:03.980","Text":"Then, we use a compound assignment to multiply the variable"},{"Start":"01:03.980 ","End":"01:08.355","Text":"by 10 and store the result back into the variable."},{"Start":"01:08.355 ","End":"01:11.630","Text":"In part h, we use another compound assignment to"},{"Start":"01:11.630 ","End":"01:15.175","Text":"add 28 to the variable and store the result back in."},{"Start":"01:15.175 ","End":"01:17.260","Text":"Finally in part i,"},{"Start":"01:17.260 ","End":"01:25.150","Text":"we\u0027re asked to use a compound assignment to do a bitwise exclusive or with a value 129."},{"Start":"01:25.150 ","End":"01:30.875","Text":"We\u0027ve been first starts to create a variable of int datatype."},{"Start":"01:30.875 ","End":"01:33.870","Text":"Let\u0027s go ahead and do that."},{"Start":"01:34.460 ","End":"01:41.405","Text":"We are asked to give it the initial value of 10 in decimal."},{"Start":"01:41.405 ","End":"01:44.060","Text":"Then in part a, we\u0027re asked to use"},{"Start":"01:44.060 ","End":"01:46.320","Text":"the post increment operator on"},{"Start":"01:46.320 ","End":"01:49.505","Text":"the variable and to not put a semicolon on the end of the line."},{"Start":"01:49.505 ","End":"01:52.195","Text":"We get a value straight back."},{"Start":"01:52.195 ","End":"01:56.390","Text":"The increment and decrement operators are unitary."},{"Start":"01:56.390 ","End":"01:58.895","Text":"Once again, they only need one thing to operate on."},{"Start":"01:58.895 ","End":"02:01.160","Text":"If it\u0027s a post increment operator,"},{"Start":"02:01.160 ","End":"02:03.365","Text":"it follows the name of the variable."},{"Start":"02:03.365 ","End":"02:08.835","Text":"We\u0027ll put myVar, and then two pluses that will increment myVar by one."},{"Start":"02:08.835 ","End":"02:10.980","Text":"Let\u0027s see the value."},{"Start":"02:10.980 ","End":"02:14.205","Text":"Now, I had 10 in there originally."},{"Start":"02:14.205 ","End":"02:19.580","Text":"It does not seem to have changed as part b seems to suggest."},{"Start":"02:19.580 ","End":"02:23.400","Text":"It\u0027s asking, why it doesn\u0027t appear to change?"},{"Start":"02:23.400 ","End":"02:24.890","Text":"There is a clue there,"},{"Start":"02:24.890 ","End":"02:26.540","Text":"and it says appear to change."},{"Start":"02:26.540 ","End":"02:30.405","Text":"The value reflected back was 10."},{"Start":"02:30.405 ","End":"02:32.764","Text":"But what does myVar actually contain?"},{"Start":"02:32.764 ","End":"02:35.660","Text":"It actually contains 11."},{"Start":"02:35.660 ","End":"02:38.750","Text":"What we\u0027re seeing here is the difference between the post increment"},{"Start":"02:38.750 ","End":"02:42.215","Text":"and a pre increment when it\u0027s used in an expression."},{"Start":"02:42.215 ","End":"02:43.910","Text":"Although it doesn\u0027t look like it,"},{"Start":"02:43.910 ","End":"02:49.010","Text":"this is an expression and could be used in an expression if we wanted it to"},{"Start":"02:49.010 ","End":"02:54.950","Text":"but what it\u0027s doing is it\u0027s giving us the value back before it increments it."},{"Start":"02:54.950 ","End":"03:00.015","Text":"Hence, the name post increment because it will return a value."},{"Start":"03:00.015 ","End":"03:04.490","Text":"Then after post the return of the value, equal increment it."},{"Start":"03:04.490 ","End":"03:06.260","Text":"That\u0027s exactly what\u0027s happened here."},{"Start":"03:06.260 ","End":"03:07.595","Text":"We started with 10,"},{"Start":"03:07.595 ","End":"03:09.170","Text":"myVar had 10 in it,"},{"Start":"03:09.170 ","End":"03:11.975","Text":"and when we executed myVar plus, plus."},{"Start":"03:11.975 ","End":"03:16.325","Text":"It gave us back the value before the increment,"},{"Start":"03:16.325 ","End":"03:19.715","Text":"which we see here, but when we display the value,"},{"Start":"03:19.715 ","End":"03:23.820","Text":"we\u0027ve seen them, it\u0027s actually got 11 and then now."},{"Start":"03:23.820 ","End":"03:27.320","Text":"Let\u0027s see it should be fairly obvious what happens in part"},{"Start":"03:27.320 ","End":"03:32.030","Text":"c. Use the pre increment operator on the variable,"},{"Start":"03:32.030 ","End":"03:35.010","Text":"and don\u0027t put a semicolon on the end."},{"Start":"03:35.010 ","End":"03:36.829","Text":"We see the value back straightaway."},{"Start":"03:36.829 ","End":"03:39.170","Text":"If I do plus plus MyVar,"},{"Start":"03:39.170 ","End":"03:41.525","Text":"that\u0027s the pre increment."},{"Start":"03:41.525 ","End":"03:44.150","Text":"Increment because it\u0027s plus, double plus,"},{"Start":"03:44.150 ","End":"03:48.095","Text":"and pre because it comes before the variable name."},{"Start":"03:48.095 ","End":"03:52.850","Text":"It reflects back the value straight away in the expression."},{"Start":"03:52.850 ","End":"03:56.000","Text":"Obviously, there\u0027s no other parts to this expression here."},{"Start":"03:56.000 ","End":"04:00.250","Text":"But it\u0027s giving me the value back straightaway of the incremented value."},{"Start":"04:00.250 ","End":"04:03.845","Text":"It was 11, and it immediately gives me 12 back."},{"Start":"04:03.845 ","End":"04:07.340","Text":"It shows me the value 12,"},{"Start":"04:07.340 ","End":"04:11.495","Text":"and it\u0027s also got stored in it 12, you\u0027ll find there."},{"Start":"04:11.495 ","End":"04:17.145","Text":"You see the contrast now between the post increment and the pre increment."},{"Start":"04:17.145 ","End":"04:20.325","Text":"Basically, they both add 1 but 1,"},{"Start":"04:20.325 ","End":"04:25.130","Text":"if it\u0027s involved in expression will return the value before it\u0027s incremented."},{"Start":"04:25.130 ","End":"04:28.805","Text":"The other one will show you the increments straight away,"},{"Start":"04:28.805 ","End":"04:32.225","Text":"as we see in these examples here."},{"Start":"04:32.225 ","End":"04:40.010","Text":"That\u0027s us done from parts a to d. Now we\u0027ve been asked to use the pre decrement operator."},{"Start":"04:40.010 ","End":"04:43.560","Text":"Presumably, that is going to be straightforward,"},{"Start":"04:43.560 ","End":"04:45.165","Text":"and follow the same pattern."},{"Start":"04:45.165 ","End":"04:50.625","Text":"Pre decrement, decrement is minus minus."},{"Start":"04:50.625 ","End":"04:53.140","Text":"This is pre decrement."},{"Start":"04:53.140 ","End":"04:56.630","Text":"It\u0027s going to give me the value back straight away when I get it"},{"Start":"04:56.630 ","End":"05:00.285","Text":"reflected back because it\u0027s used in an expression here and it\u0027s 11."},{"Start":"05:00.285 ","End":"05:01.430","Text":"Which is what I expect,"},{"Start":"05:01.430 ","End":"05:04.605","Text":"and it will contain 11, which it does."},{"Start":"05:04.605 ","End":"05:08.840","Text":"Now I\u0027m asked to use the post decrement operator."},{"Start":"05:08.840 ","End":"05:14.360","Text":"With F^F, that\u0027ll be myVar minus, minus."},{"Start":"05:14.360 ","End":"05:16.760","Text":"What do you expect to happen here?"},{"Start":"05:16.760 ","End":"05:18.800","Text":"Because it\u0027s a post decrement,"},{"Start":"05:18.800 ","End":"05:22.310","Text":"we should see 11 reflected back because that\u0027s"},{"Start":"05:22.310 ","End":"05:26.600","Text":"the value that we expect before we take away 1."},{"Start":"05:26.600 ","End":"05:29.520","Text":"But it then should subsequently contain 10."},{"Start":"05:29.520 ","End":"05:32.790","Text":"We do indeed see 11 reflected back."},{"Start":"05:32.790 ","End":"05:35.040","Text":"If we look at myVar,"},{"Start":"05:35.040 ","End":"05:38.070","Text":"it does indeed contain 10."},{"Start":"05:38.070 ","End":"05:41.990","Text":"That\u0027s us done from parts a to f. Now"},{"Start":"05:41.990 ","End":"05:47.330","Text":"the last couple of parts to this exercise asks us to do some compound assignments."},{"Start":"05:47.330 ","End":"05:52.340","Text":"In part g says user compound assignment to multiply the variable by 10,"},{"Start":"05:52.340 ","End":"05:54.955","Text":"and store the result back into the variable."},{"Start":"05:54.955 ","End":"06:00.065","Text":"Well at compound assignment is a very lean syntax."},{"Start":"06:00.065 ","End":"06:03.200","Text":"What it will do is do some operation,"},{"Start":"06:03.200 ","End":"06:08.300","Text":"and store immediately back the value into the variable."},{"Start":"06:08.300 ","End":"06:14.215","Text":"What we want to do is say, myVar times equals 10."},{"Start":"06:14.215 ","End":"06:17.910","Text":"What we\u0027re saying, is multiplied by 10,"},{"Start":"06:17.910 ","End":"06:21.220","Text":"and store it back into myVar."},{"Start":"06:21.220 ","End":"06:29.470","Text":"We should see a 100 stored back into myVar if we\u0027ve got the syntax right, and we do."},{"Start":"06:29.470 ","End":"06:32.960","Text":"It\u0027s not just reflecting back the current value of myVar,"},{"Start":"06:32.960 ","End":"06:35.330","Text":"it\u0027s actually stored that in MyVar as well."},{"Start":"06:35.330 ","End":"06:37.055","Text":"Just to prove it, I\u0027ll do that."},{"Start":"06:37.055 ","End":"06:43.660","Text":"The expression results in 10 being multiplied by 10 because that\u0027s what myVar had in it,"},{"Start":"06:43.660 ","End":"06:45.590","Text":"and that\u0027s what we see reflected back here."},{"Start":"06:45.590 ","End":"06:51.650","Text":"But it also results in the assignment of a new value to myVar."},{"Start":"06:51.650 ","End":"06:54.320","Text":"We\u0027re doing two things that we\u0027re doing a multiplication,"},{"Start":"06:54.320 ","End":"06:57.635","Text":"and then we\u0027re storing it back into the original variables."},{"Start":"06:57.635 ","End":"07:01.880","Text":"The equivalent way of doing this in slightly longer syntax would"},{"Start":"07:01.880 ","End":"07:05.900","Text":"have been this myVar equals myVar times 10 would have"},{"Start":"07:05.900 ","End":"07:07.880","Text":"had exactly the same result but it\u0027s"},{"Start":"07:07.880 ","End":"07:13.985","Text":"a slightly more compact form to do it with the compound assignment."},{"Start":"07:13.985 ","End":"07:16.820","Text":"That\u0027s part g. Now it\u0027s saying use"},{"Start":"07:16.820 ","End":"07:21.035","Text":"a compound assignment to add 28 to the variable and store the results."},{"Start":"07:21.035 ","End":"07:22.760","Text":"That\u0027s exactly the same."},{"Start":"07:22.760 ","End":"07:25.655","Text":"We just obviously going to use a different symbol."},{"Start":"07:25.655 ","End":"07:27.950","Text":"A plus comes first,"},{"Start":"07:27.950 ","End":"07:31.520","Text":"then the equals, and then whatever the value is,"},{"Start":"07:31.520 ","End":"07:33.365","Text":"what we want to work with."},{"Start":"07:33.365 ","End":"07:39.080","Text":"It\u0027s added 28 to what was already in there and stored it back into myVar."},{"Start":"07:39.080 ","End":"07:43.815","Text":"Myvar contains 128, nice and easy."},{"Start":"07:43.815 ","End":"07:46.940","Text":"Then the last one is to use a compound assignment to do"},{"Start":"07:46.940 ","End":"07:50.315","Text":"a bitwise exclusive or with your variable,"},{"Start":"07:50.315 ","End":"07:51.668","Text":"and the value 1, 2,"},{"Start":"07:51.668 ","End":"07:53.880","Text":"9, install them only back."},{"Start":"07:53.880 ","End":"08:02.340","Text":"That is going to be myVar bitwise exclusive or is the current symbols,"},{"Start":"08:02.340 ","End":"08:05.734","Text":"is usually shift, and, followed by equals."},{"Start":"08:05.734 ","End":"08:06.980","Text":"We just did that on its own."},{"Start":"08:06.980 ","End":"08:11.015","Text":"It would do the bitwise exclusive or but it wouldn\u0027t store it back into myVar."},{"Start":"08:11.015 ","End":"08:15.485","Text":"We put the equals to store it back into myVar."},{"Start":"08:15.485 ","End":"08:18.432","Text":"Then we will use the value 1,"},{"Start":"08:18.432 ","End":"08:20.520","Text":"2, 9, and see what we get back."},{"Start":"08:20.520 ","End":"08:22.095","Text":"We get 1 back."},{"Start":"08:22.095 ","End":"08:25.725","Text":"Because remember the bitwise exclusive or,"},{"Start":"08:25.725 ","End":"08:29.415","Text":"doesn\u0027t want to see two 1s\u0027 in any bit position,"},{"Start":"08:29.415 ","End":"08:30.942","Text":"1, 2, 8, and 1, 2,"},{"Start":"08:30.942 ","End":"08:36.500","Text":"9 are exactly the same number with the least significant bit set in 1, 2, 9."},{"Start":"08:36.500 ","End":"08:39.845","Text":"It\u0027s the same as doing this, for example."},{"Start":"08:39.845 ","End":"08:42.105","Text":"This will be 1, 2, 8."},{"Start":"08:42.105 ","End":"08:46.220","Text":"If we do a bitwise exclusive or,"},{"Start":"08:46.220 ","End":"08:47.720","Text":"with 1, 2, 9,"},{"Start":"08:47.720 ","End":"08:50.705","Text":"it\u0027ll learn this. Hence, we get 1."},{"Start":"08:50.705 ","End":"08:54.749","Text":"Because we did an compound assignment,"},{"Start":"08:54.749 ","End":"08:56.940","Text":"that value in myVar will now be stored away."},{"Start":"08:56.940 ","End":"08:58.695","Text":"MyVar will contain 1."},{"Start":"08:58.695 ","End":"09:01.305","Text":"That\u0027s it for Exercise 7."},{"Start":"09:01.305 ","End":"09:03.940","Text":"I\u0027ll see you in the next one."}],"ID":27356},{"Watched":false,"Name":"Exercise 8","Duration":"4m 17s","ChapterTopicVideoID":26929,"CourseChapterTopicPlaylistID":246358,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.940","Text":"Hey, welcome back. In this final exercise,"},{"Start":"00:02.940 ","End":"00:05.340","Text":"we\u0027re going to move away from the code pad and"},{"Start":"00:05.340 ","End":"00:08.520","Text":"instead create a program in the BlueJ editor."},{"Start":"00:08.520 ","End":"00:12.090","Text":"We\u0027ve eventually been asked to create a class in this project that we\u0027ve already"},{"Start":"00:12.090 ","End":"00:15.480","Text":"been working in code MyTempConverterApp."},{"Start":"00:15.480 ","End":"00:19.740","Text":"Then in Part A to declare a variable of an appropriate type to hold"},{"Start":"00:19.740 ","End":"00:27.600","Text":"an input temperature and to give it an initial value of 37.77778."},{"Start":"00:27.600 ","End":"00:30.750","Text":"Then in Part B, to declare a variable of an appropriate type,"},{"Start":"00:30.750 ","End":"00:33.615","Text":"again, to hold an output temperature."},{"Start":"00:33.615 ","End":"00:38.770","Text":"Then in Part C, we\u0027re asked to create a method inside the class called Convert."},{"Start":"00:38.770 ","End":"00:41.660","Text":"Then in Part D, within the Convert method,"},{"Start":"00:41.660 ","End":"00:44.540","Text":"we are asked to add a line that uses whatever operators are"},{"Start":"00:44.540 ","End":"00:47.720","Text":"needed to convert the input temperature from"},{"Start":"00:47.720 ","End":"00:51.050","Text":"Celsius to Fahrenheit and to assign"},{"Start":"00:51.050 ","End":"00:54.855","Text":"the evaluated value to the output temperature variable."},{"Start":"00:54.855 ","End":"00:56.335","Text":"Then in Part E,"},{"Start":"00:56.335 ","End":"00:59.390","Text":"we\u0027re asked to add a second line in that method which will print"},{"Start":"00:59.390 ","End":"01:03.700","Text":"the output temperature to the screen using system out print line."},{"Start":"01:03.700 ","End":"01:06.830","Text":"Then in Part F, we are asked to compile the program and test"},{"Start":"01:06.830 ","End":"01:10.324","Text":"it correct any errors that have been signaled by the compiler."},{"Start":"01:10.324 ","End":"01:16.010","Text":"In Part G, create an object from the class to finally test the code and"},{"Start":"01:16.010 ","End":"01:22.375","Text":"run the Convert method in Part H and check that the result is a 100."},{"Start":"01:22.375 ","End":"01:28.265","Text":"The first thing we need to do is to create a class within our project."},{"Start":"01:28.265 ","End":"01:30.530","Text":"Up until now, we\u0027ve been using the codePad for everything."},{"Start":"01:30.530 ","End":"01:33.410","Text":"Generally, you would have a project which will contain"},{"Start":"01:33.410 ","End":"01:36.470","Text":"all your code and that will be made up of multiple classes,"},{"Start":"01:36.470 ","End":"01:38.720","Text":"which will appear here in this exercise."},{"Start":"01:38.720 ","End":"01:42.980","Text":"We only need 1 class and we\u0027ll do for many of the initial exercises."},{"Start":"01:42.980 ","End":"01:46.190","Text":"Let\u0027s go ahead and create the new class by clicking on the button"},{"Start":"01:46.190 ","End":"01:50.630","Text":"here and giving it the name we\u0027ve been asked to give,"},{"Start":"01:50.630 ","End":"01:58.235","Text":"which is MyTempConverterApp that we are given"},{"Start":"01:58.235 ","End":"02:02.750","Text":"the class and we will have code in which BlueJ just helpfully"},{"Start":"02:02.750 ","End":"02:07.545","Text":"puts in for you while I wanted to take it out just to make it clear what we\u0027re adding."},{"Start":"02:07.545 ","End":"02:11.405","Text":"We\u0027ll just keep the opening line and the braces."},{"Start":"02:11.405 ","End":"02:14.720","Text":"In Part A, we\u0027ve been asked to declare a variable of"},{"Start":"02:14.720 ","End":"02:19.100","Text":"an appropriate type to hold an input temperature and to give it an initial value."},{"Start":"02:19.100 ","End":"02:22.370","Text":"37 point several 7, and an 8."},{"Start":"02:22.370 ","End":"02:26.740","Text":"What would be an appropriate data type for this data?"},{"Start":"02:26.740 ","End":"02:29.255","Text":"Well, it\u0027s a real number,"},{"Start":"02:29.255 ","End":"02:31.625","Text":"so our choice is a float or a double."},{"Start":"02:31.625 ","End":"02:35.270","Text":"Double would probably be overkill for this number."},{"Start":"02:35.270 ","End":"02:37.940","Text":"There\u0027s not many digits in the decimal places,"},{"Start":"02:37.940 ","End":"02:40.560","Text":"so float will suffice."},{"Start":"02:40.560 ","End":"02:42.560","Text":"If we put the data type float,"},{"Start":"02:42.560 ","End":"02:47.225","Text":"give it a name I\u0027m going to call mine input t rather than writing out temperature."},{"Start":"02:47.225 ","End":"02:51.005","Text":"But I could write temperature or even temp perhaps would be a little bit better."},{"Start":"02:51.005 ","End":"02:52.910","Text":"Input temp for temperature."},{"Start":"02:52.910 ","End":"03:02.400","Text":"I\u0027ll give it an initial value 37.77778 and a semicolon."},{"Start":"03:02.400 ","End":"03:05.090","Text":"Then I\u0027ve been asked to declare in Part B"},{"Start":"03:05.090 ","End":"03:09.395","Text":"another variable to hold an output temperature again, of an appropriate type."},{"Start":"03:09.395 ","End":"03:11.180","Text":"Well, if the input was a float,"},{"Start":"03:11.180 ","End":"03:15.900","Text":"it would make sense for the output to be a float as well."},{"Start":"03:15.900 ","End":"03:19.415","Text":"I don\u0027t need to give it an initial value, haven\u0027t been asked to."},{"Start":"03:19.415 ","End":"03:22.280","Text":"I\u0027ll just end the line with a semicolon."},{"Start":"03:22.280 ","End":"03:23.510","Text":"We\u0027re on Part C now,"},{"Start":"03:23.510 ","End":"03:28.460","Text":"so we\u0027re asked to create a method inside the class called converts."},{"Start":"03:28.460 ","End":"03:31.085","Text":"Our method is where the code belongs."},{"Start":"03:31.085 ","End":"03:33.320","Text":"We saw when we did an initial exercise what"},{"Start":"03:33.320 ","End":"03:36.350","Text":"this looks like the structure of a Java program."},{"Start":"03:36.350 ","End":"03:39.065","Text":"Without going into too much detail,"},{"Start":"03:39.065 ","End":"03:43.625","Text":"you\u0027ll need to put in front of the name of the method a keyword void,"},{"Start":"03:43.625 ","End":"03:45.590","Text":"basically saying to the compiler,"},{"Start":"03:45.590 ","End":"03:48.350","Text":"don\u0027t expect anything to come back from this program."},{"Start":"03:48.350 ","End":"03:53.210","Text":"Then we put the name of the method and you put a pair of empty brackets for the moment."},{"Start":"03:53.210 ","End":"03:54.350","Text":"Later on in the course,"},{"Start":"03:54.350 ","End":"03:56.525","Text":"we\u0027ll find out what goes in those brackets."},{"Start":"03:56.525 ","End":"04:01.250","Text":"I\u0027ll close off my method with a closing brace here."},{"Start":"04:01.250 ","End":"04:06.380","Text":"It seems to be happy and you\u0027ll see in BlueJ highlights in yellow here,"},{"Start":"04:06.380 ","End":"04:11.275","Text":"to say that it\u0027s a method and the block is complete essentially."},{"Start":"04:11.275 ","End":"04:14.930","Text":"Code inside it should be indented it\u0027s good practice."},{"Start":"04:14.930 ","End":"04:17.120","Text":"It will still work if it doesn\u0027t but should"},{"Start":"04:17.120 ","End":"04:19.745","Text":"indent it just to make your code look a bit more readable."},{"Start":"04:19.745 ","End":"04:22.490","Text":"Now when I\u0027ve been asked to do in"},{"Start":"04:22.490 ","End":"04:27.020","Text":"Part D is to add a line that uses whatever operators are needed to"},{"Start":"04:27.020 ","End":"04:29.810","Text":"convert the imprint temperature from Celsius to"},{"Start":"04:29.810 ","End":"04:34.610","Text":"Fahrenheit and to assign the evaluated value to the output temperature value."},{"Start":"04:34.610 ","End":"04:41.300","Text":"Here I need to come up with a formula for this and we do a Google search for this."},{"Start":"04:41.300 ","End":"04:47.240","Text":"But what I\u0027m doing is I\u0027m trying to put a value into the output temp variable."},{"Start":"04:47.240 ","End":"04:50.675","Text":"That\u0027s where my expression will start output temp."},{"Start":"04:50.675 ","End":"04:52.805","Text":"Then the assignment operator,"},{"Start":"04:52.805 ","End":"04:55.700","Text":"because I want a value to go into output temp."},{"Start":"04:55.700 ","End":"04:59.960","Text":"Then the rest of the expression we\u0027ll do the calculation which calculates"},{"Start":"04:59.960 ","End":"05:07.130","Text":"a temperature in Fahrenheit when given a value in centigrade or degrees Celsius."},{"Start":"05:07.130 ","End":"05:09.050","Text":"If we have it,"},{"Start":"05:09.050 ","End":"05:12.515","Text":"the value that we want an input temp,"},{"Start":"05:12.515 ","End":"05:15.245","Text":"then that\u0027s how our expression is going to start off."},{"Start":"05:15.245 ","End":"05:19.355","Text":"If you were to look up what the conversion is,"},{"Start":"05:19.355 ","End":"05:21.710","Text":"do a web search for that."},{"Start":"05:21.710 ","End":"05:26.090","Text":"You\u0027ll find that the formula is the input temperature multiplied"},{"Start":"05:26.090 ","End":"05:31.775","Text":"by 9/5 and added to that should be 32,"},{"Start":"05:31.775 ","End":"05:33.935","Text":"and that should give you the results."},{"Start":"05:33.935 ","End":"05:37.550","Text":"Now, we won\u0027t get the correct result if we do"},{"Start":"05:37.550 ","End":"05:41.615","Text":"this and you might scratch your head and think of why wouldn\u0027t get the correct result."},{"Start":"05:41.615 ","End":"05:45.035","Text":"But actually, it comes down to this little bit here,"},{"Start":"05:45.035 ","End":"05:48.570","Text":"because this is a literal fraction"},{"Start":"05:48.570 ","End":"05:53.135","Text":"and by default what will happen is this will do an integer division."},{"Start":"05:53.135 ","End":"05:57.980","Text":"What you want to do is to force the compiler to consider this as a"},{"Start":"05:57.980 ","End":"06:03.110","Text":"fractional literal and it will work nicely."},{"Start":"06:03.110 ","End":"06:06.020","Text":"You could also work out what 9/5 is actually"},{"Start":"06:06.020 ","End":"06:10.895","Text":"1.8 and put 1.8 in there instead and that would do the job as well."},{"Start":"06:10.895 ","End":"06:12.110","Text":"If you don\u0027t do that,"},{"Start":"06:12.110 ","End":"06:16.385","Text":"you\u0027ll get an incorrect result and that will be the first little hurdle for you."},{"Start":"06:16.385 ","End":"06:21.890","Text":"Let\u0027s try and do the final part which says system out,"},{"Start":"06:21.890 ","End":"06:25.590","Text":"print line, and print the results basically."},{"Start":"06:25.590 ","End":"06:27.140","Text":"What is the result going to be?"},{"Start":"06:27.140 ","End":"06:29.975","Text":"Well, it\u0027s been stored into output temp."},{"Start":"06:29.975 ","End":"06:34.585","Text":"That is what we\u0027re looking to see."},{"Start":"06:34.585 ","End":"06:42.140","Text":"We\u0027ve done all the steps now from A to E. We probably written a few too many lines here."},{"Start":"06:42.140 ","End":"06:44.555","Text":"You should really, when you\u0027re writing a couple of lines,"},{"Start":"06:44.555 ","End":"06:47.555","Text":"test by compiling them as you\u0027re going along."},{"Start":"06:47.555 ","End":"06:49.130","Text":"If we click on compile here,"},{"Start":"06:49.130 ","End":"06:51.695","Text":"you\u0027ll see already it\u0027s found an error."},{"Start":"06:51.695 ","End":"06:55.930","Text":"Highlights in the margin here where the error is."},{"Start":"06:55.930 ","End":"06:57.350","Text":"If I click on the line,"},{"Start":"06:57.350 ","End":"07:02.539","Text":"it tells me incompatible types possible lossy conversion from double to float."},{"Start":"07:02.539 ","End":"07:04.160","Text":"What it\u0027s saying here is,"},{"Start":"07:04.160 ","End":"07:07.505","Text":"it\u0027s always assuming that if you put a fractional number,"},{"Start":"07:07.505 ","End":"07:10.820","Text":"that it\u0027s a double and it\u0027s trying to convert it from a"},{"Start":"07:10.820 ","End":"07:15.425","Text":"double to a float because it knows that that\u0027s what we want to put it into."},{"Start":"07:15.425 ","End":"07:18.020","Text":"We already saw this once before."},{"Start":"07:18.020 ","End":"07:22.820","Text":"We know that the trick here is just to put an f on the end to tell it that this"},{"Start":"07:22.820 ","End":"07:28.160","Text":"is a floating-point number and it should make the error go away."},{"Start":"07:28.160 ","End":"07:31.760","Text":"Let\u0027s compile and indeed the error does go away."},{"Start":"07:31.760 ","End":"07:35.675","Text":"We\u0027ve got a literal here which is assuming is a double."},{"Start":"07:35.675 ","End":"07:37.070","Text":"I\u0027m telling it no,"},{"Start":"07:37.070 ","End":"07:38.915","Text":"it\u0027s not double, it\u0027s a float."},{"Start":"07:38.915 ","End":"07:44.630","Text":"Therefore, I can assign it to a float without getting that warning error message."},{"Start":"07:44.630 ","End":"07:48.470","Text":"That now compiles with no syntax errors."},{"Start":"07:48.470 ","End":"07:52.715","Text":"What I\u0027m able to do now is I can close the editor."},{"Start":"07:52.715 ","End":"07:55.580","Text":"As it is asked me to do in"},{"Start":"07:55.580 ","End":"08:00.380","Text":"Part F while I\u0027ve actually compiled it and done Part F. Now I need to do Part G,"},{"Start":"08:00.380 ","End":"08:03.305","Text":"test it by creating an object from the class which you remember,"},{"Start":"08:03.305 ","End":"08:07.010","Text":"you right-click say new temperature converter app."},{"Start":"08:07.010 ","End":"08:10.340","Text":"It gives me a default name, I\u0027ll just accept."},{"Start":"08:10.340 ","End":"08:12.739","Text":"Then down here on the object workbench,"},{"Start":"08:12.739 ","End":"08:16.625","Text":"I\u0027ve got the object which I can run code on."},{"Start":"08:16.625 ","End":"08:22.940","Text":"I right-click now I select the name of the method that I wanted to run."},{"Start":"08:22.940 ","End":"08:25.130","Text":"I only have 1 method and it\u0027s called convert."},{"Start":"08:25.130 ","End":"08:31.305","Text":"I run it and it should print on the terminal the results and up pops my Terminal Window."},{"Start":"08:31.305 ","End":"08:34.385","Text":"The result is indeed what I was expecting,"},{"Start":"08:34.385 ","End":"08:36.410","Text":"which is a 100."},{"Start":"08:36.410 ","End":"08:39.290","Text":"Nice and simple program,"},{"Start":"08:39.290 ","End":"08:45.860","Text":"first useful program that we\u0027ve written really that converts a temperature from degrees"},{"Start":"08:45.860 ","End":"08:49.190","Text":"Celsius into Fahrenheit and displays the result on"},{"Start":"08:49.190 ","End":"08:53.540","Text":"the screen and only took a few lines of code to do that."},{"Start":"08:53.540 ","End":"08:56.675","Text":"But the key to it was this expression here,"},{"Start":"08:56.675 ","End":"09:04.415","Text":"which evaluated what this calculation is and then store the result into output temp,"},{"Start":"09:04.415 ","End":"09:07.400","Text":"which we then displayed on the screen."},{"Start":"09:07.400 ","End":"09:11.940","Text":"Thanks very much, and I\u0027ll see you in the next video."}],"ID":28022}],"Thumbnail":null,"ID":246358},{"Name":"Iterative Control Structures","TopicPlaylistFirstVideoID":0,"Duration":null,"Videos":[{"Watched":false,"Name":"For loop","Duration":"8m 41s","ChapterTopicVideoID":26440,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:03.570","Text":"Hello, welcome to the first of 2 videos where we look at"},{"Start":"00:03.570 ","End":"00:07.320","Text":"iterative structures available to programmers in high-level languages."},{"Start":"00:07.320 ","End":"00:08.700","Text":"By the end of this section,"},{"Start":"00:08.700 ","End":"00:13.065","Text":"you\u0027ll be able to contrast conditional control structures and iterative structures."},{"Start":"00:13.065 ","End":"00:16.395","Text":"Use a count terminated iterative structure."},{"Start":"00:16.395 ","End":"00:20.430","Text":"Use a condition terminated iterative structure and"},{"Start":"00:20.430 ","End":"00:25.140","Text":"select between top and bottom terminated iterative structures."},{"Start":"00:25.140 ","End":"00:26.970","Text":"In the previous topic, we saw"},{"Start":"00:26.970 ","End":"00:32.685","Text":"how conditional control structures allow us to execute or skip a block of instructions."},{"Start":"00:32.685 ","End":"00:36.735","Text":"Iteration is the repetitive execution"},{"Start":"00:36.735 ","End":"00:41.100","Text":"of a block of program statements until a termination condition is met."},{"Start":"00:41.100 ","End":"00:44.280","Text":"Rather than running or skipping a block code,"},{"Start":"00:44.280 ","End":"00:48.635","Text":"we\u0027re interested in repeatedly running all the instructions in the block."},{"Start":"00:48.635 ","End":"00:53.720","Text":"Instructions will continue to be carried out until some condition is no longer true."},{"Start":"00:53.720 ","End":"00:57.280","Text":"To understand iteration, let\u0027s look at a visual example."},{"Start":"00:57.280 ","End":"01:03.530","Text":"Let\u0027s say we\u0027re looking for a house on a street where the door numbers go from 1-100."},{"Start":"01:03.530 ","End":"01:09.140","Text":"We walk along the street starting from the door numbered 1 and inspect the number on each"},{"Start":"01:09.140 ","End":"01:15.050","Text":"in consecutive door until we reach the number we\u0027re looking for and then we stop."},{"Start":"01:15.050 ","End":"01:18.650","Text":"If we were looking for the house numbered 50, for example,"},{"Start":"01:18.650 ","End":"01:24.205","Text":"we\u0027d say we\u0027re iterating through the door numbers from 1-50."},{"Start":"01:24.205 ","End":"01:28.570","Text":"The operation we are performing is inspecting the door number."},{"Start":"01:28.570 ","End":"01:32.545","Text":"We do this repeatedly until we find the number we\u0027re interested in."},{"Start":"01:32.545 ","End":"01:34.390","Text":"Although in this example there was"},{"Start":"01:34.390 ","End":"01:37.735","Text":"only 1 single operation of inspecting the door number,"},{"Start":"01:37.735 ","End":"01:40.270","Text":"it could have involved several operations."},{"Start":"01:40.270 ","End":"01:45.100","Text":"For example, we may have been conducting a survey or doing some door-to-door selling."},{"Start":"01:45.100 ","End":"01:47.635","Text":"In that case, you might have knocked on the door,"},{"Start":"01:47.635 ","End":"01:52.255","Text":"awaited a response, and interacted with the person who opened the door."},{"Start":"01:52.255 ","End":"01:55.645","Text":"We then move on to the next door and repeat the same process."},{"Start":"01:55.645 ","End":"01:59.845","Text":"Carrying on until we visited every house in the street."},{"Start":"01:59.845 ","End":"02:03.640","Text":"Let\u0027s now compare conditional and iterative control structures"},{"Start":"02:03.640 ","End":"02:07.445","Text":"by looking at 2 fragments of different programs."},{"Start":"02:07.445 ","End":"02:09.000","Text":"On the first loop here,"},{"Start":"02:09.000 ","End":"02:11.645","Text":"the 2 flowchart fragments look quite similar."},{"Start":"02:11.645 ","End":"02:16.040","Text":"But there\u0027s an important difference you might grasp when thinking about it a little."},{"Start":"02:16.040 ","End":"02:19.805","Text":"Let\u0027s say the flowchart on the left represents a game."},{"Start":"02:19.805 ","End":"02:21.005","Text":"When the player is hit,"},{"Start":"02:21.005 ","End":"02:22.430","Text":"they lose a life."},{"Start":"02:22.430 ","End":"02:24.680","Text":"Whether the player is hit or not,"},{"Start":"02:24.680 ","End":"02:29.880","Text":"the movement is always in the direction down from A-C."},{"Start":"02:29.880 ","End":"02:32.950","Text":"It may go via point B,"},{"Start":"02:32.950 ","End":"02:35.090","Text":"if the player has been hit."},{"Start":"02:35.090 ","End":"02:38.885","Text":"But once the program flow has passed through the point A,"},{"Start":"02:38.885 ","End":"02:41.585","Text":"it doesn\u0027t return to point A."},{"Start":"02:41.585 ","End":"02:43.700","Text":"On the other flowchart."},{"Start":"02:43.700 ","End":"02:48.550","Text":"Points A and B are visited repeatedly."},{"Start":"02:48.550 ","End":"02:55.730","Text":"In fact, they keep on getting visited until door number 50 has been inspected and only"},{"Start":"02:55.730 ","End":"02:58.730","Text":"then does the program flow continue to"},{"Start":"02:58.730 ","End":"03:02.360","Text":"point C and onto the other instructions in the program."},{"Start":"03:02.360 ","End":"03:08.870","Text":"The program instructions run around and around in a loop here between A and B."},{"Start":"03:08.870 ","End":"03:11.390","Text":"In fact, this word loop is"},{"Start":"03:11.390 ","End":"03:17.255","Text":"the more informal term programmers use when referring to iterative control structures."},{"Start":"03:17.255 ","End":"03:19.340","Text":"A loop refers to a section of"},{"Start":"03:19.340 ","End":"03:23.225","Text":"a program that\u0027s being run repeatedly until it\u0027s terminated."},{"Start":"03:23.225 ","End":"03:26.240","Text":"With a conditional structure we saw earlier and we can see here"},{"Start":"03:26.240 ","End":"03:29.150","Text":"on the left, there\u0027s no repetition."},{"Start":"03:29.150 ","End":"03:32.460","Text":"Either 1 path is followed or the other."},{"Start":"03:32.460 ","End":"03:36.245","Text":"But previous instructions are not repeated."},{"Start":"03:36.245 ","End":"03:39.380","Text":"Most imperative high-level languages will have"},{"Start":"03:39.380 ","End":"03:42.785","Text":"a type of iterative control structure called a for loop."},{"Start":"03:42.785 ","End":"03:44.585","Text":"In its simplest form,"},{"Start":"03:44.585 ","End":"03:47.365","Text":"the for loop defines a block which is to be"},{"Start":"03:47.365 ","End":"03:52.625","Text":"repeated and repeatedly executes that block a certain number of times."},{"Start":"03:52.625 ","End":"03:56.780","Text":"How many times the loop runs and what range of values the variable takes"},{"Start":"03:56.780 ","End":"04:01.460","Text":"on is determined by the values given in the opening line."},{"Start":"04:01.460 ","End":"04:06.740","Text":"In addition, a variable takes on a value each time round the loop,"},{"Start":"04:06.740 ","End":"04:10.040","Text":"and that value is automatically updated without"},{"Start":"04:10.040 ","End":"04:13.525","Text":"any additional code being supplied by the programmer."},{"Start":"04:13.525 ","End":"04:18.960","Text":"Basic was a language used to teach beginners how to program in the 1960\u0027s onwards."},{"Start":"04:18.960 ","End":"04:23.410","Text":"For loops in basic are particularly easy to read for a beginner and so"},{"Start":"04:23.410 ","End":"04:28.225","Text":"we\u0027ll use an example in basic to understand the general operation of a for loop."},{"Start":"04:28.225 ","End":"04:31.405","Text":"After the initial keyword FOR,"},{"Start":"04:31.405 ","End":"04:34.960","Text":"we state the variable name being used in the loop."},{"Start":"04:34.960 ","End":"04:39.130","Text":"In this case, we\u0027ve called it num and it will start at the value"},{"Start":"04:39.130 ","End":"04:43.945","Text":"2 and will keep going until we get to 20,"},{"Start":"04:43.945 ","End":"04:47.215","Text":"but it will go up in steps of 2."},{"Start":"04:47.215 ","End":"04:53.350","Text":"Here we see the value of num when the program first enters the loop."},{"Start":"04:53.350 ","End":"04:55.650","Text":"Once the first line of code has been run,"},{"Start":"04:55.650 ","End":"04:59.405","Text":"the message output on the screen will be this."},{"Start":"04:59.405 ","End":"05:02.680","Text":"This line will generate this output."},{"Start":"05:02.680 ","End":"05:09.390","Text":"The next line then generates this output because the current value of num is 2."},{"Start":"05:09.390 ","End":"05:11.390","Text":"At the end of the code block,"},{"Start":"05:11.390 ","End":"05:16.220","Text":"num is automatically incremented by 2."},{"Start":"05:16.220 ","End":"05:22.805","Text":"As that was the step value we set in the opening line of the for loop statement."},{"Start":"05:22.805 ","End":"05:26.150","Text":"Then execution continues from the beginning of the loop"},{"Start":"05:26.150 ","End":"05:29.615","Text":"again and we see the new output on the screen."},{"Start":"05:29.615 ","End":"05:33.170","Text":"Once again, num is increased by 2,"},{"Start":"05:33.170 ","End":"05:38.510","Text":"and we go back to the beginning again and the block just keeps repeating and"},{"Start":"05:38.510 ","End":"05:45.280","Text":"outputs the new value of num increment by 2 again, and so on."},{"Start":"05:45.280 ","End":"05:51.345","Text":"Loop will now run 1 final time when num reaches 20."},{"Start":"05:51.345 ","End":"05:55.175","Text":"A final value of num is output to the screen"},{"Start":"05:55.175 ","End":"05:59.750","Text":"and it won\u0027t be increased anymore and execution will"},{"Start":"05:59.750 ","End":"06:04.790","Text":"continue past the next statement as the loops ended and"},{"Start":"06:04.790 ","End":"06:07.430","Text":"whatever instructions follow the loop will now be executed in"},{"Start":"06:07.430 ","End":"06:10.400","Text":"sequence or if there are no more instructions,"},{"Start":"06:10.400 ","End":"06:12.305","Text":"the program will end."},{"Start":"06:12.305 ","End":"06:16.070","Text":"The syntax for C-style languages including C++,"},{"Start":"06:16.070 ","End":"06:20.495","Text":"C Sharp and Java is a little more difficult to read,"},{"Start":"06:20.495 ","End":"06:23.390","Text":"but operates on exactly the same principles."},{"Start":"06:23.390 ","End":"06:27.120","Text":"We have to formally declare a variable for use in the for"},{"Start":"06:27.120 ","End":"06:31.010","Text":"loop and we can initialize it with initial value here."},{"Start":"06:31.010 ","End":"06:33.275","Text":"Then follows a semicolon,"},{"Start":"06:33.275 ","End":"06:35.780","Text":"and then the termination condition."},{"Start":"06:35.780 ","End":"06:37.970","Text":"In other words, when will the loop stop?"},{"Start":"06:37.970 ","End":"06:43.460","Text":"In this case, when num is no longer less than or equal to 20."},{"Start":"06:43.460 ","End":"06:46.170","Text":"Finally, after another semicolon,"},{"Start":"06:46.170 ","End":"06:50.015","Text":"we have the part where the variable is being incremented."},{"Start":"06:50.015 ","End":"06:54.080","Text":"The opening brace or curly bracket marks where"},{"Start":"06:54.080 ","End":"06:58.715","Text":"the block starts and there\u0027s no next command as there is with basic,"},{"Start":"06:58.715 ","End":"07:02.360","Text":"the closing curly bracket here does the job of"},{"Start":"07:02.360 ","End":"07:06.725","Text":"next in marking the end of the block of instructions that repeat."},{"Start":"07:06.725 ","End":"07:12.320","Text":"The syntax for Java is identical to C. The only difference being"},{"Start":"07:12.320 ","End":"07:19.414","Text":"the output line here being different for Java than C otherwise it\u0027s identical."},{"Start":"07:19.414 ","End":"07:21.020","Text":"Syntax for Python,"},{"Start":"07:21.020 ","End":"07:23.030","Text":"however, is a little different."},{"Start":"07:23.030 ","End":"07:28.520","Text":"We still give the name of the variable which takes on the successive values in the loop."},{"Start":"07:28.520 ","End":"07:34.270","Text":"But in Python, we create a set of numbers to iterate through using range."},{"Start":"07:34.270 ","End":"07:42.535","Text":"In this case, going from 2 to 22 in steps of 2. Why 22?"},{"Start":"07:42.535 ","End":"07:46.480","Text":"Well, Python differs from the other high-level languages in that it goes up to,"},{"Start":"07:46.480 ","End":"07:49.480","Text":"but not including the upper limit."},{"Start":"07:49.480 ","End":"07:56.905","Text":"If we had put 20 num would\u0027ve taken on values 2 up to 18, but not 20."},{"Start":"07:56.905 ","End":"08:00.535","Text":"Hence the 22, which also could have been 21."},{"Start":"08:00.535 ","End":"08:07.720","Text":"The start of the block here is marked with a colon and an indentation is used"},{"Start":"08:07.720 ","End":"08:15.020","Text":"to mark where the loop is and marks out the block and when there is no more indentation,"},{"Start":"08:15.020 ","End":"08:16.925","Text":"that would be the end of the block."},{"Start":"08:16.925 ","End":"08:21.020","Text":"So slightly different syntax for Python based on the fact that there are"},{"Start":"08:21.020 ","End":"08:25.730","Text":"no braces and the opening line is also quite different too."},{"Start":"08:25.730 ","End":"08:31.325","Text":"That\u0027s it for the first video where we looked at for loops which are count-controlled."},{"Start":"08:31.325 ","End":"08:34.925","Text":"In the next video, we\u0027ll look at condition-controlled loops,"},{"Start":"08:34.925 ","End":"08:39.080","Text":"which gives us a little bit more flexibility than a for loop."},{"Start":"08:39.080 ","End":"08:42.600","Text":"I\u0027ll see you then. Thank you."}],"ID":27347},{"Watched":false,"Name":"While loop","Duration":"5m ","ChapterTopicVideoID":26441,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:05.815","Text":"Hey everyone, welcome back to the second video on iterative control structures."},{"Start":"00:05.815 ","End":"00:09.940","Text":"Previously we learned that this type of structure allows us to repeatedly"},{"Start":"00:09.940 ","End":"00:14.770","Text":"execute a block of code until some sort of termination condition is met."},{"Start":"00:14.770 ","End":"00:18.759","Text":"The informal word we use to describe each iteration was loop."},{"Start":"00:18.759 ","End":"00:22.390","Text":"The first specific structure we encountered was the for loop."},{"Start":"00:22.390 ","End":"00:27.130","Text":"That\u0027s useful in situations when there are fixed number of iterations to be completed,"},{"Start":"00:27.130 ","End":"00:31.525","Text":"and when that number is known at the time that the loop starts, executing."},{"Start":"00:31.525 ","End":"00:35.500","Text":"Loop terminates as a result of the terminal value being reached."},{"Start":"00:35.500 ","End":"00:40.210","Text":"In this example, if we know that there are 50 doors we need to inspect,"},{"Start":"00:40.210 ","End":"00:42.930","Text":"the loop will terminate after 50."},{"Start":"00:42.930 ","End":"00:47.525","Text":"A more flexible type of loop involves a condition being satisfied."},{"Start":"00:47.525 ","End":"00:50.510","Text":"Rather than repeating a fixed number of times"},{"Start":"00:50.510 ","End":"00:53.930","Text":"the block will be repeated while some condition is true."},{"Start":"00:53.930 ","End":"00:57.080","Text":"Unsurprisingly, this is called a while loop."},{"Start":"00:57.080 ","End":"00:59.929","Text":"It involves our friend, the Boolean expression,"},{"Start":"00:59.929 ","End":"01:04.070","Text":"some condition or conditions that evaluate to a Boolean."},{"Start":"01:04.070 ","End":"01:09.710","Text":"On first look, it seems almost identical to an F structure with the keyword while,"},{"Start":"01:09.710 ","End":"01:11.480","Text":"replacing the keyword, if."},{"Start":"01:11.480 ","End":"01:17.030","Text":"But the difference is that if will either skip the block or run it once,"},{"Start":"01:17.030 ","End":"01:20.600","Text":"whereas while will repeatedly runs the statements in"},{"Start":"01:20.600 ","End":"01:25.085","Text":"the block until the Boolean expression evaluates to false."},{"Start":"01:25.085 ","End":"01:29.330","Text":"Let us look at an example in Java which would be very similar in"},{"Start":"01:29.330 ","End":"01:33.830","Text":"c. The Boolean expression being evaluated here is very simple."},{"Start":"01:33.830 ","End":"01:40.055","Text":"Is the number stored in the variable num less than 13."},{"Start":"01:40.055 ","End":"01:44.570","Text":"As we set the initial value of the num variable to 1,"},{"Start":"01:44.570 ","End":"01:48.530","Text":"we know that the expression will evaluate to 2, first-time round."},{"Start":"01:48.530 ","End":"01:51.925","Text":"Therefore the code inside this block will run."},{"Start":"01:51.925 ","End":"01:56.750","Text":"The first line of the 7 times table is therefore output here."},{"Start":"01:56.750 ","End":"01:58.670","Text":"Then on the next line,"},{"Start":"01:58.670 ","End":"02:00.305","Text":"we increment num,"},{"Start":"02:00.305 ","End":"02:02.705","Text":"so now contains 2."},{"Start":"02:02.705 ","End":"02:06.005","Text":"Execution will now continue from the top of the loop again,"},{"Start":"02:06.005 ","End":"02:08.705","Text":"just as we saw with a for loop previously."},{"Start":"02:08.705 ","End":"02:11.405","Text":"The Boolean evaluation happens again,"},{"Start":"02:11.405 ","End":"02:13.640","Text":"and num is still less than 13,"},{"Start":"02:13.640 ","End":"02:17.075","Text":"so the code inside the block will run again,"},{"Start":"02:17.075 ","End":"02:21.605","Text":"printing the second line of the 7 times table."},{"Start":"02:21.605 ","End":"02:24.395","Text":"Then num will be incremented again,"},{"Start":"02:24.395 ","End":"02:26.735","Text":"and now is 3."},{"Start":"02:26.735 ","End":"02:31.729","Text":"This continues on for as long as num is less than 13."},{"Start":"02:31.729 ","End":"02:35.460","Text":"Eventually, we will reach 12."},{"Start":"02:35.460 ","End":"02:37.820","Text":"Once num hits 13,"},{"Start":"02:37.820 ","End":"02:39.335","Text":"which it has done now,"},{"Start":"02:39.335 ","End":"02:47.300","Text":"the termination codons kicks in as num is now no longer less than 13, it\u0027s equal to 13."},{"Start":"02:47.300 ","End":"02:53.165","Text":"Execution will continue on from the line after the end of the while block."},{"Start":"02:53.165 ","End":"02:58.355","Text":"The syntax of Python admits only the curly brackets as usual,"},{"Start":"02:58.355 ","End":"03:01.115","Text":"and it starts with a colon."},{"Start":"03:01.115 ","End":"03:03.680","Text":"The block is repeated."},{"Start":"03:03.680 ","End":"03:07.475","Text":"The part that\u0027s indented is repeated as before."},{"Start":"03:07.475 ","End":"03:09.335","Text":"The principle is exactly the same."},{"Start":"03:09.335 ","End":"03:12.050","Text":"A Boolean condition is evaluated at the top."},{"Start":"03:12.050 ","End":"03:17.785","Text":"While it\u0027s true, the lines inside the block will keep on executing."},{"Start":"03:17.785 ","End":"03:20.780","Text":"Now, this 7 times table example doesn\u0027t seem"},{"Start":"03:20.780 ","End":"03:23.660","Text":"too different from the for loop example we looked at earlier."},{"Start":"03:23.660 ","End":"03:27.979","Text":"In fact, we could have achieved the same outcome using a for loop."},{"Start":"03:27.979 ","End":"03:30.415","Text":"Let\u0027s look at a different example."},{"Start":"03:30.415 ","End":"03:36.050","Text":"Here, we\u0027re using a flag variable to control when the loop terminates,"},{"Start":"03:36.050 ","End":"03:38.060","Text":"we came across a flag variable earlier."},{"Start":"03:38.060 ","End":"03:40.160","Text":"They used a signal that something has happened in"},{"Start":"03:40.160 ","End":"03:43.790","Text":"the program and can only contain the value true or false."},{"Start":"03:43.790 ","End":"03:48.410","Text":"This loop will continue executing the lines in green until"},{"Start":"03:48.410 ","End":"03:53.720","Text":"the flag variable found changes from false to true."},{"Start":"03:53.720 ","End":"03:59.930","Text":"We can see that this particular line here is where it changes from false,"},{"Start":"03:59.930 ","End":"04:04.480","Text":"which was set up with initially when the program started to true."},{"Start":"04:04.480 ","End":"04:10.100","Text":"We can see that found is only under very specific circumstances when"},{"Start":"04:10.100 ","End":"04:17.270","Text":"the variable multiple divided by the variable num2 gives a remainder of 0,"},{"Start":"04:17.270 ","End":"04:21.800","Text":"because the variable multiples being updated here inside the loop,"},{"Start":"04:21.800 ","End":"04:28.040","Text":"we have to calculate the remainder of multiple divided by num2 inside the loop as well."},{"Start":"04:28.040 ","End":"04:32.120","Text":"Then we use that to signal when the loop should end."},{"Start":"04:32.120 ","End":"04:37.025","Text":"The check to see whether the loop should run again is at the top in a while loop."},{"Start":"04:37.025 ","End":"04:39.140","Text":"Each time one iteration is completed,"},{"Start":"04:39.140 ","End":"04:43.840","Text":"we go back to the top again to see whether the code inside the block should run again."},{"Start":"04:43.840 ","End":"04:47.660","Text":"This type of loops therefore sometimes called a top terminated"},{"Start":"04:47.660 ","End":"04:51.980","Text":"loop because the termination check is happening at the top."},{"Start":"04:51.980 ","End":"04:54.560","Text":"We\u0027ll pause there and in the next video,"},{"Start":"04:54.560 ","End":"04:57.530","Text":"we\u0027ll have a look at variation on the while loop"},{"Start":"04:57.530 ","End":"05:01.500","Text":"called a do-while loop. I\u0027ll see you then."}],"ID":27348},{"Watched":false,"Name":"Do While loop","Duration":"6m 5s","ChapterTopicVideoID":26442,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.640","Text":"Hello again everyone. Welcome back to"},{"Start":"00:02.640 ","End":"00:06.180","Text":"this third video in a sequence of videos on iteration."},{"Start":"00:06.180 ","End":"00:07.560","Text":"In the previous video,"},{"Start":"00:07.560 ","End":"00:10.950","Text":"we looked at the while loop and iteration structure that involves"},{"Start":"00:10.950 ","End":"00:15.405","Text":"a conditional evaluation at the top of a block of code to be repeated,"},{"Start":"00:15.405 ","End":"00:19.245","Text":"and this type of loop is therefore called a top terminated loop."},{"Start":"00:19.245 ","End":"00:23.595","Text":"Looking at the earlier example of the 7 times table program,"},{"Start":"00:23.595 ","End":"00:25.365","Text":"it\u0027s easy to see why."},{"Start":"00:25.365 ","End":"00:31.185","Text":"The decision to continue or terminate the loop is made at the top here."},{"Start":"00:31.185 ","End":"00:36.080","Text":"As soon as num is no longer less than 13,"},{"Start":"00:36.080 ","End":"00:38.309","Text":"the loop will terminate."},{"Start":"00:38.309 ","End":"00:41.540","Text":"While num is less than 13,"},{"Start":"00:41.540 ","End":"00:48.245","Text":"execution will continue from point A to point B and back again."},{"Start":"00:48.245 ","End":"00:53.705","Text":"An alternative is where the termination check happens at the bottom of the loop."},{"Start":"00:53.705 ","End":"00:57.290","Text":"This example shows a typical keyboard-driven program"},{"Start":"00:57.290 ","End":"01:00.320","Text":"where a user enters a single letter as an option,"},{"Start":"01:00.320 ","End":"01:01.970","Text":"A, B, C,"},{"Start":"01:01.970 ","End":"01:05.225","Text":"or whatever, and that triggers some action."},{"Start":"01:05.225 ","End":"01:08.815","Text":"Option q would quit the program."},{"Start":"01:08.815 ","End":"01:12.470","Text":"We see that on entry to the loop at point A,"},{"Start":"01:12.470 ","End":"01:17.225","Text":"the variable k stores whatever key was typed at the keyboard."},{"Start":"01:17.225 ","End":"01:21.350","Text":"Then code within the symbol labeled menu is"},{"Start":"01:21.350 ","End":"01:25.385","Text":"executed and some action is performed depending on what key was pressed,"},{"Start":"01:25.385 ","End":"01:28.370","Text":"and then the check at the bottom here determines"},{"Start":"01:28.370 ","End":"01:31.490","Text":"whether the loop will continue back to point A or not."},{"Start":"01:31.490 ","End":"01:34.745","Text":"In this example, it will keep looping back,"},{"Start":"01:34.745 ","End":"01:40.385","Text":"while k is not equal to the lowercase letter q."},{"Start":"01:40.385 ","End":"01:47.400","Text":"While it\u0027s not, it will loop back to A as soon as it does contain q,"},{"Start":"01:47.400 ","End":"01:51.740","Text":"it will exit at point C. In C and Java,"},{"Start":"01:51.740 ","End":"01:57.515","Text":"this bottom terminated loop is called a do while loop or sometimes just a do loop."},{"Start":"01:57.515 ","End":"02:01.955","Text":"You can see here the program we wrote earlier for the 7 times table,"},{"Start":"02:01.955 ","End":"02:06.935","Text":"using while is almost identical when using do while,"},{"Start":"02:06.935 ","End":"02:11.870","Text":"which is the opening and closing lines changing."},{"Start":"02:11.870 ","End":"02:15.500","Text":"Note that there needs to be a semicolon here,"},{"Start":"02:15.500 ","End":"02:19.265","Text":"after the while, or you\u0027ll get an error when compiling."},{"Start":"02:19.265 ","End":"02:24.770","Text":"You recall we said earlier that lines in C or Java always end in a semicolon or"},{"Start":"02:24.770 ","End":"02:28.220","Text":"curly bracket as this block is being"},{"Start":"02:28.220 ","End":"02:32.810","Text":"repeatedly executed and it\u0027s before the while statement."},{"Start":"02:32.810 ","End":"02:36.485","Text":"There are no curly brackets after the Boolean condition,"},{"Start":"02:36.485 ","End":"02:40.670","Text":"so we need this semicolon to end the line."},{"Start":"02:40.670 ","End":"02:43.280","Text":"Looking at the example from the flowchart earlier,"},{"Start":"02:43.280 ","End":"02:45.125","Text":"here\u0027s the code in C,"},{"Start":"02:45.125 ","End":"02:51.004","Text":"which will take an input character from the keyboard and then simply"},{"Start":"02:51.004 ","End":"02:54.215","Text":"output the same character to the screen rather than doing anything"},{"Start":"02:54.215 ","End":"02:57.890","Text":"useful like running a particular manual operation."},{"Start":"02:57.890 ","End":"03:00.320","Text":"We\u0027ve done that just to keep the code simple."},{"Start":"03:00.320 ","End":"03:06.360","Text":"It will keep doing this for any key except for lowercase q."},{"Start":"03:06.360 ","End":"03:08.705","Text":"If lowercase q is entered,"},{"Start":"03:08.705 ","End":"03:10.565","Text":"the loop terminates,"},{"Start":"03:10.565 ","End":"03:12.870","Text":"and the program ends."},{"Start":"03:12.870 ","End":"03:18.080","Text":"do while is useful in cases where the loop will always run at least once."},{"Start":"03:18.080 ","End":"03:22.550","Text":"Here we want to read the key from the keyboard to know what to do."},{"Start":"03:22.550 ","End":"03:27.380","Text":"The code to read the input key may as well be inside the loop."},{"Start":"03:27.380 ","End":"03:31.100","Text":"Every time around the loop we want to get a different input to allow the user of"},{"Start":"03:31.100 ","End":"03:35.960","Text":"the program to enter another option of the available options A,"},{"Start":"03:35.960 ","End":"03:37.490","Text":"B, C, D, or whatever."},{"Start":"03:37.490 ","End":"03:40.655","Text":"Contrast this with the top terminated loop,"},{"Start":"03:40.655 ","End":"03:44.000","Text":"which checks the condition before going into"},{"Start":"03:44.000 ","End":"03:48.680","Text":"the loop and could potentially not execute the code inside the loop at all."},{"Start":"03:48.680 ","End":"03:52.730","Text":"We need to have an extra line to read the key before we even"},{"Start":"03:52.730 ","End":"03:57.425","Text":"get to the loop so that we can compare it to lowercase q."},{"Start":"03:57.425 ","End":"04:00.020","Text":"We\u0027ve also had to reorganize the lines"},{"Start":"04:00.020 ","End":"04:03.979","Text":"inside the loop so the character is displayed first,"},{"Start":"04:03.979 ","End":"04:09.020","Text":"and the key is read again on the second line inside the block."},{"Start":"04:09.020 ","End":"04:13.085","Text":"As you can see here, they are in a different order in the do while loop."},{"Start":"04:13.085 ","End":"04:15.425","Text":"Python doesn\u0027t have a do while loop,"},{"Start":"04:15.425 ","End":"04:20.240","Text":"and you can achieve a similar effect using if and break statements,"},{"Start":"04:20.240 ","End":"04:23.450","Text":"but this is not considered a good programming practice."},{"Start":"04:23.450 ","End":"04:26.450","Text":"You can do pretty much anything you need to with a while loop,"},{"Start":"04:26.450 ","End":"04:30.125","Text":"but there may be a few more lines needed as we\u0027ve seen here,"},{"Start":"04:30.125 ","End":"04:37.490","Text":"and depending on the situation it might not read as elegantly as a do while loop."},{"Start":"04:37.490 ","End":"04:41.535","Text":"Finally, it\u0027s possible to create a loop that never ends."},{"Start":"04:41.535 ","End":"04:44.285","Text":"We call this an infinite loop."},{"Start":"04:44.285 ","End":"04:51.470","Text":"In this example, the Boolean expression being evaluated is simply the keyword true,"},{"Start":"04:51.470 ","End":"04:53.540","Text":"which will always evaluate to true."},{"Start":"04:53.540 ","End":"04:56.660","Text":"Therefore, a termination condition is never going to be"},{"Start":"04:56.660 ","End":"04:59.990","Text":"met and this loop will continue forever."},{"Start":"04:59.990 ","End":"05:02.510","Text":"You might ask, why would you ever want to do this?"},{"Start":"05:02.510 ","End":"05:04.712","Text":"But it is actually surprisingly common."},{"Start":"05:04.712 ","End":"05:09.170","Text":"A software that\u0027s written for hardware that doesn\u0027t ever stop, for example,"},{"Start":"05:09.170 ","End":"05:13.879","Text":"monitoring systems such as an alarm system or a temperature control,"},{"Start":"05:13.879 ","End":"05:16.070","Text":"they won\u0027t ever need to quit."},{"Start":"05:16.070 ","End":"05:17.510","Text":"If you want it to stop,"},{"Start":"05:17.510 ","End":"05:22.115","Text":"you simply power down the hardware that your software is running on."},{"Start":"05:22.115 ","End":"05:24.770","Text":"However, it\u0027s also possible to accidentally create"},{"Start":"05:24.770 ","End":"05:27.829","Text":"an infinite loop biological error in a program."},{"Start":"05:27.829 ","End":"05:32.195","Text":"It\u0027s a programmer\u0027s responsibility to look at and test their code"},{"Start":"05:32.195 ","End":"05:35.390","Text":"carefully to make sure that it\u0027s possible for the"},{"Start":"05:35.390 ","End":"05:38.990","Text":"termination condition in any loops to be met."},{"Start":"05:38.990 ","End":"05:40.865","Text":"That\u0027s it for this topic."},{"Start":"05:40.865 ","End":"05:43.940","Text":"In this section, we learned how to contrast"},{"Start":"05:43.940 ","End":"05:47.405","Text":"conditional control structures and iterative structures,"},{"Start":"05:47.405 ","End":"05:50.420","Text":"how to use a count terminated iterative structure,"},{"Start":"05:50.420 ","End":"05:54.420","Text":"how to use a condition terminated iterative structure,"},{"Start":"05:54.420 ","End":"06:00.620","Text":"and to select between top and bottom terminated iterative structures."},{"Start":"06:00.620 ","End":"06:05.430","Text":"Thank you very much, and I\u0027ll see you for the next one."}],"ID":27349},{"Watched":false,"Name":"Exercise 1","Duration":"5m 28s","ChapterTopicVideoID":26936,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:04.665","Text":"Hi. In this first exercise we\u0027ve been asked to create a new project in BlueJ,"},{"Start":"00:04.665 ","End":"00:07.560","Text":"and a new class inside it called IterationApp."},{"Start":"00:07.560 ","End":"00:12.460","Text":"In part a, we are then asked to create a new method called forCountUp()."},{"Start":"00:12.460 ","End":"00:17.250","Text":"In part b, to use a for-loop to output the numbers from 1-10."},{"Start":"00:17.250 ","End":"00:21.705","Text":"In part c, we\u0027re asked to create another method called forCountDown(),"},{"Start":"00:21.705 ","End":"00:25.320","Text":"and then in part d to use a for-loop this time to"},{"Start":"00:25.320 ","End":"00:28.875","Text":"output the numbers from 5-1, ending on 1."},{"Start":"00:28.875 ","End":"00:30.750","Text":"Finally, in part e,"},{"Start":"00:30.750 ","End":"00:33.420","Text":"we\u0027re asked to test both methods by creating"},{"Start":"00:33.420 ","End":"00:37.635","Text":"an object on the workbench and to correct any errors found."},{"Start":"00:37.635 ","End":"00:41.330","Text":"The first thing we need to do is to create the project,"},{"Start":"00:41.330 ","End":"00:45.380","Text":"so I\u0027ll go ahead and call mine Topic6."},{"Start":"00:45.380 ","End":"00:47.944","Text":"Then within the project,"},{"Start":"00:47.944 ","End":"00:56.128","Text":"we need to create a new class and we\u0027ve been asked to call that class IterationApp,"},{"Start":"00:56.128 ","End":"01:02.400","Text":"and then within there for part a I need to create a method called countUp."},{"Start":"01:02.800 ","End":"01:09.310","Text":"I\u0027ll remove the initial code from the class that BlueJ has created for me,"},{"Start":"01:09.310 ","End":"01:13.135","Text":"and I\u0027ll create my method called countUp()."},{"Start":"01:13.135 ","End":"01:15.244","Text":"That\u0027s the beginning,"},{"Start":"01:15.244 ","End":"01:17.570","Text":"and what I now need to do is to create"},{"Start":"01:17.570 ","End":"01:23.235","Text":"my for-loop to output the numbers from 1-10 in part b."},{"Start":"01:23.235 ","End":"01:25.323","Text":"For is the keyword."},{"Start":"01:25.323 ","End":"01:27.285","Text":"I need to round brackets,"},{"Start":"01:27.285 ","End":"01:30.035","Text":"and then I start with the initial value."},{"Start":"01:30.035 ","End":"01:32.060","Text":"Because I don\u0027t have a variable yet,"},{"Start":"01:32.060 ","End":"01:36.050","Text":"I can declare a variable inside the for-loop so for int"},{"Start":"01:36.050 ","End":"01:41.180","Text":"i and start with the initial value of 1 and then a semicolon."},{"Start":"01:41.180 ","End":"01:43.250","Text":"The next part is the termination clause."},{"Start":"01:43.250 ","End":"01:45.170","Text":"When does the loop stop?"},{"Start":"01:45.170 ","End":"01:49.445","Text":"In my case it\u0027s when I get to beyond 10."},{"Start":"01:49.445 ","End":"01:55.150","Text":"I\u0027m going to say int i equals 1;"},{"Start":"01:55.150 ","End":"01:58.345","Text":"i is less than or equal to 10."},{"Start":"01:58.345 ","End":"02:03.410","Text":"I could make that less than 11 if I prefer and have the same effect,"},{"Start":"02:03.410 ","End":"02:07.265","Text":"but I think this will do me and it\u0027s reasonably readable."},{"Start":"02:07.265 ","End":"02:10.430","Text":"It\u0027s clear that I\u0027m going between 1 and 10."},{"Start":"02:10.430 ","End":"02:14.045","Text":"Then the last part is what do I increment i by?"},{"Start":"02:14.045 ","End":"02:16.460","Text":"I want to increment by one each time around the loop,"},{"Start":"02:16.460 ","End":"02:19.340","Text":"so the best thing for me to do is to just use the increment operator"},{"Start":"02:19.340 ","End":"02:22.630","Text":"there and that will increment by 1."},{"Start":"02:22.630 ","End":"02:26.630","Text":"Now, whatever I put between the curly brackets here will"},{"Start":"02:26.630 ","End":"02:30.479","Text":"be the part that\u0027s going to be repeatedly run,"},{"Start":"02:30.479 ","End":"02:34.580","Text":"and I just want a single line inside my loop that outputs"},{"Start":"02:34.580 ","End":"02:39.500","Text":"the current value of the i variable."},{"Start":"02:39.500 ","End":"02:47.810","Text":"This should put out the numbers 1-10 each on a separate line if that works successfully."},{"Start":"02:47.810 ","End":"02:50.015","Text":"That\u0027s countUp() down,"},{"Start":"02:50.015 ","End":"02:53.180","Text":"and I\u0027ll just check that it compiles without any errors before I move"},{"Start":"02:53.180 ","End":"02:56.480","Text":"on because I\u0027m not going to test it yet and that seems to be fine."},{"Start":"02:56.480 ","End":"03:01.744","Text":"I can now do the second part of part c of this exercise,"},{"Start":"03:01.744 ","End":"03:04.129","Text":"so it\u0027s called forCountDown(),"},{"Start":"03:04.129 ","End":"03:06.570","Text":"another method I\u0027ve been asked to create."},{"Start":"03:06.570 ","End":"03:10.160","Text":"I could\u0027ve done it in the previous one, but that\u0027s fine."},{"Start":"03:10.160 ","End":"03:14.780","Text":"I can do in separate methods just for ease of testing I guess."},{"Start":"03:14.780 ","End":"03:18.710","Text":"Now this one we have to go from 5-1,"},{"Start":"03:18.710 ","End":"03:20.765","Text":"so I need 2."},{"Start":"03:20.765 ","End":"03:23.180","Text":"Interestingly, I could have a variable"},{"Start":"03:23.180 ","End":"03:27.305","Text":"declared up here which both methods would have available."},{"Start":"03:27.305 ","End":"03:29.060","Text":"If I\u0027m going to declare a variable in"},{"Start":"03:29.060 ","End":"03:31.565","Text":"one method it\u0027s not accessible in the other method,"},{"Start":"03:31.565 ","End":"03:33.335","Text":"so I have to declare it again."},{"Start":"03:33.335 ","End":"03:37.125","Text":"I\u0027m going to do that here. I\u0027ll call it i again and they\u0027ll be completely separate."},{"Start":"03:37.125 ","End":"03:39.995","Text":"They are independent of each other because they\u0027re in different methods,"},{"Start":"03:39.995 ","End":"03:44.450","Text":"and I\u0027m going to start this time at 5."},{"Start":"03:44.450 ","End":"03:50.450","Text":"The termination clause is to say is it greater than or equal to 0?"},{"Start":"03:50.450 ","End":"03:52.730","Text":"I could say greater than minus 1,"},{"Start":"03:52.730 ","End":"03:56.720","Text":"but I\u0027m sure you\u0027ll agree that\u0027s a bit more readable to say greater than or equal to 0."},{"Start":"03:56.720 ","End":"03:59.330","Text":"This time instead of incrementing i,"},{"Start":"03:59.330 ","End":"04:01.850","Text":"I\u0027m going to decrement it."},{"Start":"04:01.850 ","End":"04:06.620","Text":"Meaning, I\u0027m going to take 1 off the value of i each time around the loop."},{"Start":"04:06.620 ","End":"04:10.280","Text":"The rest is the same as what we had previously,"},{"Start":"04:10.280 ","End":"04:13.745","Text":"so I might as well just copy that line rather than type it out."},{"Start":"04:13.745 ","End":"04:20.040","Text":"In this one, it should print out the numbers from 5-0."},{"Start":"04:20.040 ","End":"04:22.690","Text":"In fact actually I have been asked to end on 1,"},{"Start":"04:22.690 ","End":"04:24.850","Text":"so it doesn\u0027t need to be greater than 0."},{"Start":"04:24.850 ","End":"04:27.490","Text":"It needs to be greater than or equal to 1."},{"Start":"04:27.490 ","End":"04:31.195","Text":"If I had done greater than 0 that would have worked as well,"},{"Start":"04:31.195 ","End":"04:34.240","Text":"but not greater than or equal to 0 because that would have"},{"Start":"04:34.240 ","End":"04:38.515","Text":"printed the number 0 and I wasn\u0027t asked to do that in the exercise."},{"Start":"04:38.515 ","End":"04:40.120","Text":"Let\u0027s compile that."},{"Start":"04:40.120 ","End":"04:41.570","Text":"There are no errors,"},{"Start":"04:41.570 ","End":"04:45.100","Text":"and let\u0027s see if it generates the output that I\u0027m expecting."},{"Start":"04:45.100 ","End":"04:50.470","Text":"I\u0027ll run first of all countUp() and I expect the numbers to go from 1-10, and they do."},{"Start":"04:50.470 ","End":"04:51.910","Text":"There we go, 1-10."},{"Start":"04:51.910 ","End":"04:54.925","Text":"Let\u0027s try countDown() and see what that does."},{"Start":"04:54.925 ","End":"04:58.235","Text":"CountDown, then I\u0027m going to just test,"},{"Start":"04:58.235 ","End":"05:04.610","Text":"and that does generate the numbers from 5-1 as I would expect."},{"Start":"05:04.610 ","End":"05:09.109","Text":"If you have had different output from your test methods,"},{"Start":"05:09.109 ","End":"05:15.319","Text":"you probably want to check this little clause here and here for the correct values."},{"Start":"05:15.319 ","End":"05:18.505","Text":"For example you might have put 0 there as I initially did,"},{"Start":"05:18.505 ","End":"05:19.780","Text":"and you would count from"},{"Start":"05:19.780 ","End":"05:25.065","Text":"5-0 rather than 5-1 which is what we were asked to do in the question."},{"Start":"05:25.065 ","End":"05:26.955","Text":"That\u0027s it for this exercise,"},{"Start":"05:26.955 ","End":"05:29.140","Text":"I\u0027ll see you for the next one."}],"ID":28024},{"Watched":false,"Name":"Exercise 2","Duration":"3m 39s","ChapterTopicVideoID":26937,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:04.410","Text":"Hello, again. In this exercise we\u0027ve been asked in the same class as previously to"},{"Start":"00:04.410 ","End":"00:09.225","Text":"create a new method in part a called forCountIn2s."},{"Start":"00:09.225 ","End":"00:16.290","Text":"Then in part b, to use a for-loop to output the numbers from 2-24 in steps of 2."},{"Start":"00:16.290 ","End":"00:21.320","Text":"In part c, we\u0027re asked to create a new method called forCountIn10s."},{"Start":"00:21.320 ","End":"00:23.810","Text":"Then in part d, inside that method,"},{"Start":"00:23.810 ","End":"00:30.500","Text":"we\u0027re asked to use a for-loop to output numbers from 100 to 0 in steps of minus 10."},{"Start":"00:30.500 ","End":"00:32.180","Text":"Finally, in part e,"},{"Start":"00:32.180 ","End":"00:35.060","Text":"we\u0027re asked to test both methods by creating"},{"Start":"00:35.060 ","End":"00:39.005","Text":"an object on the workbench and to correct any errors found."},{"Start":"00:39.005 ","End":"00:42.110","Text":"Now, we\u0027ve been asked to add a new method"},{"Start":"00:42.110 ","End":"00:45.050","Text":"in the same class as previously Iteration app,"},{"Start":"00:45.050 ","End":"00:48.575","Text":"and call this method CountIn2s."},{"Start":"00:48.575 ","End":"00:50.345","Text":"Let\u0027s go ahead and do that."},{"Start":"00:50.345 ","End":"00:52.370","Text":"After the previous method,"},{"Start":"00:52.370 ","End":"00:54.110","Text":"I can create a new one."},{"Start":"00:54.110 ","End":"00:57.245","Text":"I\u0027m going to call it forCountIn2s."},{"Start":"00:57.245 ","End":"01:01.265","Text":"Of course, I could have created it before the previous method if I wanted to."},{"Start":"01:01.265 ","End":"01:03.560","Text":"Wouldn\u0027t make any difference."},{"Start":"01:03.560 ","End":"01:06.695","Text":"There we go for the opening line."},{"Start":"01:06.695 ","End":"01:13.595","Text":"What we need to do is use steps of 2 to output the numbers from 2-24."},{"Start":"01:13.595 ","End":"01:17.510","Text":"What I\u0027m going to do is I\u0027m just going to copy what I had up here,"},{"Start":"01:17.510 ","End":"01:19.430","Text":"save myself some typing,"},{"Start":"01:19.430 ","End":"01:20.990","Text":"and put it down here."},{"Start":"01:20.990 ","End":"01:24.200","Text":"Because this variable is in a different method,"},{"Start":"01:24.200 ","End":"01:25.610","Text":"I do need to declare it, again,"},{"Start":"01:25.610 ","End":"01:27.410","Text":"even though it\u0027s in the same class,"},{"Start":"01:27.410 ","End":"01:30.736","Text":"I have to declare my variables inside the methods,"},{"Start":"01:30.736 ","End":"01:32.059","Text":"unless I put them up here,"},{"Start":"01:32.059 ","End":"01:36.245","Text":"and then the variables will be available to all the methods in the class."},{"Start":"01:36.245 ","End":"01:38.510","Text":"But I\u0027ll just do it again in here."},{"Start":"01:38.510 ","End":"01:42.710","Text":"What I\u0027ve got to do now is start at 2,"},{"Start":"01:42.710 ","End":"01:45.650","Text":"and I want to go up to 24."},{"Start":"01:45.650 ","End":"01:47.780","Text":"But because I want to go in steps of 2,"},{"Start":"01:47.780 ","End":"01:49.580","Text":"I can\u0027t use the increment operator."},{"Start":"01:49.580 ","End":"01:52.505","Text":"I have to say i equals i plus 2."},{"Start":"01:52.505 ","End":"01:53.900","Text":"It\u0027s as simple as that."},{"Start":"01:53.900 ","End":"01:56.360","Text":"That will do what I\u0027ve been asked to do,"},{"Start":"01:56.360 ","End":"01:57.890","Text":"which is to go from 2-24."},{"Start":"01:57.890 ","End":"02:00.245","Text":"We\u0027ll see that in a moment when we test it."},{"Start":"02:00.245 ","End":"02:01.850","Text":"In part c,"},{"Start":"02:01.850 ","End":"02:07.595","Text":"I need to create another method called CountIn10s."},{"Start":"02:07.595 ","End":"02:11.383","Text":"What I\u0027ll do for that is I\u0027ll copy this,"},{"Start":"02:11.383 ","End":"02:14.600","Text":"and paste it below and just change the name."},{"Start":"02:14.600 ","End":"02:16.550","Text":"You\u0027ll see it\u0027s giving me an error message here because I\u0027ve"},{"Start":"02:16.550 ","End":"02:18.965","Text":"already got a method called CountIn2s."},{"Start":"02:18.965 ","End":"02:21.450","Text":"Let\u0027s change it to CountIn10s."},{"Start":"02:22.390 ","End":"02:27.440","Text":"We, obviously, want to go from 100,"},{"Start":"02:27.440 ","End":"02:31.145","Text":"as that\u0027s what the question asked for, to 0."},{"Start":"02:31.145 ","End":"02:33.050","Text":"This has got to be different."},{"Start":"02:33.050 ","End":"02:34.546","Text":"So I\u0027m going to say,"},{"Start":"02:34.546 ","End":"02:36.680","Text":"greater than or equal to 0,"},{"Start":"02:36.680 ","End":"02:39.230","Text":"or I could say greater than minus 1 if I wanted to,"},{"Start":"02:39.230 ","End":"02:41.895","Text":"but I would say this reads probably a little bit better."},{"Start":"02:41.895 ","End":"02:48.270","Text":"What we\u0027re doing to i is we\u0027re changing it by 10 each time around the loop."},{"Start":"02:48.270 ","End":"02:50.590","Text":"So we\u0027ve got to say i equals i minus 10."},{"Start":"02:52.190 ","End":"02:56.340","Text":"Let\u0027s have a go at running that."},{"Start":"02:56.340 ","End":"02:58.515","Text":"Now is when I compile it."},{"Start":"02:58.515 ","End":"03:04.920","Text":"Let\u0027s see if I get the output that I\u0027m expecting for CountIn2s,"},{"Start":"03:04.920 ","End":"03:07.730","Text":"I get 2 up to 24,"},{"Start":"03:07.730 ","End":"03:09.680","Text":"which is exactly what I expect."},{"Start":"03:09.680 ","End":"03:11.975","Text":"Then for CountIn10s,"},{"Start":"03:11.975 ","End":"03:16.070","Text":"I get 100 down to 0,"},{"Start":"03:16.070 ","End":"03:17.514","Text":"which is, again,"},{"Start":"03:17.514 ","End":"03:18.950","Text":"exactly what I expect."},{"Start":"03:18.950 ","End":"03:21.575","Text":"Once again, if you\u0027ve got an error,"},{"Start":"03:21.575 ","End":"03:26.785","Text":"check whether you\u0027ve got the right conditionals in the middle of these 2 statements,"},{"Start":"03:26.785 ","End":"03:29.690","Text":"and you\u0027ll probably find that that does what you want."},{"Start":"03:29.690 ","End":"03:35.232","Text":"That\u0027s it for simple for-loops in first 2 exercises."},{"Start":"03:35.232 ","End":"03:36.620","Text":"So we\u0027ll move on to something a little bit more"},{"Start":"03:36.620 ","End":"03:39.870","Text":"useful in the next exercise, and I\u0027ll see you then."}],"ID":28025},{"Watched":false,"Name":"Exercise 3","Duration":"6m 7s","ChapterTopicVideoID":26938,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.460","Text":"Hi everyone. In this exercise,"},{"Start":"00:02.460 ","End":"00:05.640","Text":"we\u0027ve been asked to create a new method called sevenTimesTable,"},{"Start":"00:05.640 ","End":"00:08.640","Text":"and then within there to create an integer variable called"},{"Start":"00:08.640 ","End":"00:11.730","Text":"table and to initialize it with the value 7."},{"Start":"00:11.730 ","End":"00:16.035","Text":"Then a second integer variable called multiplier with no initial value."},{"Start":"00:16.035 ","End":"00:19.260","Text":"In part b, we\u0027re asked to use a for loop to iterate"},{"Start":"00:19.260 ","End":"00:23.190","Text":"the multiplier variable through the numbers 1-12."},{"Start":"00:23.190 ","End":"00:26.370","Text":"In part c, we\u0027re asked inside the for loop"},{"Start":"00:26.370 ","End":"00:29.610","Text":"to output the contents of the multiplier variable,"},{"Start":"00:29.610 ","End":"00:32.235","Text":"followed by the string x,"},{"Start":"00:32.235 ","End":"00:35.880","Text":"followed by the contents of the table variable,"},{"Start":"00:35.880 ","End":"00:38.505","Text":"followed by the string equals."},{"Start":"00:38.505 ","End":"00:41.750","Text":"In part d, we\u0027re asked on the same line as the previous output to"},{"Start":"00:41.750 ","End":"00:45.760","Text":"output the product of the multiplier and table variables."},{"Start":"00:45.760 ","End":"00:47.440","Text":"Then finally in part e,"},{"Start":"00:47.440 ","End":"00:50.923","Text":"we are asked to test the method by creating an object on the workbench,"},{"Start":"00:50.923 ","End":"00:56.015","Text":"checking that all 12 lines of the sevenTimesTable are correctly output,"},{"Start":"00:56.015 ","End":"00:59.170","Text":"and to correct any errors if found."},{"Start":"00:59.170 ","End":"01:07.055","Text":"Let\u0027s then create a new method called sevenTimesTables inside existing class."},{"Start":"01:07.055 ","End":"01:10.355","Text":"Let\u0027s do that."},{"Start":"01:10.355 ","End":"01:15.080","Text":"The first part is asking us to create an integer variable called table and to"},{"Start":"01:15.080 ","End":"01:21.495","Text":"initialize it with the value 7, and that\u0027s done."},{"Start":"01:21.495 ","End":"01:24.385","Text":"Then a second multiplier,"},{"Start":"01:24.385 ","End":"01:27.910","Text":"a variable called multiplier with no initial values."},{"Start":"01:27.910 ","End":"01:35.590","Text":"I\u0027m going to assume that\u0027s a integer as well and no initial value given. That\u0027s fine."},{"Start":"01:35.590 ","End":"01:39.295","Text":"Now, I\u0027m now being asked to use a for loop to"},{"Start":"01:39.295 ","End":"01:44.200","Text":"iterate the multiplier variable through the numbers 1-12,"},{"Start":"01:44.200 ","End":"01:49.208","Text":"which is a way of saying I wanted to take on the values 1,"},{"Start":"01:49.208 ","End":"01:50.398","Text":"2, 3, 4, 5, 6,"},{"Start":"01:50.398 ","End":"01:52.465","Text":"7, 8, 9, 10, 11, 12."},{"Start":"01:52.465 ","End":"01:55.270","Text":"How would I do that? We\u0027ve seen previously, how we do it,"},{"Start":"01:55.270 ","End":"01:59.885","Text":"but we have a variable already called multiplier."},{"Start":"01:59.885 ","End":"02:05.155","Text":"We are going to start it at 1."},{"Start":"02:05.155 ","End":"02:09.005","Text":"We want it to keep going while it\u0027s"},{"Start":"02:09.005 ","End":"02:13.790","Text":"less than or equal to 12 because that\u0027s where we want it to go to."},{"Start":"02:13.790 ","End":"02:18.540","Text":"It\u0027s going to go up by 1 each time around the loop,"},{"Start":"02:18.540 ","End":"02:21.950","Text":"so we can just use the increment operator to do that."},{"Start":"02:21.950 ","End":"02:25.850","Text":"That\u0027s the initial part that we need to do."},{"Start":"02:25.850 ","End":"02:27.530","Text":"It says now in part c,"},{"Start":"02:27.530 ","End":"02:29.195","Text":"inside the for loop,"},{"Start":"02:29.195 ","End":"02:32.000","Text":"output the contents of the multiplier variable,"},{"Start":"02:32.000 ","End":"02:34.520","Text":"followed by the string x with spaces"},{"Start":"02:34.520 ","End":"02:37.205","Text":"either side followed by the contents of the table variable,"},{"Start":"02:37.205 ","End":"02:38.525","Text":"followed by the string,"},{"Start":"02:38.525 ","End":"02:40.460","Text":"and equals with spaces either sides,"},{"Start":"02:40.460 ","End":"02:42.230","Text":"so let\u0027s do that."},{"Start":"02:42.230 ","End":"02:45.365","Text":"We start off with the contents of the multiplier variable,"},{"Start":"02:45.365 ","End":"02:46.865","Text":"so I\u0027ll just put multiplier."},{"Start":"02:46.865 ","End":"02:48.905","Text":"Now, if I put plus here,"},{"Start":"02:48.905 ","End":"02:52.700","Text":"it will convert multiplier to a string when it prints it,"},{"Start":"02:52.700 ","End":"02:54.770","Text":"and it would join it to another string."},{"Start":"02:54.770 ","End":"02:59.600","Text":"In this case, it\u0027s the string space x with another space."},{"Start":"02:59.600 ","End":"03:02.240","Text":"Then I want to put the table variables,"},{"Start":"03:02.240 ","End":"03:04.955","Text":"so I\u0027d join it to the contents of the table variable."},{"Start":"03:04.955 ","End":"03:06.395","Text":"I\u0027m not adding numbers together,"},{"Start":"03:06.395 ","End":"03:08.425","Text":"I\u0027m joining strings together here."},{"Start":"03:08.425 ","End":"03:13.770","Text":"The next part is the string equals."},{"Start":"03:13.770 ","End":"03:16.580","Text":"I\u0027m just going to check at this point whether my code"},{"Start":"03:16.580 ","End":"03:19.480","Text":"throws up any errors and it has thrown up an error,"},{"Start":"03:19.480 ","End":"03:21.410","Text":"so let\u0027s have a look at what it is."},{"Start":"03:21.410 ","End":"03:29.045","Text":"Cannot find variable multiplier and It\u0027s because I\u0027ve put an I in the wrong place here."},{"Start":"03:29.045 ","End":"03:31.505","Text":"The variable I declared,"},{"Start":"03:31.505 ","End":"03:35.980","Text":"and the variable I was trying to use here were different, hence the error."},{"Start":"03:35.980 ","End":"03:39.740","Text":"That\u0027s good and that\u0027s why it\u0027s worth checking as you\u0027re going along for"},{"Start":"03:39.740 ","End":"03:44.360","Text":"any errors and to try not to have too many when you get to the end."},{"Start":"03:44.360 ","End":"03:46.700","Text":"It can become quite overwhelming if you\u0027ve got lots of errors,"},{"Start":"03:46.700 ","End":"03:48.560","Text":"you don\u0027t know where to start."},{"Start":"03:48.560 ","End":"03:51.125","Text":"That first part is done."},{"Start":"03:51.125 ","End":"03:55.520","Text":"Now it says in part d on the same line as the previous output."},{"Start":"03:55.520 ","End":"03:59.945","Text":"Output, the product of the multiplier and table variables."},{"Start":"03:59.945 ","End":"04:01.760","Text":"If I want to do it on the same line,"},{"Start":"04:01.760 ","End":"04:04.220","Text":"I don\u0027t use print line for this first part."},{"Start":"04:04.220 ","End":"04:05.915","Text":"I\u0027ll just use print,"},{"Start":"04:05.915 ","End":"04:09.680","Text":"that will not force the output onto a new line afterwards,"},{"Start":"04:09.680 ","End":"04:14.870","Text":"and so it will carry on printing from the last place it printed."},{"Start":"04:14.870 ","End":"04:19.610","Text":"But I actually do want to use print line on the next line because I want to force"},{"Start":"04:19.610 ","End":"04:22.340","Text":"a new line at the end of the output so that we"},{"Start":"04:22.340 ","End":"04:25.370","Text":"see the next line of the times table on a different line."},{"Start":"04:25.370 ","End":"04:27.050","Text":"If you just put print,"},{"Start":"04:27.050 ","End":"04:31.385","Text":"all your output would be on one line for the entire program and that\u0027s not what we want."},{"Start":"04:31.385 ","End":"04:34.265","Text":"Let\u0027s print line where the previous one is print."},{"Start":"04:34.265 ","End":"04:39.470","Text":"What we want here is the product of the multiplier and the table variables."},{"Start":"04:39.470 ","End":"04:45.825","Text":"So let\u0027s multiply them together using hashtag symbol which represents multiply,"},{"Start":"04:45.825 ","End":"04:49.290","Text":"and that should give us our result."},{"Start":"04:49.290 ","End":"04:51.050","Text":"That\u0027s us done in part e,"},{"Start":"04:51.050 ","End":"04:55.370","Text":"we were asked to test the method and check that the lines of"},{"Start":"04:55.370 ","End":"05:00.290","Text":"the sevenTimesTable are currently output all 12 lines and to correct any errors found."},{"Start":"05:00.290 ","End":"05:03.875","Text":"Hopefully, we won\u0027t have any errors and it\u0027s relatively straightforward."},{"Start":"05:03.875 ","End":"05:06.860","Text":"We\u0027ve already got rid of that one error we had previously."},{"Start":"05:06.860 ","End":"05:08.980","Text":"Now, let\u0027s have a go testing it."},{"Start":"05:08.980 ","End":"05:15.435","Text":"Sure enough, I see the sevenTimesTable pretty much as I would expect."},{"Start":"05:15.435 ","End":"05:22.410","Text":"If you\u0027ve had any errors I would imagine it\u0027s because you didn\u0027t calculate correctly."},{"Start":"05:22.410 ","End":"05:23.915","Text":"For some reason this was wrong,"},{"Start":"05:23.915 ","End":"05:26.000","Text":"or you didn\u0027t iterate correctly,"},{"Start":"05:26.000 ","End":"05:30.395","Text":"or just the way you output things weren\u0027t quite as it was expected."},{"Start":"05:30.395 ","End":"05:32.120","Text":"Just as to look at this again,"},{"Start":"05:32.120 ","End":"05:35.765","Text":"we first output the multiplier variable\u0027s contents,"},{"Start":"05:35.765 ","End":"05:39.440","Text":"then a literal string of an x with spaces either side,"},{"Start":"05:39.440 ","End":"05:42.244","Text":"then the contents of the table variable,"},{"Start":"05:42.244 ","End":"05:45.770","Text":"then a literal string with an equal sign with spaces."},{"Start":"05:45.770 ","End":"05:47.570","Text":"On the next part,"},{"Start":"05:47.570 ","End":"05:49.310","Text":"on this next statement here,"},{"Start":"05:49.310 ","End":"05:52.040","Text":"which will print on the same line as the previous one,"},{"Start":"05:52.040 ","End":"05:55.220","Text":"because print here and print line here,"},{"Start":"05:55.220 ","End":"05:56.960","Text":"when it does this calculation,"},{"Start":"05:56.960 ","End":"06:03.140","Text":"it will output it and then force the output onto a new line for any subsequent output."},{"Start":"06:03.140 ","End":"06:04.565","Text":"I hope that makes sense."},{"Start":"06:04.565 ","End":"06:08.010","Text":"That\u0027s it for this one. I\u0027ll see you in the next one."}],"ID":28026},{"Watched":false,"Name":"Exercise 4","Duration":"8m 44s","ChapterTopicVideoID":26939,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.093","Text":"Hello again. In this exercise,"},{"Start":"00:02.093 ","End":"00:04.035","Text":"we\u0027ve been asked to create a new method called"},{"Start":"00:04.035 ","End":"00:08.250","Text":"allTimesTable and within there to create an integer variable called"},{"Start":"00:08.250 ","End":"00:10.380","Text":"table with no initial value and"},{"Start":"00:10.380 ","End":"00:14.820","Text":"a second integer variable called multiplier again with no initial value."},{"Start":"00:14.820 ","End":"00:19.155","Text":"In Part b, we\u0027re asked to create a pair of nested for loops,"},{"Start":"00:19.155 ","End":"00:22.380","Text":"both of which it\u0027s right between 1 and 12."},{"Start":"00:22.380 ","End":"00:25.080","Text":"The inner loop should iterate multiplier,"},{"Start":"00:25.080 ","End":"00:27.915","Text":"and the outer loop should iterate table."},{"Start":"00:27.915 ","End":"00:30.060","Text":"At the appropriate point in the code,"},{"Start":"00:30.060 ","End":"00:34.200","Text":"we\u0027re asked to output the contents of the multiplier variable followed by"},{"Start":"00:34.200 ","End":"00:39.450","Text":"the string \" x \" followed by the contents of the table variable,"},{"Start":"00:39.450 ","End":"00:44.690","Text":"followed by the string \" = \"."},{"Start":"00:44.690 ","End":"00:47.117","Text":"On the same line as the previous output,"},{"Start":"00:47.117 ","End":"00:52.325","Text":"we\u0027re asked in Part d to output the product of the multiplier and table variables."},{"Start":"00:52.325 ","End":"00:54.410","Text":"In Part e, we\u0027re asked to check that"},{"Start":"00:54.410 ","End":"00:57.880","Text":"the unlimited buffering option is ticked in the terminal window of BlueJ,"},{"Start":"00:57.880 ","End":"01:02.390","Text":"and then to test the method by creating an object on the workbench and checking that"},{"Start":"01:02.390 ","End":"01:08.285","Text":"all 12 lines of the 1 times table to the 12 times table are correctly output,"},{"Start":"01:08.285 ","End":"01:10.910","Text":"and that\u0027s 144 lines in total."},{"Start":"01:10.910 ","End":"01:14.120","Text":"You are asked to then correct any errors found in."},{"Start":"01:14.120 ","End":"01:16.700","Text":"in Part f at an appropriate point in the code,"},{"Start":"01:16.700 ","End":"01:18.770","Text":"we\u0027re asked to output the contents of"},{"Start":"01:18.770 ","End":"01:22.959","Text":"the table variable followed by the string times table"},{"Start":"01:22.959 ","End":"01:25.670","Text":": so that each table is proceeded by"},{"Start":"01:25.670 ","End":"01:30.410","Text":"a heading indicating which times table is being output."},{"Start":"01:30.410 ","End":"01:36.715","Text":"Let\u0027s go ahead and create the new method called allTimesTable()."},{"Start":"01:36.715 ","End":"01:40.565","Text":"Because in the first part I need the same variables as previously,"},{"Start":"01:40.565 ","End":"01:44.960","Text":"I\u0027m just going to copy that to save myself typing those again."},{"Start":"01:44.960 ","End":"01:49.280","Text":"I make sure I close off my method and change this name,"},{"Start":"01:49.280 ","End":"01:52.326","Text":"so this is called allTimesTables()."},{"Start":"01:52.326 ","End":"01:54.425","Text":"I don\u0027t need initial values,"},{"Start":"01:54.425 ","End":"01:58.130","Text":"it tells me in Part a for table or multiplier."},{"Start":"01:58.130 ","End":"02:00.605","Text":"Now I\u0027m ready for Part b."},{"Start":"02:00.605 ","End":"02:03.235","Text":"Now we\u0027re going to do something slightly different."},{"Start":"02:03.235 ","End":"02:07.378","Text":"We are going to create a pair of nested loop,"},{"Start":"02:07.378 ","End":"02:10.325","Text":"so one loop inside another loop."},{"Start":"02:10.325 ","End":"02:18.710","Text":"The first one is used to iterate multiplier and the outer loop iterates tables,"},{"Start":"02:18.710 ","End":"02:22.355","Text":"so let\u0027s do it outside and then the inside."},{"Start":"02:22.355 ","End":"02:24.290","Text":"Outer loop should iterate table,"},{"Start":"02:24.290 ","End":"02:30.180","Text":"so table is going to take on the values 1-12."},{"Start":"02:30.180 ","End":"02:32.250","Text":"So table equals 1."},{"Start":"02:32.250 ","End":"02:36.405","Text":"Table is less than or equal to 12."},{"Start":"02:36.405 ","End":"02:40.290","Text":"Table++ will increment to the next value."},{"Start":"02:40.290 ","End":"02:45.410","Text":"That\u0027s my outer loop and I\u0027m going to need another loop inside it,"},{"Start":"02:45.410 ","End":"02:49.130","Text":"so I\u0027m going to indent and then start another for-loop."},{"Start":"02:49.130 ","End":"02:52.681","Text":"This time I\u0027m iterating multiplier,"},{"Start":"02:52.681 ","End":"02:57.530","Text":"and again I\u0027m going between the values of 1 and 12."},{"Start":"02:57.530 ","End":"03:00.620","Text":"Multiplier should be less than or equal to 12,"},{"Start":"03:00.620 ","End":"03:05.750","Text":"and then I do multiplier++."},{"Start":"03:05.750 ","End":"03:09.920","Text":"I need a pair of brackets there as well because that will contain"},{"Start":"03:09.920 ","End":"03:15.075","Text":"whatever operations I want to do inside the inner loop."},{"Start":"03:15.075 ","End":"03:17.405","Text":"There is Part b done."},{"Start":"03:17.405 ","End":"03:21.665","Text":"I\u0027ve created a pair of nested loops and they iterate between 1 and 12."},{"Start":"03:21.665 ","End":"03:24.494","Text":"The inner loop is iterating multiplier,"},{"Start":"03:24.494 ","End":"03:27.790","Text":"the outer loop is iterating table."},{"Start":"03:27.790 ","End":"03:30.555","Text":"Now Part c at the appropriate point in the code,"},{"Start":"03:30.555 ","End":"03:34.130","Text":"output the contents of the multiplier variable followed by a string x,"},{"Start":"03:34.130 ","End":"03:35.450","Text":"followed by the contents of the table,"},{"Start":"03:35.450 ","End":"03:38.450","Text":"followed by the string equals just like we did last time."},{"Start":"03:38.450 ","End":"03:42.350","Text":"The appropriate point in the code we are supposed to choose naturally go here."},{"Start":"03:42.350 ","End":"03:45.260","Text":"Should it go here outside the method itself?"},{"Start":"03:45.260 ","End":"03:50.510","Text":"Well, if we want to do every line of every times table,"},{"Start":"03:50.510 ","End":"03:53.180","Text":"the only line that\u0027s going to do that for"},{"Start":"03:53.180 ","End":"03:56.255","Text":"us is this one here in the middle of the inner loop."},{"Start":"03:56.255 ","End":"03:57.800","Text":"This inner loop is going to run"},{"Start":"03:57.800 ","End":"04:04.530","Text":"144 times the line inside because it will run 12 times here,"},{"Start":"04:04.530 ","End":"04:10.310","Text":"and then times 12 overall because of this outer loop."},{"Start":"04:10.310 ","End":"04:15.260","Text":"The inner loop will run 12 times but the outer loop runs 12 times as well,"},{"Start":"04:15.260 ","End":"04:19.915","Text":"and that means this one line here is going to run 144 times."},{"Start":"04:19.915 ","End":"04:25.419","Text":"The output is as we had before,"},{"Start":"04:25.419 ","End":"04:27.495","Text":"so let me type it out;"},{"Start":"04:27.495 ","End":"04:36.296","Text":"System.out.println and we want the multiplier variable followed by the string x,"},{"Start":"04:36.296 ","End":"04:41.615","Text":"followed by the contents of the table variable,"},{"Start":"04:41.615 ","End":"04:46.855","Text":"followed by the string = just as we had in that previous exercise."},{"Start":"04:46.855 ","End":"04:48.010","Text":"There\u0027s the first line,"},{"Start":"04:48.010 ","End":"04:50.960","Text":"and then it says on the same line as"},{"Start":"04:50.960 ","End":"04:54.830","Text":"the previous output products of the multiplier and table variables."},{"Start":"04:54.830 ","End":"04:57.209","Text":"Again, we need to remove the ln here,"},{"Start":"04:57.209 ","End":"04:59.334","Text":"so we don\u0027t want to force it onto a new line."},{"Start":"04:59.334 ","End":"05:01.115","Text":"We want to keep it on the same line,"},{"Start":"05:01.115 ","End":"05:05.270","Text":"but the next line we do want to force a line break at the end."},{"Start":"05:05.270 ","End":"05:08.930","Text":"So we put print line and the output is going to"},{"Start":"05:08.930 ","End":"05:14.370","Text":"be just as it was before multiplier times table,"},{"Start":"05:14.370 ","End":"05:19.160","Text":"but this time the table value will be changing and it won\u0027t be"},{"Start":"05:19.160 ","End":"05:25.500","Text":"7 all the time as it was in the previous exercise because it\u0027s writing through 1-12 here."},{"Start":"05:25.760 ","End":"05:31.260","Text":"That\u0027s it, I\u0027ll compile and I don\u0027t have any errors."},{"Start":"05:31.260 ","End":"05:35.930","Text":"It does say to check the terminal window because what happens with"},{"Start":"05:35.930 ","End":"05:41.075","Text":"the BlueJ terminal is if you don\u0027t have this option turned on unlimited buffering,"},{"Start":"05:41.075 ","End":"05:45.440","Text":"it will only display a certain number of lines in this display and you will"},{"Start":"05:45.440 ","End":"05:50.435","Text":"lose some of the earlier output because we\u0027re outputting 144 lines here."},{"Start":"05:50.435 ","End":"05:52.580","Text":"You just won\u0027t see the early ones and you\u0027ll think"},{"Start":"05:52.580 ","End":"05:55.385","Text":"your code hasn\u0027t worked when it in fact it has."},{"Start":"05:55.385 ","End":"06:00.530","Text":"Let\u0027s see if that works now because we did have our Unlimited buffering ticked."},{"Start":"06:00.530 ","End":"06:04.685","Text":"We now need to create an object and then we\u0027ll run"},{"Start":"06:04.685 ","End":"06:08.690","Text":"allTimesTable() method in it. There we go."},{"Start":"06:08.690 ","End":"06:10.010","Text":"If I scroll up and down,"},{"Start":"06:10.010 ","End":"06:12.920","Text":"there is a scroll bar here in the terminal window in BlueJ."},{"Start":"06:12.920 ","End":"06:18.016","Text":"I can see that I\u0027ve got all of the times tables: the 1 times table,"},{"Start":"06:18.016 ","End":"06:19.430","Text":"2 times table,"},{"Start":"06:19.430 ","End":"06:20.510","Text":"3 times table,"},{"Start":"06:20.510 ","End":"06:27.530","Text":"and so on all the way up to the 12 times table."},{"Start":"06:27.530 ","End":"06:31.770","Text":"For part of the exercise f we"},{"Start":"06:31.770 ","End":"06:36.590","Text":"are asked at an appropriate point in the code to output the contents of"},{"Start":"06:36.590 ","End":"06:40.835","Text":"the table variable followed by the string times tables so that"},{"Start":"06:40.835 ","End":"06:46.055","Text":"each table is proceeded by a heading indicating which timetable has been output."},{"Start":"06:46.055 ","End":"06:50.825","Text":"Here we see that 11 times table has ended here and the 12 times table start."},{"Start":"06:50.825 ","End":"06:52.805","Text":"It would be nice to have a heading above"},{"Start":"06:52.805 ","End":"06:56.630","Text":"each table so we know which one is just about to be printed."},{"Start":"06:56.630 ","End":"07:00.995","Text":"Where would be the appropriate place to put that?"},{"Start":"07:00.995 ","End":"07:08.600","Text":"Well, each time the table changes we want to output the new table,"},{"Start":"07:08.600 ","End":"07:13.250","Text":"and so here would seem to be a sensible place for it to be output."},{"Start":"07:13.250 ","End":"07:14.546","Text":"It definitely wouldn\u0027t go in here,"},{"Start":"07:14.546 ","End":"07:18.710","Text":"otherwise against every line we\u0027d be printing what times table we\u0027re printing."},{"Start":"07:18.710 ","End":"07:24.995","Text":"We just want to do it once every time a new value of table is taken on."},{"Start":"07:24.995 ","End":"07:28.580","Text":"What we\u0027ll do is do it here;"},{"Start":"07:28.580 ","End":"07:35.750","Text":"System.out.println and I do want println because I want a new line to start afterwards."},{"Start":"07:35.750 ","End":"07:39.245","Text":"I\u0027m going to print the content of the table variable,"},{"Start":"07:39.245 ","End":"07:45.230","Text":"followed by the string times table with a colon on the end,"},{"Start":"07:45.230 ","End":"07:49.820","Text":"and let\u0027s see how the output changes for that."},{"Start":"07:49.820 ","End":"07:52.490","Text":"Hopefully, it\u0027ll be a little bit more easy to follow"},{"Start":"07:52.490 ","End":"07:55.655","Text":"in the terminal window when we looked at it."},{"Start":"07:55.655 ","End":"07:59.300","Text":"There we go, it has shown us ahead of each table."},{"Start":"07:59.300 ","End":"08:00.757","Text":"You\u0027ve got the 1 times table,"},{"Start":"08:00.757 ","End":"08:02.060","Text":"2 times table, 3 times table,"},{"Start":"08:02.060 ","End":"08:05.405","Text":"and so on all the way up to 12."},{"Start":"08:05.405 ","End":"08:08.210","Text":"That was again pretty straightforward,"},{"Start":"08:08.210 ","End":"08:10.820","Text":"more complex in the sense that you had to have"},{"Start":"08:10.820 ","End":"08:14.603","Text":"a nested loop and understanding what nested loop is first of all,"},{"Start":"08:14.603 ","End":"08:18.230","Text":"but also how you\u0027ve got to place lines at"},{"Start":"08:18.230 ","End":"08:22.295","Text":"the appropriate place in either the inner loop,"},{"Start":"08:22.295 ","End":"08:23.960","Text":"or the outer loop,"},{"Start":"08:23.960 ","End":"08:25.730","Text":"or even outside both loops."},{"Start":"08:25.730 ","End":"08:30.080","Text":"I could have had a message here saying end of program if I wanted to,"},{"Start":"08:30.080 ","End":"08:31.970","Text":"and it would only ever print that once."},{"Start":"08:31.970 ","End":"08:35.884","Text":"Maybe it\u0027s going to be a little bit time of messing around changing"},{"Start":"08:35.884 ","End":"08:40.221","Text":"the output and just see the effect of the placement of your line,"},{"Start":"08:40.221 ","End":"08:45.120","Text":"what it would be on the program. See you for the next one."}],"ID":28027},{"Watched":false,"Name":"Exercise 5","Duration":"9m 34s","ChapterTopicVideoID":26931,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:01.185","Text":"Hi everyone."},{"Start":"00:01.185 ","End":"00:02.310","Text":"In this exercise,"},{"Start":"00:02.310 ","End":"00:05.310","Text":"we\u0027ve been asked to create a new method called whileCount,"},{"Start":"00:05.310 ","End":"00:06.705","Text":"and in Part a,"},{"Start":"00:06.705 ","End":"00:11.985","Text":"we\u0027ve been told to use a while loop and output the numbers from 1-10."},{"Start":"00:11.985 ","End":"00:14.565","Text":"In Part b, we\u0027re asked to test the method."},{"Start":"00:14.565 ","End":"00:18.525","Text":"If it continues producing output past 10 or appears to have crashed,"},{"Start":"00:18.525 ","End":"00:19.770","Text":"we\u0027re told to click on"},{"Start":"00:19.770 ","End":"00:22.170","Text":"the \"Reset virtual machine\" icon in"},{"Start":"00:22.170 ","End":"00:25.350","Text":"the bottom right corner of the BlueJ application window."},{"Start":"00:25.350 ","End":"00:28.215","Text":"Then to correct any errors found."},{"Start":"00:28.215 ","End":"00:30.710","Text":"In Part c, in the same method,"},{"Start":"00:30.710 ","End":"00:33.725","Text":"we are asked to add another while loop after the previous one,"},{"Start":"00:33.725 ","End":"00:38.485","Text":"which outputs the numbers from 10-100 in steps of 10."},{"Start":"00:38.485 ","End":"00:41.280","Text":"In Part d, we\u0027re asked to test again."},{"Start":"00:41.280 ","End":"00:45.410","Text":"If it continues producing output past 100 or appears to have crashed,"},{"Start":"00:45.410 ","End":"00:46.640","Text":"again we can click on"},{"Start":"00:46.640 ","End":"00:51.870","Text":"the \"Reset virtual machine\" icon in BlueJ to reset the virtual machine,"},{"Start":"00:51.870 ","End":"00:54.475","Text":"and then we can correct any errors found."},{"Start":"00:54.475 ","End":"00:56.930","Text":"In Part e, in the same method we are"},{"Start":"00:56.930 ","End":"00:59.555","Text":"asked to add another while loop after the previous one,"},{"Start":"00:59.555 ","End":"01:07.330","Text":"which outputs the numbers from 2,020 to minus 5,000 in steps of minus 100."},{"Start":"01:07.330 ","End":"01:09.120","Text":"Finally, in Part f,"},{"Start":"01:09.120 ","End":"01:10.935","Text":"we\u0027re asked to test again."},{"Start":"01:10.935 ","End":"01:16.100","Text":"If it continues producing the output past minus 5,000 or appears to have crashed,"},{"Start":"01:16.100 ","End":"01:21.530","Text":"once more we can reset BlueJ using the virtual machine reset icon,"},{"Start":"01:21.530 ","End":"01:24.710","Text":"and then we can correct any errors found."},{"Start":"01:24.710 ","End":"01:29.060","Text":"Let\u0027s now create a method called whileCount,"},{"Start":"01:29.060 ","End":"01:32.075","Text":"after all the existing methods."},{"Start":"01:32.075 ","End":"01:34.355","Text":"This time we\u0027re going to be using"},{"Start":"01:34.355 ","End":"01:38.540","Text":"a while loop rather than a for loop that we\u0027ve been using before."},{"Start":"01:38.540 ","End":"01:42.919","Text":"But the exercise is very familiar from the initial for-loop exercises,"},{"Start":"01:42.919 ","End":"01:47.585","Text":"so let\u0027s see what the difference is in syntax and operation of a while loop."},{"Start":"01:47.585 ","End":"01:50.405","Text":"We\u0027re going to output the numbers 1-10 in Part a."},{"Start":"01:50.405 ","End":"01:52.925","Text":"Let\u0027s start with the keyword \"while\"."},{"Start":"01:52.925 ","End":"01:57.560","Text":"Now for while, all we need is a Boolean condition inside"},{"Start":"01:57.560 ","End":"02:04.755","Text":"the brackets that determines when while loop is going to stop executing."},{"Start":"02:04.755 ","End":"02:09.365","Text":"We\u0027ll need a variable to hold the number,"},{"Start":"02:09.365 ","End":"02:13.710","Text":"so let\u0027s call it i. It\u0027s nice and short."},{"Start":"02:13.710 ","End":"02:15.650","Text":"i usually stands for index by the way,"},{"Start":"02:15.650 ","End":"02:17.780","Text":"which we\u0027ll come across very soon."},{"Start":"02:17.780 ","End":"02:22.045","Text":"But if you wonder why everyone uses i as their variable name,"},{"Start":"02:22.045 ","End":"02:23.515","Text":"it\u0027s nice and short,"},{"Start":"02:23.515 ","End":"02:27.035","Text":"and there\u0027s often a case for a variable called an index variable."},{"Start":"02:27.035 ","End":"02:29.360","Text":"Let\u0027s just call it as i,"},{"Start":"02:29.360 ","End":"02:32.270","Text":"and we want to start 1 rather than 0."},{"Start":"02:32.270 ","End":"02:34.760","Text":"Let\u0027s change that initial value to 1."},{"Start":"02:34.760 ","End":"02:39.670","Text":"While i is less than or equal to 10,"},{"Start":"02:39.670 ","End":"02:43.424","Text":"we want to keep our loop executing."},{"Start":"02:43.424 ","End":"02:49.830","Text":"The syntax in this first line is actually much simpler than for the for-loop,"},{"Start":"02:49.830 ","End":"02:56.940","Text":"because all we need to do is say what the termination condition is going to be."},{"Start":"02:59.150 ","End":"03:04.085","Text":"Inside is exactly as it would have been for the for-loop."},{"Start":"03:04.085 ","End":"03:06.500","Text":"On the surface it looks easier,"},{"Start":"03:06.500 ","End":"03:09.740","Text":"but there\u0027s one thing we do need to do with a while-loop,"},{"Start":"03:09.740 ","End":"03:15.275","Text":"which is to make sure that this clause here can ever actually terminate."},{"Start":"03:15.275 ","End":"03:20.285","Text":"With a for-loop it takes care of the incrementing of the variable that you\u0027re using."},{"Start":"03:20.285 ","End":"03:22.160","Text":"But this could be anything in here,"},{"Start":"03:22.160 ","End":"03:27.770","Text":"so we\u0027ve got to be responsible for making sure that this condition is actually possible."},{"Start":"03:27.770 ","End":"03:30.185","Text":"Now if i is 1 and never is changed,"},{"Start":"03:30.185 ","End":"03:32.000","Text":"then this will run forever."},{"Start":"03:32.000 ","End":"03:33.575","Text":"This will be an infinite loop."},{"Start":"03:33.575 ","End":"03:35.818","Text":"We do actually need to do something,"},{"Start":"03:35.818 ","End":"03:38.465","Text":"and really it\u0027s as simple as incrementing i,"},{"Start":"03:38.465 ","End":"03:43.910","Text":"so that each time around the loop i takes on a new value until it reaches 10,"},{"Start":"03:43.910 ","End":"03:46.970","Text":"and then the program will cease execution."},{"Start":"03:46.970 ","End":"03:51.380","Text":"I\u0027ll compile that just to check my syntax is correct,"},{"Start":"03:51.380 ","End":"03:52.994","Text":"which it does seem to be."},{"Start":"03:52.994 ","End":"03:58.775","Text":"It says then to test if it continues producing output past 10 or appears to have crashed,"},{"Start":"03:58.775 ","End":"04:03.290","Text":"you can click on the \"Reset virtual machine\" icon and correct any errors."},{"Start":"04:03.290 ","End":"04:06.125","Text":"Let\u0027s see what mine does."},{"Start":"04:06.125 ","End":"04:10.205","Text":"I\u0027ll create my object and execute the method,"},{"Start":"04:10.205 ","End":"04:12.190","Text":"which is called whileCount."},{"Start":"04:12.190 ","End":"04:14.239","Text":"It seems to work, no problem."},{"Start":"04:14.239 ","End":"04:18.725","Text":"No need to hit the \"Reset\" button, which is over here."},{"Start":"04:18.725 ","End":"04:20.815","Text":"If I hover over it you\u0027ll see it appears,"},{"Start":"04:20.815 ","End":"04:22.605","Text":"\"Reset Java Virtual Machine\"."},{"Start":"04:22.605 ","End":"04:24.410","Text":"That will stop the program running."},{"Start":"04:24.410 ","End":"04:27.260","Text":"If I had an infinite loop I\u0027d have to wait an awful long time"},{"Start":"04:27.260 ","End":"04:31.280","Text":"potentially for it to wrap around to 0 again,"},{"Start":"04:31.280 ","End":"04:33.725","Text":"and maybe I\u0027d hit what I\u0027m looking for."},{"Start":"04:33.725 ","End":"04:36.140","Text":"But I\u0027ve got it right, so I don\u0027t need to do that."},{"Start":"04:36.140 ","End":"04:38.660","Text":"Let\u0027s move on to Part c in"},{"Start":"04:38.660 ","End":"04:42.140","Text":"the same method to add another while loop after the previous one,"},{"Start":"04:42.140 ","End":"04:46.430","Text":"which outputs the numbers from 10-100 in steps of 10."},{"Start":"04:46.430 ","End":"04:48.170","Text":"I\u0027m not going to create a new method,"},{"Start":"04:48.170 ","End":"04:50.900","Text":"I\u0027m going to do it inside the existing one."},{"Start":"04:50.900 ","End":"04:56.670","Text":"I want it to go now up to 100 in steps of 10."},{"Start":"04:56.670 ","End":"05:00.765","Text":"This time i is going to be less than or equal to 100."},{"Start":"05:00.765 ","End":"05:07.020","Text":"The inside of the loop is still going to output the value of i,"},{"Start":"05:07.020 ","End":"05:09.455","Text":"because I don\u0027t need to output something."},{"Start":"05:09.455 ","End":"05:12.455","Text":"But now instead of adding 1 to y,"},{"Start":"05:12.455 ","End":"05:13.700","Text":"I need to add 10."},{"Start":"05:13.700 ","End":"05:16.700","Text":"Let\u0027s try and use the compound operator."},{"Start":"05:16.700 ","End":"05:18.665","Text":"You remember it\u0027s just saying,"},{"Start":"05:18.665 ","End":"05:24.464","Text":"I\u0027m going to assign something and I\u0027m going to add to it before I do the assignment."},{"Start":"05:24.464 ","End":"05:28.850","Text":"This will have the equivalent effect of i equals i plus 10."},{"Start":"05:28.850 ","End":"05:34.245","Text":"This will go up to 100 in steps of 10, or it would,"},{"Start":"05:34.245 ","End":"05:40.050","Text":"but actually I need to make sure I\u0027ve set the value of i to what I need it to be here."},{"Start":"05:40.050 ","End":"05:41.860","Text":"I\u0027m starting at 10,"},{"Start":"05:41.860 ","End":"05:44.660","Text":"so I need to be responsible with setting"},{"Start":"05:44.660 ","End":"05:48.890","Text":"i\u0027s initial value before we even go into the loop."},{"Start":"05:48.890 ","End":"05:56.235","Text":"Let\u0027s have a go at that and see if I do get output from 10-100 in steps of 10,"},{"Start":"05:56.235 ","End":"05:58.250","Text":"and if not, we\u0027ll fix it."},{"Start":"05:58.250 ","End":"06:00.350","Text":"It\u0027s still got the previous output."},{"Start":"06:00.350 ","End":"06:02.330","Text":"There\u0027s 1, 2, 3, 4, 5, 6, 7, 8,"},{"Start":"06:02.330 ","End":"06:04.565","Text":"9, 10, from the first part of the program."},{"Start":"06:04.565 ","End":"06:06.440","Text":"Then the second part, 10, 20,"},{"Start":"06:06.440 ","End":"06:09.365","Text":"30, and so on, up to 100,"},{"Start":"06:09.365 ","End":"06:15.319","Text":"so that seems to have done what I need to for Part c. Let\u0027s look at Part e then,"},{"Start":"06:15.319 ","End":"06:18.890","Text":"in the same method add another while-loop after the previous ones,"},{"Start":"06:18.890 ","End":"06:26.005","Text":"which outputs the numbers from 2,020 to minus 5,000 in steps of minus 100."},{"Start":"06:26.005 ","End":"06:28.325","Text":"Why those strange numbers?"},{"Start":"06:28.325 ","End":"06:30.740","Text":"Well actually they could represent years, couldn\u0027t they?"},{"Start":"06:30.740 ","End":"06:33.605","Text":"We could be doing a timeline of some sort,"},{"Start":"06:33.605 ","End":"06:36.005","Text":"going back to BC times."},{"Start":"06:36.005 ","End":"06:37.940","Text":"Let\u0027s go ahead and do that."},{"Start":"06:37.940 ","End":"06:43.025","Text":"We start with our initial value of 2,020 potentially,"},{"Start":"06:43.025 ","End":"06:47.460","Text":"and then we want to go down in steps of minus 100."},{"Start":"06:47.460 ","End":"06:50.675","Text":"It\u0027s going to be very similar to before,"},{"Start":"06:50.675 ","End":"06:57.485","Text":"but this time we want to check that i becomes a smaller number than minus 5,000,"},{"Start":"06:57.485 ","End":"07:00.290","Text":"we will want to terminate the loop."},{"Start":"07:00.290 ","End":"07:03.440","Text":"When it goes to minus 5,100,"},{"Start":"07:03.440 ","End":"07:05.435","Text":"we should have stopped before that point."},{"Start":"07:05.435 ","End":"07:10.170","Text":"We\u0027ll produce our output as ever."},{"Start":"07:10.170 ","End":"07:14.615","Text":"This time we need to decrement by 100 each time."},{"Start":"07:14.615 ","End":"07:20.380","Text":"I\u0027m going to try and use the compound assignment operator again."},{"Start":"07:20.380 ","End":"07:26.029","Text":"Minus equals 100 means take 100 off i each time."},{"Start":"07:26.029 ","End":"07:27.755","Text":"The order is important by the way,"},{"Start":"07:27.755 ","End":"07:29.810","Text":"if I put equals minus 100,"},{"Start":"07:29.810 ","End":"07:34.565","Text":"it would just replace the contents of i with minus 100 every time around the loop."},{"Start":"07:34.565 ","End":"07:36.490","Text":"So this will become an infinite loop."},{"Start":"07:36.490 ","End":"07:44.605","Text":"What I\u0027m interested in doing is taking 100 off and assigning the results into i."},{"Start":"07:44.605 ","End":"07:49.275","Text":"Let\u0027s see for Part f then if that works."},{"Start":"07:49.275 ","End":"07:52.335","Text":"Compile it first, no errors."},{"Start":"07:52.335 ","End":"07:55.230","Text":"Let\u0027s then run it."},{"Start":"07:55.230 ","End":"07:57.945","Text":"I should see 3 sets of output now."},{"Start":"07:57.945 ","End":"08:00.120","Text":"Last one is very long,"},{"Start":"08:00.120 ","End":"08:02.040","Text":"so let me scroll up and check it."},{"Start":"08:02.040 ","End":"08:03.150","Text":"I\u0027ve still got my 1-10,"},{"Start":"08:03.150 ","End":"08:04.805","Text":"I\u0027ve still got my 10-100."},{"Start":"08:04.805 ","End":"08:07.145","Text":"Then I\u0027ve got this new output here,"},{"Start":"08:07.145 ","End":"08:08.700","Text":"where it goes 2,020,"},{"Start":"08:08.700 ","End":"08:10.420","Text":"1,920, 1,820,"},{"Start":"08:10.420 ","End":"08:13.730","Text":"and so on, goes down to the 0,"},{"Start":"08:13.730 ","End":"08:19.265","Text":"and then it goes below 0 up to minus,"},{"Start":"08:19.265 ","End":"08:21.990","Text":"interesting, 4,980,"},{"Start":"08:21.990 ","End":"08:23.130","Text":"so what\u0027s happened here?"},{"Start":"08:23.130 ","End":"08:27.995","Text":"What I\u0027ve been doing is I\u0027ve been taking 100 off,"},{"Start":"08:27.995 ","End":"08:29.591","Text":"and that\u0027s correct,"},{"Start":"08:29.591 ","End":"08:31.805","Text":"and I started in 20s,"},{"Start":"08:31.805 ","End":"08:34.670","Text":"so it would indeed finish up minus 4,980,"},{"Start":"08:34.670 ","End":"08:36.620","Text":"that\u0027s exactly what I\u0027d expect."},{"Start":"08:36.620 ","End":"08:39.020","Text":"It\u0027s doing exactly what it should do."},{"Start":"08:39.020 ","End":"08:40.955","Text":"It\u0027s taking 100 off each time,"},{"Start":"08:40.955 ","End":"08:43.430","Text":"but it\u0027s not finishing on minus 5,000,"},{"Start":"08:43.430 ","End":"08:45.485","Text":"it\u0027s finishing on minus 4,980,"},{"Start":"08:45.485 ","End":"08:50.180","Text":"because if I take another 100 off it would take me below minus 5,000."},{"Start":"08:50.180 ","End":"08:52.955","Text":"If I started at exactly 2,000,"},{"Start":"08:52.955 ","End":"08:55.370","Text":"it would hit 5,000 exactly as well."},{"Start":"08:55.370 ","End":"08:57.695","Text":"But I started at 2,020."},{"Start":"08:57.695 ","End":"09:00.930","Text":"That works as I would expect it to,"},{"Start":"09:00.930 ","End":"09:02.930","Text":"although initially I was thinking, \"Oh, does that work?\""},{"Start":"09:02.930 ","End":"09:06.125","Text":"Yes, it does, it\u0027s just the numbers that we\u0027ve used."},{"Start":"09:06.125 ","End":"09:08.330","Text":"That\u0027s it for this exercise,"},{"Start":"09:08.330 ","End":"09:11.030","Text":"where we looked at using a while-loop to"},{"Start":"09:11.030 ","End":"09:14.090","Text":"do what we were doing previously with a for-loop,"},{"Start":"09:14.090 ","End":"09:18.305","Text":"the difference being you\u0027re responsible for maintaining"},{"Start":"09:18.305 ","End":"09:23.495","Text":"the variables inside the loop that you\u0027re going to use to break out the loop."},{"Start":"09:23.495 ","End":"09:25.760","Text":"In my case it was always a number,"},{"Start":"09:25.760 ","End":"09:27.650","Text":"but it could be something else,"},{"Start":"09:27.650 ","End":"09:29.165","Text":"or it could be a combination of things."},{"Start":"09:29.165 ","End":"09:32.010","Text":"That\u0027s what we\u0027ll look at in the subsequent exercises."},{"Start":"09:32.010 ","End":"09:34.969","Text":"I\u0027ll see you shortly for those."}],"ID":28028},{"Watched":false,"Name":"Exercise 6","Duration":"5m 11s","ChapterTopicVideoID":26932,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.740 ","End":"00:04.290","Text":"Hello, welcome back. In this next exercise,"},{"Start":"00:04.290 ","End":"00:07.320","Text":"we\u0027ve been asked to create a new method called Fibonacci."},{"Start":"00:07.320 ","End":"00:11.190","Text":"Within it, we\u0027ve been asked to declare and initialize a number of variables,"},{"Start":"00:11.190 ","End":"00:13.500","Text":"num1 with a value 0,"},{"Start":"00:13.500 ","End":"00:15.570","Text":"num2 with the value 1,"},{"Start":"00:15.570 ","End":"00:17.744","Text":"limit with the value 12,"},{"Start":"00:17.744 ","End":"00:20.130","Text":"temp with the value 0,"},{"Start":"00:20.130 ","End":"00:23.010","Text":"and term with the value 0."},{"Start":"00:23.010 ","End":"00:26.865","Text":"In part b, we\u0027re then asked to use a while loop to iterate"},{"Start":"00:26.865 ","End":"00:31.214","Text":"while term is less than or equal to limit."},{"Start":"00:31.214 ","End":"00:32.610","Text":"In part c,"},{"Start":"00:32.610 ","End":"00:38.210","Text":"we\u0027re asked inside the loop to output num1 assigned to temp,"},{"Start":"00:38.210 ","End":"00:42.530","Text":"the sum of num1 and num2 assigned to num1,"},{"Start":"00:42.530 ","End":"00:44.345","Text":"the contents of num2,"},{"Start":"00:44.345 ","End":"00:47.885","Text":"assign to num2 the contents of temp,"},{"Start":"00:47.885 ","End":"00:50.750","Text":"and then to increment the term variable."},{"Start":"00:50.750 ","End":"00:55.850","Text":"In part d, we\u0027re asked to test the method outputs the Fibonacci sequence,"},{"Start":"00:55.850 ","End":"00:57.605","Text":"this series of numbers here."},{"Start":"00:57.605 ","End":"01:02.690","Text":"Let\u0027s go ahead and create a method called Fibonacci."},{"Start":"01:02.690 ","End":"01:08.735","Text":"We\u0027ve initially been asked to assign values to various variables and create them."},{"Start":"01:08.735 ","End":"01:16.205","Text":"They all seem to be integers so we can do that in one line, num1 is 0,"},{"Start":"01:16.205 ","End":"01:19.085","Text":"num2 is 1,"},{"Start":"01:19.085 ","End":"01:22.130","Text":"limit is 12,"},{"Start":"01:22.130 ","End":"01:24.275","Text":"temp is 0,"},{"Start":"01:24.275 ","End":"01:28.390","Text":"and term is 0."},{"Start":"01:28.390 ","End":"01:31.070","Text":"That\u0027s great."},{"Start":"01:31.070 ","End":"01:34.190","Text":"The next part is to use a while loop to"},{"Start":"01:34.190 ","End":"01:40.290","Text":"iterate while term is less than or equal to limit."},{"Start":"01:40.360 ","End":"01:42.830","Text":"That\u0027s pretty straightforward."},{"Start":"01:42.830 ","End":"01:46.190","Text":"Term is less than or equal to limit,"},{"Start":"01:46.190 ","End":"01:53.370","Text":"as long as that is true the inside of this loop is going to keep ongoing."},{"Start":"01:53.390 ","End":"01:56.100","Text":"Then inside the loop in part c,"},{"Start":"01:56.100 ","End":"01:57.680","Text":"we\u0027ve asked to do a number of things."},{"Start":"01:57.680 ","End":"02:01.175","Text":"The first thing is to output num1,"},{"Start":"02:01.175 ","End":"02:03.335","Text":"the content of num1,"},{"Start":"02:03.335 ","End":"02:06.890","Text":"so let\u0027s do that."},{"Start":"02:06.890 ","End":"02:13.145","Text":"Then to assign 2 temp the sum of num1 and num2 in part c2."},{"Start":"02:13.145 ","End":"02:14.750","Text":"We\u0027re assigning 2 temp."},{"Start":"02:14.750 ","End":"02:18.785","Text":"Temp comes on the left-hand side of the assignment operator,"},{"Start":"02:18.785 ","End":"02:23.215","Text":"the sum of num1 and num2. There we go."},{"Start":"02:23.215 ","End":"02:30.635","Text":"Then the next line we\u0027re required to assign 2 num1 the contents of num2."},{"Start":"02:30.635 ","End":"02:37.355","Text":"Num1 gets the contents of num2 on the right-hand side of the assignment operator."},{"Start":"02:37.355 ","End":"02:38.915","Text":"Then in Part 4,"},{"Start":"02:38.915 ","End":"02:41.870","Text":"assign to num2 the content of temp."},{"Start":"02:41.870 ","End":"02:45.200","Text":"So num2 gets the contents of temp,"},{"Start":"02:45.200 ","End":"02:46.910","Text":"which is on the right-hand side."},{"Start":"02:46.910 ","End":"02:49.655","Text":"Finally, we\u0027re asked to increment"},{"Start":"02:49.655 ","End":"02:53.045","Text":"the term variable so that we can involve any other variables."},{"Start":"02:53.045 ","End":"02:57.965","Text":"Just term plus plus is going to do it. That is it."},{"Start":"02:57.965 ","End":"03:03.145","Text":"Let\u0027s see what output is generated as part d asks us to do."},{"Start":"03:03.145 ","End":"03:06.850","Text":"Hopefully, it will match the numbers there."},{"Start":"03:06.850 ","End":"03:13.021","Text":"We are told the Fibonacci sequence does 0,"},{"Start":"03:13.021 ","End":"03:14.373","Text":"1, 1,"},{"Start":"03:14.373 ","End":"03:16.127","Text":"2, 3, 5,"},{"Start":"03:16.127 ","End":"03:18.005","Text":"8, 13, 21,"},{"Start":"03:18.005 ","End":"03:20.750","Text":"34, 55, 89, and 144."},{"Start":"03:20.750 ","End":"03:23.180","Text":"Let\u0027s have a look at what\u0027s actually going on here."},{"Start":"03:23.180 ","End":"03:27.020","Text":"We\u0027re terminating when term is less than or equal to limit."},{"Start":"03:27.020 ","End":"03:32.240","Text":"Presumably, we want a certain number of terms in the Fibonacci sequence,"},{"Start":"03:32.240 ","End":"03:33.710","Text":"12 is what we\u0027re looking for."},{"Start":"03:33.710 ","End":"03:38.390","Text":"We actually get 13 because we started with 0 being output."},{"Start":"03:38.390 ","End":"03:40.280","Text":"That\u0027s fine and that could be fixed if we wanted to,"},{"Start":"03:40.280 ","End":"03:41.810","Text":"but it\u0027s not too big a deal."},{"Start":"03:41.810 ","End":"03:44.160","Text":"We output the number."},{"Start":"03:44.160 ","End":"03:47.840","Text":"Then what we do is the way the Fibonacci sequence works is"},{"Start":"03:47.840 ","End":"03:51.950","Text":"each term in the sequence is the previous 2 add it together."},{"Start":"03:51.950 ","End":"03:57.185","Text":"That\u0027s why the first one being printed was 0 because that\u0027s what num1 was,"},{"Start":"03:57.185 ","End":"04:02.245","Text":"then we swapped num1 and num2 over num2 went into num1."},{"Start":"04:02.245 ","End":"04:04.790","Text":"But num2 got a new value,"},{"Start":"04:04.790 ","End":"04:08.615","Text":"which was the previous 2 added together and that\u0027s why we needed"},{"Start":"04:08.615 ","End":"04:13.370","Text":"temp pair because it was the value of num1 before we changed it in this line,"},{"Start":"04:13.370 ","End":"04:16.425","Text":"added to num2 before we change it in this line."},{"Start":"04:16.425 ","End":"04:17.865","Text":"We need a third variable,"},{"Start":"04:17.865 ","End":"04:19.680","Text":"temp in order to do that."},{"Start":"04:19.680 ","End":"04:21.620","Text":"It\u0027s a very common thing when you\u0027re swapping variables,"},{"Start":"04:21.620 ","End":"04:25.370","Text":"you\u0027ll need a third variable each time around the loop."},{"Start":"04:25.370 ","End":"04:27.485","Text":"Then we print the new value of num1,"},{"Start":"04:27.485 ","End":"04:29.990","Text":"which used to be the value of num2."},{"Start":"04:29.990 ","End":"04:35.360","Text":"Then it prints out all of the numbers in the sequence that we\u0027re expecting."},{"Start":"04:35.360 ","End":"04:37.435","Text":"If I wanted to print more numbers,"},{"Start":"04:37.435 ","End":"04:41.360","Text":"just change limit to 20 because I\u0027m limiting it to"},{"Start":"04:41.360 ","End":"04:45.620","Text":"the first 20 or 21 because I\u0027m counting zeros as well, terms."},{"Start":"04:45.620 ","End":"04:47.964","Text":"Let\u0027s just prove that that works."},{"Start":"04:47.964 ","End":"04:52.580","Text":"There you see we\u0027ve got the next items in the Fibonacci sequence."},{"Start":"04:52.580 ","End":"04:56.270","Text":"That\u0027s something a little bit more interesting than what we previously had."},{"Start":"04:56.270 ","End":"04:58.775","Text":"You could have actually done this with a for loop as well."},{"Start":"04:58.775 ","End":"05:02.300","Text":"But it\u0027s nice and elegant in the while loop,"},{"Start":"05:02.300 ","End":"05:07.610","Text":"they\u0027re relatively easy to follow once you understand how our Fibonacci sequence works."},{"Start":"05:07.610 ","End":"05:12.060","Text":"That\u0027s it for this one. I hope that\u0027s clear and I see you for the next one."}],"ID":28029},{"Watched":false,"Name":"Exercise 7","Duration":"9m 11s","ChapterTopicVideoID":26933,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:02.700","Text":"Welcome back to this next exercise,"},{"Start":"00:02.700 ","End":"00:07.590","Text":"which we have been asked to create a method for called while times tables."},{"Start":"00:07.590 ","End":"00:09.570","Text":"In that method, first of all,"},{"Start":"00:09.570 ","End":"00:14.230","Text":"we are asked to create an integer variable called table with an initial value of 2."},{"Start":"00:14.230 ","End":"00:17.025","Text":"Second integer variable called multiplier,"},{"Start":"00:17.025 ","End":"00:19.325","Text":"with an initial value of 1."},{"Start":"00:19.325 ","End":"00:23.475","Text":"In part b, we\u0027re asked to create a pair of nested while loops."},{"Start":"00:23.475 ","End":"00:25.350","Text":"The inner loop should iterate,"},{"Start":"00:25.350 ","End":"00:27.270","Text":"multiplier from 1 to 12,"},{"Start":"00:27.270 ","End":"00:31.215","Text":"and the outer loop should iterate table from 2 to 12."},{"Start":"00:31.215 ","End":"00:34.110","Text":"In Part c, we\u0027re asked at the appropriate point in"},{"Start":"00:34.110 ","End":"00:37.665","Text":"the code to output the contents of the multiplier variable,"},{"Start":"00:37.665 ","End":"00:40.075","Text":"followed by the String x,"},{"Start":"00:40.075 ","End":"00:42.515","Text":"followed by the contents of the table variable,"},{"Start":"00:42.515 ","End":"00:44.680","Text":"followed by the string equals."},{"Start":"00:44.680 ","End":"00:47.870","Text":"On the same line as the previous output in Part d,"},{"Start":"00:47.870 ","End":"00:52.340","Text":"we\u0027re asked to output the product of the multiplier and table variables."},{"Start":"00:52.340 ","End":"00:54.830","Text":"In Part e, we are asked to check that"},{"Start":"00:54.830 ","End":"00:59.540","Text":"the unlimited buffering option is ticked in the terminal window of BlueJ then test"},{"Start":"00:59.540 ","End":"01:03.320","Text":"the method by creating an object on the workbench and"},{"Start":"01:03.320 ","End":"01:07.475","Text":"checking that all 12 lines of each table are correctly output,"},{"Start":"01:07.475 ","End":"01:09.780","Text":"and to correct any errors found."},{"Start":"01:09.780 ","End":"01:12.980","Text":"In Part f, we\u0027re asked to add an integer variable called"},{"Start":"01:12.980 ","End":"01:15.980","Text":"line and to display its contents followed by"},{"Start":"01:15.980 ","End":"01:18.905","Text":"the literal string colon and a space before"},{"Start":"01:18.905 ","End":"01:22.295","Text":"each line of the times table is output to the screen."},{"Start":"01:22.295 ","End":"01:23.810","Text":"Finally, in Part g,"},{"Start":"01:23.810 ","End":"01:25.265","Text":"we\u0027re asked to test the method,"},{"Start":"01:25.265 ","End":"01:28.760","Text":"checking at all a 132 line numbers are"},{"Start":"01:28.760 ","End":"01:33.265","Text":"printed next to each line and to correct any errors found."},{"Start":"01:33.265 ","End":"01:38.405","Text":"Been asked to create a method called while times tables."},{"Start":"01:38.405 ","End":"01:45.634","Text":"It\u0027s going to do very much the same thing as we did previously with for-loop."},{"Start":"01:45.634 ","End":"01:49.790","Text":"Just to show us the difference between the 2 things and the fact"},{"Start":"01:49.790 ","End":"01:53.450","Text":"that really you can do pretty much anything you can do in a for-loop,"},{"Start":"01:53.450 ","End":"01:54.830","Text":"you can do with a while loop,"},{"Start":"01:54.830 ","End":"01:57.830","Text":"but it might be more elegant to do it in a for-loop."},{"Start":"01:57.830 ","End":"02:00.745","Text":"Let\u0027s carry on from 7a."},{"Start":"02:00.745 ","End":"02:05.195","Text":"We got to create an integer variable called table with initial value of 2 this time,"},{"Start":"02:05.195 ","End":"02:10.295","Text":"and a second integer variable called multiplier with an initial value of 1."},{"Start":"02:10.295 ","End":"02:12.155","Text":"Let\u0027s do that."},{"Start":"02:12.155 ","End":"02:20.930","Text":"Int table equals 2 and another integer called multiplier starts at 1."},{"Start":"02:20.930 ","End":"02:24.740","Text":"Then we\u0027re asked to create a pair of nested while loops."},{"Start":"02:24.740 ","End":"02:26.795","Text":"Let\u0027s create the first one."},{"Start":"02:26.795 ","End":"02:28.100","Text":"The inner loop should iterate,"},{"Start":"02:28.100 ","End":"02:29.540","Text":"multiplier from 1 to 12,"},{"Start":"02:29.540 ","End":"02:32.590","Text":"the outer loop should iterate table from 2 to 12."},{"Start":"02:32.590 ","End":"02:39.515","Text":"The outer loop is going to be table and we want to go up to an including 12."},{"Start":"02:39.515 ","End":"02:42.290","Text":"That is the outer loop,"},{"Start":"02:42.290 ","End":"02:49.260","Text":"and the inner loop needs to look like this because it\u0027s going to iterate multiplier."},{"Start":"02:51.430 ","End":"02:55.040","Text":"Part c asks us to,"},{"Start":"02:55.040 ","End":"02:56.870","Text":"at the appropriate point,"},{"Start":"02:56.870 ","End":"03:00.440","Text":"output the contents of the multiplier variable, followed by the String x,"},{"Start":"03:00.440 ","End":"03:02.225","Text":"followed by the contents of the table variable,"},{"Start":"03:02.225 ","End":"03:03.980","Text":"followed by the string equals."},{"Start":"03:03.980 ","End":"03:06.560","Text":"So where would be the appropriate point while the output"},{"Start":"03:06.560 ","End":"03:10.470","Text":"has to happen inside the inner loop?"},{"Start":"03:10.510 ","End":"03:13.940","Text":"This is the appropriate place to do it."},{"Start":"03:13.940 ","End":"03:20.615","Text":"We\u0027re going to put multiplier followed by x"},{"Start":"03:20.615 ","End":"03:28.099","Text":"followed by table and then a literal string with an equal sign in spaces."},{"Start":"03:28.099 ","End":"03:36.035","Text":"That\u0027s the first part and the second part should be print line here rather than print."},{"Start":"03:36.035 ","End":"03:40.805","Text":"We\u0027re going to multiply output."},{"Start":"03:40.805 ","End":"03:45.910","Text":"That\u0027s it. That should be what we need to before, or is it."},{"Start":"03:45.910 ","End":"03:47.990","Text":"Now with a for-loop,"},{"Start":"03:47.990 ","End":"03:49.370","Text":"we would have been done,"},{"Start":"03:49.370 ","End":"03:51.800","Text":"but with a while loop,"},{"Start":"03:51.800 ","End":"03:54.530","Text":"we are responsible for incrementing"},{"Start":"03:54.530 ","End":"03:58.670","Text":"the variables being used to terminate the loop if I was to run this now,"},{"Start":"03:58.670 ","End":"04:01.240","Text":"this would never end because"},{"Start":"04:01.240 ","End":"04:06.560","Text":"table is always going to be less than 12 because it always has 2,"},{"Start":"04:06.560 ","End":"04:07.985","Text":"and it never changes."},{"Start":"04:07.985 ","End":"04:09.910","Text":"Multiply would always be 1."},{"Start":"04:09.910 ","End":"04:12.905","Text":"This would just sit here forever printing the same old line."},{"Start":"04:12.905 ","End":"04:14.285","Text":"If you want me to prove it,"},{"Start":"04:14.285 ","End":"04:19.220","Text":"we can do I forgot to put void in front of this keyword here, so that\u0027s compliant."},{"Start":"04:19.220 ","End":"04:21.690","Text":"Le\u0027s try again. There we go."},{"Start":"04:21.700 ","End":"04:25.390","Text":"Let\u0027s try and run this method and see what happens,"},{"Start":"04:25.390 ","End":"04:29.035","Text":"and it would be, as I just predicted,"},{"Start":"04:29.035 ","End":"04:30.810","Text":"while times table,"},{"Start":"04:30.810 ","End":"04:34.880","Text":"and it just constantly prints out the same output again and again and again and"},{"Start":"04:34.880 ","End":"04:39.275","Text":"the only way I can stop it is to reset the virtual machine by clicking on that."},{"Start":"04:39.275 ","End":"04:40.910","Text":"Because that would run forever."},{"Start":"04:40.910 ","End":"04:42.500","Text":"You can see the output,"},{"Start":"04:42.500 ","End":"04:44.930","Text":"it\u0027s just repeating the same thing again and again"},{"Start":"04:44.930 ","End":"04:48.290","Text":"because I don\u0027t have a termination clause well I do,"},{"Start":"04:48.290 ","End":"04:52.025","Text":"but it\u0027s never going to satisfy this termination clause or this one"},{"Start":"04:52.025 ","End":"04:56.720","Text":"because I haven\u0027t ever changed the value of the multiplier and table variables."},{"Start":"04:56.720 ","End":"04:58.280","Text":"I\u0027m responsible for doing those,"},{"Start":"04:58.280 ","End":"05:01.700","Text":"so each time around this loop,"},{"Start":"05:01.700 ","End":"05:05.585","Text":"I need to increment multiplier,"},{"Start":"05:05.585 ","End":"05:08.795","Text":"and each time round this loop,"},{"Start":"05:08.795 ","End":"05:11.990","Text":"I need to increment table."},{"Start":"05:11.990 ","End":"05:16.225","Text":"That should then do what I need."},{"Start":"05:16.225 ","End":"05:18.330","Text":"Let\u0027s test that then,"},{"Start":"05:18.330 ","End":"05:23.020","Text":"and now it\u0027s worked for 1 table. Interesting. Why has it only worked for 1 table?"},{"Start":"05:23.570 ","End":"05:26.330","Text":"It\u0027s done the 2 times tables,"},{"Start":"05:26.330 ","End":"05:28.040","Text":"which is where I would have started."},{"Start":"05:28.040 ","End":"05:34.310","Text":"Is there something that is wrong here or what was happening here is it will"},{"Start":"05:34.310 ","End":"05:41.310","Text":"finish the first part and table is being incremented to the next table,"},{"Start":"05:41.310 ","End":"05:45.530","Text":"but it will never get to this again because I need to reset"},{"Start":"05:45.530 ","End":"05:53.020","Text":"multiplier to 0 or it will run this first line,"},{"Start":"05:53.020 ","End":"05:55.820","Text":"but it will find that multipliers already"},{"Start":"05:55.820 ","End":"05:59.445","Text":"more than 12 and therefore it\u0027s not going to do any of this."},{"Start":"05:59.445 ","End":"06:02.210","Text":"Low it was coming to this line each time we never saw"},{"Start":"06:02.210 ","End":"06:05.225","Text":"any output because it never got inside the loop."},{"Start":"06:05.225 ","End":"06:08.285","Text":"If I set multiplier to 0,"},{"Start":"06:08.285 ","End":"06:11.570","Text":"it should now do what I need it to do."},{"Start":"06:11.570 ","End":"06:13.670","Text":"Well and spelled it correctly,"},{"Start":"06:13.670 ","End":"06:16.295","Text":"so that will complain and that\u0027s better."},{"Start":"06:16.295 ","End":"06:19.280","Text":"Now let\u0027s see what happens. There we go."},{"Start":"06:19.280 ","End":"06:24.095","Text":"It seems to have corrected the error we had initially."},{"Start":"06:24.095 ","End":"06:26.615","Text":"There\u0027s all of our tables."},{"Start":"06:26.615 ","End":"06:31.910","Text":"The final bit we needed to do was to add an integer variable called line and"},{"Start":"06:31.910 ","End":"06:34.325","Text":"display its contents followed by"},{"Start":"06:34.325 ","End":"06:38.225","Text":"literal string before each line of the times tables output to the screen."},{"Start":"06:38.225 ","End":"06:40.505","Text":"Let\u0027s have a look at that."},{"Start":"06:40.505 ","End":"06:45.555","Text":"We need an integer variable called line on a separate line."},{"Start":"06:45.555 ","End":"06:50.975","Text":"I\u0027m going to start it at 1 because the first line is Line 1."},{"Start":"06:50.975 ","End":"06:53.450","Text":"Where should I output that?"},{"Start":"06:53.450 ","End":"06:56.180","Text":"Before I have any other output,"},{"Start":"06:56.180 ","End":"07:00.320","Text":"I want to output the number of the line."},{"Start":"07:00.320 ","End":"07:05.150","Text":"Here would seem to be an appropriate price system."},{"Start":"07:05.150 ","End":"07:09.035","Text":"I want it to be on the same line."},{"Start":"07:09.035 ","End":"07:15.345","Text":"I put line plus colon and a space."},{"Start":"07:15.345 ","End":"07:21.235","Text":"I also I\u0027m responsible for incrementing line."},{"Start":"07:21.235 ","End":"07:25.820","Text":"I\u0027ll do that each time I print 1 line, I need to increment."},{"Start":"07:25.820 ","End":"07:28.325","Text":"I can do it down here wouldn\u0027t make any difference,"},{"Start":"07:28.325 ","End":"07:31.145","Text":"but it doesn\u0027t need to be inside this inner loop."},{"Start":"07:31.145 ","End":"07:33.575","Text":"Let\u0027s see what happens."},{"Start":"07:33.575 ","End":"07:36.755","Text":"Now and it does do what I expect,"},{"Start":"07:36.755 ","End":"07:42.740","Text":"except for the fact that it\u0027s printing more lines than I would expect."},{"Start":"07:42.740 ","End":"07:45.985","Text":"That\u0027s because it\u0027s going to 0."},{"Start":"07:45.985 ","End":"07:49.040","Text":"It shouldn\u0027t be going to 0, it should be going to 1."},{"Start":"07:49.040 ","End":"07:52.175","Text":"When I set multiplier to 0,"},{"Start":"07:52.175 ","End":"07:55.865","Text":"I don\u0027t want to see that line 0 times something."},{"Start":"07:55.865 ","End":"07:58.285","Text":"That\u0027s the error had there."},{"Start":"07:58.285 ","End":"08:04.970","Text":"Even with a very small, better code is really easy to make multiple small errors."},{"Start":"08:04.970 ","End":"08:07.460","Text":"Now that should be a fix,"},{"Start":"08:07.460 ","End":"08:12.740","Text":"and I get a 132 lines, printed,"},{"Start":"08:12.740 ","End":"08:15.380","Text":"which is exactly what I expected,"},{"Start":"08:15.380 ","End":"08:19.145","Text":"but this time around there was scope for a few errors and I did have a few errors,"},{"Start":"08:19.145 ","End":"08:25.820","Text":"but I do have a 132 why 132 and 144 we didn\u0027t print the 1 times table, did we?"},{"Start":"08:25.820 ","End":"08:31.535","Text":"Because we started at 2 and we\u0027re 12 short of 144,"},{"Start":"08:31.535 ","End":"08:34.205","Text":"which is why it\u0027s a 132."},{"Start":"08:34.205 ","End":"08:35.780","Text":"Hope that made sense."},{"Start":"08:35.780 ","End":"08:38.615","Text":"We have done exactly what we had before."},{"Start":"08:38.615 ","End":"08:43.700","Text":"We\u0027ve got a couple of while loops nested inside each other."},{"Start":"08:43.700 ","End":"08:46.940","Text":"We are responsible for incrementing multiplier inside"},{"Start":"08:46.940 ","End":"08:50.450","Text":"this loop and table and the outer loop,"},{"Start":"08:50.450 ","End":"08:53.975","Text":"but we also have to set multiplier back to 1,"},{"Start":"08:53.975 ","End":"08:56.780","Text":"not 0 as I did but 1,"},{"Start":"08:56.780 ","End":"09:00.875","Text":"so that we see the first line of the table and next time around here."},{"Start":"09:00.875 ","End":"09:03.800","Text":"Otherwise, it will skip everything in here because it thinks"},{"Start":"09:03.800 ","End":"09:07.915","Text":"multiplier is already greater than or equal to 12."},{"Start":"09:07.915 ","End":"09:12.680","Text":"That\u0027s it. I\u0027ll see you in the next one."}],"ID":28030},{"Watched":false,"Name":"Exercise 8","Duration":"7m 2s","ChapterTopicVideoID":26934,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:03.450","Text":"Hi again, everyone. In this exercise we\u0027ve"},{"Start":"00:03.450 ","End":"00:06.544","Text":"been asked to create a new method called doWhileCount,"},{"Start":"00:06.544 ","End":"00:11.415","Text":"and in part A to use a doWhile loop to output the numbers from 1-10."},{"Start":"00:11.415 ","End":"00:14.190","Text":"In part B, we\u0027re asked to test the method and if it"},{"Start":"00:14.190 ","End":"00:17.850","Text":"continues producing output past 10 or appear to have crashed,"},{"Start":"00:17.850 ","End":"00:21.975","Text":"we can reset using the virtual machine icon in BlueJ."},{"Start":"00:21.975 ","End":"00:25.065","Text":"We are asked to then correct any errors found."},{"Start":"00:25.065 ","End":"00:27.270","Text":"In part c, in the same method,"},{"Start":"00:27.270 ","End":"00:30.285","Text":"we add another doWhile loop after the previous one,"},{"Start":"00:30.285 ","End":"00:34.995","Text":"which outputs the numbers from 10-100 in steps of 10."},{"Start":"00:34.995 ","End":"00:42.335","Text":"Once again, we test in part d and if it continues past 100 or appears to have crashed,"},{"Start":"00:42.335 ","End":"00:48.065","Text":"we click on the reset virtual machine icon in BlueJ and correct any errors found."},{"Start":"00:48.065 ","End":"00:50.930","Text":"In part e, we\u0027re asked in the same method"},{"Start":"00:50.930 ","End":"00:54.050","Text":"to add another doWhile loop after the previous one,"},{"Start":"00:54.050 ","End":"01:01.040","Text":"which outputs the numbers from 2,000 to minus 5,000 in steps of 100."},{"Start":"01:01.040 ","End":"01:02.420","Text":"Then in part F,"},{"Start":"01:02.420 ","End":"01:03.925","Text":"we test the method again,"},{"Start":"01:03.925 ","End":"01:07.655","Text":"if it goes past minus 5,000 or appears to crash,"},{"Start":"01:07.655 ","End":"01:09.920","Text":"we can reset using the BlueJ."},{"Start":"01:09.920 ","End":"01:12.095","Text":"But reset virtual machine icon,"},{"Start":"01:12.095 ","End":"01:15.085","Text":"and then we can correct any errors found."},{"Start":"01:15.085 ","End":"01:21.605","Text":"Now we\u0027re going to create some doWhile loop in the method called doWhileCount."},{"Start":"01:21.605 ","End":"01:24.770","Text":"Very similar to what we\u0027ve already done but using doWhile loops."},{"Start":"01:24.770 ","End":"01:26.840","Text":"Let\u0027s have a look at the difference in"},{"Start":"01:26.840 ","End":"01:31.805","Text":"syntax between this and a while loop and this a for loop."},{"Start":"01:31.805 ","End":"01:34.865","Text":"It starts with the keyword do,"},{"Start":"01:34.865 ","End":"01:37.820","Text":"and this time there are no brackets at all,"},{"Start":"01:37.820 ","End":"01:40.835","Text":"you close the brackets."},{"Start":"01:40.835 ","End":"01:44.378","Text":"At the end of the brackets you have the call or"},{"Start":"01:44.378 ","End":"01:48.829","Text":"the clause for the while and it didn\u0027t give me that hint there while expected."},{"Start":"01:48.829 ","End":"01:53.645","Text":"In this case, we\u0027ve been asked to output the numbers from 1-10."},{"Start":"01:53.645 ","End":"01:55.925","Text":"I want to keep going round while,"},{"Start":"01:55.925 ","End":"01:59.475","Text":"let\u0027s say i, is less than 10."},{"Start":"01:59.475 ","End":"02:02.180","Text":"It will still give me an error if I try and"},{"Start":"02:02.180 ","End":"02:05.270","Text":"compile that because this line needs terminating,"},{"Start":"02:05.270 ","End":"02:09.440","Text":"you\u0027ll see there\u0027s a red block there and it\u0027s telling me there\u0027s an error."},{"Start":"02:09.440 ","End":"02:14.840","Text":"It did say that semicolon expected so it\u0027s giving me a hint here in BlueJ currently,"},{"Start":"02:14.840 ","End":"02:18.740","Text":"but the syntax does require a semicolon."},{"Start":"02:18.740 ","End":"02:21.530","Text":"Didn\u0027t require that for a while loop or for a 4 loop and that\u0027s"},{"Start":"02:21.530 ","End":"02:26.330","Text":"because the closing bracket marks off the end of the block."},{"Start":"02:26.330 ","End":"02:29.623","Text":"Here, we\u0027ve got something following the block."},{"Start":"02:29.623 ","End":"02:32.315","Text":"It does need that line terminated."},{"Start":"02:32.315 ","End":"02:35.550","Text":"That would be what the syntax for the loop\u0027s going to look like,"},{"Start":"02:35.550 ","End":"02:38.750","Text":"but we didn\u0027t actually declare a variable i."},{"Start":"02:38.750 ","End":"02:40.215","Text":"We need to make sure we do that."},{"Start":"02:40.215 ","End":"02:44.835","Text":"It starting at 1 and it\u0027s going to go up to 10,"},{"Start":"02:44.835 ","End":"02:50.420","Text":"and the inside of the loop is going to be just the same as before."},{"Start":"02:50.420 ","End":"02:55.450","Text":"We are simply going to print the value of our variable."},{"Start":"02:55.450 ","End":"02:58.910","Text":"That is part A done and let\u0027s have"},{"Start":"02:58.910 ","End":"03:02.435","Text":"a go at doing it and seeing if there\u0027s any errors, there will be an error."},{"Start":"03:02.435 ","End":"03:03.740","Text":"What have I forgotten?"},{"Start":"03:03.740 ","End":"03:06.440","Text":"I forgotten to iterate the variables,"},{"Start":"03:06.440 ","End":"03:08.810","Text":"so I would have got a infinite loop again,"},{"Start":"03:08.810 ","End":"03:10.805","Text":"it would have just printed 1 forever"},{"Start":"03:10.805 ","End":"03:14.990","Text":"because i would never be greater than or equal to 10."},{"Start":"03:14.990 ","End":"03:19.558","Text":"Let\u0027s not make that error and let\u0027s just run it."},{"Start":"03:19.558 ","End":"03:23.645","Text":"I would expect the numbers 1-10 to be output and they are."},{"Start":"03:23.645 ","End":"03:28.895","Text":"Let\u0027s move on to part c. It\u0027s is same as before."},{"Start":"03:28.895 ","End":"03:36.165","Text":"This time we\u0027re going to terminate the loop when i reaches 100,"},{"Start":"03:36.165 ","End":"03:39.050","Text":"so i needs to be less than or equal to 100."},{"Start":"03:39.050 ","End":"03:40.775","Text":"In order for this loop to keep going,"},{"Start":"03:40.775 ","End":"03:43.235","Text":"don\u0027t forget the semicolon."},{"Start":"03:43.235 ","End":"03:46.820","Text":"We\u0027re going to increment i by 10 each"},{"Start":"03:46.820 ","End":"03:51.650","Text":"time around a loop and obviously we still need to output it."},{"Start":"03:51.650 ","End":"03:59.660","Text":"There we go, so system.out.printline and the increment is inside there."},{"Start":"03:59.660 ","End":"04:04.905","Text":"That will output from 10-100 in steps of 10."},{"Start":"04:04.905 ","End":"04:07.570","Text":"I should really set the value of i here,"},{"Start":"04:07.570 ","End":"04:13.090","Text":"but I know it\u0027s already going to be 10 when this loop finishes, or is it?"},{"Start":"04:13.090 ","End":"04:15.580","Text":"Let\u0027s try. Let\u0027s see what happens."},{"Start":"04:15.580 ","End":"04:19.270","Text":"What\u0027s happened is, is actually 11 and 21 and so on."},{"Start":"04:19.270 ","End":"04:21.955","Text":"Because at the end of the loop,"},{"Start":"04:21.955 ","End":"04:28.420","Text":"it had already incremented the value path 10-11."},{"Start":"04:28.420 ","End":"04:34.410","Text":"I do indeed need to set an i to 10 again,"},{"Start":"04:34.410 ","End":"04:38.980","Text":"because i would\u0027ve been incremented at this point and reached 11."},{"Start":"04:38.980 ","End":"04:41.440","Text":"The while clause then ran saying,"},{"Start":"04:41.440 ","End":"04:43.960","Text":"is it less than or equal to 10?"},{"Start":"04:43.960 ","End":"04:45.610","Text":"Now it\u0027s not, it\u0027s 11."},{"Start":"04:45.610 ","End":"04:47.635","Text":"Then it would exit out of the loop."},{"Start":"04:47.635 ","End":"04:50.142","Text":"If I had carried on printing, it will be 11, 21,"},{"Start":"04:50.142 ","End":"04:52.230","Text":"31 and so on,"},{"Start":"04:52.230 ","End":"04:54.700","Text":"so I do need to reset i to 10 there."},{"Start":"04:54.700 ","End":"04:58.280","Text":"Now, trust me, when I say that that will work and we\u0027ll test it next time around."},{"Start":"04:58.280 ","End":"05:01.790","Text":"In the final part, part E and F,"},{"Start":"05:01.790 ","End":"05:11.125","Text":"we are going to use the doWhile loop to output the numbers from 2,000 to minus 5,000."},{"Start":"05:11.125 ","End":"05:14.240","Text":"This is a slight variation on the earlier one,"},{"Start":"05:14.240 ","End":"05:17.520","Text":"where we would start to get 2,020,"},{"Start":"05:17.520 ","End":"05:22.970","Text":"and so the odd numbers came out at the end slightly [inaudible]."},{"Start":"05:22.970 ","End":"05:29.525","Text":"Let\u0027s have a look. This course that should be greater than or equal to minus 5,000."},{"Start":"05:29.525 ","End":"05:30.800","Text":"Whilst that is true,"},{"Start":"05:30.800 ","End":"05:33.059","Text":"we carry on printing."},{"Start":"05:33.140 ","End":"05:37.950","Text":"The value is in here."},{"Start":"05:37.950 ","End":"05:44.255","Text":"What we need to do with i is to subtract 100 each time around the loop."},{"Start":"05:44.255 ","End":"05:49.415","Text":"We do need an initial value of i of 2,000,"},{"Start":"05:49.415 ","End":"05:54.215","Text":"not 2,020 because it\u0027s easier to see the result with 2,000."},{"Start":"05:54.215 ","End":"05:59.162","Text":"That\u0027s it. Let\u0027s see what happens when we test it."},{"Start":"05:59.162 ","End":"06:08.070","Text":"Yes, it\u0027s hit minus 5,000 and it started at 2,000 here,"},{"Start":"06:08.070 ","End":"06:10.340","Text":"and we can still see the previous output as well,"},{"Start":"06:10.340 ","End":"06:14.180","Text":"the numbers 1-10 and then 10-100."},{"Start":"06:14.180 ","End":"06:17.405","Text":"We fix that problem that we had earlier wherever it\u0027s going from 11."},{"Start":"06:17.405 ","End":"06:22.130","Text":"The doWhile loop looks very similar to the while loop."},{"Start":"06:22.130 ","End":"06:25.640","Text":"We\u0027ve just got the termination clause at the bottom,"},{"Start":"06:25.640 ","End":"06:30.610","Text":"that does mean that the inside is always going to run at least once."},{"Start":"06:30.610 ","End":"06:33.515","Text":"If that\u0027s going to make a difference to your program,"},{"Start":"06:33.515 ","End":"06:36.260","Text":"didn\u0027t particularly in this one compared to the while loop 1,"},{"Start":"06:36.260 ","End":"06:37.805","Text":"they do exactly the same thing."},{"Start":"06:37.805 ","End":"06:42.620","Text":"But it could be possible for a doWhile loop to be more appropriate than"},{"Start":"06:42.620 ","End":"06:48.825","Text":"a while loop in situations where you want the inside always run at least once."},{"Start":"06:48.825 ","End":"06:52.445","Text":"If that\u0027s the case, then a doWhile loop it\u0027s going to be more appropriate."},{"Start":"06:52.445 ","End":"06:54.020","Text":"That\u0027s it for this one,"},{"Start":"06:54.020 ","End":"06:55.445","Text":"and in the final video,"},{"Start":"06:55.445 ","End":"07:00.500","Text":"we will see something slightly more useful using a doWhile loop,"},{"Start":"07:00.500 ","End":"07:03.180","Text":"so I\u0027ll see you shortly for that one."}],"ID":28031},{"Watched":false,"Name":"Exercise 9","Duration":"10m 22s","ChapterTopicVideoID":26935,"CourseChapterTopicPlaylistID":255413,"HasSubtitles":true,"ThumbnailPath":null,"UploadDate":null,"DurationForVideoObject":null,"Description":null,"MetaTitle":null,"MetaDescription":null,"Canonical":null,"VideoComments":[],"Subtitles":[{"Start":"00:00.000 ","End":"00:03.210","Text":"Hello again, everyone. In this exercise,"},{"Start":"00:03.210 ","End":"00:05.940","Text":"we\u0027re asked to create a new method called primeNumbers and in"},{"Start":"00:05.940 ","End":"00:08.910","Text":"Part a to declare and initialize a number of variables."},{"Start":"00:08.910 ","End":"00:12.490","Text":"Firstly, a variable called number with the value 2,"},{"Start":"00:12.490 ","End":"00:15.885","Text":"then a variable called factorsFound with the value 0,"},{"Start":"00:15.885 ","End":"00:18.720","Text":"limit with a value 20,"},{"Start":"00:18.720 ","End":"00:21.455","Text":"and a factor with no initial value."},{"Start":"00:21.455 ","End":"00:24.335","Text":"In Part b, we are asked to create a do while loop,"},{"Start":"00:24.335 ","End":"00:29.995","Text":"which terminates when number is no longer less than or equal to limit."},{"Start":"00:29.995 ","End":"00:31.470","Text":"In Part c,"},{"Start":"00:31.470 ","End":"00:33.770","Text":"within the do while loop that we created,"},{"Start":"00:33.770 ","End":"00:37.685","Text":"we\u0027re asked to first of all assign the value of number to factor,"},{"Start":"00:37.685 ","End":"00:40.880","Text":"then to create another do while loop which terminates"},{"Start":"00:40.880 ","End":"00:44.390","Text":"when factor is no longer greater than or equal to 2."},{"Start":"00:44.390 ","End":"00:46.265","Text":"Within the inner while loop,"},{"Start":"00:46.265 ","End":"00:50.510","Text":"we\u0027re asked to determine whether number divided by factor gives"},{"Start":"00:50.510 ","End":"00:56.120","Text":"a remainder of 0 and to increment the factorsFound variable when it does."},{"Start":"00:56.120 ","End":"00:58.815","Text":"Finally, within the inner do while loop"},{"Start":"00:58.815 ","End":"01:02.000","Text":"but after the conditional statement in Part iii above,"},{"Start":"01:02.000 ","End":"01:05.275","Text":"we\u0027re asked to decrement the factor variable."},{"Start":"01:05.275 ","End":"01:09.020","Text":"In Part d directly after the inner do while loop,"},{"Start":"01:09.020 ","End":"01:11.645","Text":"but inside the outer do while loop,"},{"Start":"01:11.645 ","End":"01:14.975","Text":"we\u0027re asked to check if factorsFound=1."},{"Start":"01:14.975 ","End":"01:18.800","Text":"If so, to output a message showing the current value of"},{"Start":"01:18.800 ","End":"01:23.310","Text":"the number variable followed by the literal string \"is a prime.\""},{"Start":"01:23.310 ","End":"01:27.320","Text":"In Part d ii, were asked to increment the number variable and in"},{"Start":"01:27.320 ","End":"01:31.715","Text":"d iii to assign a value 0 to factorsFound."},{"Start":"01:31.715 ","End":"01:34.460","Text":"Then we\u0027re asked to test the method produces"},{"Start":"01:34.460 ","End":"01:37.645","Text":"an output of all the prime numbers below 20,"},{"Start":"01:37.645 ","End":"01:41.750","Text":"these numbers here, and to correct any errors found."},{"Start":"01:41.750 ","End":"01:47.720","Text":"Finally, we\u0027re asked to change the initial value of limit to 100 and to test the method"},{"Start":"01:47.720 ","End":"01:54.405","Text":"again and that it produces output of all of the prime numbers below 100,"},{"Start":"01:54.405 ","End":"01:56.264","Text":"which would be these numbers,"},{"Start":"01:56.264 ","End":"01:59.665","Text":"and then to correct any errors found."},{"Start":"01:59.665 ","End":"02:06.440","Text":"Let\u0027s go and create a method called primeNumbers."},{"Start":"02:06.440 ","End":"02:10.930","Text":"Then we\u0027ve got to create some variables as usual in Part a."},{"Start":"02:10.930 ","End":"02:13.460","Text":"They look like they\u0027re all integers,"},{"Start":"02:13.460 ","End":"02:15.560","Text":"and so we can do that in one line."},{"Start":"02:15.560 ","End":"02:22.790","Text":"Number=2, factorsFound=0,"},{"Start":"02:22.790 ","End":"02:29.765","Text":"limit=20, and factor has no initial value."},{"Start":"02:29.765 ","End":"02:31.790","Text":"That\u0027s it for Part a."},{"Start":"02:31.790 ","End":"02:34.820","Text":"Then for Part b, we\u0027re asked to create a do while loop,"},{"Start":"02:34.820 ","End":"02:39.935","Text":"which terminates when number is no longer less than or equal to limit."},{"Start":"02:39.935 ","End":"02:45.260","Text":"Let\u0027s just think about the logic of the block."},{"Start":"02:45.260 ","End":"02:52.220","Text":"What needs to go in here terminates when number is no longer less than or equal to limit."},{"Start":"02:52.220 ","End":"02:59.255","Text":"Number needs to be greater than or equal to limit."},{"Start":"02:59.255 ","End":"03:05.945","Text":"As soon as it\u0027s no longer greater than or equal to limit, it will terminate."},{"Start":"03:05.945 ","End":"03:08.255","Text":"That\u0027s the Part b done."},{"Start":"03:08.255 ","End":"03:11.600","Text":"Then within this do while loop,"},{"Start":"03:11.600 ","End":"03:13.385","Text":"Part c i,"},{"Start":"03:13.385 ","End":"03:18.970","Text":"we\u0027re asked to assign the value of number to factor."},{"Start":"03:22.490 ","End":"03:28.250","Text":"Number goes into factor because we are assigning the value of number to factor."},{"Start":"03:28.250 ","End":"03:30.485","Text":"Then in Part c ii,"},{"Start":"03:30.485 ","End":"03:33.720","Text":"we were asked to create another do while loop,"},{"Start":"03:33.720 ","End":"03:35.970","Text":"so that\u0027s nested do while loop."},{"Start":"03:35.970 ","End":"03:41.360","Text":"Let\u0027s do that before we think about the termination clauses to do the blocks there."},{"Start":"03:41.360 ","End":"03:45.935","Text":"Let\u0027s then put while and it\u0027s saying"},{"Start":"03:45.935 ","End":"03:50.570","Text":"terminate when factor is no longer greater than or equal to 2."},{"Start":"03:50.570 ","End":"03:55.775","Text":"I want factor to be greater than or equal to 2."},{"Start":"03:55.775 ","End":"03:58.430","Text":"When it\u0027s not, it will terminate."},{"Start":"03:58.430 ","End":"04:01.100","Text":"Inside the inner do loop,"},{"Start":"04:01.100 ","End":"04:05.405","Text":"we determine whether a number divided by factor gives"},{"Start":"04:05.405 ","End":"04:09.680","Text":"a remainder of 0 and increment the factorsFound variable when it does."},{"Start":"04:09.680 ","End":"04:12.710","Text":"That sounds like we need an if statement."},{"Start":"04:12.710 ","End":"04:20.270","Text":"If number modulo factor=0,"},{"Start":"04:20.270 ","End":"04:23.214","Text":"because that\u0027s what we\u0027re doing when we use the modulo operator,"},{"Start":"04:23.214 ","End":"04:30.110","Text":"we\u0027re dividing factor into number and then we\u0027re comparing the remainder to 0,"},{"Start":"04:30.110 ","End":"04:32.525","Text":"see if there is no remainder."},{"Start":"04:32.525 ","End":"04:36.890","Text":"If it does, we increment the factorsFound variable."},{"Start":"04:36.890 ","End":"04:41.420","Text":"I can do that on the same line as the if statement."},{"Start":"04:41.420 ","End":"04:44.375","Text":"I don\u0027t need curly brackets if it\u0027s just one statement,"},{"Start":"04:44.375 ","End":"04:49.775","Text":"I can just put it immediately after the condition and then terminate with a semicolon."},{"Start":"04:49.775 ","End":"04:53.180","Text":"Then within the inner do while loop but after"},{"Start":"04:53.180 ","End":"04:56.555","Text":"the conditional statement that we\u0027ve just done,"},{"Start":"04:56.555 ","End":"04:59.240","Text":"we decrement the factor variable."},{"Start":"04:59.240 ","End":"05:04.980","Text":"We say factor minus minus to decrement."},{"Start":"05:04.980 ","End":"05:07.965","Text":"That\u0027s Part iv done."},{"Start":"05:07.965 ","End":"05:09.790","Text":"Then in Part d,"},{"Start":"05:09.790 ","End":"05:14.615","Text":"it\u0027s saying directly after the inner do while loop."},{"Start":"05:14.615 ","End":"05:19.940","Text":"This is the inner do while loop but inside the outer do while loop."},{"Start":"05:19.940 ","End":"05:22.280","Text":"This is the line that\u0027s directly after it."},{"Start":"05:22.280 ","End":"05:25.345","Text":"Check if factorsFound is=1."},{"Start":"05:25.345 ","End":"05:28.190","Text":"If so, output a message showing the current value of"},{"Start":"05:28.190 ","End":"05:32.525","Text":"the number variable followed by the literal string \"is a prime.\""},{"Start":"05:32.525 ","End":"05:35.720","Text":"We\u0027re going to need another if statement here and this time we\u0027re"},{"Start":"05:35.720 ","End":"05:42.435","Text":"saying if factorsFound is=1."},{"Start":"05:42.435 ","End":"05:45.050","Text":"When it is, we\u0027ll do another one line"},{"Start":"05:45.050 ","End":"05:49.130","Text":"if statement here because there\u0027s no else or anything else."},{"Start":"05:49.130 ","End":"05:50.390","Text":"There\u0027s only single line,"},{"Start":"05:50.390 ","End":"05:53.510","Text":"we don\u0027t need to have curly brackets."},{"Start":"05:53.510 ","End":"05:59.060","Text":"System out print line and we want to say the current value of"},{"Start":"05:59.060 ","End":"06:02.090","Text":"the number variable and then follow it with"},{"Start":"06:02.090 ","End":"06:08.480","Text":"a literal string \"is a prime\" and that\u0027s done."},{"Start":"06:08.480 ","End":"06:12.950","Text":"Then after that, but still inside the inner do while loop,"},{"Start":"06:12.950 ","End":"06:20.495","Text":"we want to increment a number variable and then assign the value 0 to factorsFound."},{"Start":"06:20.495 ","End":"06:23.105","Text":"That\u0027s everything we\u0027ve been asked to do."},{"Start":"06:23.105 ","End":"06:24.350","Text":"You should be able to run this."},{"Start":"06:24.350 ","End":"06:26.690","Text":"Now we\u0027ve got a do while loop and then"},{"Start":"06:26.690 ","End":"06:29.700","Text":"another one embedded inside that outer do while loop."},{"Start":"06:29.700 ","End":"06:35.805","Text":"Then a number of lines before and after do in a do while loop."},{"Start":"06:35.805 ","End":"06:38.210","Text":"We\u0027ve also got some conditionals in various places"},{"Start":"06:38.210 ","End":"06:40.715","Text":"that are a lot more complex than what we\u0027ve seen before."},{"Start":"06:40.715 ","End":"06:47.965","Text":"Let\u0027s see if we get what\u0027s expected in Part e. So create our object."},{"Start":"06:47.965 ","End":"06:49.925","Text":"We now have quite a few methods,"},{"Start":"06:49.925 ","End":"06:51.890","Text":"so we need to find where our method is."},{"Start":"06:51.890 ","End":"06:53.930","Text":"There it is, void primeNumbers."},{"Start":"06:53.930 ","End":"06:58.160","Text":"Let\u0027s run that, we\u0027re expecting a series of numbers,"},{"Start":"06:58.160 ","End":"07:00.055","Text":"but I only get one."},{"Start":"07:00.055 ","End":"07:01.955","Text":"What have I done wrong?"},{"Start":"07:01.955 ","End":"07:05.330","Text":"We know there\u0027s more than one prime number below 20."},{"Start":"07:05.330 ","End":"07:09.005","Text":"I have done something wrong somewhere."},{"Start":"07:09.005 ","End":"07:12.140","Text":"What it is, is this line here."},{"Start":"07:12.140 ","End":"07:16.070","Text":"I\u0027ve said, well, number is greater than or equal to limit."},{"Start":"07:16.070 ","End":"07:19.340","Text":"That\u0027s going to work the first time round because"},{"Start":"07:19.340 ","End":"07:22.640","Text":"it will always run once, this thing here."},{"Start":"07:22.640 ","End":"07:28.865","Text":"But number is not going to be greater than or equal to limit at any point."},{"Start":"07:28.865 ","End":"07:32.840","Text":"It will run once, but it will never run again because number is only"},{"Start":"07:32.840 ","End":"07:37.220","Text":"2 when we start and it gets incremented by 1 each time around the loop."},{"Start":"07:37.220 ","End":"07:39.260","Text":"I\u0027ve got this the wrong way round."},{"Start":"07:39.260 ","End":"07:44.374","Text":"It should be while number is less than or equal to limit."},{"Start":"07:44.374 ","End":"07:48.230","Text":"That hopefully will fix my problem."},{"Start":"07:48.230 ","End":"07:50.250","Text":"Let\u0027s see if that\u0027s true."},{"Start":"07:50.250 ","End":"07:54.650","Text":"Sure enough, I get all of the prime numbers below 20; 2, 3,"},{"Start":"07:54.650 ","End":"07:56.450","Text":"5, 7, 11,"},{"Start":"07:56.450 ","End":"07:59.750","Text":"13, 17, and 19."},{"Start":"07:59.750 ","End":"08:02.840","Text":"I was asked then to change in Part f,"},{"Start":"08:02.840 ","End":"08:08.117","Text":"the initial value of limit to 100 because it was only 20 before,"},{"Start":"08:08.117 ","End":"08:14.045","Text":"just to see if my code still works for all of the prime numbers below 100."},{"Start":"08:14.045 ","End":"08:19.045","Text":"Let\u0027s see if that does indeed generate the output I\u0027m expecting."},{"Start":"08:19.045 ","End":"08:22.970","Text":"There we go, all the numbers that I had previously,"},{"Start":"08:22.970 ","End":"08:25.010","Text":"but then we\u0027re going beyond 20 now,"},{"Start":"08:25.010 ","End":"08:28.025","Text":"all the way up to but not including 100."},{"Start":"08:28.025 ","End":"08:30.590","Text":"These are all of the numbers below 100."},{"Start":"08:30.590 ","End":"08:32.300","Text":"100 is not a prime number itself,"},{"Start":"08:32.300 ","End":"08:33.605","Text":"so that\u0027s why we\u0027re not going to see 100,"},{"Start":"08:33.605 ","End":"08:36.080","Text":"but there will be a number just above it."},{"Start":"08:36.080 ","End":"08:38.750","Text":"That is it."},{"Start":"08:38.750 ","End":"08:41.900","Text":"Quite complex program really."},{"Start":"08:41.900 ","End":"08:45.824","Text":"What it was doing was this inner do"},{"Start":"08:45.824 ","End":"08:51.095","Text":"while loop here was trying to see how many factors we find."},{"Start":"08:51.095 ","End":"08:53.225","Text":"A prime number by definition,"},{"Start":"08:53.225 ","End":"08:57.050","Text":"is only a prime number if it only has one factor,"},{"Start":"08:57.050 ","End":"08:58.840","Text":"not including 1,"},{"Start":"08:58.840 ","End":"09:03.780","Text":"so is divisible by itself and 1."},{"Start":"09:03.780 ","End":"09:05.885","Text":"We weren\u0027t dividing by 1 anyway here,"},{"Start":"09:05.885 ","End":"09:08.705","Text":"so we were just looking to see if it had more than one factor."},{"Start":"09:08.705 ","End":"09:13.010","Text":"If it did, we know that it\u0027s not a prime number,"},{"Start":"09:13.010 ","End":"09:15.740","Text":"but if it did I only have exactly one factor,"},{"Start":"09:15.740 ","End":"09:19.475","Text":"then it was a prime number and we printed out this line here."},{"Start":"09:19.475 ","End":"09:23.060","Text":"It just carried on until it reached the limit,"},{"Start":"09:23.060 ","End":"09:25.690","Text":"in which case it just stop."},{"Start":"09:25.690 ","End":"09:31.925","Text":"We can make this as big as we like and it would generate a whole series of numbers."},{"Start":"09:31.925 ","End":"09:36.215","Text":"The beauty of programming really is you can do with very little effort,"},{"Start":"09:36.215 ","End":"09:38.060","Text":"a lot more work."},{"Start":"09:38.060 ","End":"09:39.895","Text":"Let\u0027s just see that and look at that,"},{"Start":"09:39.895 ","End":"09:41.810","Text":"all of the prime numbers up to 1,000."},{"Start":"09:41.810 ","End":"09:45.335","Text":"We could do 1,000,000 if we wanted to and it would happily do them,"},{"Start":"09:45.335 ","End":"09:48.560","Text":"but perhaps not in this exercise right now."},{"Start":"09:48.560 ","End":"09:52.325","Text":"That\u0027s it, so I hope that was straightforward."},{"Start":"09:52.325 ","End":"09:55.040","Text":"In the end, there was a lot of different steps."},{"Start":"09:55.040 ","End":"10:00.200","Text":"But the real main thing we\u0027re looking here for and my deliberate error at the beginning"},{"Start":"10:00.200 ","End":"10:05.645","Text":"there was just to show you that you\u0027d always run at least once a do while loop."},{"Start":"10:05.645 ","End":"10:07.700","Text":"That\u0027s why when I had an error before,"},{"Start":"10:07.700 ","End":"10:09.335","Text":"when I had this the wrong way around,"},{"Start":"10:09.335 ","End":"10:11.675","Text":"it did show at least 1 prime number,"},{"Start":"10:11.675 ","End":"10:14.105","Text":"but it didn\u0027t show all of them because"},{"Start":"10:14.105 ","End":"10:17.690","Text":"this was terminating the loop after it had done one."},{"Start":"10:17.690 ","End":"10:22.680","Text":"Thanks very much for watching and I\u0027ll see you soon."}],"ID":28032}],"Thumbnail":null,"ID":255413}]
[{"ID":237667,"Videos":[26341,26342]},{"ID":237668,"Videos":[26343,26344,28018,28019,28020,28021]},{"ID":237669,"Videos":[26345,26346,26823,27342,27343,27344,27345,27346]},{"ID":246357,"Videos":[26824,26825,27334,27335,27336,27337,27338,27339,27340,27341]},{"ID":246358,"Videos":[26827,26828,26829,27350,27351,27352,27353,27354,27355,27356,28022]},{"ID":255413,"Videos":[27347,27348,27349,28024,28025,28026,28027,28028,28029,28030,28031,28032]}];
[26343,26344,28018,28019,28020,28021];
1.2
11

Continue watching

Get unlimited access to 1500 subjects including personalised modules
Start your free trial
proprep
General Modules
  • Intermediate And Advanced Algebra
  • Linear Algebra
  • Calculus I
  • Calculus II
  • Calculus III
  • Complex Analysis
  • Ordinary Differential Equations
  • Partial Differential Equations
  • Probability
  • Statistics
  • Statistics Arabic
  • Physics 1 Mechanics Waves and Thermodynamics
  • Physics 2 Electricity and Magnetism
  • Physics Arabic Introduction
  • General Chemistry
  • General Chemistry Arabic
  • General Chemistry Spanish
  • Organic Chemistry
  • Organic Chemistry Arabic
  • Introduction to Biology
  • Biochemistry
  • Introduction to Financial Accounting and Reporting
  • Principles of Programming
  • Learn Parametric CAD and CAM Design with Fusion 360
Company
  • Blog
  • Press Room
  • For Educators
Contact us
  • Call us:+44-161-850-4375
  • Email us:[email protected]
Social
  • Facebook
  • Twitter
  • LinkedIn

  • Youtube
  • Instagram
  • Whatsapp
  • © 2023 Proprep. All rights reserved.
  • Terms of Service
  • Cookies Policy
  • Privacy Notice

Proprep is not endorsed by any college or university

  • © 2023 Proprep. All rights reserved.
All
Universities
Modules/Textbooks
Chapters
Topics
Close

Universities

Customised Modules

General Modules

Textbooks

Chapters

Topics

We couldn't find any results for

Can't find your subject or module?

Upload your syllabus now and our team will create a customised module especially for you!
Upload Syllabus

Announcement

Ok
Yes No
Alert

Upload your syllabus

and we will create a personalised module (just for you) in less than 48 hours...

Your file

Drag and drop files or browse Add file
Uploaded Image

Sign up to get your personalised module

See how it works

Now check your email for your code

Send code again

Verify code

What subjects are you looking for?

Subjects

Enter your email and will notify you when we add the subject

Upload syllabus

Drag and drop files or browse Add file
Uploaded Image
Cancel