好好學習.天天向上

嶺南大學社區學院 資訊科技、數學及科學組

Archive for September 17th, 2007

ISM001 Class Summary (2)

without comments

Dear students of ISM001,

Last Friday we went through our second class in Java programming. We continued with the last two examples of Chapter 2:

  1. In Addition.java, we learned how to take an input from the command line using java.util.Scanner. We also performed our very first arithmetic operation to add two integers together. Most of you were able to modify the program to do subtractions, which was very good.
  2. In Comparison.java, we went through some equality operators (== and !=) and relational operators (>, <, >=, <=) to compare two numbers. I also emphasized the difference between == and =. Make sure that you don’t confuse the two in your programs.

Chapter 3 was about classes and objects, which are the building blocks of an Object-Oriented Program. In particular, we went through a few simple examples to learn the idea of OOP. An outline of the important stuff:

  1. Students should understand the meanings of a few terms: class, object, instance variable, and method. I don’t mean to memorize the definitions, but to know how to design these in a real program, such as Little Fighter (小朋友齊打交): If we define 小朋友 as a class, then what instance variables and methods should we use in this class? What is an object in this case?
  2. In GradeBookTest.java, how does the compiler know the definition of GradeBook when we declare myGradeBook in the program? What happens if we use GradeBook2 instead? Try to break the program and you would understand.
  3. I mentioned the get and set methods, and explained the meanings of private and public. I also explained that we used these instead of directly changing / showing the instance variables because of data hiding (or data encapsulation). Again, try to break the program by changing a private variable outside the class (e.g. in GradeBookTest.java) and see what happens.
  4. There are primitive data types (int, float, double, etc.) and reference data types (String, GradeBook, Scanner, etc.) in Java. What are their differences?

Again, it is impossible to cover everything in the textbook during the class. After you go through and break all the example programs, please make sure to read Sections 2.5-2.8, 3.1-3.6 of the textbook to avoid missing anything important. As a self-test, try some of the programming exercises at the end of Chapter 2 and 3 before the next class.

In the next class, I would continue with a few more examples in Chapter 3 and then proceed to Chapter 4 to talk about Control Statements in Java.

Powered by ScribeFire.

Written by 張真人

September 17th, 2007 at 10:11 am

Posted in Class summary, ISM001

Close
E-mail It