Lecture 181 CS110 Lecture 18 Tuesday, April 6, 2004 Announcements –hw8 due Thursday, April 8 –pass/fail, withdraw deadline Thursday, April 8 Agenda –Questions.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Lecture 211 CS110 Lecture 21 Thursday, April 15, 2004 Announcements –hw9 due tonight –hw9 due Thursday, April 22 –exam Tuesday, April 27 Agenda –Questions.
Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision.
CS 497C – Introduction to UNIX Lecture 11: - The File System Chin-Chih Chang
Inheritance Inheritance Reserved word protected Reserved word super
Department of computer science N. Harika. Inheritance Inheritance is a fundamental Object Oriented concept A class can be defined as a "subclass" of another.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Inheritance The objectives of this chapter are: To explore the concept and implications of inheritance Polymorphism To define the syntax of inheritance.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Lecture 221 CS110 Lecture 22 Tuesday, April 20, 2004 Announcements –hw10 due Thursday, April 22 –exam next Tuesday, April 27 Agenda –Questions –Error handling.
CPSC150 Abstract Classes and Interfaces Chapter 10.
Lecture 171 CS110 Lecture 17 Thursday, April 1, 2004 Announcements –hw7 due tonight –pass/fail, withdraw deadline April 8 Agenda –Questions –Juno –JFile.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
Lecture 241 CS110 Lecture 25 Tuesday, May 4, 2004 Announcements –final exam Thursday, May 20, 8:00 AM McCormack, Floor 01, Room 0608 (easier than last.
Lecture 161 CS110 Lecture 16 Tuesday, March 30, 2004 Announcements –hw7 due Thursday –pass/fail, withdraw deadline April 8 Agenda –Questions –toString.
Guide To UNIX Using Linux Third Edition
Abstract Classes and Interfaces
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
The file structure and related utilities CS240 Computer Science II.
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Java Language and SW Dev’t
Unix Basics Chapter 4.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Lecture 61 CS110 Lecture 6 Thursday, February 12, 2004 Announcements –hw2 due today Agenda –questions –testing –modeling text files –declarations (classes,
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
The Java Programming Language
Files. What are files? A series of data bits. a place for output a place to obtain input.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Wrapup1 CS110 Wrapup Tuesday, May 11, 2004 Announcements –final exam Thursday, May 20, 8:00 AM McCormack, Floor 01, Room 0608 (easier than last exam?!)
Lecture 21 CS110 Lecture 2 January 29, 2004 Announcements –hw1 part 1 – due right now –hw1 part 2 – due Tuesday night Questions Agenda –turnin –Object.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
Lecture 131 CS110 Lecture 13 Thursday, March 11, 2004 Announcements –hw5 due tonight –Spring break next week –hw6 due two weeks from tonight Agenda –questions.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
Lecture 71 CS110 Lecture 7 February 17, 2004 Announcements –hw3 due Thursday Agenda –questions –hw3 tips –getters and setters – information hiding –delegation.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
Programming in Java CSCI-2220 Object Oriented Programming.
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
1 Lecture 9 Enhanced Class Design Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Lecture 71 CS110 Lecture 8 February 19, 2004 Announcements –hw3 due tonight –hw4 available, due Thursday February 26 –exam Tuesday March 2 Agenda –questions.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
FTP COMMANDS OBJECTIVES. General overview. Introduction to FTP server. Types of FTP users. FTP commands examples. FTP commands in action (example of use).
Lecture 261 CS110 Lecture 26 Thursday, May 6, 2004 This lecture not delivered from slides Announcements –final exam Thursday, May 20, 8:00 AM McCormack,
Lecture Topics: 11/29 File System Interface –Files and Directories –Access Methods –Protection –Consistency.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Lecture 241 CS110 Lecture 24 Thursday, April 29, 2004 Announcements –exam answers, final project (WISE) posted –final exam Thursday, May 20, 8:00 AM McCormack,
Inheritance ITI1121 Nour El Kadri.
University of Central Florida COP 3330 Object Oriented Programming
Shell Script Assignment 1.
Programming Language Concepts (CIS 635)
Creating and Modifying Text part 2
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
File I/O ICS 111: Introduction to Computer Science I
Inheritance Inheritance is a fundamental Object Oriented concept
OO Design with Inheritance
Chapter 14 Abstract Classes and Interfaces
Presentation transcript:

Lecture 181 CS110 Lecture 18 Tuesday, April 6, 2004 Announcements –hw8 due Thursday, April 8 –pass/fail, withdraw deadline Thursday, April 8 Agenda –Questions –Juno –JFile system internals

Lecture 182 Juno classes

Lecture 183 Shell “shell” is standard computer science terminology for an operating system’s command line interface Windows Command Prompt is a shell xemacs gives you access to the same shell Juno has a shell, presented to a user after she logs in

Lecture 184 Shell object Constructor sets some fields –the Juno system that created this Shell (37) (like issuing Bank in BankAccount) –the User and the console (38, 39) –the current Directory (the User’s home) (40) Then invokes CLIShell (command line interface) which works just like LoginInterpreter –get an input line from the user (50) –invoke this Shell’s interpret method –done when interpret returns false for moreWork (user has typed “logout”)

Lecture 185 Shell interpret method (60) Create a StringTokenizer for the input line, after throwing away Juno comments (# …) First token is the commandName (66) If it’s “logout”, then done (return false) Replace if else if … with dispatch table –(70,71) look up commandObject in command table (commandName String is key) –(76) send commandObject a doIt() message Polymorphism!

Lecture 186 Polymorphism poly (many) + morph (shape) ShellCommandTable.java –maintains a list of (abstract) ShellCommand objects –client retrieves them and sends them messages –without knowing what kinds of JFiles they are! Client refers to objects of type Parent that are really instances of a Child extending Parent Powerful design tool - ignorance is bliss

Lecture 187 abstract class ShellCommand Documentation managed here –helpString and argstring fields (19, 20) –initialized by protected constructor (31, 32) doIt() method (54): abstract public void doIt ( StringTokenizer args, Shell sh ); doIt is passed the rest of the text on the Juno command line, and the Shell it’s acting for Each concrete ShellCommand implements its own doIt() - polymorphism

Lecture 188 Designing a ShellCommand object MkdirCommand extends ShellCommand (18) Constructor (24) –super invokes ShellCommand constructor, telling it help string and argument string for mkdir implement abstract method doIt (37) –next token on line is the name of the Directory to be made –tell Directory constructor the name, owner, parent public void doIt( StringTokenizer args, Shell sh ) { String filename = args.nextToken(); new Directory(filename, sh.getUser(), sh.getDot()); }

Lecture 189 ShellCommandTable Juno constructor creates a ShellCommandTable (Juno.java line 52) ShellCommandTable.java –declare and initialize a TreeMap (line 23) –constructor (line 31) invokes fillTable (line 69) –fillTable creates one of each concrete ShellCommand objects, invokes install (line 61) to put it in the table –client (a Shell) invokes lookup (43), which wraps Map get method (and does the cast)

Lecture 1810 How the dispatch table works (reprise) In CLIShell loop: –get first token on the line: commandName –lookup commandObject with commandName key –send doIt() message Each particular ShellCommand extends the abstract ShellCommand class, implementing doIt() in its own way Polymorphism at work

Lecture 1811 How LoginInterpreter interpret works (reprise) get first token on the line use if - else if - else if … logic –if “exit” return false! // leave loop in CLIlogin –if “register” // create account for new user –if “help” // give help –else // input is a username

Lecture 1812 Dispatch table vs if-else if-else if To add new commands just add a table entry Command semantics separate from syntax Lots of design overhead, hard to understand Good for large command sets that will grow (Juno shell commands) To add new commands must edit the main loop Command semantics and syntax in same place Quick and dirty, easy to understand and code Good for small command sets that stay put (Juno login loop)

Lecture 1813 JFile system uses two trees Java class hierarchy class Object class JFile class Directoryclass TextFile Juno Directory and TextFile hierarchy \ users\ eb\ backup\ Foo.java memo.txt bill\

Lecture 1814 JFile (easy part) private fields for String name Date createDate User ownerDate modDate getters and setters as appropriate abstract getSize method since each child must provide its own implementation: –number of JFiles in a Directory –number of characters in a TextFile

Lecture 1815 Testing JFile, Directory, TextFile JFile version 5 (before Juno) has static code for testing JFile and its subclasses We didn’t study it Best way to test these classes as a part of Juno is to write Juno commands –type to test newfile (done) –cd and list to test mkdir (done for Juno 7) Read CdCommand hw9: improve the ListCommand we will provide

Lecture 1816 JFiles in Juno Directory constructor signature: (String directoryName, User owner, Directory parent) User constructor signature (String loginName, Directory home, String realName) Circular reference problem needs solving

Lecture 1817 Set up Juno file system (Juno.java 56-60) // create root directory slash = new Directory( "", null, null ); // create system administrator (a User) User root = new User ( "root", slash, "Rick Martin" ); // add system administrator to user table users.put( "root", root ); // system administrator owns his home slash.setOwner(root); // create Directory for regular user homes userHomes = new Directory ( "users", root, slash );

Lecture 1818 Home Directory Each User has a home directory, in users, created when User is created (LoginInterpreter register method, line 100) Any user can read or write in any other user’s home directory

Lecture 1819 Managing the JFile tree A Directory –keeps a TreeMap of JFiles in its jfile field, keyed by name –has methods to add and retrieve JFiles by name –has a method that allows client to loop on contents A JFile has a parent field (line 37) in which it keeps a reference to the Directory it lives in (like BankAccount – Bank)

Lecture 1820 JFile constructor JFile.java, line 49 protected : visible to children, not public lines are easy: they initialize fields if (parent != null) ( line 53) parent.addJFile( name, this ); if this JFile has a parent (not top of JFile tree) send message to parent to add this JFile (Directory or TextFile) to its TreeMap, with name as key. (Directory.java line 67) Careful: parent directory != parent class

Lecture 1821 Current Directory When a Juno user logs in, the current Directory is her home Directory Convention (in the world of shells). signifies the current Directory.. signifies its parent Juno Shell provides getDot and setDot methods

Lecture 1822 cd Syntax cd # change to home directory cd foo # change to subdirectory foo cd. # stay where you are cd.. # change to parent of current directory cd..\bar\whatever # not supported in Juno

Lecture 1823 doIt() in CdCommand class String dirname = ""; Directory d = sh.getUser().getHome(); if ( args.hasMoreTokens() ) { dirname = args.nextToken(); if (dirname.equals("..")) { if (sh.getDot().isRoot()) d = sh.getDot(); // no change else d = sh.getDot().getParent(); } else if (dirname.equals(".")) d = sh.getDot(); // no change else d = (Directory)sh.getDot(). retrieveJFile(dirname)); } sh.setDot( d );

Lecture 1824 JFile getSuffix A unix/linux tradition appends a / when listing the name of a Directory We want JFiles to behave this way, but to use the windows \ instead Ask a JFile to tell you its suffix by sending it a getSuffix message getSuffix is abstract in JFile.java \ users\ eb\ backup\ Foo.java memo.txt bill\

Lecture 1825 “\” vs “/” Windows uses one, Unix the other Java knows about both File.java (in the Java API) declares public static final String separator JFile.java declares public static String separator = File.separator

Lecture 1826 full path name in shell prompt directories first, including. and.. file, directory and character counts, including. and.. dir (windows)

Lecture 1827 mars:\users\eb> list Directory of \users\eb 04/05/ :34 AM. 04/05/ :34 AM.. 04/05/ :31 AM 2 backup\ 04/05/ :33 AM 13 Foo.java 04/05/ :32 AM 17 memo.txt 2 File(s) 30 bytes 3 Dir(s) list (Juno) full path name in shell prompt file, directory and character counts, including. and..

Lecture 1828 getPathName (JFile line 77) public String getPathName() { if (this.isRoot()) { return separator; } if (parent.isRoot()) { return separator + getName(); } return parent.getPathName() + separator + getName(); }

Lecture 1829 Boxes and arrows coming soon

Lecture 1830 Formatting Dates Numbers I18N