Wednesday, December 17, 2008

EVERYTHING FOR FREE

Want new MP3s files as they get released? how about pdfs on any topic of your choice? Hot new videos, free softwares and more? you are just one mail away; email me at donkellxs@gmail.com and i will send you all that your heart desires. you are free to share it with the world if you so desire!!!! Free you'd get so freely share too Ma people!!!

Java Prog.

you begin a journey, it's a good idea to have a mental map of the terrain you'll be passing through. The same is true for an intellectual journey, such as learning to write computer programs. In this case, you'll need to know the basics of what computers are and how they work. You'll want to have some idea of what a computer program is and how one is created. Since you will be writing programs in the Java programming language, you'll want to know something about that language in particular and about the modern, networked computing environment for which Java is designed.

As you read this chapter, don't worry if you can't understand everything in detail. (In fact, it would be impossible for you to learn all the details from the brief expositions in this chapter.) Concentrate on learning enough about the big ideas to orient yourself, in preparation for the rest of the book. Most of what is covered in this chapter will be covered in much greater detail later in the book.

[ Previous Section | Next Section | Chapter Index | Main Index ]
Section 1.2
Asynchronous Events: Polling Loops and Interrupts

The CPU spends almost all of its time fetching instructions from memory and executing them. However, the CPU and main memory are only two out of many components in a real computer system. A complete system contains other devices such as:
A hard disk for storing programs and data files. (Note that main memory holds only a comparatively small amount of information, and holds it only as long as the power is turned on. A hard disk is necessary for permanent storage of larger amounts of information, but programs have to be loaded from disk into main memory before they can actually be executed.)
A keyboard and mouse for user input.
A monitor and printer which can be used to display the computer's output.
A modem that allows the computer to communicate with other computers over telephone lines.
A network interface that allows the computer to communicate with other computers that are connected to it on a network.
A scanner that converts images into coded binary numbers that can be stored and manipulated on the computer.

The list of devices is entirely open ended, and computer systems are built so that they can easily be expanded by adding new devices. Somehow the CPU has to communicate with and control all these devices. The CPU can only do this by executing machine language instructions (which is all it can do, period). The way this works is that for each device in a system, there is a device driver, which consists of software that the CPU executes when it has to deal with the device. Installing a new device on a system generally has two steps: plugging the device physically into the computer, and installing the device driver software. Without the device driver, the actual physical device would be useless, since the CPU would not be able to communicate with it.

A computer system consisting of many devices is typically organized by connecting those devices to one or more busses. A bus is a set of wires that carry various sorts of information between the devices connected to those wires. The wires carry data, addresses, and control signals. An address directs the data to a particular device and perhaps to a particular register or location within that device. Control signals can be used, for example, by one device to alert another that data is available for it on the data bus. A fairly simple computer system might be organized like this:





Now, devices such as keyboard, mouse, and network interface can produce input that needs to be processed by the CPU. How does the CPU know that the data is there? One simple idea, which turns out to be not very satisfactory, is for the CPU to keep checking for incoming data over and over. Whenever it finds data, it processes it. This method is called polling, since the CPU polls the input devices continually to see whether they have any input data to report. Unfortunately, although polling is very simple, it is also very inefficient. The CPU can waste an awful lot of time just waiting for input.

To avoid this inefficiency, interrupts are often used instead of polling. An interrupt is a signal sent by another device to the CPU. The CPU responds to an interrupt signal by putting aside whatever it is doing in order to respond to the interrupt. Once it has handled the interrupt, it returns to what it was doing before the interrupt occurred. For example, when you press a key on your computer keyboard, a keyboard interrupt is sent to the CPU. The CPU responds to this signal by interrupting what it is doing, reading the key that you pressed, processing it, and then returning to the task it was performing before you pressed the key.

Again, you should understand that this is a purely mechanical process: A device signals an interrupt simply by turning on a wire. The CPU is built so that when that wire is turned on, the CPU saves enough information about what it is currently doing so that it can return to the same state later. This information consists of the contents of important internal registers such as the program counter. Then the CPU jumps to some predetermined memory location and begins executing the instructions stored there. Those instructions make up an interrupt handler that does the processing necessary to respond to the interrupt. (This interrupt handler is part of the device driver software for the device that signalled the interrupt.) At the end of the interrupt handler is an instruction that tells the CPU to jump back to what it was doing; it does that by restoring its previously saved state.

Interrupts allow the CPU to deal with asynchronous events. In the regular fetch-and-execute cycle, things happen in a predetermined order; everything that happens is "synchronized" with everything else. Interrupts make it possible for the CPU to deal efficiently with events that happen "asynchronously," that is, at unpredictable times.

As another example of how interrupts are used, consider what happens when the CPU needs to access data that is stored on the hard disk. The CPU can access data directly only if it is in main memory. Data on the disk has to be copied into memory before it can be accessed. Unfortunately, on the scale of speed at which the CPU operates, the disk drive is extremely slow. When the CPU needs data from the disk, it sends a signal to the disk drive telling it to locate the data and get it ready. (This signal is sent synchronously, under the control of a regular program.) Then, instead of just waiting the long and unpredictalble amount of time that the disk drive will take to do this, the CPU goes on with some other task. When the disk drive has the data ready, it sends an interrupt signal to the CPU. The interrupt handler can then read the requested data.

Now, you might have noticed that all this only makes sense if the CPU actually has several tasks to perform. If it has nothing better to do, it might as well spend its time polling for input or waiting for disk drive operations to complete. All modern computers use multitasking to perform several tasks at once. Some computers can be used by several people at once. Since the CPU is so fast, it can quickly switch its attention from one user to another, devoting a fraction of a second to each user in turn. This application of multitasking is called timesharing. But a modern personal computer with just a single user also uses multitasking. For example, the user might be typing a paper while a clock is continuously displaying the time and a file is being downloaded over the network.

