You are on page 1of 23

UNIT 1: INTRODUCTION TO OPERATING SYSTEMS

WHAT OPERATING SYSTEM DO

 An OS is an intermediary between the user of the computer & the computer


hardware.
 It provides a basis for application program & acts as an intermediary between user of
computer & computer hardware.
 The purpose of an OS is to provide a environment in which the user can execute the
program in a convenient & efficient manner.
 OS is an important part of almost every computer systems.

Operating system objectives:

 Convenience: Make the computer system convenient to use


 Efficiency: OS allows computer system resources to be used in efficient manner.
 Ability to evolve: OS should be constructed in such a way as to permit the effective
development, testing and introduction of new system functions without interfering
with service.

 A computer system can be roughly divided into four components


a. The Hardware
b. The OS
c. The application Program
d. The user

Computer System Components

 The Hardware consists of memory, CPU, ALU, I/O devices, peripherals devices &
storage devices.
 The application program mainly consisted of word processors, spread sheets,
compilers & web browsers defines the ways in which the resources are used to solve
the problems of the users.
 The OS controls & co-ordinates the use of hardware among various application
program for various users.
 Utilities: it is system software designed to help, analyze, configure, optimize or
maintain a computer. User can often install or replace additional utilities. It is used to
support computer infrastructure.
 Ex: antivirus, archives, backup software, file manager, disk compression.

The following figure shows the conceptual view of a computer system


Services Provided by the OS
1. Program development
 Editors and debuggers
2. Program execution
3. Access I/O devices
4. Controlled access to files
5. System access
6. Error detection and response
 Internal and external hardware errors
 Software errors
 Operating system cannot grant request of application
7. Accounting
 Collect usage statistics
 Monitor performance
 Used to anticipate future enhancements
 Used for billing purposes

Operating System as a Resource Manager


 Responsible for managing resources
 Functions same way as ordinary computer software
o It is a program that is executed
 Operating system relinquishes control of the processor.
Kernel
 Portion of operating system that is in main memory
 Contains most frequently used functions
 Also called the nucleus
Evolution of Operating Systems
n An OS may evolve while time elapses due to the following reasons:
 Hardware upgrades plus new types of hardware: With hardware technologies
development, the OS also needs to upgrade so as to utilize the new mechanisms
introduced by new hardware
 New services: An OS may also expand to include more services in response to user
demand.
 Fixes: any program may contain more or less bugs or defects, thus fixes should be
made from time to time.
1. Serial processing
o Earlier computers (1940’s to 1950’s) had no operating system.
o Machines run from a console with display lights, toggle switches, input device,
and printer
o Users have to reserve time slots in advance, and during the allotted period,
they occupy the computer exclusively.
Two major problems:
1. Users may finish their tasks earlier than you have expected, and unfortunately
the rest time is simply wasted.
2. Programs are loaded into memory via a card reader. Setup included loading the
compiler, source program, saving compiled program, and loading and linking. Thus
much time is wasted.
2. Simple batch system: Introduced (after 1950) to improve the utilization of computer
systems.
Monitor: Software that controls the sequence of events
 Batch jobs together
 To process user programs, the monitor first has to be loaded into
memory
 Program returns control to monitor when finished
Job Control Language
 Special type of programming language, provides instruction to the monitor
o What compiler to use, what data to use.
Advantage:
 Monitor automates the execution of multiple jobs thus much time is saved by
avoiding manual operations.
 Processor is often idle.
3. Multiprogrammed batch systems
 Even with the automatic job processing by a monitor, the processor is still often
idle.
 Solution: multiprogramming or multitasking (runs multiple programs
concurrently).
Advantage: utilization of processor is greatly improved.
Problem: To run multiple programs concurrently, some form of scheduling and memory
management techniques is needed to obtain better performance.
The memory layout of simple batch system is shown below

OS
User
program
area

Disadvantages of Batch Systems:-


1. Turnaround time can be large from user.
2. Difficult to debug the program.
3. A job can enter into infinite loop.
4. A job could corrupt the monitor.
5. Due to lack of protection scheme, one job may affect the pending jobs.

4. Time Sharing Systems


 Using multiprogramming to handle multiple interactive jobs Processor’s time is
shared among multiple users.
 Multiple users simultaneously access the system through terminals.
 Time sharing system or multi tasking is logical extension of multi programming
systems. The CPU executes multiple jobs by switching between them but the
switching occurs so frequently that user can interact with each program while it is
running.
Hardware Features
Memory protection
o Does not allow the memory area containing the monitor to be altered
Timer
o Prevents a job from monopolizing the system
Privileged instructions
o Certain machine level instructions can only be executed by the monitor
Interrupts
o Early computer models did not have this capability
Memory Protection
o User program executes in user mode
o Certain instructions may not be executed
o Monitor executes in system mode
o Kernel mode
o Privileged instructions are executed
o Protected areas of memory may be accessed
Uniprogramming
o Processor must wait for I/O instruction to complete before proceeding

Multiprogramming
o When one job needs to wait for I/O, the processor can switch to the other job

Operating system operations

Modern OS are interrupt driven. No work -OS sit quietly. Events are signaled by the
occurrence of an interrupt/trap. A trap/exception is a software generated interrupt
caused either by an error or by a specific request from a user program that an OS
service be performed. For each type of interrupt, separate segments of code in the OS
determine what action should be taken. An ISR is responsible for dealing with the
interrupt.

Dual mode operation

 User mode.

 Kernel mode/superviser mode/system mode/privileged mode

 Mode bit is added to the hardware of the computer to indicate the current mode.

Kernel- 0

User -1

With mode bit we can easily distinguish the task that is executed on behalf of OS and on
behalf of the user. When user application is running- user mode. If user application
requests a service from the OS via system call, it must transition from user mode to
kernel mode.
Transition from user mode to kernel mode

Boot time, h/w starts in kernel mode. The OS is loaded and starts applications in user
mode. When interrupt occurs, h/w switches from 1 to 0. When OS gains control of the
computer, it is in 0 mode. System switches to 1 before passing control to the user
program. Dual mode of operation protects the OS from errant users. Privileged
instruction: the instruction to switch to the user mode, I/O control, timer management,
interrupts management.

Timer

OS maintains control over the cpu. To prevent a user program getting stuck in an infinite
loop or calling system services and never returning control to the OS, we use timer. A
timer can be set to interrupt the computer after a specified period. The period may be
fixed (1/60 second) or variable( from 1millisec to 1 second).

Common System Components


o Process Management
o Main Memory Management
o File Management
o I/O System Management
o Secondary Management
o Networking
o Protection System
o Command-Interpreter System
Process management

A program does nothing unless its instructions are executed by a CPU. Process –
complier, word processing program, system task( sending output to a printer). Process
needs certain resources- including CPU time, memory, files and I/O devices to
accomplish its task. These resources are either given to the process when it is created or
allocated to it while it is running. Program is a passive entity such as the contents of a
file stored on disk. Process is an active entity.

The OS is responsible for the following activities in connection with process


management.

 Creating and deleting both user and system processes


 Suspending and resuming processes
 Providing mechanism for process synchronization
 Providing mechanism for process communication
 Providing mechanisms for deadlock handling

Memory management

The main memory is central to the operation of a modern computer system. It contains
large array of words/bytes. Each word has its own address. Main memory is repository
of quickly accessible data shared by the CPU and I/O devices. The central processor
reads instructions from main memory during the instruction fetch cycle and both reads
and writes data from main memory during the data fetch cycle. The main memory is the
storage device that the CPU is able to address and access directly.

To improve both the utilization of the CPU and the speed of the computer’s response to
its users, general purpose computers must keep several programs in memory, creating a
need for memory management. The OS is responsible for the following activities in
connection with memory management.

 Keeping track of which part of memory is currently being used and by


