Computer Software vs. Hardware
Topic: Java in the Computer World
Programming languages High-level languages: –single statements could be written to accomplish substantial tasks. Assembly languages: –English-like abbreviations; –elementary operations Machine languages: –1's and 0's; –machine-dependent Machine language : Assembly language High-level language
Example (Programming languages) Machine languages: Assembly languages: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY High-level languages: grossPay = basePay +overTimePay
Java Software Development Environment You can have 4 separate parts: –Editor –Compiler –Interpreter –Debugger Or you can combine some of these parts
Integrated Development Environment (IDE) IDE combins –editor, compiler, interpreter and debugger IDE is a tool for developing software This course is not about IDE This course is about designing software
Where is Java in the compter world? -- section summary Machine language : Assembly language High-level language
Topic: Object Oriented Design Classes Methods
Classes = Classification = The classification process Classification is good Classification takes places in everyday life Classes
Classes -- How to classify Example object group ==>classes –class monitor (output device) –class printer (output device) –class speaker (output device) –class computer tower (computing device) –class keyboard (input device) –class mouse (input device) Classes
Class and Object Relation An object is an instance of a class A class represents a category of objects Class monitorClass printer obj Classes
Class and method relation Classes
Why Different Classes? Classes Good thing about such modular design: –Independent objects ==>local problem only Example –bad keyboard, but everything else is still working fine –Easy to find problems –try a new keyboard --> find out the old keyboard is bad –Easy to fix problems –buy a new keyboard for $15 –If the system does not have such modular design we’d be in trouble.
Sub-class Classes A big class might have sub-classes Good vs. bad classification Example: make sub-classes for books in a bookstore –Good classification: literature, arts, science, religion, sports, home, map… –Bad classification: alphabetically order books: section A,B,C...
About Class: section summary Classes We have learned –Classification is good classification = categorization –(motivated why we want to split things into classes –Good classification vs. bad classification –Sometimes, a class has sub-classes
About Class: section summary (continue…) Classes Also, we have learned... –An object is an instance of a class –A method is inside of a class Class monitor obj
Methods Each method belongs to a class A class can have many methods
Make Methods (Example) Methods Example: make up some methods for the printer class What does the printer do? –Let’s draw a flow chart...
Methods
Flow chart --> Methods Flow chart –help us to think through –breaks big task to smaller sub-tasks –small sub-tasks ==> methods Each method is an action Now, we are ready to write the skeleton of “class printer”... methods
// // class Printer // class Printer { // // define variables // boolean double_sided; // The variable "double_sided" // as type "boolean", so it can // take only values "true" or "false". int maximum_memory_size; // The maximum size of the memory // is an integer. Type "int"=integer. // // Method: receive_file // DOES: Receive files to be printed. // void receive_file() { //... // We don't know how to program the method yet. } methods
About Methods: section summary In this section, we learned that –A class consists of many/some methods –A class might have methods to handle some tasks –Break a big task into small sub-tasks –method = sub-tasks (manageable sub-tasks) –often, mehtods ==> an action methods
Topic Summary: Class and method Class classification class modular design class = (method) + (method) +… big task = (small sub-task) + (small sub-task) +... Methods small sub-task We are happy -- that we designed a nice schematic Printer class.
Programming process ideas Program text, on paper or in head Work done at the keyboard with a text editor Program text, in a file such as Test.java Compiler-- a program for translating programs Program in Java byte code, in the file Test.class Java Virtual Machine JVM, executes the program Test.class