Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Introduction to Programming: Aims and Objectives Introduction to Programming: Aims and Objectives This is a statement of the aims and objectives of the course Introduction to Programming taught by Matthew Huntbach in the years 1998-2001. It has been updated slightly since then to keep the links live. The role of programming in Computer Science Programming forms the core of Computer Science. Other aspects of the subject are either side-issues, or specialisations from the basic programming core. Therefore Introduction to Programming is the core first-year course in all our Computer Science degrees, and is an essential prerequisite to almost all that follows in the second and third year. Programming is about writing the instructions which a computer follows to enable it to store knowledge, process knowledge, and communicate knowledge with the outside world. Stemming from storing knowledge we can move into data structures and databases. Stemming from processing knowledge we can move into algorithms and computations. Stemming from communicating knowledge we can move into human-computer interaction and network issues. We can look in more detail at what is actually happening when a computer runs programs, considering how the instructions we write are translated to real changes in the electronic mechanisms of computer machinery. We can step back and consider more generally how we can organise the process of writing computer programs. We can develop mathematics to help us describe and analyse the behaviour of computer programs. We can look at some of the common applications of computers, and methods of programming those applications. We can think of new things we would like computers to do for us, and try and work out how we can write programs to make them do those things. The aim of an introductory programming course In a Computer Science degree we aim to teach you skills that will be relevant many years in the future. That is not always easy because we know computers and computing are changing rapidly. The machines, computer applications and even the role of computers in society today are very different from what they were ten, twenty or thirty years ago, and we can be sure that they will be different again ten, twenty or thirty years into the future. That is why we don't see our job as giving detailed training in whatever are the current leading systems on the market. Instead we are concerned with teaching more general principles. However, programming is a practical subject: you will be taught enough to be able to write real working programs, albeit ones on a much smaller scale than those used in industry or sold as commercial software applications. The important skills which underly programming are abstract ones. The ability to see patterns and to abstract from specific examples to the more general case is crucial. Being able to think logically so you can predict in advance the behaviour of a system working to a fixed set of rules is essential. You need the imagination to be able to take the instructions in a computer program and visualise them as commanding real entities interacting with each other, even though there is nothing to see when it happens. Skills like this are difficult to teach. Some would say they are skills you either have or don't have, and that is why when we admit students to the degree programme we look first at things like qualifications in mathematics which require similar sorts of skills. However, I believe we can develop these skills through practice. That is why a lot of what is done in Introduction to Programming is not teaching but practice. An Australian Computer Science lecturer who teaches a similar course to this describes it as Problem Based Learning. You will be given examples to practice on to develop your abstract skills. You need to seek out further examples from the textbooks and supporting material. Programming is not something you can sit back and be taught, it is something you have to put your own effort into to learn by experience. In fact a subsidiary aim of Introduction to Programming is for you to learn good working practices: self-motivation, good time management, making use of information sources, thinking and acting rationally, learning how to learn, and learning how to behave and get the best from the adult environment of lecture room, laboratory and community of academics. Java and object-oriented programming Introduction to Programming is taught using the Java programming language, but note the course is not called "Introduction to Java Programming". It is about programming in general, and not just programming in Java. Thus a lot of the emphasis will be on programming techniques that are applicable in most standard programming languages. You won't be taught, and won't be expected to know at the end of the course, minute details of the Java programming language. In fact, only those aspects of Java relevant to putting across more general principles of programming will be covered. Java is a large and complex language, but most of its complexity comes from the extensive library of pre-written code supplied with the language that gives it the ability to produce images on the computer screen, to interact across the internet, and to do various other things. If you wanted to be a professional Java programmer you would need to know more about this, and indeed you will get chance to cover some of it later in your degree programme. However, in Introduction to Programming, I have made the decision to concentrate on "basic Java", making only minimal use of the Java libraries. As a result, the programs you write will seem rather old-fashioned: interacting by reading and writing text to and from the screen rather than through graphical user interfaces. I won't be dealing with the web aspects of Java, even though Java has become known as "the language of the web" and it took over as a leading programming language because of its affinity with web applications. This may seem a little boring, but I believe it's important to get the basics right first without getting distracted by other matters. Once you have a thorough grounding in basic Java, you will be better placed to appreciate what is happening in Java programs that look more exciting when they run and do exciting things over the internet. Along with the decision to concentrate on "basic Java", I have also decided not to make use of an "Interactive Development Environment" (IDE). Such environments can make some aspects of Java programming easier, as they do some of the routine work and organisation for you. On the other hand, they can look complex as they are designed for more advanced Java programmers who want to do far more than we shall cover in this course. I feel it is important to get a good hands-on feel for how Java works to start off writing your programs from scratch using a text editor ( emacs is recommended, but vi is an alternative), and organise your files using a command-line interface operating system (we shall be using Linux). You will be able to make better use of IDEs in the future if you have started off knowing what happens underneath. Java is an object-oriented language, and there is a growing consensus in the computing world, both educational and industrial, that computer programming should be thought of primarily in object-oriented terms. In the early days of computers, a computer was a standalone device into which you fed in data, it did some calculations and gave you some output. The emphasis then was on trying to give some structure to the instructions which made the computer do the calculations, so that the instructions as a whole could be broken down into smaller self-contained parts. Being able to divide a program into parts like this made it easier to understand, and the job of programming was made easier if you planned what you were doing by breaking the task down into parts. This was termed "structured programming". Structured programming was seen as the program as one structured entity operating on the data as another, hence the phrase that was used to describe it "Program=Algorithm+Data Structure" ("algorithm" is defined in the on-line dictionary of computer terms as "A detailed sequence of actions to perform to accomplish some task"). In contrast, object-oriented programming sees computing as a large number of entities, each of which has both its own data to hold and instructions to follow, interacting with each other. Object-oriented programming fits better than structured programming into the modern world where computers are not standalone devices but devices linked with each other and interacting through networks. While performing complex calculations is still one thing we use computers for, these days there is far more emphasis on computer programs that interact with users (and in more advanced applications such as robotics interact more generally with the world around them). Much computer programming now is about bringing together existing components and making them interact rather than designing algorithms from scratch. Computer code libraries, such as that provided with Java, give descriptions of objects in terms of the data they hold and the way they interact with other objects, and computer programming involves making use of these libraries and adding to them by making descriptions of new sorts of objects. But object-oriented programming should be seen as a descendant of structured programming, and not a rival. Java descends from the structured language C through an intermediate form called C++. C++ is widely used, and has the advantage of combining some of the hands-on direct manipulation of the computer which C gives us, with the object-oriented approach. Java is a purer object-oriented language because, unlike C++, it does not give us ways of escaping from the object-oriented way of thinking. Learning to program in Java means you learn to program in an object-oriented way. One particularly good thing about Java is that it has achieved widespread use in education (it is probably now the most widely used language for introductory programming courses in university departments) while also gaining an increasing share of programming language use in industry. In the past there was often a gulf between languages academic Computer Scientists preferred to use for teaching which never got used in the "real world" and the languages used by industry which academics considered too unstructured t o be suitable for teaching. Having said this, it should not be considered that Java is the ideal. In many ways it is a compromise choice. And we should not be surprised to see some time in the future another language appearing and pushing Java aside, just as Java appeared suddenly in the mid-1990s. Object-oriented programming shares with structured programming the view that programs should be developed methodically, so that the different parts of them can be isolated, having well-defined behaviours and not interacting in unexpected ways. Since programs used in realistic applications tend to be very large, that is important. A large but poorly-structured program is likely to contain many mistakes since there are far more opportunities for things to go wrong. It is harder to understand how it works and correct the mistakes, and harder to change the program if a new version of it is required. For this reason the Introduction to Programming course will emphasise the development of well-structured programs, and stress the importance of good design. Programming is something you should think about, programs should be designed carefully not just thrown together and then tweaked until they work. A program which works in the sense that it does what was asked, but does it in a way that's hard to understand, is not satisfactory and in assessments will not get full marks. The details The exact material in the course varies from year to year. I don't have a fixed set of lectures I will give come what may. I will try to respond to the reaction I get from the class - slowing down or introducing more examples if there's any area it seems the class is finding difficult, dropping things altogether if there's no room for them, or adding new things if I decide on thinking about then that they're important and you ought to cover them. This is why it's important that I do get comments from people on the course - I would like to be able to use the newsgroup for on-going discussions (if you are going to use newsgroups, Emily Postnews's page of misleading tips might be helpful) . If you don't understand something, let me know, or post your concern to the newsgroup. However, I expect the course to be fairly close to how it was last year and the year before that, which are the two years I've taught it (previous to that it was taught by someone else, with a different emphasis). So past exam papers for 2000 and 1999 give a very good idea of the level I expect you to reach by the end of the course. The local notes that were written for this course also give a good idea of the course content and the topics covered. However, do bear in mind that these notes were written two years ago, and haven't been fully updated. The details of what is taught each year vary in response to how the course is going, and my own continuing study of Java and the best ways to teach programming using it. So I can't guarantee that everything in the notes will be covered in the lectures, or everything in the lectures will be covered in the notes, or that the examples in the lectures will be exactly like those in the notes. Here's the topics that will definitely be covered: Java program structure - Java programs are made up of a collection of classes. Java classes have two roles: a class can either be a description of a type of object, or a collection of static methods (or it can combine both roles). A method consists of a signature followed by a list of statements. Java statements, values and variables - simple Java statements may be variable declarations, assignments and calls to void-returning methods. It is important to distinguish between statements, which do something, and values which do nothing on their own but are assigned to variables in assignments or passed as arguments to methods (to confuse things, some value do do something - called a side-effect). Control structures - the statements in a method are obeyed one at a time in order, but a statement may be a compound statement containing statements within it. When a selection statement is obeyed, only some of the statements within it are obeyed, when a loop statement is obeyed, the statements within in it may be obeyed several times. Objects and methods - an object consists of a collection of variables known as fields. A method which has access to an object, either because it constructed it or was passed it as a parameter can generally only interact with that object by calling the object's methods. A class describes an object in terms of the fields and methods it has. Interfaces - an interface is a way of describing objects in terms of what they can do (i.e. their methods) without saying how they do it. How an object obeys the methods listed in an interface is defined by a further class. As several different classes may implement one interface, this allows for generic code. Exceptions - an exception enables us to "expect the unexpected". When obeying a statement involves doing something that cannot be done normally, an exception is thrown and try-catch can be used to recover and handle the problem. Arrays - an array is an indexable collection of data. It is an example of a mutable data structure, as its contents may be changed. Arrays, like all objects, are represented in Java by references, thus assignment to an array variable may cause aliasing, and arrays may be permanently changed when passed as parameters. Input/output and strings - this is the only time we will look at predefined classes from the Java library. Strings, in contrast to arrays, are immutable objects. We shall do enough on input/output to be able to read from and write to the command window and also read from and write to files. This will include the use of string-tokenizers to break up lines of text, and command-line arguments will also be considered as an alternative way for Java progams to interact with the outside world. Inheritance and polymorphism - one Java class may extend another Java class, meaning it is defined by the way it adds to or alters that class (known as its superclass). A variable of a type defined by one class may be set to refer to a value of a type defined by a class to which its class is a superclass. This is known as polymorphism. The type Object is a superclass to all classes, so a variable of type Object could be set to refer to any object. List data structures - if a class has a field of its own type, the result is a linked-list data structure. There will be some consideration of this, just the simplest form of recursive data structure, with a consideration also of recursive methods. A contrast will be drawn between concrete data structures, and abstract data types. Abstract data types are defined by interfaces rather than classes. The minimal use of Java's library is intended to give you a thorough grounding in the "nuts and bolts" of Java before you move on to using those nuts and bolts to build things out of the components provided by the library. The basic principles of object-orientation covered can easily be applied to other languages. The philosophy behind this is that you will concentrate better on these basic principles without being distracted by the great variety of things in Java's library. How to fail this course It is a sad fact that Introduction to Programming has a high failure rate. This seems to be common in Computer Science departments - students start, most with an interest in, some claiming significant experience with computers. Yet many end their first year failing, and quite often it's those with the computer experience who fail. Lecturers don't like to fail students. Apart from it being a poor reflection on ourselves, our livelihood depends on us having a sufficient number of students to pay our salaries. If we throw students out we make life harder for ourselves. So why do we do it? The answer is quality. If we fail students who don't come up to a certain standard, that is a guarantee that the rest have come up to that standard of quality. Queen Mary is part of the University of London and thus keeps to the same standards as the other University of London colleges, such as Imperial, UCL, Kings College. If you are not prepared to put in the work required to reach that standard, and not willing to meet the challenge of rigorous courses that entails, you should have applied somewhere else to do your degree. So why do students fail? In my experience there is a small number who really do have a natural lack of ability in the subject. They try hard but still don't get anywhere. Our admissions procedures (the author of these notes is also the department's admissions' tutor) try to avoid giving places to people like this by considering qualifications, statements on UCAS forms, interviews and so on. But some still slip through - if you are one of them, sorry! There are also some who suffer genuine personal problems during the year which stop them from succeeding. If you are one of these, tell us (we can't make allowances if we don't know) and don't be afraid to seek help. But many fail for a variety of reasons and misconceptions that could be avoided. Here are some of them: I know this stuff. Some will have done some programming before. But there is a big difference between what is done in secondary schools (when they do any programming at all), what is covered in the hobby press, and so on, and what is covered in a serious course introducing programming using Java in an object-oriented style. In my experience, the number of students who start really knowing this stuff is approximately zero. The number of sudents who only find out they don't know this stuff when it's too late is somewhat higher. Passing exams is just about memorising things then regurgitating them. I believe one of the most pernicious myths in education is to confuse learning with memorisation. I have never set an exam which can be passed by memorisation, and never intend to. One of the reasons I make minimal use of the Java libraries in this course is that it reduces the risk of people putting effort into memorising stuff (like the contents of these libraries) rather than understanding things. If you have come from a background which has confused rote memorisation with understanding, sorry, you will have to break out of it. If you are someone who has succeeded so far by being bone idle for most of the year and doing last minute "cramming" before exams, sorry, that won't work here. This stuff is too hard, so I won't bother. Yes, it is hard, that is why mastering it is worthwhile. But you won't get anywhere by giving up as soon as you find it involves a bit of hard thinking and understanding. If you don't understand, ask questions, read the notes and other material you can find, email me, and above all do the lab exercises as programming is a practical subject which is best learnt by doing it. If you are asking for help, try to sit down and work out exactly what you're finding difficult. It's easier to offer help if you have put some effort into analysing where you need help. I've got to do my job etc. Your job is being a Computer Science student. You ought to treat that as a full time job, 40 hours a week in term time. You get long holidays (unlike we academics who do our research while you're on holiday), and 40 hours a week still leaves time for other things. But you should make yourself available for all lectures, labs and anything else associated with the course, as well as put in extra time on personal study and practice to make up a full working week. We appreciate student support is not as generous as it used to be, but the decision to reduce it was made by politicians not by us academics, so don't moan at us about it. Is it really worth risking your degree, which could get you a highly paid job in the software industry, in order for a few pounds in a part-time job now? The train was late, I overslept, etc. Learning to keep good time is part of being an adult. At university you don't have someone pushing you. It's up to you to work out you may have to catch an earlier train if your service is unreliable, and to manage your social life so that you don't miss morning lectures, tutorials or labs, and so on. Remember, once you graduate and get a job, your boss is unlikely to accept the excuses we commonly hear for poor lecture attendances. Regular attendance is particularly important in a subject like programming, where each part of the course makes use of material covered in earlier parts of the course. Missing one bit may mean the next bit makes no sense, and after that you're completely lost. The first year doesn't count. Although this course is a second year option for some, it's a core first year course for Computer Science students. Strictly, in the Computer Science Department, first year course unit marks aren't used in the decision on which degree class to award at the end of the degree. However, that will be irrelevant if you fail to get enough units to progress beyond the first year (current regulations state you need to pass six, with Introduction to Programming counting as two, being a double unit course). Taking it for granted because you think you're bound to get at least a pass and that's all you need isn't a good idea. Firstly, many of those who take this attitude don't get a pass. Secondly, since Introduction to Programming is so fundamental a foundation for most of the later course units, doing well in it will help you do well in those later units. How to pass this course One of the first things to remember is that university is not like school. You are at university because you want to be at university (if you don't, you can obtain a withdrawal form from the Registry). You are working for yourself and will need to motivate yourself. You will have to get used to not being told what to do the whole time, but instead learning to make use of the resources which are available. This course unit and the setting in which it is given provides you with a bundle of resources - make sure you use them to the full. Here are the main resources available: Lectures. I've sometimes even heard students refer to lectures as "lessons", but that's wrong. At school, most of your learning is done through lessons, but they only form a small part of it at university. You will note that Introduction to Programming, in common with other course units, has only two hours of lectures a week, but if you followed the advice above and put in a full working week to being a students, you should put ten hours a week into each of your four course units. So most of your learning will be done outside lectures, and indeed we recognise that lectures are not a good way of getting material across. So why bother with them at all? My view is that lectures serve as a pacemaker for a university course. They give you a feel for the rate at which the topics should be covered, and the relative importance of each topic. Because there are only two of them a week they are very concentrated, and you may find it hard to follow everything exactly during a lecture. That's why it's important to follow up your lectures by reading through your notes afterwards, comparing them with other sources of information, experimenting with the material that's been covered in practice. If you get into the habit of skipping lectures, you will lose the pace of the course, and not be able to pick out from other sources of information what's the important aspects. Labs. You will have an hour or two of formal laboratory time per week. During this time you will be guaranteed a place in the department's Informatics Teaching Laboratory, and you will be expected to work on exercises that have been set for that lab period. There will be staff and teaching assistants in attendance to help you out. Judging when to ask for help is important - it's good to think things out for yourself first as you learn nothing by just being told the answer without having thought about the question first. On the other hand, if you are stuck on some simple point, it's silly to waste hours over it when there may be something obvious (in programming, it's common for something to seem obvious after it's been pointed out) which you keep missing and where a little assistance would get you back on track. Some lab work (called "course work") is assessed and contributes some marks towards your final grade for the course. But you shouldn't get into the habit of only doing the assessed work. Computer programming is something you can only learn by doing it (do you think you could learn to drive a car just by reading books about it? - same with programming, it only makes sense when you actually do it), and lab exercises are given to help you learn this way. The ITL is open for long hours, so apart from your set lab time you should make use of it at other times as well (apart from when it is set aside for some other course). Try experimenting with the Java language constructs you've been taught and with exercises in books and other notes as well as those that have been set for you. Although it isn't essential, many people have their own computers at home, so you can also make use of your home computer to gain additional practical experience. You can download the Java language for free from the Sun's Java Site. Web notes.The local web notes were written for this course and are available only on the local pages of the Department of Computer Science here. Although they are made available for your use, and the relevant sections should be read when (or preferably just before) the topic it covers is covered in a lecture, please don't expect these notes to coincide completely with the lectures. In particular, reading the notes should not be a substitute for lecture attendance. The worldwide web resources have been carefully chosen to be useful for this course. You will find web notes for similar courses there, as well as wider references to Java and programming in general. Use these to find out further explanations and examples of material you've covered in the lectures. I also hope you are interested enough in the subject to want to read beyond the material which is directly related to what is covered in class and hence examinable. Learning to make use of resources such as these yourself is a very important part of progressing from being a school pupil to being a university student. In some ways, particularly in a fast-moving subject like programming, web-sites have replaced the book as the way of getting information. I will be referring you to the web notes rather than giving out printed notes during the course. However, printed pages are still often more convenient to handle, but please don't abuse this by printing off vast amounts of material available from web sites. Books. As mentioned above, it's often nicer to handle a book (you can read it anywhere, you can easily flick though its pages) than a web-site, so books are not redundant yet! You have been give a list of suitable books for the course. These have been carefully chosen from the large numbers of books on Java currently available on the market. The important thing about them is that they aim to teach programming in general through the medium of the Java language. They should be distinguished from books which teach Java programming, but spend a lot of time on intricate details of the Java libraries (which aren't relevant for this course) while missing adequate discussion of more general programming principles (which are). Many Java books are designed to introduce the language to people who already advanced programming skills in other languages, and so would not be suitable for this course which makes no assumption of existing programming experience. Other Java books are on advanced aspects of the language, and so again are not suitable for this course. A lot of Java books present Java mainly in terms of its use for web-site graphics applications, which is not what this course is about, although it's what first brought attention to the Java language. In my experience, books which promise to teach you Java in 21 days or even 24 hours do nothing of the sort - still if they think you can do it that quickly, you ought (but you won't) find it leisurely to do it in the 7 months between start of the academic year and the end of year exam. In general you should pick a book or two which suits you to buy, maybe cooperate with friends so you can share several. It helps to see how the same topic is covered by different authors, and to see plenty of example programs. Once you're familiar with Java, or if you're already a confident programmer, you may find it helpful to have also a concise Java reference book such as the one by Flanagan. Don't forget, a book is of no use to you if you just keep it on a shelf. Refer regularly to your books, using the lectures to keep pace with the material you need to cover. Library and bookshops. Some books on Java are in the College's library, although as there's a large number of people on this and other courses using Java and only a limited number of copies of each book in the library, the likelihood is anything you want will be on loan. The College has a branch of Waterstone's bookshop on campus, which should have copies for sale of all books recommended as course textbooks. Tutorials. All first years students in the Department of Computer Science have a weekly hour-long tutorial. This is a chance for you to meet in a small group with a member of staff. Different members of staff have different ways they use tutorials, but we think it's important that you do meet on a small scale in a setting where you can engage in conversation with an academic, as well as the large-scale of the lecture theatre where interaction between staff and students can only be limited (most lecturers probably don't mind answering a few questions in lectures, so don't be afraid to put up your hand and ask). Tutorials are not meant to be "mini-lectures" although some tutors may spend some time going over with you some of the exercises you've been set. Other tutors may prefer to talk about Computer Science in general, trying to set what you've done in a larger context. Others may offer general suggestions on study skills, future options, and so on. But tutorials are meant to be a chance for you to do the talking. You will get the best out of them if you come along ready with questions and comments. Yourselves. Working together with other students in the department is fine. It helps to discuss the course material, share references and books, make sure your understanding of a topic is the same as other people's. Someone who is in the same position as you i.e. a fellow student, may do a better job of explaining something you are trying to understand than anyone else. However, if you do get used to working with a group of people you get on with, beware of the syndrome where one person in the group ends up doing all the work and the others just copy it. Seeing how someone else has solved a problem is no substitute for working on it yourself and making sure you can solve it on your own. In particular, when you have a piece of assessed programming coursework, you may be tempted to take someone else's solution and present it as your own work. This is a form of plagiarism which can be treated as an exam offence (please note, we can often tell when a piece of programming code has been trivially altered so it isn't exactly like someone else's). It's important to remember that exercises are set because you learn by doing them. Is it worth getting a few coursework marks because you copied someone else's solution, but then failing the end-of-year exam because doing that meant you never learnt how to solve problems of that sort? So, as you can see, there are a lot of resources available. Putting together notes and web sites, and preparing and giving lectures is hard work for me, but it's what you (still to some extent aided by the taxpayer) are paying for - make sure you use it. I don't want to be continuously moaning at you throughout the course of the year on the need to work hard, but if I do, remember it's because I want you to pass and do well. We lecturers know from long experience that steady work throughout the academic year is the way to pass a course. This is particularly so in a practical subject like computer programming where you learn by doing it. Computer programming is a difficult subject, but a rewarding one. This course aims to stretch people rather than water down the subject so that everyone can pass (but many will get bored). But you wouldn't have been selected to join the department unless we thought you could do it. If you're a "natural" who can sail through it - great! If you're one of the majority who struggles at times, hang on there, ask questions, seek answers from the resources available, make sure you attend all the lectures, labs and tutorials, and Don't Panic. Matthew Huntbach Last modified: 3 March 2006