The basis for education in the last millennium was “reading, writing, and arithmetic;” now it is reading, writing, and computing. Learning to program is an essential part of the education of every student, not just in the sciences and engineering, but in the arts, social sciences, and humanities, as well. Beyond direct applications, it is the first step in understanding the nature of computer science’s undeniable impact on the modern world. This course covers the first half of our book Computer Science: An Interdisciplinary Approach (the second half is covered in our Coursera course Computer Science: Algorithms, Theory, and Machines). Our intent is to teach programming to those who need or want to learn it, in a scientific context.
We begin by introducing basic programming elements such as variables, conditionals, loops, arrays, and I/O. Next, we turn to functions, introducing key concepts such as recursion, modular programming, and code reuse. Then, we present a modern introduction to object-oriented programming.
We use the Java programming language and teach basic skills for computational problem solving that are applicable in many modern computing environments. Proficiency in Java is a goal, but we focus on fundamental concepts in programming, not Java per se.
All the features of this course are available for free. It does not offer a certificate upon completion.

レビュー

LM

I liked this course very much. Good materials and perfect lecturers. Good structured and well explained material and interesting exercises ranging from very beginner to challenging.

JH

May 20, 2020

Filled StarFilled StarFilled StarFilled StarFilled Star

It did not just teach coding, but taught efficient coding and how to think about performance issues, and separation of program parts into objects

レッスンから

CREATING DATA TYPES

Creating your own data types is the central activity in modern Java programming. This lecture covers the mechanics (instance variables, constructors, instance methods, and test clients) and then develops several examples, culminating in a program that uses a quintessential mathematical abstraction (complex numbers) to create visual representations of the famous Mandelbrot set.

講師

Robert Sedgewick

Kevin Wayne

字幕

Well, last lecture, you saw the utility of using data types that you can create on your own. This time, we're going to take a look at the process of creating our own data types. Let's start with a quick overview of what we need to do. This is the last in our building blocks for programming where we've already considered all these basic things up through functions and modules. And now we're going to talk about programming with objects, and this is going to give you the ability to bring your own abstractions to life. So in general, this process is called object-oriented programming or OOP. It's where we create your own data types, create our own data types, use them in our programs, and creating the data type and using it in our programs is really where we talk about these objects. Where an object is something that holds the data type value. So our variable names refer to objects and objects hold data type value. So for example when we worked with color, we had our set of values and our operations were get red component and brighten and so forth. There were objects that hold these data type values that we manipulated. And we looked at picture, where the set of values was to the array of colors. And then we have objects that hold those values in strings and so forth. And really what we usually want to do is create what's called an abstract data type, where it's the data type whose representation is hidden from the client. The impact of that is that we can use abstract data types without knowing much about the implementation details, and these are examples of abstract data types. Last time we used those we wrote programs that made use of them without knowing anything about the implementation details. We talk about client programs for several abstract data types in the previous lecture. Now we're going to talk about how to create and how to implement your own abstract data types. So, to create it what we have to do is provide some code, and very specific task that we need to do with this code. So one thing we have to do is define the set of values. And we do that with what's called instance variables. And then we have to implement operations on those values, and those are called methods. And we also have to be able to create and initialize the values of new objects. And we do that with special methods called constuctors. So what are instance variables? Well, they're declarations that associate variable names with types, as usual. But the set of type values of the set of instance variables is the set of values for the data type. And we'll see that in examples, it's very simple. Methods or like static methods, and they can refer to instance variables, and again, it's very similar to static methods, but with a profound difference, and you'll see it with some simple examples in the beginning. And a constructor is also like a method that has the same name as the type. And it doesn't actually return, it doesn't have a return type because it's going to return reference to an object of the data type. Those are the basic steps that we have to do and we look at this in much more detail in just a minute. The constructor, by the way, is invoked by new keyword in Java and it returns an object of the type. So, in Java, all of this put together is known as a class. And so, a Java class that we consider are all going to have this basic structure. For every data type that we implement, we'll look at exactly in this framework. We'll look at what are instance variables, what's the set of data type values. What are the constructors? How do you create an object and initialize it's value? What are the methods? What are the operations that we can perform on the values? And then also, we always add a test client or include a test client in every Java data type that we implement. So that's the process that we're going to go through for several examples in this lecture. So here's just an anatomy of a class with real code and then we'll look at each piece of this code in detail in just in a minute. So we put the whole class in a text file named Charge.Java, and that class name, we go public class and give the class name, that's going to be the same as the file name. And then inside the braces go our four components, the instance variables, the constructor, the methods and test client. Now main is a static method, and you can have other static methods in a class, so we're familiar with that. These methods here are not static, and we'll talk about what that means. That's really the essence of what goes on with object oriented programming, and that's really what this lecture is going to be all about.