Saturday, July 25, 2009

Lesson 1 Summary

Please refer to the resource box on your right and download the Lesson 1 Concept (Powerpoint), Java class files (Person.java, Student.java, MonashStudent.java) and Java driver class files (StudentApp.java, StudentArrayApp.java, MonashStudentApp.java).

[ Lesson 1 Concept Powerpoint ]
Lesson 1 Concept illustrates the context in example 1 and example 2.

[ Example 1 ]
In example 1, we describe inheritance using Person class, Student class.

Person -> Student

Student class inherits the attributes of Person class using the "extends" keyword.

The StudentApp.java is a driver class that is used to demonstrate object instantiation as well as concept elucidation.

[ Example 2 ]
In example 2, we describe polymorphism in inheritance using Method overriding.

Person -> Student -> MonashStudent

MonashStudent inherits all the methods and attributes from the Student class which inturn inherits from Person class.

MonashStudentApp.java is the driver class that articulate method overriding and polymorphism. The methods that are overridden are getGpa and setGpa.

In method overriding, we preserve the method signature but change the logic (content) in the method body.

[ Others ]
We have also went through a short session on Array of objects. You can recall this in StudentArrayApp.java.

[ Notes ]
In the next lesson, we will be talking about protected and how can protected allow the derived class to access the attributes in the base class.

Super class = Parent class = Base Class
Sub class = Child class = Derived Class

We use the "super" keyword to initialise the base class' attributes via the derived class constructor. The "super" keyword is also used to reference to base class method.

usage: super.getGpa();

For a better and clearer example on polymorphism, please visit http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming#Java

Using JGRASP to edit and compile my Java program

JGRASP is a lightweight integrated development environment software that allows one to edit and compile your Java program at ease. I strongly encourage you to get a copy of this software at http://www.jgrasp.org/.

In order for JGRASP to work properly, you will need to install JDK 5 (1.5) from http://java.sun.com/javase/downloads/index_jdk5.jsp.

Set up the Java development environment in week 1 of this semester and this will help you to pave the way for success in DSAG.