 All right, time for today's mini lecture and we're going to go over some of the topics for the midterm, which is coming up on Wednesday. These first three are from the first, first four are from the first chapter. And you should probably know the difference between a syntax error. The compiler catches that a runtime error. You find that when the program runs, hence the name. And the logic error is no error message. But the program doesn't do what you want. How the Java compiler works. You have to understand that you have your source code and the compiler translates that to JVM bytecode or just bytecode. And then the Java virtual machine executes the bytecode declaring and initializing variables. We've been doing that pretty much all semester. You have your data type, the name, the assignment operator and some value to declare and initialize. So for example, in quantity becomes 42. You can also have something like, for example, float or not float hello, or Thysenberg double price, and then you can initialize it in a statement later on. Declaring and initializing a constant when we have a constant is called final. So for example, final int and by convention. They're all uppercase, which means we use underscores to separate individual words. And once you set a constant, you cannot change it again. Low level languages run directly on the machine's hardware. And this would be assembly or machine language. And then a high level, let's call this low, and a high level needs to be translated to run on the hardware. And that would be things like CC plus plus Python, Java, etc. Portable languages. Look at this one up to make absolutely sure, but basically can run the same source code on multiple different kinds of hardware. Writing a comment in Java. This is the one line comment. Everything to the end of the line is ignored. And this is the multi line comment between a slash star and star slash know the priority of operations integer versus floating point division, some very interesting stuff goes on here. So for example, if I have let's say, oh, oh, I don't know. 19 divided by two that comes out to nine. Why because when you do an integer division integers divided by integers become integers. Now, let's go into a shell for this one. I think this would be a good idea. So let's say I say system dot out dot print line of 19 divided by two. Now this one's interesting. Let's say I say, double X becomes 19 divided by two. What do you think's going to happen when we get X is it going to be nine and a half or nine. And the answer is it's going to be 9.0. And the reason is, because we always always always evaluate the right hand side completely before even looking at the left hand side of the assignment. So we divide it by two as integers is nine and that gets promoted to a double which gives us 9.0. And in fact, if we were to do a system dot out dot print line of X, we would get 9.0. Around this problem is to use a cast. If I say double X becomes double 19 divided by two, then we'll get nine and a half, or I could say 19.0 divided by two, or 19 divided by 2.0. Yeah, I guess I should have an assignment in there shouldn't I. There we go. And then I get my nine and a half. Oh hi somebody has come in here. Hold on let me stop sharing for a moment. Hi, do you have any questions. Let me pause there. Okay, back to this. Well I'd already talked about that format specifiers for print f percent D is good for integer and long integer percent sign dot to f or however many you want is good for double percent sign s is for strings. So we're not going to be carrying a lot about them percent sign C is for character type variables. You know I don't remember what it is for bullions. But we don't need those aren't going to come up on the test anyway, and percent sign n is same as backslash and which means new line. Okay, you know how to write the methods header. So how does a string work with strings and numbers. Well that's sort of interesting. So for example, yeah, number plus numbers number that's not that that's a. What if I say three plus, and I add a string to it, that gives me three five. If I have let's say five plus three, it will convert because I have it whenever you have a string everything gets converted to a string. So if I say car plus three plus seven, I'll get car three seven, but if I three say three plus seven plus cars. It's going to do them from left to right so I'll get 10 because it's numbers and then I'll add on the string and I'll get 10 cars. Okay. And then the geometric functions, very functions take radians as their input. So for example, if I want the sign of 30 degrees, and I try math dot sign of 30, that's not going to give me what I want. Instead I have to say math dot sign of math dot to radians of 30. And that will convert 30 degrees to radians and then we can take the sign and we'll get one, one half, or as close as we can get to one half because of the way floating point works local variables. Anything you declare inside braces is local to that block. No method calls can be nested and usually I'll just do this with math because it's easier I can say math dot sign of math dot square root of math dot absolute value of X. So those are I've composed three functions. I've nested the absolute value call comes first then I take the square root and then I take the sign of that relational operators are going to be less than greater than or equal greater than or equal equals remember that the two equal signs in a row and not equal. And by the way I also forgot the. I think they're called the conditional operators. And those are and or and not switch statement. Remember that each case, the switch should have a break after it. The break, the switch falls through to the next case, and you use the default case to handle everything at the end that wasn't caught before. If statement we've talked about that oh evaluating compound conditions using and remember that what we have here is. And which is and both conditions must be true for the result to be true either condition. Is true. The whole thing is true. So that's a real quick overview of that. Let's go real quick here and do this midterm sample. So is Java low level language or high level language answer. It's a high level language. Now there's a kind of thing I love to put on a test is correct the errors in this job of program when I'm doing this with a class full of people. It's really great because everybody finds all the errors. First error is there's no semicolon here. That looks good. That looks good. Oh no that doesn't look good this has to be a small M. In fact what I'm going to do is I'm going to hold I'm going to put that in italics so we can see it here. So put italics here and in fact what make it read so we can see it. Okay this is correct. Enter base double base becomes input dot next int. Well the problem is if this is a double then this has to be next double. Otherwise if somebody tries to type in a double variable like 3.5 it'll go kaboom double height becomes input dot next double cool. Now this one's a tricky one. The formula half the base times the height and somebody say oh I see that that shouldn't be a plus sign that should be an asterisk. I see that that's so far so good. Except this is going to screw them up because remember into we go from left to right and integer divided by integer is integer so one divided by two is zero. So the area will always come out to zero. Several different ways to correct it you could say 1.0. 2.0 times the base times the height or my preference would be just to say 0.5. And then here we should have a capital S system and the area is plus area that looks good input dot close and oopsie I am missing a closing curly brace there. I think I've caught all of them. Yeah, it's called input input dot close. Yeah, that looks good. I'm happy. Okay, what kind of error is it if you have unbalanced parentheses you can either say a compile error or a syntax error. Write a Java comment well we know about I already talked about that, namely, or you could go with, I keep forgetting that I'm in a word processor not in a text editor here. What does this expression work out to. Well the fact that I have one floating point number in here means that I'm going to have a double result. There's no question about that. All right so what happens first while we have five times three which is 15. And remember multiplication and division go from left to right there are people priority. So I have 15 divided by two which is seven and a half. So seven and a half is 14 and a half minus one should be 13 and a half. And let's just go real quick into J shell and see if that's correct seven plus five times three divided by 2.0 minus one. Yep 13 and a half. I'm happy. Okay. There's less than B and C is greater than D. A is not equal to be or C is equal to D remember you mean the two equal signs in a row. Okay now here's a fun one what would be the value number after the following statements actually we've got a lovely switch statement here. So number starts off as one. And our character is the letter C. This case doesn't match. This case doesn't match. This case does match which says number to 67 but there's no break so we fall straight through the case D with number being 68 and we break out and so the value of number will be 68. Okay. This is one of these where you're going to have to do a little bit of work. So here are values for ABC and D. And I'm going to have you plug them into this expression. Well let's see is 50 less than 40. No it is not. So this part is false. That means we have to look at C and D. 70 is definitely not equal to 60. So this part is false. And this part is true. And because I have an or that whole thing works out to true and we're going to print good. Okay is 60 less than 30. No it is not. Is 20 not equal to 20. No it's not. That means it's bad. Is 20 less than 70. Yes it is. Okay well this is this first one is true we know the whole thing is going to be true it's an or. I don't even have to look at the other one. And 45 is less than 85 is less than B. Which means I don't even have to care about C and D as long as I have one of them that's true the whole thing is true and it's going to be good. And then, oh, this is this is this is one of those things where you have to know what you're doing and keep track of stuff. Okay so here's what I'm going to do I'm going to bring up this here. I'm going to get this. I need to make this smaller here so I can keep track of things here. My message window there. All right so here's what I would do. Yeah, I always start with my main. So here in Maine I have a which is a seven and E which is a five. Now I'm calling do stuff. So here I go into do stuff and a here gets copied into this into a. That means oops. So inside do stuff. A is going to be a copy of a. And he gets copied into be so B is now five. I'm going to do more stuff and so I'm going to do another call here called do more stuff. C is going to be a copy of a times B. So C is going to be 35. A plus B is 12 and that gets copied into D. Now I have another. Excuse me. This is not be doors. We do more stuff. Now I have a becomes C minus D. And this a here is local to do more stuff. It has nothing to do with any of these other variables called a. So a becomes C minus D which is 23. And I print out in more stuff. A is 23. Now I return a. The result of calling do more stuff was 23 and that's going to go into C. So in do stuff C is going to become 23. And then I will print out doing stuff with. A B and C with seven and five. A gives 23. There's no return statement in here. It's void, but when I'm done with do stuff, I come back to main. And I'm done. So let's go and let's take a look at this here. And let's go here. Let's. Save this as. I don't want to just save it there. That's, that's a totally different course. And we'll call this example. Java. And let's compile it. Oh, it's example program. Okay, fine. I'm too lazy to rename it. Call the example. And let's run it and see what happens. In more stuff is 23 doing stuff with seven and five gives 23. And that is exactly what I predicted would happen. But again, I did this. Don't be a friend. I did this on the screen because. A, I don't have a webcam that will. Reverse left and right. So you can see me writing stuff and B. My handwriting is so crappy that nobody can read it anyway. But there's no rule that says you can't use paper and pencil to do exactly what I did here. To keep track of all your variables. Namely, you know, which, which method am I in and what are my variables. That's an easy way to keep track of it. Well, I want to say it's an easy way to keep track of it. It's a way to keep track of it. And then here in the lab portion, I'm not going to go and write this program. But that's a good idea of the kind of thing that you might be my seeing on the midterm. At least for the question and answer portion. And that will do the mini lecture for today. And what I will do for tomorrow is I will start with the. This is about a raise in references on chapter seven, because that is our subject for the week. See you all whenever.