1 QB
1 QB
Procedure‐Oriented Programming
In Multi‐function program important data items are placed as global so that they may be
accessed by all functions. Each function may have its own local data.
• Since every function has complete access to the global variables, a new
programmer can corrupt the data accidentally by creating function.
• We can access the data of one function from other since, there is no protection.
• In large program it is very difficult to identify what data is used by which function.
• Similarly, if new data is to be added, all the function needed to be modified to access
the data.
• Does not model real world problem very well.
Object ties the data more closely to the functions that operate on it, and protects it
from accidental modification from the outside functions. Data of an object can be accessed
only by the functions associated with that object.
• POP is less secure as compared to OOP because in OOP the access specifier limits the access
to attributes or functions which increase the security.
● SOFTWARE ENGINEERING
● Software engineering discusses systematic and cost-effective techniques for software
development. These techniques help develop software using an engineering approach.
● Software life cycle
● The life cycle of a software represents the series of identifiable stages through which it
evolves during its life time.
● A Software development life cycle (SDLC) model (also called software life cycle model
and software development process model ) describes the different activities that need to
be carried out for the software to evolve in its life cycle.
● In fact, it is hard to put this model into use in any non-trivial software development
project.
● All other life cycle models can be thought of as being extensions of the classical waterfall
model.
Phases of the classical waterfall model
Feasibility study
● The main focus of the feasibility study stage is to determine whether it
would be financially and technically feasible to develop the software.
Requirements analysis and specification
● The aim of the requirements analysis and specification phase is to understand the exact
requirements of the customer and to document them properly.
● This phase consists of two distinct activities, namely requirements gathering and analysis,
and requirements specification.
● Phases of the classical waterfall model
Design
● The goal of the design phase is to transform the requirements specified
in the SRS document into a structure that is suitable for implementation
in some programming language.
● In technical terms, during the design phase the software architecture is derived from the
SRS document.
● Two distinctly different design approaches
➢ Function-oriented design(Procedural design approach)
➢ Object-oriented design approach
● Phases of the classical waterfall model
Coding and unit testing
● The purpose of the coding and unit testing phase is to translate a
software design into source code and to ensure that individually each
function is working correctly.
● The coding phase is also sometimes called the implementation phase, since the design is
implemented into a workable solution in this phase.
● The end-product of this phase is a set of program modules that have been individually
unit tested.
● The main objective of unit testing is to determine the correct working of the individual
modules.
● Phases of the classical waterfall model
Integration and system testing
● During the integration and system testing phase, the different modules are integrated in a
planned manner.
● Integration of various modules are normally carried out incrementally over a number of
steps.
● Finally, after all the modules have been successfully integrated and tested, the full
working system is obtained.
● System testing is carried out on this fully working system
● Phases of the classical waterfall model
Maintenance
● Maintenance is carried out to correct errors that were not discovered during the product
development phase.
● Maintenance is carried out to improve the performance of the system, or to enhance the
functionalities of the system based on customer’s requests.
✓ Object-oriented Design
✓ Function-oriented Design
Salient features of the function-oriented design approach:
1. Top-down decomposition
● A system, to start with, is viewed as a black box that provides certain services (also
known as high-level functions) to the users of the system.
● In top-down decomposition, starting at a high-level view of the system, each high-level
function is successively refined into more detailed functions.
● Consider a function create-new-library member which essentially creates the record for a
new member, assigns a unique membership number to him, and prints a bill towards his
membership charge.
●
2.Centralised system state
● The system state can be defined as the values of certain data items that determine the
response of the system to a user
action or external event.
● For example, the set of books (i.e. whether borrowed by different users or available for
issue) determines the state of a library automation system.
● Such data in procedural programs usually have global scope and are shared by many
modules.
● For example, in the library management system, several functions such as the following
share data such as member-records for reference and updation:
✓ create-new-member
✓ delete-member
✓ update-member-record
✓
Object-oriented Design
● In the object-oriented design (OOD) approach, a system is viewed as
being made up of a collection of objects (i.e. entities).
● Each object is associated with a set of functions that are called its methods.
● Each object contains its own data and is responsible for managing it.
● The data internal to an object cannot be accessed directly by other objects and only
through invocation of the methods of the object.
● The system state is decentralised since there is no globally shared data in the system and
data is stored in each object.
● For example, in a library automation software, each library member may be a separate
object with its own data and functions to operate on the stored data.
● The object-oriented design paradigm makes extensive use of the principles of abstraction
and decomposition as explained below.
● Objects decompose a system into functionally independent modules. Objects can also be
considered as instances of abstract data types (ADTs).
● Three important concepts associated with abstract data types (ADTs)
➢ Abstraction
➢ Data structure
➢ Data type
Data abstraction
● The principle of data abstraction implies that how data is exactly stored is abstracted
away.
● This means that any entity external to the object (that is, an instance of an ADT) would
have no knowledge about how data is exactly stored, organised, and manipulated inside
the object.
● The entities external to the object can access the data internal to an object only by calling
certain well-defined methods supported by the object.
Data structure:
● A data structure is constructed from a collection of primitive data items.
● Just as a civil engineer builds a large civil engineering structure using primitive building
materials such as bricks, iron rods, and cement;
● A programmer can construct a data structure as an organised collection of primitive
data items such as integer, floating point numbers, characters, etc.
Data type
● A type is a programming language terminology that refers to anything that can be
instantiated.
● For example, int, float, char etc., are the basic data types supported by C programming
language.
● Thus, we can say that ADTs are user defined data types.
● Unlike function-oriented design methods in OOD, the basic abstraction is not the services
available to the users of the system such as issuebook ,display-book-details, find-issued-
books, etc., But real-world entities such as member, book, book-register, etc.
● For example in OOD, an employee pay-roll software is not developed by designing
functions such as update-employee-record, get-employee-address,etc., but by designing
objects such as employees, departments, etc.
● In OOD, state information exists in the f orm of data distributed among several objects
of the system.
● In contrast, in a procedural design, the state information is available in a centralised
shared data store.
● For example, while developing an employee pay-roll system, the employee data such as
the names of the employees, their code numbers, basic salaries, etc., are usually
implemented as global data in a traditional programming system; whereas in an object-
oriented design, these data are distributed among different employee objects of the
system.
● Objects communicate by message passing.
CASE STUDY Automated fire-alarm system
Customer requirements
● The owner of a large multi-storied building wants to have a computerised fire alarm
system designed, developed, and installed in his building.
● Smoke detectors and fire alarms would be placed in each room of the building.
● The fire alarm system would monitor the status of these smoke detectors.
● Whenever a fire condition is reported by any of the smoke detectors, the fire alarm
system should determine the location at which the fire has been sensed and then sound
the alarms only in the neighbouring locations
● The fire alarm system should also flash an alarm message on the computer console.
● Fire fighting personnel would man the console round the clock. After a fire condition has
been successfully handled, the fire alarm system should support resetting the alarms by
the fire fighting personnel.
Function-oriented approach:
● In this approach, the different high-level functions are first identified, and then the data
structures are designed
The functions which operate on the system state are:
➢ interrogate_detectors();
➢ get_detector_location();
➢ determine_neighbour_alarm();
➢ determine_neighbour_sprinkler();
➢ ring_alarm();
➢ activate_sprinkler();
➢ reset_alarm();
➢ reset_sprinkler();
➢ report_fire_location();
Object-oriented approach
● In the object-oriented approach, the different classes of objects are identified.
● Subsequently, the methods and data for each object are identified.
● Finally, an appropriate number of instances of each class is created.
Object-oriented approach
➢ class detector
attributes: status, location, neighbours
operations: create, sense-status, get-location,find-neighbours
➢ class alarm
attributes: location, status
operations: create, ring-alarm, get_location, resetalarm
➢ class sprinkler
attributes: location, status
operations: create, activate-sprinkler, get_location,reset- sprinkler
CLASS
▪ Collection of objects is called class.
▪ CLASS are a blueprint or a set of instructions to build a specific type of object.
▪ An object is an instance of a class.
▪ Class in Java determines how an object will behave and what the object will contain.
▪ Let’s take Human Being as a class. My name is John, and I am an instance/object of
the class Human Being.
▪ Object has a physical existence while a class is just a logical definition.
▪ Car is the class and wheels, speed limits, mileage are their properties.
▪ A Class is a user defined data-type which has data members and member functions.
▪ Data members are the data variables and member functions are the functions used to
manipulate these variables and together these data members and member functions
defines the properties and behavior of the objects in a Class.
▪ In the above example of class Car, the data member will be speed limit, mileage etc and
member functions can be apply brakes, increase speed etc.
String name;
int roll no,total_marks;
void total() {
System.out.println(“total mark:" +total_marks );
}
}
<<class-name>><<object-name>>;
For example, if ”Student” is the class created by user
Student ram, shyam;
Here ram and shyam are name of objects for class Student.
Once a class has been defined we can create any number of objects for that class.we can
assign values to attributes during instantiation using this object .Methods defined can be
invoked with the objects. It can change the state of object attributes.
Inheritance
▪ The capability of a class to derive properties and characteristic from another class is
called Inheritance.
▪ Sub Class : The class that inherits properties from another class is called Sub class
or Derived Class.
▪ Super Class : The class whose properties are inherited by sub class is called Base
Class or Super class.
▪ The subclass can add its own fields and methods in addition to the superclass fields and
methods.
▪ It supports the concept of hierarchical classification.
Advantages of inheritance
➢ Reusability: facility to use methods of base class with out rewriting the same.
➢ Data hiding: Using access specifiers, base class can decide to keep some data private so
that it cannot be altered by the derive class.
➢ Extensibility: extending the base class logic.
➢ Through effective use of inheritance, you can save lot of time in your programming and a
lso reduce errors, which in turn will increase the quality of work and productivity.
. The different types of Inheritance are:
1. Single Inheritance
2. Hierarchical Inheritance
3. Multiple Inheritance
4. Multi Level Inheritance
5.Hybrid Inheritance
• Single Inheritance − A subclass derives from a single super-class.
• Multiple Inheritance − A subclass derives from more than one super-classes.
o
• Multilevel Inheritance − A subclass derives from a super-class which in turn is derived
from another class and so on.
• Hybrid Inheritance − A combination of multiple and multilevel inheritance so as to form
a lattice structure.
o
• Hierarchical Inheritance − A class has a number of subclasses each of which may have
subsequent subclasses, continuing for a number of levels, so as to form a tree structure.
Encapsulation
▪ It is the process of binding both attributes and methods together in a single unit , as a
class.
▪ Through encapsulation, the internal details of a class can be hidden from outside.
▪ It permits the elements of the class to be accessed from outside only through the
interface provided by the class.
Binding (or wrapping) code and data together into a single unit are known as encapsulation.
For example: consider a Medical store. Lets say you have to buy
some medicines. You go to the medical store and ask the chemist for the medicines.
Only the chemist has access to the medicines in the store based on your prescription .Chemist
knows what medicines to give to you.
▪ In this example
▪ MEDICAL STORE: class
▪ MEDICINES: Member Variables.
▪ CHEMIST: Member Methods.
▪ You: External Application or piece of Code accessing members with method in class
▪ Through Encapsulation, Data is not accessible to the outside world, and only those
functions which are wrapped in the class can access it.
▪ In encapsulation, the variables of a class will be hidden from other classes and can be
accessed only through the methods of their current class. Therefore, it is also known
as data hiding.
To achieve encapsulation in Java −
▪ Declare the variables of a class as private for data hiding.
▪ Provide public setter and getter methods to modify and view the
variables values.
▪ Data Hiding: It is a way to achieve data hiding in Java because other class will not be
able to access the data through the private data members.
ADVANTAGES OF ENCAPSULATION
▪ Protection of data from accidental corruption,by means of access specifiers
(Private/Public),it provides security.
▪ Encapsulation protects an object from unwanted access by clients.
▪ Increased Flexibility: We can make the variables of the class as read-only or write-only
depending on our requirement.
▪ Reduction in complexity.
Abstraction
➢ Data Abstraction is the property by virtue of which only the essential details are
displayed to the user.
➢ Data Abstraction may also be defined as the process of identifying only the required
characteristics of an object ignoring the irrelevant details.
➢ In other words, the user will have the information on what the object d oes instead of how
it does it.
➢ The trivial or the non-essentials units are not displayed to the user. Ex: A car is viewed as
a car rather than its individual components.
● Basic Object Oriented concepts
Abstraction
➢ Consider a real-life example of a man driving a car.
➢ The man only knows that pressing the accelerators will increase the speed of car or
applying brakes will stop the car but he does not know about how on pressing the
accelerator the speed is actually increasing, he does not know about the inner me chanism
of the car or the implementation of accelerator, brakes etc in the car.
➢ In java, abstraction is achieved by interfaces and abstract classes.
POLYMORPHISM
➢ The word polymorphism means having many forms. Poly means many and morph
means form; which means objects can take many different forms .
➢ Suppose if you are in class room that time you behave like a student, when you are in
market at that time you behave like a customer, when you at your home at that time you
behave like a son or daughter, Here one person present in different-different behaviors.
ADVANTAGES OF POLYMORPHISM
▪ Method overloading allows methods that perform similar or closely related
functions to be accessed through a common name. Method overloading allows you
to define three methods with the same name and different types of parameters to
handle the array of operations.
▪ Method overriding allows a sub class to use all the general definitions that a super
class provides and add specialized definitions through overridden methods.
▪ Method overriding works together with inheritance to enable code reuse of existing
classes without the need for re-compilation.
▪ It helps the programmer to reuse the codes.
The essence of the software development process that consists of analysis, design,
implementation, testing, and refinement is to transform user’s needs into a software solution
that satisfies those needs. The software development process can be divided into smaller,
interacting sub processes. Generally software development can be seen as a series of
transformations, where the output of one transformation becomes the input of the
subsequent transformation.
Object–Oriented Analysis
• In this stage, the problem is formulated, user requirements are identified, and then a
model is built based upon real–world objects.
• The analysis produces models on how the desired system should function and how it
must be developed.
• The models do not include any implementation details so that it can be understood and
examined by any non–technical application expert.
Object–Oriented Design
This phase includes two stages: system design & object design.
System Design :
• In this stage, the complete architecture of the desired system is designed.
• The system is conceived as a set of interacting subsystems that in turn is composed of a
hierarchy of interacting objects, grouped into classes.
• System design is done according to system analysis model and proposed system
architecture.
• Emphasis is on the objects comprising the system rather than the processes in the
system.
Object Design
• a design model is developed based on both the models developed in the system analysis
phase and system design phase.
• All the classes required are identified.
• The designer decides whether :
◦ new classes are to be created from scratch,
◦ any existing classes can be used in their original form, or
◦ new classes should be inherited from the existing classes.
• The associations between the identified classes are established and the hierarchies of
classes are identified.
• Besides, the developer designs the internal details of the classes and their associations,
Object–Oriented Implementation and Testing
• In this stage, the design model developed in the object design is translated into code in
an appropriate programming language or software tool.
• The databases are created and the specific hardware requirements are ascertained.
• Once the code is ready, it is tested using specialized techniques to identify and remove
the errors in the code
UML is a language for specifying, constructing, visualizing and documenting the software
system and its components.UML is a graphical language with set of rules & semantics expressed
in English, in a form known as object constraint language (OCL) .
● It helps to manage the complexity in a problem and facilitates arriving at good solutions
and at the same time helps to reduce the design costs.
● Analysis and Design models can be used for a variety of purposes during software
development:
● Analysis
● Specification
● Design
● Coding
● Visualisation and understanding of an implementation.
● Testing, etc.
UML DIAGRAMS
11
UML diagrams can be divided into two categories. The first type representing structural
information. The second representing general types of behavior.
Structure diagrams are used in documenting the architecture of software systems and are
involved in the system being modeled.
Different structure diagrams are:
Class Diagram: represents system class, attributes and relationships among the classes.
Component Diagram: represents how components are split in a software system and
dependencies among the components.
Deployment Diagram: describes the hardware used in system implementations.
Object Diagram: represents a complete or partial view of the structure of a modeled system.
Behavior diagrams represent functionality of software system and emphasize on what must
happen in the system being modeled.
The different behavior diagrams are:
Activity Diagram: represents step by step workflow of business and operational components.
Use Case Diagram: describes functionality of a system in terms of actors, goals as use cases and
dependencies among the use cases.
UML State Machine Diagram: represents states and state transition.
Interaction Diagram: provides an overview and nodes representing communication diagrams.
Sequence Diagram: represents communication between objects in terms of a sequence of
messages.
● A use case typically involves a sequence of interactions between the user and the
system.
● A use case consists of one main line sequence and several alternate sequences.
● The main line sequence represents the interactions between a user and the system
that normally take place.
● For example, in the mainline sequence of the withdraw cash use case supported by a
bank ATM would be—the user inserts the ATM card, enters password, selects the
amount withdraw option, enters the amount to be withdrawn, completes the
transaction, and collects the amount.
● Several variations to the main line sequence (called alternate sequences) may also exist.
● For the bank ATM example, consider the following variations or alternate sequences:
✓ Password is invalid.
✓ The amount to be withdrawn exceeds the account balance.
5.GENERALIZATION OF AN ACTOR
✓ Generalization of an actor means an actor can inherit the role of the other actor.
✓ Descendent inherits all the usecases of the ancestor
✓ The descendent has one or more usecases that are specific to that role
13.Draw the usecase diagram for ATM system with include and
extend relationship.
● The classes represent entities with common features, i.e., attributes and operations.
● Classes are represented as solid outline rectangles with compartments.
● Classes have a mandatory name compartment where the name is written centered in
boldface.
● The class name is usually written using mixed case convention and begins with an
uppercase (e.g. LibraryMember).
● Object names on the other hand, are written using a mixed case convention, but starts
with a small case letter (e.g., studentMember).
● Classes have optional attributes and operations compartments
Class notation
: Drawn as rectangle with three components – name, attributes, list of operations
● Class Name:
● The name of the class appears in the first partition.
● Class Attributes:
● Attributes are shown in the second partition.
● The attribute type is shown after the colon.
● Attributes map onto member variables (data members) in code
● Class Operations (Methods):
● Operations are shown in the third partition. They are services the class provides.
● The return type of a method is shown after the colon at the end of the method
signature.
● The return type of method parameters are shown after the colon following the
parameter name. Operations map onto class methods in code
Class Visibility
● The +, - and # symbols before an attribute and operation name in a class denote the
visibility of the attribute and operation.
1.Association
▪ Associations are relationships between classes in a UML Class Diagram. They are
represented by a solid line between classes.
▪ When two classes are associated, they can take each others help (i.e. invoke each others
methods) to serve user requests.
▪ If one class is associated with another bidirectionally, the object of one class to invoke
the methods of the corresponding object of the other class.
▪ A Student can register in one Elective subject. In this example, the class Student is
associated with the class ElectiveSubject.
2.Dependency
▪ A class is said to be dependent on another class, if any changes to the latter class
necessitates a change to be made to the dependent class..
▪ A dependency relation between two classes shows that any change made to the
independent class would require the corresponding change to be made to the dependent
class.
● Exists between two classes if changes to the definition of one may cause changes to the
other .
● Class1 depends on Class2
▪ The figure below shows another example of dependency. The Person class might ha ve a
hasRead method with a Book parameter that returns true if the person has read the book
(perhaps by checking some database).
3.Aggregation
4.COMPOSITION
● Composition is a restricted form of Aggregation in which two entities are highly
dependent on each other.
● It represents part-of relationship.
● A special type of aggregation where parts are destroyed when the whole is destroyed.
● Objects of Class2 live and die with Class1.
● Class2 cannot stand by itself
5. INHERITANCE
● The inheritance relationship is represented by means of an empty arrow pointing from the
subclass to the superclass. The arrow may be directly drawn from the subclass to the
superclass.
• Binary association: Association between two classes; drawn as a solid path connecting two
classes.
Example : Person sits on a Chair
• Association navigation
• Arrow may be attached to the end of path to indicate that navigation is
supported in the direction of the class pointed to.
◦ Means “a part of ”
◦ Form of association representing a structural relationship between a whole and its
parts.Aggregation implicit a relationship where the child can exist independently of
the parent.
Example
Composition
• Shows a relationship where the child cannot exist independent of the parent.
In the above diagram, we can see the example for multiplicity and generalization
between multiple classes.
In the above diagram, we can see the example for generalization between multiple
classes.
● Since it shows instances of classes, rather than the classes themselves, it is often called
as an instance diagram.
You use object diagrams to model the static design view or static process view of a system just
as you do with class diagrams, but from the perspective of real or prototypical instances
● ·
● It is used for general conceptual modeling of the structure of the application, and for
detailed modeling translating the models into programming code.
● Helps us to understand the functionalities that the system should deliver to the users.
● Verify the class diagrams for completeness and accuracy by using Object Diagrams as
specific test cases.
● Typically, each interaction diagram realises the behaviour of a single use case.
● For complex use cases, more than one interaction diagrams may be necessary to
capture the behaviour.
● An interaction diagram shows a number of example objects and the messages that are
passed between the objects within the use case.
● The interaction diagrams play a major role in any effective object oriented design
process
1. Sequence diagram
2. Collaboration diagram
3. Timing diagram
• Focus on the instance at which a message is sent from one object to another object.
1. Sequence diagram
● The objects participating in the interaction are shown at the top of the chart as boxes
attached to a vertical dashed line.
● Inside the box the name of the object is written with a colon separating it from the
name of the class and both the name of the object and the class are underlined.
● Any point on the lifeline implies that the object exists at that point. Absence of lifeline
after some point indicates that the object ceases to exist after that point in time,
particular point of time.
● A rectangle called the activation symbol is drawn on the lifeline of an object to indicate
the points of time at which the object is active.
● Thus an activation symbol indicates that an object is active as long as the symbol
(rectangle) exists on the lifeline.
● Each message is indicated as an arrow between the lifelines of two objects. The
messages are shown in chronological order from the top to the bottom.
Collaboration diagram
explicitly.
▪ This is unlike a sequence diagram which shows only the behavioural aspects.
● The structural aspect of a collaboration diagram consists of objects and links among
them indicating association.
● The behavioural aspect is described by the set of messages exchanged among the
different objects.
● A Collaboration is a collection of named objects and actors with links connecting them.
They collaborate in performing some task.
● The collaboration diagram is used to show the relationship between the objects in a
system.
● The sequence and the collaboration diagrams represent the same information but
differently.
● Instead of showing the flow of messages, it depicts the architecture of the object
residing in the system as it is based on object-oriented programming.
● Objects: The representation of an object is done by an object symbol with its name and
class underlined, separated by a colon.
● Actors: In the collaboration diagram, the actor plays the main role as it invokes the
interaction. Each actor has its respective role and name.
● Links: The link is an instance of association, which associates the objects and actors. It is
represented by a solid line.
✓ Second, you can focus on the structural relationships among the objects in an
interaction and then consider how messages are passed within the context of
that structure.
• Either model generic interactions (showing all possible paths through the
interaction) or specific instances of a interaction (showing just one path through the
interaction)
control. Activities ultimately result in some action, which is made up of executable atomic
computations that results in a change in state of the system or the return of a value.
Activity diagrams are not only important for modeling the dynamic aspects of a system,
but also for constructing executable systems through forward and reverse engineering.
● Activity diagram is essentially an advanced version of flow chart that modelling the
flow from one activity to another activity.
● We can depict both sequential processing and concurrent processing of activities using
an activity diagram.
Guards
In UML, guards are a statement written next to a decision diamond that must be true before moving
next to the next activity
An association can have a name, and you use that name to describe the nature of the
relationship
Role
When a class participates in an association, it has a specific role that it plays in that relationship;
a role is just the face the class at the near end of the association presents to the class at the
other end of the association
Multiplicity
• A state corresponds to the interval between two events received by an object and
describes
the "value" of the object for that time period.
• A state is an abstraction of an object's attribute values and links, where sets of values
are grouped together into a state according to properties that affect the general
behavior of the object. For instance, stack is empty or stack is full are different states of
the object stack. As state corresponds to interval between two events received by an
object so it has duration.
Event
Conditions
Events
• Represents incidents that cause objects to transition from one state to another..\
• Internal or External Events trigger some activity that changes the state of the system
and of some of its parts.
• An event signature is described as Event-name (comma-separated-parameter-list).
• Events appear in the internal transition compartment of a state or on a transition
between states.
● To model the life time of a reactive system[a system that responds to external or
internal events.]
The Java Development Kit (JDK) is a software development environment used for developing
and executing Java applications and applets.
✓ JRE is an installation package which provides environment to only run(not develop) the
java program(or application)onto your machine.
40.Summarize JVM
▪ JVM (Java Virtual Machine) is an abstract machine that enables your computer to run a
Java program.
▪ JVM is a program which provides the runtime environment to execute Java programs.
▪ JVM is a virtual machine that resides in the real machine (your computer) and the
machine language for JVM is byte code.
▪ Java compiler first compiles your Java code to bytecode.
▪ Then, the JVM translates bytecode into native machine code (set of instructions that a
computer's CPU executes directly).
▪ A virtual machine(VM) is a software implementation of an abstract computer.
▪ Java has a VM specification that formally describes what is required in a Java VM
implementation.
▪ Java Virtual Machine(JVM) is implemented as per Java VM specification to execute the
Java bytecode (ie, instruction set understandable to the VM).
▪ Most of the JVMs are implemented using C language, JVM developed for one platform
will not work on another. ie, JVM is platform dependent.
▪ It provides the runtime environment to execute Java programs (bytecode) on a
particular platform.
▪ Platform independency of Java is due to JVM.
▪ When we write a program in Java, firstly, the compiler compiles that program and a
bytecode is generated for that piece of code.
▪ When a Java program is compiled, a Bytecode is generated for that program in the form
of a .class file.
▪ The bytecode generated after the compilation is run by the Java virtual machine.
▪ Resources required to run the bytecode are made available by theJava Virtual Machine,
which calls the processor to allocate the required resources.
▪ Java byte code is the instruction set for the Java Virtual Machine.
▪ It is the machine code in the form of a .class file.
▪ Byte code is a machine independent code.
▪ It is not completely a compiled code but it is an intermediate code somewhere in the
middle which is later interpreted and executed by JVM.
▪ Byte code is a machine code for JVM.
▪ Byte code implementation makes Java a platform- Independent language.
▪ Platform independence is one of the soul reasons for which James Gosling started the
formation of java and it is this implementation of bytecode which helps us to achieve
this.
▪ When a program is written and compiled in JAVA a separate file is created for a
compiled program. This file (.class) is called bytecode in java.\
▪ Byte code generated in a particular platform can be executed in any other platform i.e.
the byte code generated in windows OS can also be executed in Unix OS.
▪ The one which makes this possible is the JVM (JAVA VIRTUAL MACHINE).
▪ When the program is written and compiled the compiler send the generated bytecodes
to the JVM in the machine and this JVM converts the byte codes into native code which
is readable by a particular machine. Thus the output is displayed.
JavaFX
▪ JavaFX is a software platform for creating and delivering desktop
applications, as well as rich Internet applications (RIAs) that can run across
a wide variety of devices.
▪ The applications built in JavaFX, can run on multiple platforms including
Web, Mobile and Desktops.
▪ JavaFX is intended to replace swing in Java applications as a GUI
framework.
▪ JavaFX is a set of graphics and media packages that enables developers to
design, create, test, debug, and deploy rich client applications that operate
consistently across diverse platforms.
▪ Java FX technology was a platform for creating rich internet applications
written in Java FX Script.
▪ Java FX Script is a statically typed declarative language that is compiled to
Java technology bytecode , which can then be run on a Java VM.
▪ Now it is merged with Java SE.
▪ Java was designed to be easy for the professional programmer to learn and
use effectively.
▪ If you already understand the basic concepts of object-oriented
programming, learning Java will be even easier.
▪ C++ programmer can move to JAVA with very little effort to learn.
▪ Java syntax is based on C++
▪ Java has removed many complicated and rarely-used features, for
example, explicit pointers, operator overloading, etc.
2. Object-Oriented
▪ Java strongly supports the concepts of Object-Oriented Programming .
▪ Java supports major Object-Oriented programming features like
Encapsulation, Abstraction, and Inheritance.
▪ Almost everything in Java is an object. All programs and data live within
objects and classes.
▪ ‘Objects’ model Java rather than the ‘processes’.
3.Secure
▪ It has a bytecode verifier that checks the code fragments for any illegal
code that violates the access right.
➢ Java Sandbox
➢ Security API’s
➢ Exception Handling
4.Robust
5.Multithreaded
▪ The code of java is divided into smaller parts and Java executes them in
a sequential and timely manner.
6.Architecture-Neutral
▪ Basically, when using JIT Compiler, the native code is easily executed by the
hardware when compared to JVM Interpreter. By doing so, there will be a
huge gain in execution speed.
8. Portable
▪ Java compiler converts the source code into an intermediate code called
the byte code and this byte code is further translated to machine-
dependent form by another layer of software called JVM (Java Virtual
Machine).
▪ This is where the “Write Once, run anywhere” (WORA) slogan for Java
comes in, which means that we can develop applications on one
environment (OS) and run on any other environment without doing any
modification in the code.
10. Distributed
▪ In Java, we can split a program into many parts and store these parts on
different computers. A Java programmer sitting on a machine can access
another program running on the other machine.
▪ Java comes with an extensive library of classes for interacting, using TCP/IP
protocols such as HTTP and FTP, which makes creating network
connections much easier than in C/C++.
Documentation Section
▪ You can write a comment in this section. It helps to understand the code.
These are optional.
▪ It is used to improve the readability of the program.
▪ The compiler ignores these comments during the time of execution
▪ Types of comments that Java supports
Ms.Mithu Mary George ,CSE, TIST Page 103
Toc H Institute Of Science & Technology, Arakkunnam
Department of Computer Science & Engineering
CST205 OOP MODULE 1 QUESTION BANK WITH ANSWER KEY
Class Definition
▪ A Java program may contain several class definitions. Classes are the main
and essential elements of any Java program.
Main Method Class
▪ The main method is from where the execution actually starts .
▪ Every Java stand-alone program requires the main method as the starting
point of the program.
▪ This is an essential part of a Java program.
▪ There may be many classes in a Java program, and only one class defines
the main method
▪ Methods contain data type declaration and executable statements.
class Example {
// Your program begins with a call to main().
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
}
}
class Example {
• This line uses the keyword class to declare that a new class is being defined.
• This line outputs the string “This is a simple Java program.” followed by a new line on
the screen.
• Output is actually accomplished by the built-in println( ) method, defined in PrintStream
class.
• System is a final class in java.lang package .It provides standard input and output
functions.
• Out: is an object or variable of Output stream class in System class.
called source file. If the program contains multiple class, the filename should be the
name of the class containing the main method.All source files have the extension “.java”.
2) Compiling the Program: To compile the program, execute the compiler, javac,
specifying the name of the source file on the command line, as shown here:
Eg: C:\>javac Example.java
Javac compiler creates a file called Example.class that contains bytecode
version of program.
3)Running the program: To actually run the program, you must use the Java application
launcher, called java.To do so, pass the class name as a command-line argument, as shown
here:
Eg: C:\>java Example
When the program is run, the output of the programis displayed on the output
console.
48. Draw the Use Case diagram of online railway ticket reservation
system .
• Java compiler produces a unique type of code called bytecode unlike c compiler where
compiler produces only natively executable code for a particular machine.
• When the Java program runs in a particular machine it is sent to java compiler, which
converts this code into intermediate code called bytecode.
• This bytecode is sent to Java virtual machine (JVM) which resides in the RAM of any
operating system.
• JVM recognizes the platform it is on and converts the bytecodes into native machine
code. Hence java is called platform independent language.
• When a program is written and compiled in C/C++ language, the code is directly
converted into machine readable language .i.e. executable code.
• generated .exe file can run only on specific operating system. i.e. when the program is
compiled in windows OS .exe file can run only in windows OS and not on Unix OS.
• When the program written in java is compiled by the compiler the intermediate code
generated are called Byte codes. Like native codes Byte codes are not executable codes.
The virtual machine present in the machine executes these byte codes. These bytecodes
can be executed in any other platform irrespective of their generated platform.
• When a program is written and compiled in JAVA a separate file is created for a compiled
program. This file (.class) is called bytecode in java.
• The .class file created cannot be executed directly.
• Instead it will be converted into executable code by a virtual machine in the system. These
bytecodes generated by the compiled program are to achieve the purpose of platform
independency.
• Byte code generated in a particular platform can be executed in any other platform i.e. the
byte code generated in windows OS can also be executed in Unix OS. The one which
makes this possible is the JVM (JAVA VIRTUAL MACHINE).
• When the program is written and compiled the compiler send the generated bytecodes to
the JVM resent in the machine and this JVM converts the byte codes into native code
which is readable by a particular machine. Thus the output is displayed.
Irrespective of the platform the JVM belongs to, the generated bytecode can run on any JVM.
The outputs of the bytecode run on any JVM will be the same.
• main method is static in Java, so that it can be called without creating any instance. While
JVM tries to execute Java program it doesn't know how to create instance of main class
as there is no standard constructor is defined for main class.
• The static main() method makes it very clear for the JVM to call it for launching the
Java Application
• main method is void in Java because it doesn't return any thing to caller which is JVM .
• First Save Java program with same as class name with .java extension.
Example: Sum.java
• Compile: javac Filename.java
Example, javac Sum.java
Note: Here javac is tools or application programs or exe files which is used for Compile the Java program.
An association describes a group of links with common structure and common semantics
between two or more classes . Association is represented by a line labeled with the association
name in italics.
There are seven qualities to be satisfied for a programming language to be pure Object
Oriented. They are:
1. Encapsulation/Data Hiding
2. Inheritance
3. Polymorphism
4. Abstraction
If you look at these seven qualities, Java does satisfy most of them. Java supports Encapsulation
at class and package level, It supports Abstraction, Inheritance and Polymorphism, and all user
defined types are also objects. What it doesn't support is #5, all predefined types are not
objects in Java, because you can define primitive types. This means it also violates #6. That's
why Java is not a pure object oriented language.
Basic process.
▪ In the first step, unreferenced objects are identified and marked as ready for garbage
collection.
▪ In the second step, marked objects are deleted.
▪ Optionally, memory can be compacted after the garbage collector deletes objects, so
remaining objects are in a contiguous block at the start of the heap.
▪ The compaction process makes it easier to allocate memory to new objects sequentially
after the block of memory allocated to existing objects..
Whitespace
▪ Java is a free-form language. This means that you do not need to follow any special
indentation rules.
▪ There should be at least one whitespace character between each token that was not
already delineated by an operator or separator.
▪ In Java, whitespace is a space, tab, or newline.
▪ White space in Java is used to separate tokens in the source file. It is also used to improve
readability of the source code.
▪ Eg: int i = 0;
Identifiers
▪ Java Identifiers are the user-defined names of variables, methods,
classes, arrays, packages, and interfaces.
▪ An identifier may be any descriptive sequence of uppercase and lowercase letters,
numbers, or the underscore and dollar-sign characters.
▪ They must not begin with a number.
▪ Again, Java is case-sensitive, so VALUE is a different identifier than Value.
▪ Some examples of valid identifiers are
identifiers.
➢ They can be any length Eg: int a; char name;
Constants or Literals
➢ Literals or Constants are fixed values of a particular type of data, which cannot be
modified in a program.
➢ literals are constant variables with fixed values.
➢ For example, here are some literals:
➢ Eg int num = 100;
Operators
An operator is a symbol that takes one or more arguments and operates on them to produce a
result.
• Unary Operator
• Arithmetic Operator
• shift Operator
• Relational Operator
• Bitwise Operator
• Logical Operator
• Ternary Operator
• Assignment Operator
object can exist. While the class diagram show a static picture of the classes and their
relationships, state transition diagrams model the dynamic behavior of a systen in response to
1. States , which show the possible situations in which an object can find itself
2. Transitions , which show the different events which cause a change in the state of an object.
2. Action States , which represent uninterruptible actions of entities, or steps in the execution
of an algorithm
3. Action Flows , which represent relationships between the different action states on an entity
4. Object Flows , which represent utilization of objects by action states, or influence of action
states on objects.
69. Consider the process of ordering a pizza over the phone. Draw an activity diagram
representing each step of the process, from the moment you pick up the phone to the point
where you start eating the pizza. Do not represent any exceptions. Include activities that
others need to perform.
70. Draw the state diagram for a telephone line. At the start of a call, the telephone line is id le. Wh en
the phone is removed from the hook, it emits a dial tone and can accept the dialing of digits.Upon
entry of a valid number, the phone system tries to connect the call and route it to the proper
destination. The connection can fail if the number or trunk are busy. If the connection is successful the
called phone begins ringing. If the called party answers th e phone, a conversatio n can o ccur. Wh en
the called party hangs up the phone disconnects and rewards to idle when put on hook again.