whom.
 Deciding which processes and data to move into and out of memory.
 Allocating and deallocating memory space as needed.

Storage Management

OS provides a uniform, logical view of information storage for convenient use. OS


abstracts from the physical properties of its storage devices to define a logical storage
unit- the FILE. OS maps files into physical media and access these files via storage
devices.

1. File System management

Visible component of an OS. Different types of storage media


 Magnetic disk
 Optical disk
 Magnetic tape
Each one of these has its own characteristics and physical organization. Each one is
controlled by device such as disk drive or tape drive and has its own unique
characteristics like access speed, capacity, data transfer rate and access method.

File: collection of related information defined by its creator. File represents programs
and data. Data files may be numeric, alphabetic, alphanumeric or binary. Files are
normally organized in to directories to make them easier to use. When multiple users
have access to files, it may be desirable to control by whom and in what ways files may
be accessed.

The OS is responsible for the following activities.


 Creating and deleting files
 Creating and deleting directories to organize files.
 Supporting primitives for manipulating files and directories.
 Mapping files into secondary storage
 Backing up files on stable (non volatile) storage media.

2. Mass storage management

The OS is responsible for the following activities in connection with the disk
management.
 Free space management
 Storage allocation
 Disk scheduling

Because secondary storage is used frequently, it must be used efficiently.

3. I/O systems

The I/O systems consists of several components


 A memory management component that includes buffering, caching
and spooling.

 A general device driver interface.

 Drivers for specific hardware devices.

Networking (Distributed Systems)


A distributed system is a collection processors that do not share memory or a clock.
Each processor has its own local memory.
The processors in the system are connected through a communication network.
Communication takes place using a protocol(FTP.HTTP,NFS).
The processors in a distributed system vary in size and function.
A distributed system provides user access to various system resources.
Access to a shared resource allows:
o Computation speed-up
o Increased data availability
o Enhanced reliability

Protection and Security


Modern computer system supports many users & allows the concurrent execution of
multiple processes organization rely on computers to store information. It necessary that
the information & devices must be protected from unauthorized users or processors.
• The protection is a mechanism for controlling the access of program, processes or
users to the resources defined by a computer system.
• Protection mechanism are implemented in OS to support various security policies.
• The goal of security system is to authenticate their access to any object.
• Protection can improve reliability by detecting latent errors at the interface between
component sub system.

Command-Interpreter System
o One of the most important systems programs for an operating system is the
command interpreter, which is the interface between the user and the OS.
o Some operating systems include the command interpreter in the kernel.
o Other operating systems, such as MS-DOS and UNIX, treat the command
interpreter as a special program that is running when a job is initiated, or when a
user first logs on.
o The program that reads and interprets control statements is called variously:
o command-line interpreter
o shell (in UNIX)
o Its function is to get and execute the next command statement.
o Many commands are given to the operating system by control statements which
deal with:
o process creation and management
o I/O handling
o secondary-storage management
o main-memory management
o file-system access
o Protection and networking

USER OPERATING SYSTEM INTERFACE


1. Command Line Interface (CLI)
• Command interpreter system between the user & the OS. It is a system program to
the OS. Sometimes implemented in kernel, sometimes by systems program.
• Command interpreter is a special program in UNIX & MS DOS OS i.e. running when the
user logs on.
• Many commands are given to the OS through control statements when the user logs
on, a program that reads & interprets control statements is executed automatically. This
program is sometimes called the control card interpreter or command line interpreter
and is also called as shell.
• Sometimes commands built-in, sometimes just names of programs.
• The command statements themselves deal with process creation & management, I/O
handling, secondary storage management, main memory management, file system
access, protection & Network
.
2. Graphical User Interface(GUI)
A second strategy for interfacing with the operating system is through a user friendly
graphical user interface or GUI, Rather than having users directly enter commands via a
command-line interface, a GUI allows provides a mouse-based window-and-menu system as
an interface. A GUI provides a desktop metaphor where the mouse is moved to position its
pointer on images, or icons, on the screen (the desktop) that represent programs, files,
directories, and system functions.
 User-friendly desktop interface
 Usually mouse, keyboard, and monitor

