Thursday, 30 October 2008

Java Concepts By Cay Horstmann - Part5

Couple of Days back i started reading Java Concepts 5th Edition By Cay Horstmann.

Nice book written by Cay Horstmann.

I wanted to share few quotations from the next two (9-10) chapters.

1) Use interface types to make code more reusable.

2) A Java interface type declares a set of methods and their signatures.

3) Unlike a class, an interface type provides no implementation.

4) Use the implements keyword to indicate that a class implements an interface type.

Example:


public class Coin implements Measurable
{
public double getMeasure()
{
return value;
}
. . .
}



5) Interfaces can reduce the coupling between classes.

6) You can convert from a class type to an interface type, provided the class implements the interface.

7) You need a cast to convert from an interface type to a class type.

8) Polymorphism denotes the principle that behavior can vary depending on the actual type of an object.

9) Early binding of methods occurs if the compiler selects a method from several possible candidates. Late binding occurs if the method selection takes place when the program runs.

10) An inner class is declared inside another class. Inner classes are commonly used for tactical classes that should not be visible elsewhere in a program.

11) To define an inner class whose scope is restricted to a single method or the methods of a single class.

12) Operating Systems

Without an operating system, a computer would not be useful. Minimally, you need an operating system to locate files and to start programs. The programs that you run need services from the operating system to access devices and to interact with other programs. Operating systems on large computers need to provide more
services than those on personal computers do.

Here are some typical services:

a) Program loading. Every operating system provides some way of launching application programs. The user indicates what program should be run,usually by typing the name of the program or by clicking on an icon. The
operating system locates the program code, loads it into memory, and starts it.

b) Managing files. A storage device, such as a hard disk is, electronically,simply a device capable of storing a huge sequence of zeroes and ones. It is up to the operating system to bring some structure to the storage layout and organize it into files, folders, and so on. The operating system also needs to impose some amount of security and redundancy into the file system so that a power outage does not jeopardize the contents of an entire hard disk. Some operating systems do a better job in this regard than others.

c) Virtual memory. RAM is expensive, and few computers have enough RAM to hold all programs and their data that a user would like to run simultaneously. Most operating systems extend the available memory by storing some data on the hard disk. The application programs do not realize whether a particular data item is in memory or in the virtual memory disk storage. When a program accesses a data item that is currently not in RAM,
the processor senses this and notifies the operating system. The operating system swaps the needed data from the hard disk into RAM, simultaneously swapping out a memory block of equal size that had not been accessed for
some time.

d) Handling multiple users. The operating systems of large and powerful computers allow simultaneous access by multiple users. Each user is connected to the computer through a separate terminal. The operating system authenticates users by checking that each one has a valid account and password. It gives each user a small slice of processor time, then serves the next user.

e) Multitasking. Even if you are the sole user of a computer, you may want to run multiple applications—for example, to read your e-mail in one window and run the Java compiler in another. The operating system is responsible for dividing processor time between the applications you are running, so that each can make progress.

f) Printing. The operating system queues up the print requests that are sent by multiple applications. This is necessary to make sure that the printed pages do not contain a mixture of words sent simultaneously from separate programs.

g) Windows. Many operating systems present their users with a desktop made up of multiple windows. The operating system manages the location and appearance of the window frames; the applications are responsible for the interiors.

h) Fonts. To render text on the screen and the printer, the shapes of characters must be defined. This is especially important for programs that can display multiple type styles and sizes. Modern operating systems contain a central font repository.

i) Communicating between programs. The operating system can facilitate the transfer of information between programs. That transfer can happen through cut and paste or interprocess communication. Cut and paste is a
user-initiated data transfer in which the user copies data from one application into a transfer buffer (often called a "clipboard") managed by the operating system and inserts the buffer's contents into another application. Interprocess communication is initiated by applications that transfer data without direct user involvement.

j) Networking. The operating system provides protocols and services for enabling applications to reach information on other computers attached to the network.

13) User interface events include key presses, mouse moves, button clicks, menu selections, and so on.

An event listener belongs to a class that is provided by the application programmer. Its methods describe the actions to be taken when an event occurs

Event sources report on events. When an event occurs, the event source notifies all event listeners.

14) Methods of an inner class can access local variables from surrounding blocks and fields from surrounding classes.

15) Local variables that are accessed by an inner-class method must be declared as final.

16) You often install event listeners as inner classes so that they can have access to the surrounding fields, methods, and final variables.

17) You use a mouse listener to capture mouse events.

18) Inheritance is a mechanism for extending existing classes by adding methods and fields.

19) The more general class is called a superclass. The more specialized class that inherits from the superclass is called the subclass.

Every class extends the Object class either directly or indirectly.

20) Inheriting from a class differs from implementing an interface: The subclass inherits behavior and state from the superclass.

21) One advantage of inheritance is code reuse.

22) When defining a subclass, you specify added instance fields, added methods, and changed or overridden methods.

23) Sets of classes can form complex inheritance hierarchies.

24) A subclass has no access to private fields of its superclass.

25) Use the super keyword to call a method of the superclass.

26) To call the superclass constructor, you use the super keyword in the first statement of the subclass constructor.

27) Subclass references can be converted to superclass references.

28) The instanceof operator tests whether an object belongs to a particular type.

29) An abstract method is a method whose implementation is not specified.

30) An abstract class is a class that cannot be instantiated.

31) Field or method that is not declared as public, private, or protected can be accessed by all classes in the same package, which is usually not desirable.

32) Protected features can be accessed by all subclasses and all classes in the same package.

33) Define the toString method to yield a string that describes the object state.

34) Define the equals method to test whether two objects have equal state.

35) The clone method makes a new object with the same state as an existing object.

About the Author

Cay Horstmann grew up in Northern Germany and attended the Christian-Albrechts-Universität in Kiel,a harbor town at the Baltic sea. I received a M.S. in computer science from Syracuse University , and a Ph.D. in mathematics from the University of Michigan in Ann Arbor. I now teach computer science at San Jose State University . In my copious spare time I write books and articles on Java and consult on internet programming.

No comments: