Tài liệu 1 computer systems This book is about writing well-designed software. To understand software, we pdf

904 462 0
Tài liệu 1 computer systems This book is about writing well-designed software. To understand software, we pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

1 in a computer system Hardware chapter objectives and software cooperate in a computer system to accomplish complex tasks The nature of ◗ Describe the relationship between hardware and software that cooperation and the purpose ◗ Define various types of software and how they are used are important prerequisites to ◗ Identify the core hardware components of a computer and explain their purposes ment Furthermore, computer ◗ Explain how the hardware components interact to execute programs and manage data ◗ Describe how computers are connected together into networks to share information ◗ Explain the impact and significance of the Internet and the World Wide Web ◗ Introduce the Java programming language ◗ Describe the steps involved in program compilation and execution ◗ Introduce graphics and their representations of various hardware components the study of software developnetworks have revolutionized the manner in which computers are used, and they now play a key role in even basic software development This chapter explores a broad range of computing issues, laying the foundation for the study of software development computer systems This book is about writing well-designed software To understand software, we must first have a fundamental understanding of its role CHAPTER computer systems 1.0 introduction We begin our exploration of computer systems with an overview of computer processing, defining some fundamental terminology and showing how the key pieces of a computer system interact key concept basic computer processing A computer system is made up of hardware and software The hardware components of a computer system are the physical, tangible pieces that support the computing effort They include chips, boxes, wires, keyboards, speakers, disks, cables, plugs, printers, mice, monitors, and so on If you can physically A computer system consists of touch it and it can be considered part of a computer system, then it is hardware and software that computer hardware work in concert to help us solve problems The hardware components of a computer are essentially useless without instructions to tell them what to A program is a series of instructions that the hardware executes one after another Software consists of programs and the data those programs use Software is the intangible counterpart to the physical hardware components Together they form a tool that we can use to solve problems The key hardware components in a computer system are: ◗ central processing unit (CPU) ◗ input/output (I/O) devices ◗ main memory ◗ secondary memory devices Each of these hardware components is described in detail in the next section For now, let’s simply examine their basic roles The central processing unit (CPU) is the device that executes the individual commands of a program Input/output (I/O) devices, such as the keyboard, mouse, and monitor, allow a human being to interact with the computer Programs and data are held in storage devices called memory, which fall into two categories: main memory and secondary memory Main memory is the storage device that holds the software while it is being processed by the CPU Secondary memory devices store software in a relatively permanent manner The most important secondary memory device of a typical computer system is the hard disk that resides inside the main computer box A floppy disk is similar to a hard disk, but it cannot store nearly as much information as a hard disk Floppy 1.0 introduction disks have the advantage of portability; they can be removed temporarily or moved from computer to computer as needed Other portable secondary memory devices include zip disks and compact discs (CDs) The process of executing a program is fundamental to the operation of a computer All computer systems basically work in the same way software categories Software can be classified into many categories using various criteria At this point we will simply differentiate between system programs and application programs The operating system is the core software of a computer It performs two important functions First, it provides a user interface that allows the user to Hard disk Keyboard Main memory Floppy disk figure 1.1 CPU Monitor A simplified view of a computer system key concept Figure 1.1 shows how information moves among the basic hardware components of a computer Suppose you have an executable program you wish to run The program is stored on some secondary memory device, such as a hard disk.When you instruct the computer to execute your program, a copy of the program is brought in from secondary memory and stored in To execute a program, the main memory The CPU reads the individual program instructions computer first copies the program from secondary memory from main memory The CPU then executes the instructions one at a to main memory The CPU time until the program ends The data that the instructions use, such then reads the program as two numbers that will be added together, are also stored in main instructions from main memmemory They are either brought in from secondary memory or read ory, executing them one at a time until the program ends from an input device such as the keyboard During execution, the program may display information to an output device such as a monitor key concept CHAPTER computer systems interact with the machine Second, the operating system manages computer resources such as the CPU and main memory It determines when programs are allowed to run, where they are loaded into memory, and how hardware devices communicate It is the operating system’s job to make the computer easy to use and to ensure that it runs efficiently The operating system provides a user interface and manages computer resources Several popular operating systems are in use today Windows 98, Windows NT, Windows 2000, and Windows XP are several versions of the operating system developed by Microsoft for personal computers Various versions of the Unix operating system are also quite popular, especially in larger computer systems A version of Unix called Linux was developed as an open source project, which means that many people contributed to its development and its code is freely available Because of that, Linux has become a particular favorite among some users Mac OS is the operating system used for computing systems developed by Apple Computers An application is a generic term for just about any software other than the operating system Word processors, missile control systems, database managers, Web browsers, and games can all be considered application programs Each application program has its own user interface that allows the user to interact with that particular program The user interface for most modern operating systems and applications is a graphical user interface (GUI), which, as the name implies, make use of graphical screen elements These elements include: ◗ windows, which are used to separate the screen into distinct work areas ◗ icons, which are small images that represent computer resources, such as a file ◗ pull-down menus, which provide the user with lists of options ◗ scroll bars, which allow the user to move up and down in a particular window ◗ buttons, which can be “pushed” with a mouse click to indicate a user selection The mouse is the primary input device used with GUIs; thus, GUIs are sometimes called point-and-click interfaces The screen shot in Fig 1.2 shows an example of a GUI The interface to an application or operating system is an important part of the software because it is the only part of the program with which the user directly interacts To the user, the interface is the program Chapter discusses the creation of graphical user interfaces 1.0 introduction figure 1.2 An example of a graphical user interface (GUI) (Palm Desktop™ courtesy of 3COM Corporation) As far as the user is concerned, the interface is the program digital computers Two fundamental techniques are used to store and manage information: analog and digital Analog information is continuous, in direct proportion to the source of the information For example, a mercury thermometer is an analog device for measuring temperature The mercury rises in a tube in direct proportion to the temperature outside the tube Another example of analog information is an electronic signal used to represent the vibrations of a sound wave The signal’s voltage varies in direct proportion to the original sound wave A stereo amplifier sends this kind of electronic signal to its speakers, which vibrate to reproduce the sound We use the term analog because the signal is directly analogous to the information it represents Figure 1.3 graphically depicts a sound wave captured by a microphone and represented as an electronic signal key concept The focus of this book is the development of high-quality application programs We explore how to design and write software that will perform calculations, make decisions, and control graphics We use the Java programming language throughout the text to demonstrate various computing concepts CHAPTER computer systems Sound wave figure 1.3 Analog signal of the sound wave A sound wave and an electronic analog signal that represents the wave key concept Digital technology breaks information into discrete pieces and represents those pieces as numbers The music on a compact disc is stored digitally, as a series of numbers Each number represents the voltage level of one specific instance of the recording Many of these measurements are taken in a short period of time, perhaps 40,000 measurements every second The number of measurements per second is called the sampling rate If samples are taken often enough, the discrete voltage measurements can be used to generate a continuous analog signal that is “close enough” to the original In most cases, the goal is to create a reproduction of the original signal that is good enough to satisfy the human ear Digital computers store information by breaking it into pieces and representing each piece as a number Figure 1.4 shows the sampling of an analog signal When analog information is converted to a digital format by breaking it into pieces, we say it has been digitized Because the changes that occur in a signal between samples are lost, the sampling rate must be sufficiently fast Sampling is only one way to digitize information For example, a sentence of text is stored on a computer as a series of numbers, where each number represents a single character in the sentence Every letter, digit, and punctuation symbol has been assigned a number Even the space character is assigned a number Consider the following sentence: Hi, Heather 1.0 introduction Information can be lost between samples Analog signal Sampling process Sampled values figure 1.4 12 11 39 40 14 47 Digitizing an analog signal by sampling The characters of the sentence are represented as a series of 12 numbers, as shown in Fig 1.5 When a character is repeated, such as the uppercase ‘H’, the same representation number is used Note that the uppercase version of a letter is stored as a different number from the lowercase version, such as the ‘H’ and ‘h’ in the word Heather They are considered separate and distinct characters Modern electronic computers are digital Every kind of information, including text, images, numbers, audio, video, and even program instructions, is broken into pieces Each piece is represented as a number The information is stored by storing those numbers H i , 72 105 figure 1.5 44 32 72 H e a t h e r 101 97 116 104 101 114 46 Text is stored by mapping each character to a number CHAPTER computer systems binary numbers A digital computer stores information as numbers, but those numbers are not stored as decimal values All information in a computer is stored and managed as binary values Unlike the decimal system, which has 10 digits (0 through 9), the binary number system has only two digits (0 and 1) A single binary digit is called a bit key concept All number systems work according to the same rules The base value of a number system dictates how many digits we have to work with and indicates the place value of each digit in a number The decimal number system is base 10, whereas the binary number system is base Appendix B contains a detailed discussion of number systems Binary values are used to store all information in a computer because the devices that store and manipulate binary information are inexpensive and reliable Modern computers use binary numbers because the devices that store and move information are less expensive and more reliable if they have to represent only one of two possible values Other than this characteristic, there is nothing special about the binary number system Computers have been created that use other number systems to store information, but they aren’t as convenient Some computer memory devices, such as hard drives, are magnetic in nature Magnetic material can be polarized easily to one extreme or the other, but intermediate levels are difficult to distinguish Therefore magnetic devices can be used to represent binary values quite efficiently—a magnetized area represents a binary and a demagnetized area represents a binary Other computer memory devices are made up of tiny electrical circuits These devices are easier to create and are less likely to fail if they have to switch between only two states We’re better off reproducing millions of these simple devices than creating fewer, more complicated ones Binary values and digital electronic signals go hand in hand They improve our ability to transmit information reliably along a wire As we’ve seen, analog signal has continuously varying voltage, but a digital signal is discrete, which means the voltage changes dramatically between one extreme (such as +5 volts) and the other (such as –5 volts) At any point, the voltage of a digital signal is considered to be either “high,” which represents a binary 1, or “low,” which represents a binary Figure 1.6 compares these two types of signals As a signal moves down a wire, it gets weaker and degrades due to environmental conditions That is, the voltage levels of the original signal change slightly The trouble with an analog signal is that as it fluctuates, it loses its original information Since the information is directly analogous to the signal, any change in the signal changes the information The changes in an analog signal cannot be 1.0 introduction Analog signal Digital signal figure 1.6 An analog signal vs a digital signal recovered because the degraded signal is just as valid as the original A digital signal degrades just as an analog signal does, but because the digital signal is originally at one of two extremes, it can be reinforced before any information is lost The voltage may change slightly from its original value, but it still can be interpreted as either high or low The number of bits we use in any given situation determines the number of unique items we can represent A single bit has two possible values, and 1, and therefore can represent two possible items or situations If we want to represent the state of a light bulb (off or on), one bit will suffice, because we can interpret as the light bulb being off and as the light bulb being on If we want to represent more than two things, we need more than one bit Three bits can represent eight unique items, because there are eight permutations of three bits Similarly, four bits can represent 16 items, five bits can represent 32 items, and so on Figure 1.7 shows the relationship between the number of bits used and the number of items they can represent In general, N bits can represent 2N unique items For every bit added, the number of items that can be represented doubles key concept Two bits, taken together, can represent four possible items because there are exactly four permutations of two bits: 00, 01, 10, and 11 Suppose we want to represent the gear that a car is in (park, drive, reverse, or neutral) We would need only two bits, and could set up a mapping between the bit permutations and the gears For instance, we could say that 00 represents park, There are exactly 2N permutations of N bits Therefore N 01 represents drive, 10 represents reverse, and 11 represents neutral bits can represent up to 2N In this case, it wouldn’t matter if we switched that mapping around, unique items though in some cases the relationships between the bit permutations and what they represent is important 10 CHAPTER computer systems bit items bits items bits items bits 16 items 00 000 0000 00000 10000 01 001 0001 00001 10001 10 010 0010 00010 10010 11 011 0011 00011 10011 100 0100 00100 10100 101 0101 00101 10101 110 0110 00110 10110 111 0111 00111 10111 1000 01000 11000 1001 01001 11001 1010 01010 11010 1011 01011 11011 1100 01100 11100 1101 01101 11101 1110 01110 11110 1111 01111 11111 figure 1.7 bits 32 items The number of bits used determines the number of items that can be represented We’ve seen how a sentence of text is stored on a computer by mapping characters to numeric values Those numeric values are stored as binary numbers Suppose we want to represent character strings in a language that contains 256 characters and symbols We would need to use eight bits to store each character because there are 256 unique permutations of eight bits (28 equals 256) Each bit permutation, or binary value, is mapped to a specific character Ultimately, representing information on a computer boils down to the number of items there are to represent and determining the way those items are mapped to binary values 1.1 hardware components Let’s examine the hardware components of a computer system in more detail Consider the computer described in Fig 1.8 What does it all mean? Is the system capable of running the software you want it to? How does it compare to other systems? These terms are explained throughout this section 892 APPENDIX M the java class library public boolean hasMoreTokens() Returns a true value if there are more tokens to be returned by this string tokenizer hasMoreElements() is identical to hasMoreTokens() and is implemented to complete the implementation of the Enumerated interface public Object nextElement() throws NoSuchElementException public String nextToken() throws NoSuchElementException public String nextToken(String delims) throws NoSuchElementException Returns the next token in the string nextElement() is identical to nextToken() and is implemented to complete the implementation of the Enumerated interface New delimiters can be spec- ified in the last method, and stay in effect until changed System (java.lang) A public final class, derived from Object, that contains the standard input, output, and error streams, as well as various system related methods variables and constructs public static PrintStream err public static InputStream in public static PrintStream out Constant values that are the standard error output stream (stderr), standard input stream (stdin), and the standard output stream (stdout) methods public static void arraycopy(Object source, int srcindex, Object dest, int destindex, int size) throws ArrayIndexOutOfBoundsException, ArrayStoreException Copies a subarray of size objects from source, starting at index srcindex, to dest starting at destindex public static long currentTimeMillis() Returns the current system in milliseconds from midnight, January 1st, 1970 UTC public static void exit(int num) throws SecurityException Exits the program with the status code of num public static void gc() Executes the gc method of the Runtime class, which attempts to garbage collect any unused objects, freeing system memory public static Properties getProperties() throws SecurityException APPENDIX M the java class library 893 public static void setProperties(Properties newprops) throws SecurityException Returns or sets the current system properties public static String getProperty(String name) throws SecurityException public static String getProperty(String name, String default) throws SecurityException Returns the system property for name, or returns the value default as a default result if no such name exists public static SecurityManager getSecurityManager() public static void setSecurityManager(SecurityManager mgr) throws SecurityException Returns or sets the security manager for the current application If no security manager has been initialized, then a null value is returned by the get method public static int identityHashCode(Object arg) Returns the hash code for the specified object This will return the default hash code, in the event that the object’s hashCode method has been overridden public static void load(String name) throws UnsatisfiedLinkError, SecurityException Loads name as a dynamic library public static void loadLibrary(String name) throws UnsatisfiedLinkError, SecurityException Loads name as a system library public static void runFinalization() Requests that the Java Virtual Machine execute the finalize method on any outstanding objects public static void runFinalizersOnExit(boolean toggle) Allows the execution of the finalizer methods for all objects, when toggle is true public static void setErr(PrintStream strm) public static void setIn(InputStream strm) public static void setOut(PrintStream strm) Reassigns the error stream, input stream, or output stream to strm SystemColor (java.awt) A public final class, derived from Color and implementing Serializable, that represents the current window system color for the current system If the user changes the window system colors for this system and the window system can update the new color selection, these color values will change as well variables and constructs public final static int ACTIVE_CAPTION Constant index to the active caption color in the system color array 894 APPENDIX M the java class library public final static int ACTIVE_CAPTION_BORDER public final static int ACTIVE_CAPTION_TEXT Constant indices to the active caption border and text colors in the system color array public final static int CONTROL Constant index to the control color in the system color array public final static int CONTROL_DK_SHADOW public final static int CONTROL_SHADOW Constant indices to the control shadow and control dark shadow colors in the system color array public final static int CONTROL_HIGHLIGHT public final static int CONTROL_LT_HIGHLIGHT Constant indices to the control highlight and light highlight colors in the system color array public final static int CONTROL_TEXT Constant index to the control text color in the system color array public final static int DESKTOP Constant index to the desktop color in the system color array public final static int INACTIVE_CAPTION Constant index to the inactive caption color in the system color array public final static int INACTIVE_CAPTION_BORDER public final static int INACTIVE_CAPTION_TEXT Constant indices to the inactive caption border and text colors in the system color array public final static int INFO Constant index to the information (help) text background color in the system color array public final static int INFO_TEXT public final static int MENU_TEXT Constant indices to the information (help) and menu text colors in the system color array public final static int NUM_COLORS Constant value that holds the number of colors in the system color array public final static int SCROLLBAR Constant index to the scrollbar background color in the system color array public final static int TEXT Constant index to the background color of text components in the system color array public final static int TEXT_HIGHLIGHT public final static int TEXT_HIGHLIGHT_TEXT Constant indices to the background and text colors for highlighted text in the system color array public final static int TEXT_INACTIVE_TEXT Constant index to the inactive text color in the system color array public final static int TEXT_TEXT Constant index to the color of text components in the system color array APPENDIX M the java class library public final static int WINDOW Constant index to the background color of windows in the system color array public final static int WINDOW_BORDER public final static int WINDOW_TEXT Constant indices to the border and text colors of windows in the system color array public final static SystemColor activeCaption The system’s background color for window border captions public final static SystemColor activeCaptionBorder public final static SystemColor activeCaptionText The system’s border and text colors for window border captions public final static SystemColor control The system’s color for window control objects public final static SystemColor controlDkShadow public final static SystemColor controlShadow The system’s dark shadow and regular shadow colors for control objects public final static SystemColor controlHighlight public final static SystemColor controlLtHighlight The system’s highlight and light highlight colors for control objects public final static SystemColor controlText The system’s text color for control objects public final static SystemColor desktop The system’s color of the desktop background public final static SystemColor inactiveCaption The system’s background color for inactive caption areas of window borders public final static SystemColor inactiveCaptionBorder public final static SystemColor inactiveCaptionText The system’s border and text colors for inactive caption areas of window borders public final static SystemColor info The system’s background color for information (help) text public final static SystemColor infoText The system’s text color for information (help) text public final static SystemColor menu The system’s background color for menus public final static SystemColor menuText The system’s text color for menus public final static SystemColor scrollbar The system’s background color for scrollbars 895 896 APPENDIX M the java class library public final static SystemColor text The system’s color for text components public final static SystemColor textHighlight The system’s background color for highlighted text public final static SystemColor textHighlightText public final static SystemColor textInactiveText The system’s text color for highlighted and inactive text public final static SystemColor textText The system’s text color for text components public final static SystemColor window The system’s background color for windows public final static SystemColor windowBorder public final static SystemColor windowText The system’s border and text colors for windows methods public int getRGB() Returns the RGB values of this SystemColor’s symbolic color public String toString() Returns a string representation of this SystemColor’s values Thread (java.lang) A public class, derived from Object and implementing Runnable, that handles the implementation and management of Java execution threads variables and constructs public final static int MAX_PRIORITY public final static int MIN_PRIORITY public final static int NORM_PRIORITY Constant values that contain the maximum (10), minimum (1), and normal (6) priority values a thread can have constructors public Thread() Creates a new instance of a thread APPENDIX M the java class library 897 public Thread(Runnable arg) Creates a new instance of a thread arg specifies which object’s run method is invoked to start the thread public Thread(String str) public Thread(Runnable arg, String str) Creates a new instance of a thread, named str arg specifies which object’s run method is invoked to start the thread public Thread(ThreadGroup tgrp, String str) throws SecurityException public Thread(ThreadGroup tgrp, Runnable arg) throws SecurityException public Thread(ThreadGroup tgrp, Runnable arg, String str) throws SecurityException Creates a new instance of a thread, named str and belonging to thread group tgrp The arg parameter specifies which object’s run method is invoked to start the thread methods public static int activeCount() Returns the number of active threads in this thread’s group public void checkAccess() throws SecurityException Validates that the current executing thread has permission to modify this thread public static Thread currentThread() Returns the currently executing thread public void destroy() Destroys this thread public static void dumpStack() Dumps a trace of the stack for the current thread public static int enumerate(Thread[] dest) Copies each of the members of this thread’s group into the thread array dest public final String getName() public final int getPriority() public final ThreadGroup getThreadGroup() Returns the name, priority, or thread group of this thread public void interrupt() Interrupts this thread’s execution public static boolean interrupted() Returns a true value if the current thread’s execution has been interrupted public final boolean isAlive() public boolean isInterrupted() Returns a true value if this thread’s execution is alive or has been interrupted 898 APPENDIX M the java class library public final boolean isDaemon() Returns a true value if this thread is a daemon thread public final void join() throws InterruptedException public final void join(long msec) throws InterruptedException public final void join(long msec, int nsec) throws InterruptedException Waits up to msec milliseconds and nsec nanoseconds for this thread to die The join() method waits forever for this thread to die public void run() Method containing the main body of the executing thread code Run methods can run concurrently with other thread run methods public final void setDaemon(boolean flag) throws IllegalThreadStateException Sets this thread as a daemon thread, if flag is true public final void setName(String str) throws SecurityException public final void setPriority(int val) throws SecurityException Sets the name of this thread to str or the priority to val public static void sleep(long msec) throws InterruptedException public static void sleep(long msec, int nsec) throws InterruptedException Causes the current thread to sleep for msec milliseconds and nsec nanoseconds public void start() throws IllegalThreadStateException Start this thread’s execution, calling this thread’s run method public String toString() Returns a string representation of this thread public static void yield() Causes the currently executing thread to pause in execution, allowing other threads to run Throwable (java.lang) A public class, derived from Object and implementing Serializable, that is the superclass of all of the errors and exceptions thrown constructors public Throwable() public Throwable(String str) Creates a new instance of a throwable object with the specified message (str) or none present methods public Throwable fillInStackTrace() Fills in the executable stack trace for this throwable object APPENDIX M the java class library 899 public String getLocalizedMessage() Returns a locale specific description of this object Locale specific messages should override this method; otherwise, the same message that the getMessage method produces will be returned public String getMessage() Returns the detail message for this throwable public void printStackTrace() public void printStackTrace(PrintStream stream) public void printStackTrace(PrintWriter stream) Prints the stack trace for this throwable to the standard error stream or to the specified stream public String toString() Returns a string representation of this throwable object Timer (javax.swing) A public class, derived from Object and implementing Serializable, that fires an action event after a specified delay Often used to control animations constructors public Timer(int delay, ActionListener listener) Creates a timer that notifies the specified action listener every delay milliseconds methods public void addActionListener(ActionListener listener) Adds the specified action listener to this timer public int getDelay() public void setDelay(int delay) Gets or sets this timer’s delay (in milliseconds) public void start() public void stop() Starts or stops this timer public boolean isRunning() Returns true if this timer is currently running TimeZone (java.util) A public abstract class, derived from Object and implementing Serializable and Cloneable, that represents an amount of time offset from GMT that results in local time Functionality is provided to allow for Daylight Savings Time within a time zone 900 APPENDIX M the java class library methods clone() Returns a copy of this TimeZone public static synchronized String[] getAvailableIDs() public static synchronized String[] getAvailableIDs(int offset) Returns a list of all of the supported time zone ids, or only those for a specified time zone offset public static synchronized TimeZone getDefault() public static synchronized void setDefault(TimeZone tz) Returns or sets the default time zone public String getID() Returns the id of this time zone public abstract int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) Returns the offset from the Greenwich Mean Time (GMT), taking into account daylight savings time public abstract int getRawOffset() public abstract void setRawOffset(int millisec) Returns or sets the offset from Greenwich Mean Time (GMT) for this SimpleTimeZone These methods not take daylight savings time into account public static synchronized TimeZone getTimeZone(String id) Returns the time zone corresponding to the specified id value public abstract boolean inDaylightTime(Date dt) Returns a true result if the specified date falls within the Daylight Savings Time for this TimeZone public void setID(String id) Sets the id value of this TimeZone public abstract boolean useDaylightTime() Returns a true value if this TimeZone uses Daylight Savings Time URL (java.net) A public final class, derived from Object and implementing Serializable, that represents a Web Uniform Resource Locator (URL) constructors public URL(String arg) throws MalformedURLException public URL(URL url, String type) throws MalformedURLException Creates a URL instance from a string argument, or by parsing a type (http, gopher, ftp) and the remaining base APPENDIX M the java class library 901 public URL(String proto, String source, int num, String doc) throws MalformedURLException public URL(String proto, String source, String doc) throws MalformedURLException Creates a URL instance using a defined protocol (proto), source system, destination port num, and document (doc) methods public boolean equals(Object obj) Returns a true value if this URL is equal in all respects (protocol, source, port, and document) to obj public final Object getContent() throws IOException Returns the retrieved contents as an Object public String getFile() public String getRef() Returns the name of the file (document) or its anchor this URL will attempt to retrieve public String getHost() public int getPort() Returns the name of the host (source) or the port this URL will attempt to connect to public String getProtocol() Returns the protocol this URL will use in retrieving the data public int hashCode() Returns the hash code for this URL public URLConnection openConnection() throws IOException public final InputStream openStream() throws IOException Returns a connection to this URL and returns the connection or a stream public boolean sameFile(URL arg) Returns a true value if this URL retrieves the same file as the arg URL protected void set(String proto, String source, int num, String doc, String anchor) Sets the protocol (proto), source, port num, file (doc) and reference (anchor) for this URL public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) throws Error Sets the URL StreamHandlerFactory for this application to fac public String toExternalForm() public String toString() Returns a string representation of this URL 902 APPENDIX M the java class library Vector (java.util) A public class, derived from Object and implementing Serializable and Cloneable, that manages an array of objects Elements can be added or removed from this list and the size of the list can change dynamically variables and constructs protected int capacityIncrement The amount of element spaces to be added to the vector each time that an increase must occur A capacityIncrement of indicates that the list will double in size at every resizing protected int elementCount protected Object elementData[] The number of elements and the array containing the elements currently in this Vector constructors public Vector() public Vector(int size) public Vector(int size, int incr) Creates a new instance of a vector with an initial size of size (or using the default of 10) An initial capacityIncrement can also be specified methods public final void addElement(Object arg) public final void insertElementAt(Object arg, int index) throws ArrayIndexOutOfBoundsException Adds element arg to the end of this Vector or at a specific index The capacity of the vector is adjusted if needed public final int capacity() public final void ensureCapacity(int size) Returns the current capacity of this Vector, or ensures that it can contain at least size elements public Object clone() Returns the clone of this Vector public final boolean contains(Object arg) Returns a true value if this Vector contains object arg public final void copyInto(Object[] dest) Copies each of the elements of this Vector into the array dest public final Object elementAt(int index) throws ArrayIndexOutOfBoundsException Returns the element at location index from this Vector APPENDIX M the java class library 903 public final Enumeration elements() Returns an Enumeration of the elements in this Vector public final Object firstElement() throws NoSuchElementException public final Object lastElement() throws NoSuchElementException Returns the first or last element in this Vector public final int indexOf(Object arg) public final int indexOf(Object arg, int index) Returns the index of the first occurrence of element arg, starting at index A –1 value is returned if the element is not found public final boolean isEmpty() Returns a true value if this Vector contains no elements public final int lastIndexOf(Object arg) public final int lastIndexOf(Object arg, int index) Returns the first index that object arg occurs at in this Vector, starting a backwards search at the specified index If the object is not located, a –1 is returned public final void removeAllElements() public final boolean removeElement(Object arg) public final void removeElementAt(int index) throws ArrayIndexOutOfBoundsException Removes element arg and returns a true value If the object requested is not located, a false value is returned An element can also be removed at a specific index value, or all elements can be removed public final void setElementAt(Object arg, int index) throws ArrayIndexOutOfBoundsException Sets the element at the specified index equal to object arg public final void setSize(int size) Sets the size of this Vector to size public final int size() Returns the number of elements in this Vector public final String toString() Returns a string representation of this Vector public final void trimToSize() Reduces the size of this Vector to contain all of the elements present Void (java.lang) An uninstantiable class that acts as a placeholder for the primitive void type in the Class object 904 APPENDIX M the java class library variables and constructs public final static Class TYPE The Void constant value of the void type class Window (java.awt) A public class, derived from Container, that creates a graphical area that has no borders or menus and can be used to contain AWT components constructors public Window(Frame frm) Creates a new instance of a window that has a parent frame (frm) The window is initially not visible methods public void addNotify() Creates this window’s peer public synchronized void addWindowListener(WindowListener listener) public synchronized void removeWindowListener(WindowListener listener) Removes or adds the specified window listener (listener) for this window public void dispose() Removes this window and deletes any resources used by this window public Component getFocusOwner() Returns the component from this active window that currently has the focus public Locale getLocale() Returns the locale for this window public Toolkit getToolkit() Returns the toolkit for this window public final String getWarningString() Returns the warning string for this window public boolean isShowing() Returns a true value if this window is currently visible on the screen public void pack() Causes all of the components of this window to be laid out according to their preferred size protected void processEvent(AWTEvent event) Processes the specified event for this window If the event is a WindowEvent, then this method calls the process WindowEvent method of this window, otherwise it will call the parent class’ processEvent method APPENDIX M the java class library 905 protected void processWindowEvent(WindowEvent event) Handles any WindowEvent (event) generated on this window, and passes them to a registered lis- tener for that event public void show() Makes this window visible to the user and brings it to the front (on top of other windows) public void toBack() void toFront() Sends this window to the back or front of other windows currently displayed on the screen WindowAdapter (java.awt.event) A public abstract class, derived from Object and implementing WindowListener, that permits a derived class to override the predefined no-op AWT window events constructors public WindowAdapter() Creates a new instance of a WindowAdapter methods public void windowActivated(WindowEvent event) public void windowClosed(WindowEvent event) public void windowClosing(WindowEvent event) public void windowDeactivated(WindowEvent event) public void windowDeiconified(WindowEvent event) public void windowIconified(WindowEvent event) public void windowOpened(WindowEvent event) Empty methods that should be overridden in order to implement event handling for window events WindowEvent (java.awt.event) A public class, derived from ComponentEvent, that describes a particular AWT window-based event variables and constructs public static final int WINDOW_ACTIVATED public static final int WINDOW_CLOSED public static final int WINDOW_CLOSING public static final int WINDOW_DEACTIVATED 906 APPENDIX M the java class library public static final int WINDOW_DEICONIFIED public static final int WINDOW_FIRST public static final int WINDOW_ICONIFIED public static final int WINDOW_LAST public static final int WINDOW_OPENED Constant values which represent a variety of window event types constructors public WindowEvent(Window src, int type) Creates a new instance of a WindowEvent from a specified source window and having a specific event type methods public Window getWindow() Returns the source window that this event was triggered in public String paramString() Returns a string containing the parameters for this WindowEvent ... 0 010 00 010 10 010 11 011 0 011 00 011 10 011 10 0 010 0 0 010 0 10 100 10 1 010 1 0 010 1 10 1 01 110 011 0 0 011 0 10 110 11 1 011 1 0 011 1 10 111 10 00 010 00 11 000 10 01 010 01 110 01 1 010 010 10 11 010 10 11 010 11 110 11. .. 010 11 110 11 110 0 011 00 11 100 11 01 011 01 111 01 111 0 011 10 11 110 11 11 011 11 111 11 figure 1. 7 bits 32 items The number of bits used determines the number of items that can be represented We? ??ve seen... Language 1d [%fp–20], %o0 1d [%fp–24], %o1 add %o0, %o1, %o0 Machine Language 11 01 1 011 11 01 1 011 10 01 0000 11 11 0 010 11 11 0000 0000 11 10 0000 11 10 0000 011 1 10 00 011 1 10 00 0000 A high-level expression

Ngày đăng: 12/12/2013, 21:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan