ShowTutorials.com

Refreshing your ideas and broadening your visions


Computers and Java

Computer architecture

A computer is a complex system consisting of many different components. But at the heart or the brain, if you want of the computer is a single component that does the actual computing. This is the Central Processing Unit , or CPU. In a modern desktop computer, the CPU is a single chip on the order of one square inch in size. The job of the CPU is to execute programs.

A program is simply a list of unambiguous instructions meant to be followed mechanically by a computer. A computer is built to carry out instructions that are written in a very simple type of language called machine language. Each type of computer has its own machine language, and the computer can directly execute a program only if the program is expressed in that language. (It can execute programs written in other languages if they are first translated into machine language)

 

computer-system

 

Below diagram shows the various components of a Computer System.

 

computer-system-diagram

 

CPU

The central processing unit or CPU is the brain of a computer. The CPU is the component that executes program instructions by fetching an instruction (stored in RAM), executing it, fetching the next instruction, executing it, and so on until it encounters an instruction to stop. The CPU contains a small number of registers, which are high-speed devices for storing data or instructions temporarily. The CPU also contains the arithmetic-logic unit (ALU), which performs arithmetic operations such as addition and subtraction and logical operations such as comparing two numbers.

 

RAM

Random access memory or RAM is a repository for both program instructions and data manipulated by the program during execution. RAM is divided into cells, with each cell having a unique address.

 

I/O Devices

Input/output or I/O devices allow communication between the user and the CPU. Input devices such as keyboards and mice are used to enter data, programs, and commands in the CPU. Output devices such as monitors and printers are used to display or print information. Other I/O devices include scanners, bar code readers, magnetic strip readers, digital video cameras, drawing tablets and musical instrument digital interface (MIDI) devices.

 

Storage Devices

Storage devices such as disk and tape drives are used to store data and programs. Secondary storage devices are called non-volatile memory, while RAM is called volatile memory. Volatile means the data stored in a device will be lost when the power to the device is turned off. Being non-volatile and much cheaper than RAM, secondary storage is an ideal medium for permanent storage of large volumes of data. A secondary storage device cannot replace RAM, though, because secondary storage is far slower in data access compared to RAM.

 

Communication Devices

A communication device connects the personal computer to an internet. The most common communication device for computers at home and in small offices is the modem. A modem, which stands for modulator-demodulator, is a device that converts analog signals to digital and digital signals to analog. By using a modem, a computer can send to and receive data from another computer over the phone line.

A communication device for connecting a computer to a LAN is a network interface card (NIC). A NIC can transfer data at a much faster rate than the fastest modem.

 

Types of Programming Languages

Programming languages are broadly classified into three levels: Machine languages, Assembly languages, and High-level languages.

 

Machine Languages

Machine language is the only programming language the CPU understands. Each type of CPU has its own machine language.

 

Assembly Languages

One level above machine language is assembly language, which allows higher-level symbolic programming. Instead of writing programs as a sequence of bits, assembly language allows programmers to write programs by using symbolic operation codes. Since programs written in assembly language are not recognized by the CPU, we use an assembler to translate programs written in assembly language into machine language.

 

High-level languages

High-level languages were developed to enable programmers to write pro-grams faster than when using assembly languages. Since programs written in a high-level language are not recognized by the CPU, we must use a compiler to translate them to assembly language equivalents. Java, C++, COBOL, Pascal are some of the high-level languages.

 

Java Virtual Machine

Machine language consists of very simple instructions that can be executed directly by the CPU of a 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.

 

java-virtual-machine-JVM

 

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.

The designers of Java chose to use a combination of compilation and interpretation. Pro-grams 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.

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 Java 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. This is one of the essential features of Java, the same compiled program can be run on many different types of computers.

 

How Java is WORA

Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java-enabled system without any adjustment. This is all possible because of JVM.


Latest Topics: