web programming assistant professor xiaozhong liu

26
Web Programming Assistant Professor Xiaozhong Liu http://scholarwiki.indiana.edu/S517/S517.

Upload: ashley-walton

Post on 12-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web Programming Assistant Professor Xiaozhong Liu

Web Programming

Assistant Professor

Xiaozhong Liu

http://scholarwiki.indiana.edu/S517/S517.html

Page 2: Web Programming Assistant Professor Xiaozhong Liu

Student…Student…

public class student {private String First_name;private String Last_name;private int ID;

public String getName () {return First_name + " " + Last_name;

}

public int getSUID () {return SUID;

}

public student () {//Constructor!

}}

Attributes or FieldsAttributes or Fields

BehaviorsBehaviors

Constructor(s)Constructor(s)

Page 3: Web Programming Assistant Professor Xiaozhong Liu

Student…Student…

public class student {private String First_name;private String Last_name;private int ID;public String major;

}

public class IUclass {public String class_name;private int ID;public student [ ] studs;

}

public class Application {

public static void main(String[] args) {student stu1 = new student();student stu2 = new student();student [ ] studs = new student [2];studs[0] = stu1;studs[1] = stu2;

IUclass S517 = new IUclass();S517.class_name = "Web Programming";S517.studs = studs;

}}

Page 4: Web Programming Assistant Professor Xiaozhong Liu

Lab – Part ILab – Part I

Design a laptop class. You will need to tell:

1.what is the attributes of the class?(at least, memory, hard drive size, type…)2.w hat is the possible methods of the class? (at least, install application, uninstall application, update memory…)3.design at least two constructors for this class4. which attribute/method should be private/public?5.create at least two instances from another class.

* Do you need to design another class – Application?

Page 5: Web Programming Assistant Professor Xiaozhong Liu

Java Doc for classJava Doc for class

Example:

http://docs.oracle.com/javase/6/docs/api/java/lang/String.html

VERY IMPORTANT! To tell the class usage.

What is the class properties? What is the functionality of each class method? Usage?

You can create your Java Doc easily!

Page 6: Web Programming Assistant Professor Xiaozhong Liu

Javadoc for classJavadoc for class

Generate Javadoc for each class, attribute, or methodEclipse: source -> Generate Element Comment

Page 7: Web Programming Assistant Professor Xiaozhong Liu

Javadoc for classJavadoc for classGenerate class HTML map:Eclipse: Project -> Generate Javadoc

Page 8: Web Programming Assistant Professor Xiaozhong Liu

Lab – Part IILab – Part II

Generate Javadoc for the laptop class you just defined:

1.Read the javadoc tutorial: http://students.cs.byu.edu/~cs240ta/fall2012/tutorials/javadoctutorial.html2.Generate comments for class, attribute, and method by using Eclipse3.Generate Javadoc by using Eclipse, and open your class HTML by using browser.

Page 9: Web Programming Assistant Professor Xiaozhong Liu

DebugDebug

Break Point for debug…Break Point for debug…

Debug As…Debug As…

Page 10: Web Programming Assistant Professor Xiaozhong Liu

DebugDebug

Run your code line by line…Run your code line by line…

Monitor variables in the memoryMonitor variables in the memory

Step into or Step OverStep into or Step Over

Page 11: Web Programming Assistant Professor Xiaozhong Liu

DebugDebug

Debug is important to tell the information flow Debug is important to tell the information flow between different objects.between different objects.

Help you to test your code!Help you to test your code!

Help you to understand the code!Help you to understand the code!

Monitor the variable value change in the memory…Monitor the variable value change in the memory…

Page 12: Web Programming Assistant Professor Xiaozhong Liu

Lab 3: Debug CodeLab 3: Debug Code

Debug your code for Laptop-Application project.Debug your code for Laptop-Application project.

Set a break point in the main function.Set a break point in the main function.

Monitor the information (variable) flow by using Monitor the information (variable) flow by using “step into”. “step into”.

Debug your Assignment 2 – step into one method, Debug your Assignment 2 – step into one method, i.e., getVotes method, and monitor the variable i.e., getVotes method, and monitor the variable value changes. value changes.

Page 13: Web Programming Assistant Professor Xiaozhong Liu

Static attribute/methodStatic attribute/method