Each of the individual tasks that the CPU is working on is called a thread. (Or a process; there are technical differences between threads and processes, but they are not important here.) At any given time, only one thread can actually be executed by a CPU. The CPU will continue running the same thread until one of several things happens:
The thread might voluntarily yield control, to give other threads a chance to run.
The thread might have to wait for some asynchronous event to occur. For example, the thread might request some data from the disk drive, or it might wait for the user to press a key. While it is waiting, the thread is said to be blocked, and other threads have a chance to run. When the event occurs, an interrupt will "wake up" the thread so that it can continue running.
The thread might use up its allotted slice of time and be suspended to allow other threads to run. Not all computers can "forcibly" suspend a thread in this way; those that can are said to use preemptive multitasking. To do preemptive multitasking, a computer needs a special timer device that generates an interrupt at regular intervals, such as 100 times per second. When a timer interrupt occurs, the CPU has a chance to switch from one thread to another, whether the thread that is currently running likes it or not.

Ordinary users, and indeed ordinary programmers, have no need to deal with interrupts and interrupt handlers. They can concentrate on the different tasks or threads that they want the computer to perform; the details of how the computer manages to get all those tasks done are not important to them. In fact, most users, and many programmers, can ignore threads and multitasking altogether. However, threads have become increasingly important as computers have become more powerful and as they have begun to make more use of multitasking. Indeed, threads are built into the Java programming language as a fundamental programming concept.

Just as important in Java and in modern programming in general is the basic concept of asynchronous events. While programmers don't actually deal with interrupts directly, they do often find themselves writing event handlers, which, like interrupt handlers, are called asynchronously when specified events occur. Such "event-driven programming" has a very different feel from the more traditional straight-through, synchronous programming. We will begin with the more traditional type of programming, which is still used for programming individual tasks, but we will return to threads and events later in the text.

By the way, the software that does all the interrupt handling and the communication with the user and with hardware devices is called the operating system. The operating system is the basic, essential software without which a computer would not be able to function. Other programs, such as word processors and World Wide Web browsers, are dependent upon the operating system. Common operating systems include Linux, DOS, Windows 2000, Windows XP, and the Macintosh OS.


Section 1.3
The Java Virtual Machine

Machine language consists of very simple instructions that can be executed directly by the CPU of a computer. Almost all programs, though, are written in high-level programming languages such as Java, Pascal, or C++. A program written in a high-level language cannot be run directly on any computer. First, it has to be translated into machine language. This translation can be done by a program called a compiler. A compiler takes a high-level-language program and translates it into an executable machine-language program. Once the translation is done, the machine-language program can be run any number of times, but of course it can only be run on one type of computer (since each type of computer has its own individual machine language). If the program is to run on another type of computer it has to be re-translated, using a different compiler, into the appropriate machine language.

There is an alternative to compiling a high-level language program. Instead of using a compiler, which translates the program all at once, you can use an interpreter, which translates it instruction-by-instruction, as necessary. An interpreter is a program that acts much like a CPU, with a kind of fetch-and-execute cycle. In order to execute a program, the interpreter runs in a loop in which it repeatedly reads one instruction from the program, decides what is necessary to carry out that instruction, and then performs the appropriate machine-language commands to do so.

One use of interpreters is to execute high-level language programs. For example, the programming language Lisp is usually executed by an interpreter rather than a compiler. However, interpreters have another purpose: they can let you use a machine-language program meant for one type of computer on a completely different type of computer. For example, there is a program called "Virtual PC" that runs on Macintosh computers. Virtual PC is an interpreter that executes machine-language programs written for IBM-PC-clone computers. If you run Virtual PC on your Macintosh, you can run any PC program, including programs written for Windows. (Unfortunately, a PC program will run much more slowly than it would on an actual IBM clone. The problem is that Virtual PC executes several Macintosh machine-language instructions for each PC machine-language instruction in the program it is interpreting. Compiled programs are inherently faster than interpreted programs.)

The designers of Java chose to use a combination of compilation and interpretation. Programs written in Java are compiled into machine language, but it is a machine language for a computer that doesn't really exist. This so-called "virtual" computer is known as the Java virtual machine. The machine language for the Java virtual machine is called Java bytecode. There is no reason why Java bytecode could not be used as the machine language of a real computer, rather than a virtual computer.

However, one of the main selling points of Java is that it can actually be used on any computer. All that the computer needs is an interpreter for Java bytecode. Such an interpreter simulates the Java virtual machine in the same way that Virtual PC simulates a PC computer.

Of course, a different Jave bytecode interpreter is needed for each type of computer, but once a computer has a Java bytecode interpreter, it can run any Java bytecode program. And the same Java bytecode program can be run on any computer that has such an interpreter. This is one of the essential features of Java: the same compiled program can be run on many different types of computers.



Why, you might wonder, use the intermediate Java bytecode at all? Why not just distribute the original Java program and let each person compile it into the machine language of whatever computer they want to run it on? There are many reasons. First of all, a compiler has to understand Java, a complex high-level language. The compiler is itself a complex program. A Java bytecode interpreter, on the other hand, is a fairly small, simple program. This makes it easy to write a bytecode interpreter for a new type of computer; once that is done, that computer can run any compiled Java program. It would be much harder to write a Java compiler for the same computer.

