Object-oriented program Pilot course is an important part of systematic object-oriented course, its goal is to help those who have a certain C language Foundation, but the object-oriented concept is unfamiliar, basically did not touch the Java programming students. This course is designed as a summer elective course, because there are no other courses, we are designed as a training camp of the nature of the course, that is, the classroom is basically not through PPT to teach the Java language grammar and object-oriented knowledge points, but around the prepared task, the classroom scene to let everyone in the program contact, and combining the practice of the program on-site to explain the Java language and object-oriented concepts, which is a problem-oriented and student acceptance of the teaching model.
The entire course consists of four times, four hours each, arranged in Tuesday and Friday. Each course does not have a natural 45 minutes for the node, but according to the training task as a node, the effect is very good. See is the students in full love, and occasionally a classmate got up to go to the toilet.
First Class
Objective: To bring into the initial object-oriented programming thinking from C language programming thinking. The main point is to understand the basic features of object-oriented programs, and its beauty.
Start with a 30-minute introduction to the course objectives and an overview of the Java language, which is why this course is available, and the ability to reach 150 lines of effective Java programs through two weeks of training. I see a lot of students in the eyes of the truth. Then live to guide you to install the Java Development environment: JDK8 + Eclipse IDE. After installation, the TA is on-site to introduce the common views (Java perspective, Debug perspective) and operations in the IDE, such as new projects, how to create new classes, syntax highlighting and compilation errors when code is written, and so on.
The highlight is the following picture:
6 tasks to complete in almost 2.5 hours. We first send the sample code to the students, and then step by step to complete the task 1~ task 6. The initial program has a full C-style, box is a data structure, the main method of manipulating the data structure, and volume calculation.
Task 1: Add the Volume method to the box class to calculate the volume. This task to OO over, let the students understand the data structure in Java Management and provide data calculation methods. In addition, through this task, students learned how to compile and execute the program, especially through system-provided out to observe the health of the program.
Task 2: The task is trained to achieve an "interaction" goal between different classes by means of the method return value. Task 1 Method Self-contained, complete the calculation and output. Task 2 is different, complete the calculation and return the calculation results, this reflects a certain division of responsibility, that is, the box class is only responsible for calculating its own volume, how to interact with the user is the main class Firstjava task.
Task 3: This task helps students to further experience the difference between object-oriented programs, that is, there can be multiple methods (overloads) with the same name. With this mechanism, a class provides a unified, functionally similar but differentiated approach.
Task 4: Uninitialized data is a common difficulty for novice users, causing the program to run in a light error that causes a crash. The object-oriented program provides an intrinsic initialization mechanism, that is, the construction method. The special thing about this method is that it has the same name as "data Structure", which is something that cannot be done in a C program. Once the construction method has been added, the students immediately notice the error in the new box () statement in the main method, which is a good time to introduce the Java default constructor and explicitly define the relationship of the construction method.
Task 5: An important mechanism of object-oriented programs is to protect data, which is fundamentally different from C programs. This task introduces the concept of data visibility and introduces three key keywords public, private and protected. Once you declare the three properties of box as private, it immediately results in syntax errors outside of access to these three properties, which achieves the goal of data protection. At this point, we have completed a complete object-oriented Java program, which has interaction and division of responsibilities between classes, the box class hides its own data, and provides a variety of volumetric computing tools/services. The main class Firstjava creates and manages box objects and provides output capabilities.
Task 6: With the power of the box class, we put forward the hope that only a little bit of work on this basis can get a more powerful class scalebox, adding a scale attribute that represents the dimension of the box class geometry (that is, units, such as in centimeters, the size of the meter corresponds to 10, And the millimeter corresponds to a scale of 0.1). This mechanism is not possible at all in the C language program, which introduces a core mechanism in object-oriented, the visual meaning of inheritance, and how to get scalebox through this mechanism. The point is to rewrite the volume method of the box class, that is, the scale factor is included in the calculation. So far, we have formed three classes in which both box and Scalebox are interacting with the Firstjava class, while the box class and the Scalebox establish an abstract hierarchical relationship. The actual practice results, the students can understand and grasp the task 1~ Task 5 in the emphasis of the content, task 6 is a bit ignorant. However, this is normal, in fact, the semantics of inheritance is relatively complex, the goal of training camp is not to grasp, but to gain an intuitive experience, especially the use of the scene experience.
Through the completion of these 6 tasks, the enthusiasm of the students was greatly mobilized, and realized the novelty of the course teaching method. Particularly prominent is that during the first class, when the students encountered grammatical errors, the basic is to raise their hands to ask teachers and assistants to assist. And from the second lesson, this phenomenon is basically gone. In the course of our discussion, we emphasized how to read grammar error hints and how to find relevant auxiliary information on the Internet.
Under these 6 tasks, we finally drained for half an hour to start our homework. First, given a complete C language program, to achieve the character set function. On this basis, provide a framework of Java code, require the classroom implementation of the corresponding Java program. This task is basically not too difficult, of course, the procedural style shows a strong C characteristics. On this basis, we have arranged the supplementary function of the job, that is, based on the completion of the class of the character set, using the inheritance means to achieve a support intersection calculation of the character set, and can record the number of services provided by the collection.
How to reach 150 line Java programs in two weeks--part 1