OPERATING SYSTEM SERVICES:


An OS provides services for the execution of the programs and the users of such
programs. The services provided by one OS may be different from other OS. OS makes
the programming task easier. The common services provided by the OS are
1. Program Execution:-The OS must able to load the program into memory & run that
program. The program must end its execution either normally or abnormally.
2. I/O Operation:-A program running may require any I/O. This I/O may be a file or a
specific device user can’t control the I/O device directly so the OS must provide a means
for controlling I/O devices.
3. File System Interface:-Program need to read or write a file. The OS should provide
permission for the creation or deletion of files by names.
4. Communication:-In certain situation one process may need to exchange information
with another process. This communication May takes place in two ways.
a. Between the processes executing on the same computer.
b. Between the processes executing on different computer that are connected by a
network. This communication can be implemented via shared memory or by OS.
5. Error Detection:-Errors may occur in CPU, I/O devices or in Memory H/w. The OS
constantly needs to be aware of possible errors. For each type of errors the OS should
take appropriate actions to ensure correct & consistent computing.

OS with multiple users provides the following services,


a. Resource Allocation:-When multiple users logs onto the system or when multiple
jobs are running, resources must be allocated to each of them. The OS manages
different types of OS resources. Some resources may need some
special allocation codes & others may have some general request & release code.
b. Accounting:-We need to keep track of which users use how many & what kind of
resources. This record keeping may be used for accounting. This accounting data may be
used for statistics or billing. It can also be used to improve system efficiency.
c. Protection:-Protection ensures that all the access to the system are controlled.
Security starts with each user having authenticated to the system, usually by means of a
password. External I/O devices must also be protected from invalid access. In multi
process environment it is possible that one process may interface with the other or with
the OS, so protection is required.

SYSTEM CALLS
• System provides interface between the process & the OS.
• The calls are generally available as assembly language instruction & certain system
allow system calls to be made directly from a high level language program.
• Several language have been defined to replace assembly language program.
• A system call instruction generates an interrupt and allows OS to gain control of the
processors.
• System calls occur in different ways depending on the computer. Some time more
information is needed to identify the desired system call. The exact type & amount of
information needed may vary according to the particular OS & call.
• Mostly accessed by programs via API rather than direct system calls.
• Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based
systems and Java API for JVM
System Call Implementation
• Typically, a number associated with each system call
o System-call interface maintains a table indexed according to these numbers
• The system call interface invokes intended system call in OS kernel and returns
status of the system call and any return values
• The caller need know nothing about how the system call is implemented
o Just needs to obey API and understand what OS will do as a result call
o Most details of OS interface hidden from programmer by API
 Managed by run-time support library (set of functions built into
libraries included with compiler)

C program invoking printf() library call, which calls write() system call
System Call Parameter Passing
 Often, more information is required than simply identity of desired system call
o Exact type and amount of information vary according to OS and call
 Three general methods used to pass parameters to the OS
o Simplest: pass the parameters in registers
 In some cases, may be more parameters than registers
o Parameters stored in a block, or table, in memory, and address of block
passed as a parameter in a register
 This approach taken by Linux and Solaris
o Parameters placed, or pushed, onto the stack by the program and popped off
the stack by the operating system
o Block and stack methods do not limit the number or length of parameters
being passed
Parameter Passing via Table
TYPES OF SYSTEM CALLS
System calls may be grouped roughly into 5 categories
 Process control
 File management
 Device management
 Information maintenance
 Communications
 Process Management:- A system call can be used to terminate the program either