public class student {private String First_name;private String Last_name;private int ID;public String major;static int number_of_students = 50000;

static public int get_num_of_students () {return number_of_students;

}}

number_of_students is instance independent!!!

Page 14: Web Programming Assistant Professor Xiaozhong Liu

Class, instance, properties…Class, instance, properties…

public class student {IDNameGPArequired_creditmin_GPA

}

Page 15: Web Programming Assistant Professor Xiaozhong Liu

Class, instance, properties…Class, instance, properties…

public class student {IDNameGPArequired_creditmin_GPA

}

instance independent!

public class student {public int ID;public String Name;public double GPA;public static int required_credit;public static double min_GPA;

public double Calculate_GPA () {…

}

public static void print_min_GPA () {…

}}

Page 16: Web Programming Assistant Professor Xiaozhong Liu

LibraryLibrary

Library is used to organize classes

For instance:

Java.util - miscellaneous utility classes

Java.io – IO classes

Java.sql – Database classes

Import … if you want use some classes or a library…

Page 17: Web Programming Assistant Professor Xiaozhong Liu

Graduate Student…Graduate Student…

public class Graduate_student {private String First_name;private String Last_name;private int ID;private String Advisor;private String Research_area;

public String getName () {return First_name + " " + Last_name;

}

public int getIUID () {return IUID;

}

public int getResearchArea () {return Research_area;

}}

Page 18: Web Programming Assistant Professor Xiaozhong Liu

Relationship between classes…Relationship between classes…Inheritance, PolymorphismInheritance, Polymorphism

Page 19: Web Programming Assistant Professor Xiaozhong Liu

Relationship between classes…Relationship between classes…

public class Undergrad_student extends student {private String Major;

public String getMajor () {return Major;

}}

public abstract class student {protected String First_name;protected String Last_name;protected int IUID;

public String getName () {return First_name + " " +

Last_name;}

public int getIUID () {return IUID;

}}

inheritance is a way to reuse code of existing objects, establish a subtype from an existing object, or both, depending upon programming language support.

Page 20: Web Programming Assistant Professor Xiaozhong Liu

Abstract classAbstract class

public abstract class SomeClass { ... public abstract void SomeMethod();}

Some of the methods in a class can be declared abstract and left with only signatures defined

A class with one or more abstract methods must be declared abstract

Page 21: Web Programming Assistant Professor Xiaozhong Liu

Super ClassSuper Class

public class graduate_student extends student { String research;

public graduate_student(String first_name, String last_name, int ID, String research) {super(first_name, last_name, ID);this.research = research;

}

public void print_student_info () {super.print_student_info();System.out.println("Research Area: " + research);

}

}

Call some method from SuperClass

Page 22: Web Programming Assistant Professor Xiaozhong Liu

SubclassSubclass

• Inherits attributes and methods of its superclass• You can add new attributes and methods • You can re-define (override) a method of the

superclass• You MUST provide its OWN constructors • Does not have direct access to its superclass’s

private attributes and methods

Page 23: Web Programming Assistant Professor Xiaozhong Liu

Relationship between classes…Relationship between classes…

Manager

Part_time

Salesman

Full_time

Employee

CEO

Page 24: Web Programming Assistant Professor Xiaozhong Liu
Page 25: Web Programming Assistant Professor Xiaozhong Liu

Lab 4: Class Relationship Lab 4: Class Relationship

• Design a list of classes for Library• 1. Library resources (i.e., books and journals), which at

least has name, publisher, author, and year information.• 2. Books, with ISBN number, can be kept by users no

more than 7 days. If overdue, user need to pay $0.5 per fay.

• 3. Journals, with with vol number, can be kept by users no more than 20 days. If overdue, user need to pay $0.1 per fay.

• 4. User. Each user can check out no more than 3 library resources. You need to design a method to calculate how much your need to pay when he/she return a resource.

Page 26: Web Programming Assistant Professor Xiaozhong Liu

Practice: Practice:

Design a library system (object oriented design)Design a library system (object oriented design)

1.1.What is library resources?What is library resources?2.2.What is library books?What is library books?3.3.What is library journals?What is library journals?4.4.What is library digitalized journals?What is library digitalized journals?5.5.How about library category? How about library category?