Today, we're going to talk about what you need to know in order to get started programming. It's quite a bit of information, but I think you'll find that it all comes pretty naturally, and also, we'll talk about some historical contexts just to make it a little bit more interesting and engaging. Okay. As a matter of fact, let's start with a question. Why programming at all? Here's a quote from a science fiction novel, where the author lists all the things that really every human being should be able to do. I don't know if we all agree that we need to know how to die gallantly and so forth, but I think the point is that everyone should know how to program a computer and that's really the point of view that we take in this course. So, that's the first thing, computers are omnipresent and it's something that everybody should be able to control. Really, what you need to know how to program for is to really get the computer to do what you want it to do. Now, naive ideal that you might think is, well, why not just tell the computer what you want it to do. See in this example here; please, simulate the motion of N heavenly bodies subject to Newton's laws. It would be nice if we could get a computer to do that. Actually, you're going to write a program to do this in a little while, but it's really naive to expect the computer to really be able to do that. Another alternative is maybe there's a prepackaged solution or an app that does- it's fine to have an app if it does what you want done. We all have our computers and mobile devices all littered with apps of all different types. But there's lots of things that there's no app for. What programming enables you to do is to make a computer do really anything you want. Well, almost anything, and we'll talk at the end of the course a little bit about the limitations. People have realized this for a long, long time. On the right, is one of the first computers, Babbage's analytical engine, and one of the first programmers was actually a woman named Ada Lovelace. That's quite interesting story that you might be interested in looking up. So, how do we tell the computer what to do? That's programming. The thing is it's not just for exports, it's a natural satisfying and creative experience, just like writing a sonnet or a paragraph. It's actually easier. But the thing about programming is it enables accomplishments that wouldn't be otherwise possible, and we're going to see lots of examples to that. Not only that, it's just a whole new intellectual endeavor that's stimulating just by itself, even if it wasn't actually accomplishing anything. Now, there's some challenges in order to get started and that's what we're going to be talking about at the beginning of the course. You need to learn what computers can do. You need to learn a programming language which is a way of communicating with the computer. It's not so easy sometimes to tell a computer what to do and we often find ourselves in this kind of situation. But I think a more positive way to look at it, is a quote from Don Knuth leading computer scientists, "Instead of imagining that our main task is to instruct a computer what to do, what we should do is concentrate on explaining to a human what we want a computer to do." I think he's talking about really what an ideal programming language would be like. But let's look at it in a little more detail. Now, there are plenty of different ways to tell a computer what to do. When you use an app, you're telling the computer what to do. At the lowest level, which we examine later on in part two of the course, there's machine language, which is the computer's language. It's very easy for the computer, but it's pretty detailed and very error-prone for a human to do it. This is the kind of code that illustrates machine language, which is to add two numbers. We'll have a lecture on that in the second part of the course. There's natural language, as I mentioned, that's easy for the human but that's pretty error-prone for the computer and there's plenty of great examples of that just getting the computer to understand what you're saying; kids make nutritious snacks, red tape holds up new bridge, police squad helps dog bite victim, local high school dropouts cut in half. These are actual newspaper headlines, and you can imagine the challenge is felt by researchers trying to get the computer to understand natural language like this. So, instead, what we use is something in between called a high-level programming language. It's a compromise; it's the same difficulty for both the computer and the human. The last several decades have shown it's an acceptable tradeoff to get us to be able to tell computers what to do. This is a Java program, that's similar to those that were going to be writing in this course. Now, but which high-level language? Actually, there's a long, long list of hundreds and hundreds of high-level languages that have been developed and one of our big choices in developing this course is choosing an appropriate one. So, again, there's a naive ideal that there's a single programming language that works for all purposes. That's just not something that can be realized, and for the same kind of reasons that there's no single natural language for us all to communicate with. We'll talk about that later again in the course. So, our choice is the Java programming language developed by James Gosling a couple of decades ago. The reason we chose Java is that it is widely used, it's widely available and it's been continuously under development for going on 25, 30 years now. It embraces a full set of modern programming abstractions that people understand and know are useful. It's got a lot of help, automatic checks to help us make sure that our programs are correct. There's a huge economy built around Java, it's a very, very widely deployed. It's in the Mars Rover, it's in your cell phones, and disc player, web servers, medical devices, supercomputers. There's millions of developers of Java programs in billions of devices that run Java. So, you're not going to go far without finding that your Java knowledge is useful. So, that's the reason that we chose Java. Now, there's facts of life and no language is perfect and there's things about Java that each one of us could think about improving. This is a famous quote by Bjarne Stroustrup who is the developer of another programming language C plus plus. He says, 'There's only two kinds of programming languages. Those that people always gripe about and those that nobody uses." So, there's going to be problems with Java we're not saying that, but you do have to start with some specific language and Java is our choice. Now, our approach is to use a minimal subset of Java that really many many of the constructs that we use are found in other languages. If you do move or use another language in the future, you'll find that a lot of our code is still useful. Really what we're trying to do is develop general programming skills that are applicable to many many different languages. It's not about the language, once you've taken a course like this and learned one general purpose programming language well, you'll find that it's not difficult to move to another one. So long as the course doesn't spend its time obsessing about detailed properties of the language and we're definitely not going to do that. So, let's just take a look at the vocabulary. Sometimes people compare learning a programming language to learning a natural language. But it's actually much much easier that's what this slide supposed to say. There's only a few different types of things we're going to talk about all of these things later in today's lecture and then a few more in the next couple of lectures. But this is pretty much all the words that you're going to use in your Java programs it's almost all the programs you write are going to be made up of symbols like this plus variable names that we create ourselves. So, the language vocabulary itself is quite limited and you'll find that not difficult to learn all these things. Then these things are the tools that you need to write a very very broad class of programs. Your programs are going to be these plus some identifiers that you make up and that's it. So, here's your first program it's called HelloWorld. Everybody writes HelloWorld, as their first program since at least the 70s. So, for Java this program is just going to be typed into a text file, you could type it in an email or use an editor and we'll talk about that in mechanics in just a minute. It's just text and it's got this specific texts in it. The most annoying thing about Java from this perspective is the braces. But they're necessary that's kind of how you can tell it's a program and not an email message. The thing HelloWorld is the program name. In Java, that program name is the same as the file name that appears right before the dot java. Then there's a thing called a Mean method. In all our programs have mean methods and we'll talk about exactly what that is and then this programme has the body of the main method is a single Java statement that says, in this case "Print this line of text out." We go through those elements because every program that you write or at least the next several are going to have the same elements. You're going to have a program that you make up my program.Java, you'll name it my program or whatever else you want to name it. It's going to have a main method and just type that exact text to get a main method. Then there's going to be a sequence of statements and we'll talk about what statements are and what they do. But all of this later in the course, we'll learn about what all these things actually mean. Right now, you say just make sure that you get exactly those characters and they say to you, "This is my program, " and that's all. Okay. So, let's do just a quick quiz question on this thing your first program. You've all run from our first assignments, you've run this program HelloWorld.Java and it printed out Hello World. What happens if you type in your program and you get this error message that says, "Main method not public?" Well, this other one that says invalid method declaration return type required. Well, in these cases, first ones pretty clear, it must have forgotten the word public and that's why it's telling you what to do. So, you put in the word public. Southern ones a little more complicated, we go back to HelloWorld.Java to see what it says and match against and oh we forgot to put the word void. Not sure what that means but need the word void. So, you'll get a few error messages like this at the beginning and then you realize that really you need to type in the exact text that we give in the template. Here's another thing about Helloworld. Here's three different versions of Helloworld. This is the way that I just showed it on the slide. This is the way that Kevin wrote it for the our online materials on the book site, and then there's another way that you could write it. In the thing about these different versions is that the color and the actual font, the comments all the extra space they're not part of the Java language. We use those two as a matter of style depending on the context. They're all the same program as far as Java goes, and I'll talk a little bit more about that in a minute. The thing is, that it depends on the context, different styles are going to be appropriate for programs the same way is true for a novel, or a magazine, article, or whatever else. We're going to talk about building a program and an integrated development environment and as I just mentioned we have programs published on our website called the Booksite. There's programs in the book, there's programs that I'm showing you on the slides, there's your own code. Those are all different contexts and sometimes people do insist on a very consistent style on programming and well, if we really wanted to completely enforce a style and say your program must look like our booksite programs, it stifles creativity a little bit but I think the more important thing is that people get confused about the difference between the style and the language. Doesn't matter how many spaces you indent your statements or whether you put the braces on the same line or not. Those are not part of the language, those are the style and enforcing a style gets people confused. On the other hand, we do like to usually emphasize consistent style. If you use the same style all the time, it makes it a little easier to spot errors in your programs. The main thing is it makes it easier for other people to read and use the code. So, usually in a group of programmers or in a class people agree on using some kind of consistent style. So, that they don't get confused by differences in style. But it's not so different than writing essays in a class and so forth. Often a teacher wants a certain style to make it easier to grade. Sometimes the development environment insist on a style to give you visual cues to make it easy to write your program that's another reason. So, usually for a student what we say is what you want to do is to listen to the person that's assigning your grade or if you're at work maybe your boss. There's somebody that wants a style then you pay attention to that style. Otherwise, my advice is to at least put a little creativity into it and put your own stamp on your programming style.