normally or abnormally. Reasons for abnormal termination are dump of memory,
error message generated etc.
 Debugger is mainly used to determine problem of the dump & returns back the dump
to the OS.
 In normal or abnormal situations the OS must transfer the control to the command
interpreter system.
 In batch system the command interpreter terminates the execution of job &
continues with the next job.
 Some systems use control cards to indicate the special recovery action to be taken in
case of errors.
 Normal & abnormal termination can be combined at some errors level. Error level is
defined before & the command interpreter uses this error level to determine next
action automatically.
 end, abort
 load, execute
 create process, terminate process
 get process attributes, set process attributes
 wait for time
 wait event, signal event
 allocate and free memory

MS-DOS:-

MS-DOS is an example of single tasking system, which has command interpreter system i.e.
invoked when the computer is started. To run a program MS-DOS uses simple method. It
does not create a process when one process is running MS-DOS the program into memory &
gives the program as much as possible. It lacks the general multitasking capabilities.
BSD:-
Free BSD is an example of multitasking system. In free BSD the command interpreter may
continue running while other program is executing. FORK is used to create new process.
FILE MANAGEMENT

 System calls can be used to create & deleting of files. System calls may require the
name of the files with attributes for creating & deleting of files.
 Other operation may involve the reading of the file, write & reposition the file after it
is opened.
 Finally we need to close the file.
 For directories some set of operation are to be performed. Sometimes we require to
reset some of the attributes on files & directories. The system call get file attribute &
set file attribute are used for this type of operation.
 create file, delete file
 open, close
 read, write, reposition
 get file attributes, set file attributes

DEVICE MANAGEMENT:-
 The system calls are also used for accessing devices.
 Many of the system calls used for files are also used for devices.
 In multi user environment the requirement are made to use the device. After using
the device must be released using release system call the device is free to be used
by another user. These function are similar to open & close system calls of files.
 Read, write & reposition system calls may be used with devices.
 MS-DOS & UNIX merge the I/O devices & the files to form file services structure. In
file device structure I/O devices are identified by file names.
 request device, release device
 read, write, reposition
 get device attributes, set device attributes
 logically attach or detach devices

INFORMATION MAINTAINANCE:-
 Many system calls are used to transfer information between user program & OS.
Example:- Most systems have the system calls to return the current time & date,
number of current users, version number of OS, amount of free memory or disk
space & so on.
 In addition the OS keeps information about all its processes & there are system calls
to access this information.
 get time or date, set time or date
 get system data, set system data
 get process, file, or device attributes
 set process, file, or device attributes

COMMUNICATION:-
 create, delete communication connection
 send, receive messages
 transfer status information
 attach or detach remote devices
There are two modes of communication,
1. Message Passing Models:-
 In this information is exchanged using inter-process communication facility provided
by OS.
 Before communication the connection should be opened.
 The name of the other communicating party should be known, it can be on the same
computer or it can be on another computer connected by a computer network.
 Each computer in a network may have a host name like IP name similarly each
process can have a process name which can be translated into equivalent identifier
by OS.
 The get host id & process id system call do this translation. These identifiers are then
passed to the open & close connection system calls.
 The recipient process must give its permission for communication to take place with
an accept connection call.
 Most processes receive the connection through special purpose system program
dedicated for that purpose called daemons. The daemon on the server side is called
server daemon & the daemon on the client side is called client daemon.
2. Shared Memory:-
 In this the processes uses the map memory system calls to gain access to memory
owned by another process.
 The OS tries to prevent one process from accessing another process memory.
 In shared memory this restriction is eliminated and they exchange information by
reading and writing data in shared areas. These areas are located by these processes
and not under OS control.
 They should ensure that they are not writing to same memory area.

 Both these types are commonly used in OS and some even implement both.
 Message passing is useful when small number of data need to be exchanged since
no conflicts are to be avoided and it is easier to implement than in shared memory.
 Shared memory allows maximum speed and convenience of communication as it is