Furthermore, many Java programs are meant to be downloaded over a network. This leads to obvious security concerns: you don't want to download and run a program that will damage your computer or your files. The bytecode interpreter acts as a buffer between you and the program you download. You are really running the interpreter, which runs the downloaded program indirectly. The interpreter can protect you from potentially dangerous actions on the part of that program.

I should note that there is no necessary connection between Java and Java bytecode. A program written in Java could certainly be compiled into the machine language of a real computer. And programs written in other languages could be compiled into Java bytecode. However, it is the combination of Java and Java bytecode that is platform-independent, secure, and network-compatible while allowing you to program in a modern high-level object-oriented language.

I should also note that the really hard part of platform-independence is providing a "Graphical User Interface" -- with windows, buttons, etc. -- that will work on all the platforms that support Java. You'll see more about this problem in Section 1.6.


Section 1.4
Fundamental Building Blocks of Programs

There are two basic aspects of programming: data and instructions. To work with data, you need to understand variables and types; to work with instructions, you need to understand control structures and subroutines. You'll spend a large part of the course becoming familiar with these concepts.

A variable is just a memory location (or several locations treated as a unit) that has been given a name so that it can be easily referred to and used in a program. The programmer only has to worry about the name; it is the compiler's responsibility to keep track of the memory location. The programmer does need to keep in mind that the name refers to a kind of "box" in memory that can hold data, even if the programmer doesn't have to know where in memory that box is located.

In Java and most other languages, a variable has a type that indicates what sort of data it can hold. One type of variable might hold integers -- whole numbers such as 3, -7, and 0 -- while another holds floating point numbers -- numbers with decimal points such as 3.14, -2.7, or 17.0. (Yes, the computer does make a distinction between the integer 17 and the floating-point number 17.0; they actually look quite different inside the computer.) There could also be types for individual characters ('A', ';', etc.), strings ("Hello", "A string can include many characters", etc.), and less common types such as dates, colors, sounds, or any other type of data that a program might need to store.

Programming languages always have commands for getting data into and out of variables and for doing computations with data. For example, the following "assignment statement," which might appear in a Java program, tells the computer to take the number stored in the variable named "principal", multiply that number by 0.07, and then store the result in the variable named "interest":
interest = principal * 0.07;

There are also "input commands" for getting data from the user or from files on the computer's disks and "output commands" for sending data in the other direction.

These basic commands -- for moving data from place to place and for performing computations -- are the building blocks for all programs. These building blocks are combined into complex programs using control structures and subroutines.

A program is a sequence of instructions. In the ordinary "flow of control," the computer executes the instructions in the sequence in which they appear, one after the other. However, this is obviously very limited: the computer would soon run out of instructions to execute. Control structures are special instructions that can change the flow of control. There are two basic types of control structure: loops, which allow a sequence of instructions to be repeated over and over, and branches, which allow the computer to decide between two or more different courses of action by testing conditions that occur as the program is running.

For example, it might be that if the value of the variable "principal" is greater than 10000, then the "interest" should be computed by multiplying the principal by 0.05; if not, then the interest should be computed by multiplying the principal by 0.04. A program needs some way of expressing this type of decision. In Java, it could be expressed using the following "if statement":
if (principal > 10000)
interest = principal * 0.05;
else
interest = principal * 0.04;

(Don't worry about the details for now. Just remember that the computer can test a condition and decide what to do next on the basis of that test.)

Loops are used when the same task has to be performed more than once. For example, if you want to print out a mailing label for each name on a mailing list, you might say, "Get the first name and address and print the label; get the second name and address and print the label; get the third name and address and print the label -- " But this quickly becomes ridiculous -- and might not work at all if you don't know in advance how many names there are. What you would like to say is something like "While there are more names to process, get the next name and address, and print the label." A loop can be used in a program to express such repetition.

Large programs are so complex that it would be almost impossible to write them if there were not some way to break them up into manageable "chunks." Subroutines provide one way to do this. A subroutine consists of the instructions for performing some task, grouped together as a unit and given a name. That name can then be used as a substitute for the whole set of instructions. For example, suppose that one of the tasks that your program needs to perform is to draw a house on the screen. You can take the necessary instructions, make them into a subroutine, and give that subroutine some appropriate name -- say, "drawHouse()". Then anyplace in your program where you need to draw a house, you can do so with the single command:
drawHouse();

This will have the same effect as repeating all the house-drawing instructions in each place.

The advantage here is not just that you save typing. Organizing your program into subroutines also helps you organize your thinking and your program design effort. While writing the house-drawing subroutine, you can concentrate on the problem of drawing a house without worrying for the moment about the rest of the program. And once the subroutine is written, you can forget about the details of drawing houses -- that problem is solved, since you have a subroutine to do it for you. A subroutine becomes just like a built-in part of the language which you can use without thinking about the details of what goes on "inside" the subroutine.

Variables, types, loops, branches, and subroutines are the basis of what might be called "traditional programming." However, as programs become larger, additional structure is needed to help deal with their complexity. One of the most effective tools that has been found is object-oriented programming, which is discussed in the next section.


Section 1.5
Objects and Object-oriented Programming

Programs must be designed. No one can just sit down at the computer and compose a program of any complexity. The discipline called software engineering is concerned with the construction of correct, working, well-written programs. The software engineer tends to use accepted and proven methods for analyzing the problem to be solved and for designing a program to solve that problem.

During the 1970s and into the 80s, the primary software engineering methodology was structured programming. The structured programming approach to program design was based on the following advice: To solve a large problem, break the problem into several pieces and work on each piece separately; to solve each piece, treat it as a new problem which can itself be broken down into smaller problems; eventually, you will work your way down to problems that can be solved directly, without further decomposition. This approach is called top-down programming.

There is nothing wrong with top-down programming. It is a valuable and often-used approach to problem-solving. However, it is incomplete. For one thing, it deals almost entirely with producing the instructions necessary to solve a problem. But as time went on, people realized that the design of the data structures for a program was as least as important as the design of subroutines and control structures. Top-down programming doesn't give adequate consideration to the data that the program manipulates.

Another problem with strict top-down programming is that it makes it difficult to reuse work done for other projects. By starting with a particular problem and subdividing it into convenient pieces, top-down programming tends to produce a design that is unique to that problem. It is unlikely that you will be able to take a large chunk of programming from another program and fit it into your project, at least not without extensive modification. Producing high-quality programs is difficult and expensive, so programmers and the people who employ them are always eager to reuse past work.

So, in practice, top-down design is often combined with bottom-up design. In bottom-up design, the approach is to start "at the bottom," with problems that you already know how to solve (and for which you might already have a reusable software component at hand). From there, you can work upwards towards a solution to the overall problem.

The reusable components should be as "modular" as possible. A module is a component of a larger system that interacts with the rest of the system in a simple, well-defined, straightforward manner. The idea is that a module can be "plugged into" a system. The details of what goes on inside the module are not important to the system as a whole, as long as the module fulfills its assigned role correctly. This is called information hiding, and it is one of the most important principles of software engineering.

One common format for software modules is to contain some data, along with some subroutines for manipulating that data. For example, a mailing-list module might contain a list of names and addresses along with a subroutine for adding a new name, a subroutine for printing mailing labels, and so forth. In such modules, the data itself is often hidden inside the module; a program that uses the module can then manipulate the data only indirectly, by calling the subroutines provided by the module. This protects the data, since it can only be manipulated in known, well-defined ways. And it makes it easier for programs to use the module, since they don't have to worry about the details of how the data is represented. Information about the representation of the data is hidden.

Modules that could support this kind of information-hiding became common in programming languages in the early 1980s. Since then, a more advanced form of the same idea has more or less taken over software engineering. This latest approach is called object-oriented programming, often abbreviated as OOP.

The central concept of object-oriented programming is the object, which is a kind of module containing data and subroutines. The point-of-view in OOP is that an object is a kind of self-sufficient entity that has an internal state (the data it contains) and that can respond to messages (calls to its subroutines). A mailing list object, for example, has a state consisting of a list of names and addresses. If you send it a message telling it to add a name, it will respond by modifying its state to reflect the change. If you send it a message telling it to print itself, it will respond by printing out its list of names and addresses.

The OOP approach to software engineering is to start by identifying the objects involved in a problem and the messages that those objects should respond to. The program that results is a collection of objects, each with its own data and its own set of responsibilities. The objects interact by sending messages to each other. There is not much "top-down" in such a program, and people used to more traditional programs can have a hard time getting used to OOP. However, people who use OOP would claim that object-oriented programs tend to be better models of the way the world itself works, and that they are therefore easier to write, easier to understand, and more likely to be correct.

You should think of objects as "knowing" how to respond to certain messages. Different objects might respond to the same message in different ways. For example, a "print" message would produce very different results, depending on the object it is sent to. This property of objects -- that different objects can respond to the same message in different ways -- is called polymorphism.

It is common for objects to bear a kind of "family resemblance" to one another. Objects that contain the same type of data and that respond to the same messages in the same way belong to the same class. (In actual programming, the class is primary; that is, a class is created and then one or more objects are created using that class as a template.) But objects can be similar without being in exactly the same class.

For example, consider a drawing program that lets the user draw lines, rectangles, ovals, polygons, and curves on the screen. In the program, each visible object on the screen could be represented by a software object in the program. There would be five classes of objects in the program, one for each type of visible object that can be drawn. All the lines would belong to one class, all the rectangles to another class, and so on. These classes are obviously related; all of them represent "drawable objects." They would, for example, all presumably be able to respond to a "draw yourself" message. Another level of grouping, based on the data needed to represent each type of object, is less obvious, but would be very useful in a program: We can group polygons and curves together as "multipoint objects," while lines, rectangles, and ovals are "two-point objects." (A line is determined by its endpoints, a rectangle by two of its corners, and an oval by two corners of the rectangle that contains it.) We could diagram these relationships as follows:





DrawableObject, MultipointObject, and TwoPointObject would be classes in the program. MultipointObject and TwoPointObject would be subclasses of DrawableObject. The class Line would be a subclass of TwoPointObject and (indirectly) of DrawableObject. A subclass of a class is said to inherit the properties of that class. The subclass can add to its inheritance and it can even "override" part of that inheritance (by defining a different response to some method). Nevertheless, lines, rectangles, and so on are drawable objects, and the class DrawableObject expresses this relationship.

Inheritance is a powerful means for organizing a program. It is also related to the problem of reusing software components. A class is the ultimate reusable component. Not only can it be reused directly if it fits exactly into a program you are trying to write, but if it just almost fits, you can still reuse it by defining a subclass and making only the small changes necessary to adapt it exactly to your needs.

So, OOP is meant to be both a superior program-development tool and a partial solution to the software reuse problem. Objects, classes, and object-oriented programming will be important themes throughout the rest of this text.

Section 1.6
The Modern User Interface

When computers were first introduced, ordinary people -- including most programmers -- couldn't get near them. They were locked up in rooms with white-coated attendants who would take your programs and data, feed them to the computer, and return the computer's response some time later. When timesharing -- where the computer switches its attention rapidly from one person to another -- was invented in the 1960s, it became possible for several people to interact directly with the computer at the same time. On a timesharing system, users sit at "terminals" where they type commands to the computer, and the computer types back its response. Early personal computers also used typed commands and responses, except that there was only one person involved at a time. This type of interaction between a user and a computer is called a command-line interface.

Today, of course, most people interact with computers in a completely different way. They use a Graphical User Interface, or GUI. The computer draws interface components on the screen. The components include things like windows, scroll bars, menus, buttons, and icons. Usually, a mouse is used to manipulate such components. Assuming that you have not just been teleported in from the 1970s, you are no doubt already familiar with the basics of graphical user interfaces!

A lot of GUI interface components have become fairly standard. That is, they have similar appearance and behavior on many different computer platforms including Macintosh, Windows, and Linux. Java programs, which are supposed to run on many different platforms without modification to the program, can use all the standard GUI components. They might vary a little in appearance from platform to platform, but their functionality should be identical on any computer on which the program runs.

Below is a very simple Java program -- actually an "applet," since it is running right here in the middle of a page -- that shows a few standard GUI interface components. There are four components that the user can interact with: a button, a checkbox, a text field, and a pop-up menu. These components are labeled. There are a few other components in the applet. The labels themselves are components (even though you can't interact with them). The right half of the applet is a text area component, which can display multiple lines of text, and a scrollbar component appears alongside the text area when the number of lines of text becomes larger than will fit in the text area. And in fact, in Java terminology, the whole applet is itself considered to be a "component." Try clicking on the button and on the checkbox, and try selecting an item from the pop-up menu. You will see a message in the text area about each action that you perform. You can type in the text field, but you might have to click on it first to activate it. When you press return while typing in the text field, you will see a message in the text area:



Now, Java actually has two complete sets of GUI components. One of these, the AWT or Abstract Windowing Toolkit, was available in the original version of Java. The other, which is known as Swing, is included in Java version 1.2 or later, and is used in preference to the AWT in most modern Java programs. The applet that is shown above uses components that are part of Swing. If your Web browser uses an old version of Java, you might get an error when the browser tries to load the applet. Remember that most of the applets in this textbook require Java 5.0 (or higher).

When a user interacts with the GUI components in this applet, an "event" is generated. For example, clicking a push button generates an event, and pressing return while typing in a text field generates an event. Each time an event is generated, a message is sent to the applet telling it that the event has occurred, and the applet responds according to its program. In fact, the program consists mainly of "event handlers" that tell the applet how to respond to various types of events. In this example, the applet has been programmed to respond to each event by displaying a message in the text area.

The use of the term "message" here is deliberate. Messages, as you saw in the previous section, are sent to objects. In fact, Java GUI components are implemented as objects. Java includes many predefined classes that represent various types of GUI components. Some of these classes are subclasses of others. Here is a diagram showing some of Swing's GUI classes and their relationships:




Don't worry about the details for now, but try to get some feel about how object-oriented programming and inheritance are used here. Note that all the GUI classes are subclasses, directly or indirectly, of a class called JComponent, which represents general properties that are shared by all Swing components. Two of the direct subclasses of JComponent themselves have subclasses. The classes JTextArea and JTextField, which have certain behaviors in common, are grouped together as subclasses of JTextComponent. Similarly JButton and JToggleButton are subclasses of JAbstractButton, which represents properties common to both buttons and checkboxes. (JComboBox, by the way, is the Swing class that represents pop-up menus.)

Just from this brief discussion, perhaps you can see how GUI programming can make effective use of object-oriented design. In fact, GUI's, with their "visible objects," are probably a major factor contributing to the popularity of OOP.

Programming with GUI components and events is one of the most interesting aspects of Java. However, we will spend several chapters on the basics before returning to this topic in Chapter 6.

Monday, December 15, 2008

Merry Xmas

In years I rolled
In time i flew

Like yesterday you came
fresh from mother earth's worm
You flowed like a new born
You came to milk Life,
You came to taste Love
And in the process you excelled
There was not a second u did not love
Not a minute you did not taste
And then you worn frail
once lovely, Eye balls bulged
The summer, the winter
all consummed in the fairy tale snow
in cold and peace you decide to lay your all up
to give up all you once cherished
because you 2008 must move on now,
Adios my friend,
Adios my Love
Mary xmas and joseph new year!!!!

Friday, November 28, 2008

Building Your own Personal Computer

Building Your Own PC, Part 1
Know-How for Do-It-Yourselfers
TABLE OF CONTENTS
• Building a PC System
• Standard Components Of A PC System
• Extra Options For Special Applications
• Case and Power Supply
• Power Connectors For Drives
• This and That: Screws, Spacers & Jumpers
• Motherboard Overview
• Onboard Components
• Basic Motherboard Configuration
• Setting The Clock Speed
• Connecting The Floppy Drives
• Connecting Hard Drives and CD-ROM/DVD
• SCSI Drives - The Exception
• Safety Notice: The destructive potential of electrostatic
• Drawing Up a Plan
Building a PC System
Anyone needing a new computer faces a tough choice: you can either go for a complete system, or you can build your own PC. As most complete systems are cheaper than the sum of their parts, when is it really worth it to build your own
Imagine you want to build a new PC and want to use a few remnants from your old system. If you were satisfied with the performance of your CD-ROM drive, hard drive, printer or monitor, then it could be worth it to simply buy the remaining components - you might not even need a new case.
We also hope that this article will reach the individualists among you, i.e., users who know exactly which processor, motherboard and graphics card they want to install, but who just don't know how to fit it all together. The third group of users we want to reach are those people who only want to swap out a component, whether a graphics card or a CPU.
Many are intimidated by hardware. Some people won't even put in a new card on their own if they can help it. Yet the computer is now a mass-market product that, thankfully, has also brought about broad standardization.
This article will guide you unerringly through each step of successfully building your own PC. Of course, this article assumes that you know how to properly handle electronic components, that you know how to use tools, and, perhaps most importantly, that you take pleasure in this kind of tinkering. As we are going to introduce a large spectrum of PC components, users who only want to upgrade individual parts can skip certain sections in this guide.
Standard Components Of A PC System
In our enthusiasm and eagerness to offer a complete do-it-yourself guide, we picked up the price list at the computer store on the corner, only to feel overwhelmed by the sheer quantity of parts on offer. If you aren't yet used to buying a PC in individual components, it can't do any harm to draw up a list of everything you need before doing anything else. That said, a complete PC system requires the following items:PC case,Motherboard,Processor,CPU cooler,RAM,Hard Drive,Graphics card,CD-ROM or DVD drive,Floppy disk drive, if needed
The following items shouldn't be forgotten:
• Monitor
• Keyboard
• Mouse
These components are necessary to run the new computer, including its operating system (e.g., Windows, Linux).
Extra Options For Special Applications
Depending on what you'll be using your PC for, you might need the following components as well; please note, though, that this list is by no means complete:
Application Required components
Internet access Modem, ISDN card, or network card (if using DSL)
Gaming and Music Sound card and loudspeakers
CD recording, archiving CD recorder, ZIP drive
Network Network card (Ethernet)
Digital camera Either a motherboard with integrated USB, or separate USB card
Video Editing & Camcorder Video capture card with IEEE1394/FireWire (i-Link) interface, if possible
Case and Power Supply
Power supply
The advent of processors breaking the gigahertz barrier has made one thing clear: their thirst for power is hard to rein in. When buying a case, take a very close look at the built-in power supply. In addition to the classic ATX power supply, it should also feature an auxiliary power connector. More and more motherboards require this plug to cover the power needs of a Pentium 4 or an Athlon XP. The only time you won't need it is if you're operating a CPU at 1400 MHz or less.
Classic ATX power supply plug.
Extra current for power-hungry CPUs: ATX12 (left) and P6 connector. (right)
An increasingly familiar sight on motherboards: on the left, the P6 (AUX); and on the right, the classic ATX plug.
An ATX12 socket on the motherboard.
Power Connectors For Drives
Your power supply will depend on how many drives you plan to install. Small cases only offer three or four connectors. Once you've used up all the available connectors, you'll have to use a Y junction to turn one plug into two.
One into two: a typical Y junction with large plugs.
This cable also comes with small plugs for connecting floppy drives and the like to a power supply.
More Questions For The Salesman
Always make a point of asking about assembly materials: are all the screws, spacers and other accessories included with the case? A small bag of assembly materials is usually stuck to the inside of the case. Always be wary of cheap offers!
Always make sure you have spacers and mounts to secure the motherboard. A few screws for the case won't hurt either, as they are generally also used to anchor plug-in boards. The screws for mounting drives (hard drive, CD-ROM, etc.) have a finer thread. You need at least four for each drive, but it's always a good idea to have a handful of replacements. By the way, you're barking up the wrong tree if you start looking for these screws at the hardware store. Go to your local computer store - they won't have to look far for the screws you need, and they're bound to be the right size. If possible, avoid plugging the monitor directly into the PC power supply - you're better off with a separate connector. While some power supplies offer an additional plug for a monitor, you'd be well-advised not to use it for screens larger than 19 inches - the high surge at power-up is a frequent source of booting problems.
Ask about the form factor. This depends on the motherboard. Since almost all new motherboards conform to the ATX form factor, your case will have to be ATX compatible. You can still scrounge up AT cases for AT motherboards. A modern ATX motherboard can be identified by the fact that all the jacks for the keyboard, mouse, parallel printer, and serial COM port are soldered directly onto the motherboard. We'll document this in the section on the motherboard
A bag of screws should be inside the empty PC case.
This and That: Screws, Spacers & Jumpers
Typical case screws are used to screw on the case covers and anchor plug-in cards to the case.
A drive screw's thread is finer and thinner than screws used for the case. The head is smaller, too. This kind of screw is generally used to affix the drives in the drive bays, and to screw the motherboard to the case.
Spacers are screwed into the backplate for the motherboard.
What Are Jumpers?
Jumpers are short and sweet.
A jumper is nothing more than a metal bridge that connects two contacts. We don't see the metal, though, because it's covered with plastic. Jumpers are often used to configure the PC. For instance, you can use them to set the processor speed or change a drive from a "master" to a "slave." Pictured above is a classic jumper, as used on drives and boards just about everywhere.
Motherboard Overview
Main components of a motherboard.
The image shows an ASUS motherboard. At the top on the right-hand side are the interfaces and connectors that stick out of the case at the back of an assembled computer. This board is designed for AMD Athlon and Duron processors. Socket A, as it's called, is labeled "CPU socket" in the picture. The expansion slots are to its left. The AGP slot is used exclusively for the graphics card. The PCI slots will hold network cards, ISDN, sound or video-editing boards. At the bottom left are the panel connectors for the on/ off button, the hard drive LED, the reset switch, and the operating LED. Take time to familiarize yourself with where they're located. By the way, LEDs that don't light up can generally be fixed by simply turning the plug around. The two IDE connectors (40-pin) are below in the middle, while the connector for the floppy drive (34-pin FDD connector) is in the left side of the image. We'll describe the cables and drive configurations on the next page.
Onboard Components
ATX connector panel

Keyboard, mouse, two serial connectors, a parallel port and two USB ports are on the ATX port panel. Some motherboards, like the one here, feature optional sound and joystick jacks. There are also models that have a monitor connection. That saves a slot and some money, but you'll have to deactivate the onboard chip if you plan to replace these cheap onboard modules with a higher-quality expansion card. It's generally impossible to run both chips at the same time. Once again, it can either be done in BIOS or with a jumper. Check your handbook to find out which method to use.
Basic Motherboard Configuration
Many modern motherboards with integrated software configuration no longer require you to do anything prior to assembly. That means that you type your processor parameters directly in BIOS (Basic Input Output System). Most of the time, you access the BIOS menu by pressing the DEL key, F2 or F10, shortly after switching on the PC. Check your handbook to find out which key to use. The latest technology even recognizes the CPU automatically, a feature that is particularly useful for beginners. But making settings manually is still a must for anyone who wants to fine-tune his or her system.
Processor Settings: FSB and Multiplier
The external clock speed is usually referred to as the Front Side Bus (FSB), or system clock. Typical physical frequencies for system clocks are 100.00 and 133.33MHz. The actual processor clock is calculated by multiplying the system clock with the multiplier. For example, a Front Side Bus of 133.33MHz and multiplier of 13 results in a physical CPU clock speed of 1733MHz. Some manufacturers provide "marketing" figures when Double Data Rate (DDR) or quad pumping raises effective bandwidth. Here's an example of such marketing figures, which have been placed in quotes: Socket/ Slot Processors System Clock (FSB)
Socket 7 AMD K6-2,
AMD K6-III,
Intel Pentium MMX 66, 100, 133 MHz
Slot 1 Intel Pentium III,
Intel Celeron 66, 100, 133 MHz
Slot A AMD Athlon (K7) 100 MHz (200 MHz DDR)
Socket 370 Intel Pentium III,
Intel Celeron,
VIA C3 100, 133 MHz
Socket A
(Socket 462) AMD Athlon (Thunderbird),
AMD Athlon XP (Palomino),
AMD Athlon XP (Thoroughbred),
AMD Duron (Spitfire, Morgan) 100 MHz (200 MHz DDR),
133 MHz (266 MHz DDR)
Socket 423 Intel Pentium 4 (Willamette),
Intel Pentium 4 (Northwood) 100 MHz (400 MHz quad-pumped)
Socket 478 Intel Pentium 4 (Northwood),
Intel Celeron (Willamette) 100 MHz (400 MHz quad-pumped),
133 MHz / (533 MHz quad-pumped)
AMD also lists a so-called P-Rating, or Number Modeling, for marketing purposes. In other words, an AMD Athlon XP 2100+ actually only runs at a physical speed of 1733MHz. "2100+" is merely a way of comparing the processor to an equivalent Intel Pentium 4. Put plainly, an AMD Athlon XP 2100+ is about as fast as a Pentium 4 2100.
Setting The Clock Speed
There is no automatic software configuration on older boards. That's why it can't hurt to know the three principles of manual configuration. By the same token, overclockers will be more likely to make settings by hand. Here are the different ways to set clock speed:
Obsolete: using jumpers, the frequency table is right next to the jumper block.
Multiplier table for older models.
Occasionally found: setting by DIP switch.
Modern: convenient configuration in BIOS.
Determining which of the three methods applies to you will depend on your motherboard. While the general tendency seems to favor BIOS, you'll still come across a DIP switch block now and again. The jumper method, on the other hand, is entirely obsolete.
Intel and AMD officially abolished the variable multiplier for their processors some time ago. They wanted to prevent people from overclocking, say, 1300MHz models to 1500MHz. That kind of overclocking would boost performance significantly without costing a dime. For the tinkerers among us, all that's left for us when trying to eke more performance out of a processor is a gentle increase of the FSB. All the same, there are a few tricks for removing the fixed multiplier, at least for AMD processors. More information on this can be found in the article, Plastic Surgery: Releasing The Athlon XP To Hit 2000+. As the motherboard manufacturers are aware of this, they attract more buyers by offering what is, in fact, a superfluous multiplier. The BIOS screenshot shows this clearly.
Connecting The Floppy Drives
Floppy drives are in danger of extinction because floppies generally don't hold much data. Most software is generally installed from CD-ROMs now, anyway. CD burners are very popular for archiving data. Nevertheless, a floppy drive can still pay off if you work with old programs or data from time to time.
Floppy connector (34-pin) above, IDE connector(40-pin) for hard drives and CD-ROM below.
It's easy to spot floppy cables. They usually have a "twist" of individual wires, as you can see in the upper corner of the image. The image shows a color marking on a cable. This is frequently a red line that marks pin 1. Pin 1 is also printed on the motherboard. On modern motherboards, notches and/ or a missing pin in the middle (see picture blow) prevent the cable from being inserted the wrong way. You still need to watch out when hooking up older drives or motherboards. The red dotted line at the other end of the cable should always point in the direction of the power supply. Here, too, there is a reverse-connection protection to keep it from being improperly configured.
Connecting Hard Drives and CD-ROM/DVD
The vast majority of hard drives and CD/DVD drives are based on the IDE (Integrated Device Electronics) standard. There's also the SCSI standard, which is mostly used for servers or workstations. In comparison to SCSI, IDE is extremely cheap to produce, which accounts for its higher popularity. There are four subgroups within the IDE class: UltraDMA/33; UltraDMA/66; UltraDMA/100; and UltraDMA/133. The number at the end describes its bandwidth. As a rule of thumb, the higher, the better. 133, for example, stands for the maximum data transfer rate of 133 megabytes per second. DMA is short for Direct Memory Access. A beginner doesn't necessarily have to know how DMA works in order to obtain good results.
Two drives can be run on each IDE connector block. Motherboards usually have two IDE connectors (Primary and Secondary IDE), so that a maximum of four devices can be connected. Modern motherboards with an additional controller can even offer four IDE connectors. If you want to connect an IDE to a drive, it is configured as a "Master" (Single). If, on the other hand, two drives need to be connected, one must be labeled "Master," and the other "Slave." The jumpers are used to connect the contacts, thus configuring the drive. The connection to the motherboard is made by way of a 40-pin ribbon cable. It has three plugs - one for the motherboard, and the other two for the two drives.
Most PC systems have one hard drive and one CD-ROM/DVD drive. CD-ROM burners are also a type of CD-ROM drive. The following configuration is recommended for IDE drives:
• Primary IDE: hard drive as Master (Single) Primary IDE:
• Secondary IDE: CD/DVD drive as Master (Single)
Users who want the full allotment of IDE components should connect the drives as follows:
• Primary IDE: hard drive 1 as Master (Dual)
• Primary IDE: hard drive 2 as Slave (Dual)
• Secondary IDE: CD/DVD drive 1 as Master (Dual)
• Secondary IDE: CD/DVD drive 2 as Slave (Dual)
There's usually a sticker on top of the drive explaining the necessary jumper settings. Or, you can also find a description in the hard drive manual.
IDE jumper table for a Maxtor hard drive.
Port panel on the hard drive: power supply, jumper blocks, IDE ribbon cable (from left to right).
Connecting the CD and/ or DVD drives is basically the same as with hard drives. The same rules apply.
CD-ROM port panel: digital audio, analog audio, jumper blocks, IDE cable, power supply (from left to right).
SCSI Drives - The Exception
Although the SCSI (Small Computer Systems Interface) bus system offers greater flexibility, it's also much more expensive. SCSI is only used for workstations and servers. Ultra2 or Ultra 160 SCSIs are typical standards. A SCSI ribbon cable has 68 pins. All SCSI standards have one thing in common: you can run at least seven drives on one adapter. "Wide" models even allow 14 devices to be operated.
It is important to know how it works. SCSI is an open bus system and allows cable lengths of well over a meter. However, the bus must be closed with a terminal resistor at each end, so that the signals don't reflect. Termination can mostly be activated by a jumper on the last device. LVD cables have their terminator as a plug-on module. The position of the individual devices on the SCSI cable, by the way, is up to you. The drives are distinguished by way of so-called SCSI Ids that run from 0 to 7 or 0 to 15. ID7 is usually the host adapter, 0 or 1 is usually used for the hard drive(s). The rest of the configuration is up to you. Jumpers are used to define the ID address from 0 to 7. In the following example, the manufacturer has named its SCSI address IDs DAS0 to DAS3.
Description of the SCSI jumper block for auxiliary connectors. DAS0 to DAS3 are the SCSI address bits.
Jumper table for setting addresses.
Connector blocks on an SCSI hard drive: power supply, jumper blocks (auxiliary connector), SCSI ribbon cable (from left to right).
In this example, termination can be activated by bridging pins 9 and 10. This is called "Enable SE SCSI Terminator" in the picture.
Safety Notice: The destructive potential of electrostatic
Walking across a floor dragging your feet will create friction, which charges us with energy. Once you stop moving, the soles of your shoes insulate you, but you're still carrying around a different voltage potential than your environment. Everyone's felt the sudden shock from a static spark, which is particularly common with plastic floors and thick, rubber-soled shoes. This electromagnetic phenomenon can have dangerous consequences for electronic components. Although the current from a static discharge isn't very high, the voltage difference may briefly peak at tens of thousands of volts. That much voltage can easily destroy sensitive components such as memory chips.
The most important thing to do before getting down to work is to ground yourself. Ideally, you'll have an antistatic armband, as used in industry. But unless you're a real electronics whiz, you're unlikely to have one. So, try this instead: before you come into contact any of your PC's components, simply touch something metal (a radiator, the protective contact on a plug or the PC case). This will ground you properly.
Drawing Up a Plan
Before you start the actual assembly, familiarize yourself with the case and components. Unpack all the parts and keep them nearby, but not so close that they interfere. Most cases don't come with instructions, so you should first check which screws and parts go where, and what each is for - and whether you may have to remove anything from the case before you can install the drives. Get yourself a proper lamp before starting, especially if you work at night. The ceiling light in your workroom is usually not bright enough.
Finally, consider where you want to put each drive. There are only a few rules for drive placement, but valuable ones to follow when in doubt:
• If the PC is under your desk, it makes sense to place the CD-ROM and/or DVD drive as high up as possible so that you don't have to bend down so far.
• Always check to make sure that the ribbon cable is long enough.
• Some components get warm or even hot when operating. Always make sure that there's enough air circulating for the heat to dissipate. That's especially important for modern graphics cards and hard drives.
• If you're intending to put in two hard drives, make sure that there's enough room between them. Otherwise, they may overheat, leading to a shortened life span and instability.
• Make sure that neither cables nor other components can get caught in a fan.
• All cables must be run so that no air vents or openings are completely blocked.
This article covered the basics and some practical aspects. In the following article, Building Your Own PC, Part 2: Assembly Step by Step, we'll describe how to put all the components together to make a functioning PC. Users who only want to swap individual components (upgrade) will also find all the information they need.
Custom Search

Friday, November 21, 2008

G ad


Wednesday, November 19, 2008

Free MP3 new songs

Hello Everyone,
Intrested in new MP3s as they get released and you arent got no pickle to pay? well here is your one stop shop to all new, free MP3 songs; hot and fresh as they get released by the day