Database Client
In
this chapter, we will look at the client side of this database application.
Files needed for this chapter are:
- MDI.java (Main form)
- Student.java (Represents a student)
- StudentForm.java (Visual form for entering
information)
The Student Class
Listing
16.1 Student.java
import java.io.*;
//Class used to represent a student.
public class Student
implements Serializable{
//Instance variables.
private int rollNumber;
private String name,course;
//Constructor
public Student(int rollNumber,
String name,String course){
//Initialize the variables.
this.rollNumber = rollNumber;
this.name = name;
this.course = course;
}
//{{ Accessor methods }} //
//method used to get roll number.
public int getRollNumber(){
return rollNumber;
}
//method used to get name.
public String getName(){
return name;
}
//method used to get course
public String getCourse(){
return course;
}
//{{Mutator methods }}//
//method used to set roll number.
public void setRollNumber(int rollNumber){
this.rollNumber = rollNumber;
}
//method used to set name.
public void setName(String name){
this.name = name;
}
//method used to set course.
public void setCourse(String course){
this.course = course;
}
//Returns a string representation of the object.
public String toString(){
return "RollNumber: " +rollNumber +
" Name: " + name +
" Course : " + course;
}
}
Explanation of Code
This class represents a student. Objects of this class will be passed
across the network. The class is not remote, so its methods can not
be invoked remotely. Note that the Student class implements the java.io.Serializable
interface. Therefore, objects of this class can be transported from
one machine to another, but the receiving machine will get the copy
of the actual object.
The Constructor of the class takes three arguments:
- Roll number of the student.
- Name of the student.
- Course for which the student is registered.
Further, the class provides some accessor and mutator methods.
|