done at memory speed when within a computer.

System Programs
System programs provide a convenient environment for program development and
execution.
They can be divided into these categories:
File management: These programs create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories.
Status information: Some programs simply ask the system for the date, time, amount
of available memory or disk space, number of users, or similar status information.
That information is then formatted, and is printed to the terminal or other output device
or file.
File modification: Several text editors may be available to create and modify the
content of files stored on disk or tape.
Programming-language support: Compilers, assemblers, and interpreters for
common programming languages (such as C, C++, Java, Visual Basic, and PERL) are
often provided to the user with the operating system.
Some of these programs are now priced and provided separately.
Program loading and execution: Once a program is assembled or compiled, it must
be loaded into memory to be executed.
The system may provide absolute loaders, relocatable loaders, linkage editors, and
overlay loaders.
Debugging systems for either higher-level languages or machine language are needed
also.
Communications: These programs provide the mechanism for creating virtual
connections among processes, users, and different computer systems.
They allow users to send messages to one another's screens, to browse web pages, to
send electronic-mail messages, to log in remotely, or to transfer files from one machine
to another.
Most users’ view of the operation system is defined by system programs, not the actual
system calls.
Most operating systems are supplied with programs that solve common problems, or
perform common operations.
Such programs include web browsers, word processors and text formatters,
spreadsheets, database systems, compiler compilers, plotting and statistical-analysis
packages, and games.
These programs are known as system utilities or application programs.

Operating System Structure


 Operating system is large and complex, so a common approach is to partition the
task into small components to function properly, rather than have one monolithic
system.
 Each of these modules should be a well-defined portion of the system, with
carefully defined inputs, outputs, and function.
1. Simple Structure
o Many commercial systems do not have a well-defined structure.
o Frequently, such operating systems started as small, simple, and limited
systems, and then grew beyond their original scope.
o MS-DOS is an example of such a system.
o Operating systems such as MS-DOS and the original UNIX did not have well-
defined structures.
o There was no dual mode (user and kernel), and so errors in applications could
cause the whole system to crash.

MS-DOS System Structure


 MS-DOS – written to provide the most functionality in the least space
 not divided into modules
 Although MS-DOS has some structure, its interfaces and levels of functionality
are not well separated.
 There was no dual mode in OS.
 User programs were able to access I/O devices directly.
 Difficult to design and implement.
 It was written to provide the most functionality in the least space (because of the
limited hardware on which it ran), so it was not divided into modules.
 UNIX is another system that was initially limited by hardware functionality.
 It consists of two separable parts: the kernel and the system programs.
 The kernel is further separated into a series of interfaces and device drivers,
which were added and expanded over the years as UNIX evolved.
 The kernel provides the file system, CPU scheduling, memory management, and
other operating-system functions through system calls.

UNIX Structure
2. Layered Approach:
 The operating system is divided into a number of layers (levels), each built on top of
lower layers.
 The bottom layer (layer 0), is the hardware; the highest (layer N) is the user
interface.
 The main advantage of the layered approach is modularity.
 With modularity, layers are selected such that each uses functions (operations) and
services of only lower-level layers.
 This approach simplifies debugging and system verification.
 The first layer can be debugged without any concern for the rest of the system,
because, by definition, it uses only the basic hardware (which is assumed correct) to
implement its functions.
 Thus, the design and implementation of the system are simplified when the system
is broken down into layers.
 The major difficulty with the layered approach involves the careful definition of the
layers, because a layer can use only those layers below it.
 A final problem with layered implementations is that they tend to be less efficient
than other types.
 Each layer adds overhead to the system call; the net result is a system call that
takes longer than does one on a non layered system.
 Slower

Examples: OS/2, MULTICS.


 Ex: OS/2 is a descendant of MSDOS that adds multitasking
and dual-mode operation, as well as other new features.
 Because of this added complexity and the more powerful hardware for which
OS/2 was designed, the system was implemented in a more layered fashion.
 OS/2 has the advantage: direct user access to low-level facilities is not allowed,
providing the operating system with more control over the hardware and more
knowledge of which resources each user program is using.

Advantages
 The main advantage is simplicity of construction and debugging.
 Modularity
Disadvantages
 The main difficulty is defining the various layers.
 The main disadvantage is that the OS tends to be less efficient than other
implementations.
 Slower
 Less efficient

3. Microkernel System Structure


 As the UNIX operating system expanded, the kernel became large and difficult to
manage.
 In the mid-1980s, researchers developed an os called Mach that modularizes the
kernel using the microkernel approach.
 Moves as much from the kernel into “user” space. This results in a small kernel.
 Communication takes place between user modules using message passing.
Benefits/Advantages:
o easier to extend a microkernel
o easier to port the operating system to new architectures
o more reliable (less code is running in kernel mode)
o more secure
Disadvantage:
 Main disadvantage is poor performance due to increased system overhead
from message passing.

 Microkernel’s provide minimal process and memory management, in addition to a


communication facility between the client program and the various services that are
also running in user space.
 Ex: UNIX, Apple MacOS, QNX.
 Windows NT uses a hybrid structure.
 Part of the Windows NT architecture uses layering.
 Windows NT is designed to run various applications, including Win32 ,0S/2, and
POSIX.
 The kernel coordinates the message passing between client applications and
application servers.

Virtual Machines
A virtual machine takes the layered approach to its logical conclusion. It treats hardware
and the operating system kernel as though they were all hardware. A virtual machine
provides an interface identical to the underlying bare hardware. The operating system
creates the illusion of multiple processes, each executing on its own processor with its own
(virtual) memory. The resources of the physical computer are shared to create the virtual
machines. CPU scheduling can create the appearance that users have their own processor.

Advantages: The virtual-machine concept provides complete protection of system


resources since each virtual machine is isolated from all other virtual machines.
 System development is done on the virtual machine, instead of on a physical
machine and so does not disrupt normal system operation.
 Multiple OS can exist on simultaneously on the same machine isolated from each
other.
 Easy maintenance, application provisioning, availability and convenient recovery
 Consumes less power and physical space.

Disadvantages:
 The virtual machine concept is difficult to implement.
 Due to isolation, no direct sharing of resources is permitted.

Java Virtual Machine


Java is a very popular object-oriented language introduced by Sun Microsystems in late
1995. In addition to a language specification and a large API library, Java also provides a
specification for a JVM. Java program consists of one or more classes. For each Java class,
the Java compiler produces an platform-neutral bytecode output (. class) file that will run
on any implementation of the JVM.

It is an environment that executes java programs. Java programs are compiled in to


intermediate language called bytecode, which is executed by JVM. Any program compiled
into bytecode can be executed on any platform that has JVM installed on it.

JVM consists of
o class loader
o class verifier
o Runtime interpreter to execute platform-neutral bytecodes.

Each programming language has their own compiler and execution engine. Execution engine
for java is JVM. It is compatible with almost all OS and can be implemented independently
on any hardware. Whenever you type java command in the command prompt to run java
class, an instance of JVM is created.

 Just-In-Time (JIT) compilers increase performance

JIT compiler that turns the platform-neutral byte codes into native machine language for
the host computer. The JVM makes it possible to develop programs that are architecture
neutral and portable. Java takes advantage of the complete environment that a virtual
machine implements. Its virtual-machine design provides a secure, efficient, object
oriented, portable, and architecture-neutral platform on which to run Java programs.

Javac Compiler: Produces bytecode.


JVM: converts bytecode into machine language and executes it.

Advantages:
 Platform independence: Written once and executed on multiple platforms
 Security: JVM has built-in security features.

Disadvantage:
 Programs run on JVM takes longer time to execute.

You might also like