CST 205 Object Oriented Programming using Java
CST 281 Object Oriented Programming
(As per KTU 2019 Syllabus)
Course overview & Module 1
Downloaded from Ktunotes.in
Overview
● 4 credit course
● Prerequisite: Topics covered under the course PROGRAMMING IN C (EST102)
● Continuous Internal Evaluation Pattern:
○ Attendance : 10 marks
○ Continuous Assessment Tests : 25 marks
○ Continuous Assessment Assignments : 15 marks
● Practice - [CS205/CS281] complete all the exercises uploaded in Virtual
Programming Lab
● URL to Virtual Lab: http://34.87.58.133/
● Prefered mode of communication : Post your queries in Google Classroom or
Whatsapp message.
Downloaded from Ktunotes.in
Course Outcomes
● CO1 - Write Java programs using the object oriented concepts - classes,
objects, constructors, data hiding, inheritance and polymorphism [Apply]
● CO2 - Utilise data types, operators, control statements, built in packages &
interfaces, Input/Output Streams and Files in Java to develop programs [Apply]
● CO3 - Illustrate how robust programs can be written in Java using exception
handling mechanism [Understand]
● CO4 - Write application programs in Java using multithreading and database
connectivity [Apply]
● CO5 - Write Graphical User Interface based application
programs by utilising event handling features and Swing
in Java [Apply]
Downloaded from Ktunotes.in
Assessment Pattern
Downloaded from Ktunotes.in
Modules
Module Contents No. of lectures
planned
1 Approaches to Software Design, OOD, UML, Java introduction 6
2 Primitive Data types, Operators, Class Fundamentals, Inheritance 9
3 Packages, Interfaces, Exception handling, Input/Output 7
4 Java Library, Collection Framework, Event handling, Multithreading 9
5 Graphical User Interface and Database support 7
Minimum number of lectures : 38~45
Downloaded from Ktunotes.in
Text books
Reference text
1. Herbert Schildt, Java: The Complete Reference, 8/e, Tata McGraw Hill, 2011.
2. Rajib Mall, Fundamentals of Software Engineering, 4th edition, PHI, 2014.
3. Paul Deitel, Harvey Deitel, Java How to Program, Early Objects 11th Edition,
Pearson,2018
Downloaded from Ktunotes.in
Module 1
► Approaches to Software Design. Functional Oriented Design, Object
Oriented Design, Case Study of Automated Fire Alarm System
► Object Modeling Using Unified Modeling Language. Basic Object Oriented
concepts, UML diagrams, Use case model, Class diagram, Interaction diagram,
Activity diagram, State chart diagram
► Introduction to Java - Java programming Environment and Runtime
Environment,, Development Platforms - Standard, Enterprise. Java Virtual
Machine, Java compiler, Bytecode, Java applet Java Buzzwords, Java program
structure, Comments, Garbage Collection, Lexical Issues
https://www.youtube.com/channel/UCTBjhZB3ni3_NCT9M0XNOpQ
Downloaded from Ktunotes.in
What is software?
● Software is a set of instructions, data or programs used
to operate computers and execute specific tasks
● Software is a set of instructions that tell a computer what
to do.
● Without software, most computers would be useless. For
example, without your Internet browser software, you
could not surf the Internet. Without an operating system,
you cannot even login to your system.
● The term was coined to differentiate these instructions
from hardware.
● By the term software, we referring to all variants such as
Middleware, O.S, Firmware etc.
Downloaded from Ktunotes.in
Types of software
There are two types of software
1. System Software
2. Application Software
● Examples of system software are Operating System, Compilers, Interpreter,
Assemblers, etc.
● Examples of Application software are Railways Reservation Software, Microsoft
Office Suite Software, Microsoft Word, etc.
Downloaded from Ktunotes.in
Software Design
Software design is a process to transform user
requirements into some suitable form, which helps the
programmer in software coding and implementation.
Software design is the process by which an agent creates
a specification of a software artifact, intended to
accomplish goals, using a set of primitive components and
subject to constraints.
Downloaded from Ktunotes.in
Software Design
The design process for software systems often has two levels. At the first level the
focus is on deciding which modules are needed for the system on the basis of
SRS (Software Requirement Specification) and how the modules should be
interconnected.
It tries to specify how to fulfill the requirements mentioned in SRS document.
Downloaded from Ktunotes.in
Approaches to Software Design
There are two generic software development approaches.
Downloaded from Ktunotes.in
Function Oriented Design (FOD) Global variables
● FOD is an approach to software design where
the design is decomposed into a set of
interacting units where each unit has a clearly
defined function.
● This design mechanism divides the whole
system into smaller functions
● Starting at this high level view of the system,
each function is successively refined into more
detailed functions
● The system state is centralized and shared
among different functions
● Top down approach
Downloaded from Ktunotes.in
Function Oriented Design (FOD)
● At first FOD views a system as a black-box that provides a
set of services to the users of the software.
● These services provided by a software to its users are also
known as the high-level functions supported by the
software.
● During the design process, these high-level functions are
successively decomposed into more detailed functions.
● The term top-down decomposition is often used to denote
the successive decomposition of a set of high-level
functions into more detailed functions.
Downloaded from Ktunotes.in
Functional Oriented Design (FOD)
These functional modules can share information among
themselves by means of information passing and using
information available globally.
Eg: Banking process
Here withdraw, deposit, transfer are functions and that
can be divided into subfunctions again.
So, in FOD, the entire problem is divided in to number of
functions and those functions are broken down into smaller
functions and these smaller functions are converted in to
software modules.
Downloaded from Ktunotes.in
Object Oriented Design (OOD)
● OOD is based on Objects and interaction between the
objects. Interaction between objects is called message
communication.
● In the object-oriented design approach, the system is viewed
as a collection of objects (i.e. entities).
● It involves the designing of objects, classes and the
relationship between the classes
● The state is decentralized among the objects and
each object manages its own state information.
● OOD follows bottom up approach
Consider the example of Banking process.
● Here, customer, money and account are objects
Downloaded from Ktunotes.in
Object Oriented Design (OOD)
For example, in banking example,each customer may be a separate object with its
own data and functions to operate on these data.
Functions defined for one object cannot refer or change data of other objects.
Objects have their own internal data which define their state.
Similar objects constitute a class. In other words, each object is an instance of
some class.
Classes may inherit features from super class. Conceptually, objects
communicate by message passing.
Downloaded from Ktunotes.in
FOD vs OOD
Downloaded from Ktunotes.in
Case study: Automated fire alarm
The owner of a large multi-storied building wants to have a computerized fire alarm
system for 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
condition is reported by any of the smoke detectors, the fire alarm system should
determine the location at which the fire condition has occurred and then sound the
alarms only in the neighboring locations. The fire alarm system should also flash
an alarm message on the computer console. Fire fighting personnel, 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.
Downloaded from Ktunotes.in
FOD: Automated fire alarm
Downloaded from Ktunotes.in
OOD: Automated fire alarm
END OF LECTURE 1
Downloaded from Ktunotes.in
Basic Object Oriented Concepts
In OOD, implementation of a software is based on the concepts of objects.
This approach is very close to the real-world applications
Downloaded from Ktunotes.in
Class & Object
CLASS
● A class is a blueprint or prototype from
which objects are created
● A class is a generalized description of an
object. No physical existence.
● Acts as a type or category.
OBJECT
● An object is an instance of a class
● Objects are real-world entities that has
their own state and behavior.
● An object has physical existence
Downloaded from Ktunotes.in
Class & Object
● Let’s take Student as a class. James is an instance / object of the class Student
● Object has a physical existence while a class is just a logical definition.
State => Variables
Name
RollNo
Behaviors => Functions
setName()
setRollNo()
Downloaded from Ktunotes.in
Abstraction
● Abstraction means displaying only essential information and hiding the internal
details.
● It is a process of generalizing things at design level.
● Data abstraction refers to providing only essential information about the data
to the outside world, hiding the background details or implementation.
● Consider a real-life example of a man driving a car. The man only knows that
pressing the accelerators will increase the speed of the car or applying brakes
will stop the car.
● All about showing necessary details.
Downloaded from Ktunotes.in
Encapsulation
● The wrapping up of data(variables) and functions (methods) that operates on the data,
into a single unit (called class) is known as encapsulation.
● It is also called "information hiding“, hides the internal representation, or state, of an
object from the outside through access modifies (Private / Public).
● Hiding unnecessary details, at implementation level.
Downloaded from Ktunotes.in
Encapsulation...
• Protection of data from accidental corruption, by means of
access specifiers (Private / Public), it provides security.
• Flexibility and extensibility of the code and reduction in
complexity
• Encapsulation of a class can hide the internal details of how an
object does something
• Encapsulation protects abstraction
Downloaded from Ktunotes.in
Abstraction & Encapsulation
Downloaded from Ktunotes.in
Inheritance
The capability of a class to derive properties and
characteristics from another class is called Inheritance.
Inheritance is the process by which objects of one
class acquired the properties of objects of another
classes
Base Class : The class whose properties are inherited
by subclass is called Base Class or Super class.
Derived Class : The class that inherits properties from
another class is called Subclass or Derived Class.
Downloaded from Ktunotes.in
Inheritance
Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to
create a new class and there is already a class that includes some of the code that
we want, we can derive our new class from the existing class. By doing this, we are
reusing the fields and methods of the existing class.
Downloaded from Ktunotes.in
Types of Inheritance
Downloaded from Ktunotes.in
Polymorphism
● The word polymorphism means having many forms.
● Refers to a programming language's ability to process objects differently
depending on their data type or class
● An operation may exhibit different behaviors in different instances. The behavior
depends upon the types of data used in the operation.
● Ability for objects of different classes related by inheritance to respond differently to
the same member function call
Downloaded from Ktunotes.in
Polymorphism...
● Static polymorphism: the binding between the method call an the method body happens
at the time of compilation and, this binding is known as static binding or early binding
● Runtime polymorphism or Dynamic Method Dispatch is a process in which a call to an
overridden method is resolved at runtime.
● Dynamic binding happens when all information needed for a function call cannot be
determined at compile-time
● In the example, same rotation of steering wheel causes, different mechanical operations,
corresponding to the steering type present in each cars.
● Brings flexibility to the implementations
Downloaded from Ktunotes.in
Association, Composition and Aggregation
Association is relation between two separate
classes which establishes through their
Objects. Association can be one-to-one,
one-to-many, many-to-one, many-to-many.
Aggregation is a special form of
● Composition: It represents part-of relationship.
Association where:
● In composition, both the entities are dependent It represents Has-A relationship.
on each other. It is a unidirectional association
● When there is a composition between two In Aggregation, both the entries can
entities, the composed object cannot exist survive individually.
without the other entity.
Downloaded from Ktunotes.in
OO concepts review
ENDfrom
Downloaded OF LECTURE 2
Ktunotes.in
Unified Modeling Language (UML)
● UML (Unified Modeling Language) is a general-purpose, graphical modeling
language in the field of Software Engineering
● Developed to help system and software developers for specifying, visualizing,
constructing, and documenting the artifacts of software systems
● UML was created by the Object Management Group (OMG)
● UML is not a programming language, it is rather a visual language.
● UML is a visual language for developing software blueprints (designs).
● For example, while constructing buildings, a designer or architect develops the
building blueprints. Similarly, we can also develop blueprints for a software
system.
Downloaded from Ktunotes.in
Unified Modeling Language (UML)
● UML is the most commonly and frequently used language for building software
system blueprints
● UML can be used for business modeling and other non software systems
● In UML there are a lot of different diagrams to get used to.
● The reason for this is that it is possible to look at a system from many different
viewpoints of the stakeholders.
● A software development will have many stakeholders playing a part
○ Analysts
○ Designers
○ Coders
○ Testers
○ Quality Assurance
○ The Customer
○ Technical Authors
Downloaded from Ktunotes.in
UML Diagrams
● UML is linked with object
oriented design and
analysis
● Structure Diagrams :
Capture static aspects or
structure of a system
● Behavior Diagrams:
Capture dynamic aspects
or behavior of the system
Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Use Case Diagram
● A UML use case diagram is the primary form of system/software requirements.
● It is a behavior diagram to illustrate a set of actions or use cases that a system
can perform in tandem with one or more external users of the system (actors)
● The purpose of a use case diagram in UML is to demonstrate the different ways
that a user might interact with a system.
● It is an effective technique for communicating system behavior in the user's terms
by specifying all externally visible system behavior.
● It does not show the order in which steps are performed to achieve the goals of
each use case.
● Use case diagrams are typically developed in the early stage of development
○ Developed by analysts together with domain experts to gather the requirements of a system.
○ Identify the external and internal factors influencing the system.
○ Show the interaction among the requirements and actors
○ Can be used to validate a systems architecture
○ Drive implementation and generate test cases
Downloaded from Ktunotes.in
Is it really needed?
Downloaded from Ktunotes.in
Use Case Diagram - Actor
● Represent “stick man” icon.
● One actor can be associated with multiple
use cases in the system
● Actor is someone who interacts with use
case (system function).
● Actor is an outsider to the system
boundary who plays a role in the operating
the system/business.
● Actor triggers use case(s). Actor is not an
insider to the system.
● Actor has a responsibility toward the
system (inputs), and Actor has
expectations from the system (outputs).
Downloaded from Ktunotes.in
Use Case Diagram - Use case
● Horizontally shaped ovals that represent the different uses that a user might have
● A use case represents a distinct functionality of a system, a component, a
package, or a class
● Represents a system function (automated or manual)
● Each Actor must be linked to a use case, while some use cases may not be linked
to actors.
Downloaded from Ktunotes.in
Structuring use case diagrams with relationship
There can be 5 relationship types in a use
case diagram.
1. Association between actor and use
case
2. Generalization of a use case
3. Generalization of an actor
4. Extend between two use cases
5. Include between two use cases
Downloaded from Ktunotes.in
Use Case Diagram - Association
● A line between actors and use cases
● The participation of an actor in a use case is shown by connecting an actor
to a use case by a solid link.
● An actor must be associated with at least one use case
● Actors may be connected to use cases by associations, indicating that the
actor and the use case communicate with one another using messages.
● UML allows the use of multiplicity (cardinality) at one or both ends of
association between the actor and the use case
Downloaded from Ktunotes.in
Generalization of an Actor
● Generalization of an actor means that one actor can inherit the role of the other
actor.
● The descendant inherits all the use cases of the ancestor.
● The descendant has one or more use cases that are specific to that role.
● In the example, how many use cases are there for NFRC customer?
Downloaded from Ktunotes.in
Use case Generalization
● A use-case-generalization is a directed relationship from a
child use case to a parent use case, specifying how a child
can specialize all behavior and characteristics described for
the parent
● A parent use case may be specialized into one or more child
use cases that represent more specific forms of the parent.
● Neither parent nor child is necessarily abstract, although the
parent in most cases is abstract.
● A child inherits all structure, behavior, and relationships of
the parent.
Downloaded from Ktunotes.in
Extend relationship between two use cases
● Extend is a directed relationship that specifies how and when the behavior defined in
extending (optional) use case can be inserted into the the extended use case.
● The extending use case is dependent on the extended (base) use case.
● The extended (base) use case must be meaningful on its own.
● The optional extending use case is triggered conditionally at an extension point.
● An extension point is a feature of an extended use case, by which it decides to extend its
functionality by inserting the extending use case.
● Extension points may be shown in a compartment of the use case oval symbol under the
heading extension points. Each extension point must have a name.
Downloaded from Ktunotes.in
Include relationship between two use cases
● Use case include is a directed relationship between two use
cases which is used to show that behavior of the included
use case is inserted into the behavior of the including use
case
● Include relationship show that the behaviour of the included
use case is part of the including (base) use case.
● The main reason for this is to reuse the common actions
across multiple use cases and to simplify complex use
cases.
● The base use case is incomplete without the included
use case.
● The included use case is mandatory and not optional.
Downloaded from Ktunotes.in
Use Case Diagram - System boundary
● An optional box that sets a system scope to use cases.
● All use cases outside the box would be considered outside the scope of that
system. If no box is given, all use cases are within the system scope.
● The system boundary is potentially the entire system as defined in the
requirements document.
● For large and complex systems, each module may be the system boundary.
Downloaded from Ktunotes.in
Use case diagram - Packages
● Packages are optional UML constructs that enable you to organize model
elements (such as use cases) into groups.
● Packages are depicted as file folders and can be used on any of the UML
diagrams, including both use case diagrams and class diagrams
Downloaded from Ktunotes.in
Business Use Case modeling notations
● Support for business modeling is declared as a goal of UML, but UML specification does
not provide any notations for business use cases.
● Business use cases were introduced in Rational Unified Process (RUP).
● Business use case should produce a result of observable value to a business actor.
● Defines what happens in the business when the use case is requested by business
actor, it describes complete workflow or business process.
● Business use case is represented in RUP with use case oval and a line crossing it.
● Business Actor is represented in RUP by "stick man" icon with a line crossing its
head.
● Not defined in UML specification.
Downloaded from Ktunotes.in
Use case diagram of a Hospital Management System
Downloaded from Ktunotes.in
END
Downloaded OF LECTURE
from 3
Ktunotes.in
Class Diagram
● Class diagram in the UML is a type of static structure diagram to represent the
design of the software system in terms of classes and their relationships..
● It shows the structure of a system at the level of classes and interfaces, along
with their attributes, operations, and the relationships among objects.
● There are several software tools available create UML Class diagrams. Rational
rose, StarUML and Lucidchart are some of the popular tools.
● Some common types of class diagrams are:
1. Domain Model Diagram - representation of real-world conceptual classes (contains only
attributes), not of software components, to understand the project domain.
2. Implementation Classes Diagram - representation of the structure of software components,
describes classes, interfaces, associations, usage, realization.
Downloaded from Ktunotes.in
UML notation for Class
A class notation consists of three parts:
1. Class Name (mandatory):
○ The name of the class appears in the first
partition.
2. Class Attributes[optional]:
○ An attribute is a named property of a class that
describes the object being modeled
○ Attributes are shown in the second partition.
○ The attribute type is shown after the colon.
○ Derived attribute is designated by a preceding ‘/’
○ Attributes map onto member variables (data members) in code.
3. Class Operations(Methods)[optional]:
○ 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.
○ Operations map onto class methods in code
Downloaded from Ktunotes.in
Member visibility
● Visibility defines whether attributes and
operations of specific classes can be seen and
used by other classes
● UML has 4 types of visibility and it is
represented by prefixing a literal( +, -, #, ~)
Downloaded from Ktunotes.in
Member visibility
PRIVATE
PROTECTED DEFAULT /
PACKAGE
PUBLIC
Downloaded from Ktunotes.in
Member scope
● The UML specifies two types of scope for
members: instance and classifier.
● Classifier members are commonly
recognized as “static” in many programming
languages. The scope is the class itself.
○ All the instances share the classifier scoped
members.
● To indicate a classifier scope for a member,
its name must be underlined. Otherwise,
instance scope is assumed by default.
● Instance members are scoped to a specific
instance.
○ Each instantiated object of the class has its own
copy of the instance members.
Downloaded from Ktunotes.in
Relationships between classes
Relationships in class diagrams include
different types of logical connections.
Downloaded from Ktunotes.in
Relationships between classes
1. Association
● Represents static relationships between two classes.
● Shows that instances of classes could be either linked to each
other or combined logically or physically.
● Represented by a solid line (with or without open arrow)
connecting two classes
2. Dependency
● A dependency means the relation between two or more classes
in which a change in one may force changes in the other.
● Dependency indicates that one class depends on another.
● A dashed line with an open arrow
Downloaded from Ktunotes.in
Relationships between classes
4. Aggregation
● A special type of association to represent a "has a" relationship eg. Team has 9 players
● A solid line with an unfilled diamond at the association end connected to the class of
composite
5. Composition
● A special type of aggregation where parts are destroyed when the whole is destroyed.
● No independent existence
● A solid line with a filled diamond at the association connected to the class of composite
Downloaded from Ktunotes.in
Relationships between classes
6. Generalization (Inheritance)
● A generalization helps to connect a subclass to its superclass.
● A sub-class is inherited from its superclass.
● A solid line with a hollow arrowhead that point from the child to the parent class
7. Realization (Implements)
● Realization relationship is a relationship between two model elements, in which
one model element (the client) realizes (implements or executes) the behavior
that the other model element (the supplier) specifies.
Downloaded from Ktunotes.in
Relationships between classes
Multiplicity
● Multiplicity defines how
many objects participate in a
relationship and it is the
number of instances of one
class related to one instance
of the other class.
● Multiplicity is represented as
a number and a * is used to
represent a multiplicity of
many
Downloaded from Ktunotes.in
Class diagram for a Pizza Order system
Downloaded from Ktunotes.in
Interaction Diagrams
● Interaction diagrams capture the dynamic behavior of the system
● An interaction is a set of messages that are interchanged between
the entities to achieve certain specified tasks in the system.
● Represents the interactions between distinct entities present.
● It is used in UML to establish communication between objects.
● Mostly focus is on message passing and how these messages
make up one functionality of the system.
● The details of interactions can be shown using different UML
diagrams.
a. Sequence diagram.
b. Collaboration(communication) diagram.
c. Timing diagram
d. Interaction overview diagram
Downloaded from Ktunotes.in
Different types of Interaction Diagrams
1. Sequence diagram
● Shows object interactions arranged in time sequence.
● Focus is on the sequence of messages exchanged.
2. Collaboration(communication) diagram
● Shows the interaction between the objects to fulfill the
functionality of a use case.
● This diagram is suitable to depict the relationship
between the objects.
3. Timing diagram
● Focus is on the instance at which a message
is sent from one object to another object.
● Suitable to represent the state transitions
of the objects.
4. Interaction overview diagram - Sequence Diagram + Activity Diagram
Downloaded from Ktunotes.in
1. Sequence Diagram
● The purpose of a sequence diagram in UML is to visualize the sequence of a
message flow in the system
● A Sequence Diagram simply depicts interaction between objects in a
sequential order.
● Lifelines, Activations and Messages are the key notations in a sequence
diagram.
● Using fragment operators, iteration and branching can be represented in
sequence diagram.
1. Lifeline
● A lifeline represents a single participant in an interaction.
● It is represented by a vertical bar, with a rectangle containing its object name
(name is optional, format object_name : class_name).
● The vertical axis represents time proceedings
● Describes how an instance participates in the interaction
Downloaded from Ktunotes.in
Activation & Messages
2. Activations
● A thin rectangle on a lifeline, represents the period during which an element is
performing an operation.
● The top and the bottom of the of the rectangle are aligned with the initiation and
the completion time respectively
3. Messages
● Communication between objects(lifelines) is represented using messages.
● The messages appear in a sequential order on the lifeline.
Downloaded from Ktunotes.in
Synchronous vs Asynchronous
● A synchronous message waits for a reply before the interaction can move
forward.
● The sender waits until the receiver has completed the processing of the message.
● A solid arrow head to represent a synchronous message.
● An asynchronous message does not wait for a reply from the receiver. The
interaction moves forward irrespective of the response for previous message.
● A solid line with open arrow head represents an asynchronous message.
Downloaded from Ktunotes.in
Other messages used
A message defines a particular communication between
Lifelines.
1. Call Message
● Call message is a kind of message that represents an
invocation of operation of target lifeline.
2. Return Message
● Return message is a reply from the target lifeline for a
previous message.
● Represented with dashed line with an open arrowhead
Downloaded from Ktunotes.in
Other messages used
3. Self Message
● Self message is a kind of message that represents the invocation
of message of the same lifeline.
4. Recursive Message
● A self message sent for recursive purpose is called a recursive
message.
● It's target points to an activation on top of the activation where
the message was invoked from.
Downloaded from Ktunotes.in
Other messages used
5. Create Message / Constructor Message
● Create message is a kind of message that
represents the creation of (target) lifeline.
● It creates the message receiver
6. Destroy Message / Destructor Message
● Destroy message is a kind of message that
represents the request of destroying the target
lifeline.
● It destroys the message receiver.
7. Duration Message / non-instantaneous message
● Duration message shows the time delay between
the send time and receive time of the message. (eg,
network communication delay)
Downloaded from Ktunotes.in
Messages used
8. Found message - Unknown sender
● A Found message is used to represent a scenario where an
unknown source sends the message.
9. Lost message - Unknown receiver
● A Lost message is used to represent a scenario where the
recipient is not known to the system.
Downloaded from Ktunotes.in
Combined fragments
● Fragment is represented as a transparent window or box, divided by horizontal
dashed lines for each operand.
● A combined fragment, has a fragment operator, [guard text] and one or more
operands which encloses a portion of the interactions within a seq. diagram.
● Operands are separated by dashed line and each operand encloses one or more
messages, interaction uses, or combined fragments.
● Fragment operator is in the top left corner of the box and it indicates the type of
fragment such as loop, break, alt, opt…Corresponding to the operator, interaction
constraints or guard is represented in [...]
Sample interaction use
Downloaded from Ktunotes.in
Types of fragment operators
Downloaded from Ktunotes.in
Sample Sequence Diagram - Place Order Scenario
The item ordered will be
sent to the member either
send by courier or by
ordinary mail depending
on membership type.
Optionally, the shop will
send the member a
confirmation notification.
Downloaded from Ktunotes.in
Example - Sequence Fragments
Downloaded from Ktunotes.in
Notes on Sequence Diagrams
Advantages
● Sequence diagrams are easier to maintain and easier to generate.
● Represent the low level details of a UML use case.
● Model the logic of a complex procedure, function, or operation.
● Shows the interaction between the objects and components to complete a
process.
Disadvantages
● Can be complex when too many lifelines are involved in the system.
● If the order of message sequence is changed, then incorrect results are
produced.
● The type of message decides the type of sequence inside the diagram
● Each sequence needs to be represented using different message numbering
schemes, which can be a little complex in large systems.
Downloaded from Ktunotes.in
2. Communication Diagram
● Communication (in UML 2. x, earlier name - Collaboration)
Diagrams are used to show how objects interact to perform
the behavior of a particular use case, or a part of a use case.
● Collaboration represents the relationships and interactions
among software objects.
● They are used to understand the object architecture within a
system rather than the flow of a message as in a sequence
diagram.
● The message flow between the objects can be represented
using a collaboration diagram.
Downloaded from Ktunotes.in
Notes on Communication Diagram
● A collaboration diagram is a collection of named objects and actors along with
the links connecting them. They collaborate in performing some task.
● A collaboration defines a set of participants and relationships that are
meaningful for performing some task.
● Objects collaborate by communicating (passing messages) with one another in
order to work together.
● Objects are able to produce high-level functionalities by working together
● Collaboration Diagram captures interactions that show the messages passing
between objects and their roles within the collaboration
● Collaboration Diagram emphasizes the structural aspects of an interaction
diagram - how lifeline connects.
● It allows you to focus on the objects rather than focusing on the message
flow as described in the sequence diagram.
Downloaded from Ktunotes.in
Collaboration Diagram...
● Its syntax is similar to that of a sequence diagram except that lifeline don't have tails.
● Each message in a collaboration diagram has a sequence number.
● Key notations are Objects, Messages and links between the objects.
● Using tools Sequence diagrams can be easily converted into a collaboration diagram
Downloaded from Ktunotes.in
Notations: Objects, Actors, Constraint, Note
● Objects are model elements that represent instances of a class.
Represented with its name and class (underlined in UML 1.x),
separated by a colon [ Object_name : class_name ]
○ Multi-object represents a set of lifeline instances.
● Actors - entity which acts as the invoker of the interaction.
○ Each Actor is named and has a role
○ One actor will be the initiator of the use case
● Link is a relationship among objects across which messages can be sent.
○ In collaboration diagrams, a link is shown as a solid line between two
objects.
○ An object interacts with, or navigates to, other objects through its links to
these objects.
○ A link can be an instance of an association, or it can be anonymous,
meaning that its association is unspecified.
Downloaded from Ktunotes.in
Notations: Messages
Messages - A message defines a particular communication
between Lifelines/objects of an Interaction
● In collaboration diagrams, a message is shown as a
labeled arrow placed near a link.
● The message is directed from sender to receiver
● The association must be navigable in that direction
Constraint - A condition or restriction expressed in natural
language text. An extension mechanism to refine the semantics
of a UML model element.
Note - Note contains comments or textual information.
Swimlane - A way to group the elements
Downloaded from Ktunotes.in
Sample collaboration/communication diagrams
Downloaded from Ktunotes.in
Sample collaboration/communication diagrams
Downloaded from Ktunotes.in
Sequence diagram vs Collaboration Diagram
Client updating some details in a database - 1. A transaction is started by the
client to update the data in DB, 2. Transaction operation writes the values to DB.
3. Once the client is notified with the commit, client destroys the transaction.
Downloaded from Ktunotes.in
Drawbacks of a Communication Diagram
● It can become complex when too many objects are present within the system.
● It is hard to explore each object inside the system.
● The state of an object changes momentarily, which makes it difficult to keep
track of every single change occurs within an object of a system.
Sequence Diagram Communication Diagram
Emphasize Time and order of events Messages exchanged between objects
Shows participants effectively Good Good
Links between participants No notation Explicitly and clearly shows
Support asynchronous messages Yes No notation
Easy to read message ordering Better
Easy to create and maintain Better
Downloaded from Ktunotes.in
3. Timing Diagram
● A timing diagram is a specific behavioral modeling diagram that focuses
on timing constraints and state changes to the objects.
● Timing diagrams are used to explore the behaviors of objects throughout
a given period of time.
● Denotes the transformation of an object from one form into another form.
● The flow between the software program at various instances of time is
represented using a waveform.
Downloaded from Ktunotes.in
How to draw a Timing Diagram
● length of a timeline to indicate how long the object remains in
a particular state by reading it from left to right.
Downloaded from Ktunotes.in
Benefits of Timing Diagram
● Timing diagrams are used to represent the state of an object at a particular
instance of time.
● It represents the effects of each events(stimuli) in object state transition.
● Timing diagram allows reverse as well as forward engineering.
● Timing diagram can be used to keep track of every change inside the system.
● Very much useful while developing time critical software systems.
Drawbacks of a Timing Diagram
● It is hard to maintain and understand.
● Available notations are less.
Downloaded from Ktunotes.in
4. Interaction overview diagram
● Interaction overview diagrams focus on the overview of the flow of control
where the nodes are interactions (sd) or interaction use (ref).
○ Node type - Interaction - An Interaction diagram of any kind may
appear inline as an Activity Invocation.
○ Node type - Interaction Use
■ Large and complex sequence diagrams could be simplified with
interaction uses.
● The other notation elements for interaction overview diagrams are the same
as for activity and sequence diagrams.
● It shows how a set of fragments (portion of interaction) might be initiated in
various scenarios
Downloaded from Ktunotes.in
Interaction Overview Diagram Example - Scheduling
System
Downloaded from Ktunotes.in
Activity Diagram
● Another important behavioral diagram in
UML to describe the control flow of the
system
● An activity diagram visually presents a series
of actions or flow of control in a system
● Similar to a flowchart or a data flow diagram.
● It is also called object-oriented flowchart
● Represents workflows of stepwise activities
and actions with support for choice, iteration
and concurrency
Downloaded from Ktunotes.in
Activity Diagram...
● Demonstrate the logic of an algorithm.
● Describe the steps performed in a UML use case.
● Illustrate a business process or workflow between users and the system.
● Simplify and improve any process by clarifying complicated use cases.
● Model software architecture elements, such as method, function, and operation
Downloaded from Ktunotes.in
Basic components of an activity diagram
1. Nodes
○ Action: A single step in the activity wherein the users or
software perform a given task.
○ Start node: Symbolizes the beginning of the activity.
The start node is represented by a black circle.
○ End node: Represents the final step in the activity. The
end node is represented by an outlined black circle.
2. Control flows: Another name for the connectors that
show the control flow between steps in the diagram.
3. Partitions (optional) - to organize the nodes in the
activity diagram.
Downloaded from Ktunotes.in
Notations for Nodes
● Start symbol - Portrays the beginning of a set of actions or activities.
● Action symbol - A task to be performed
● Activity symbol - Indicates the set of actions that make up a modeled
process. Includes short descriptions within the shape.
● Object Node - A node that is used to define object flow in an activity
name:type ● Flow final symbol - Represents the end of a specific process flow.
Does not represent the end of all flows in an activity.
No effect on parallel flows.
● End symbol - Stop all control flows and object flows in an activity.
Represented by an outlined black circle
Downloaded from Ktunotes.in
Notations for control flow
● Action Flow or Control flow - referred to as paths and edges. They
are used to show the transition from one activity state to another.
● Joint symbol / Synchronization bar - Combines two concurrent
activities and re-introduces them to a flow where only one activity
occurs at a time. Represented with a thick vertical or horizontal line.
● Fork symbol - Splits a single activity flow into two concurrent
activities. Symbolized with multiple arrowed lines from a join.
● Loop Node - A structured activity node that represents a loop with
setup, test, and body sections
Downloaded from Ktunotes.in
Notations...
● Decision Node - Represents a conditional branch point or decision
node. A decision node has one input and two or more outputs.
Guards are a statement written next to a decision diamond in [....]
● Merge Node - Merges the control flows into a single one. The
diamond symbol has several inputs and only one output.
● Accepting an Event (Action) - This action waits for an event to
occur. After the event is accepted, the flow that comes from this
action is executed.
● Sending Signals (Action) - Sending a signal means that a signal is
being sent to an accepting activity.
Downloaded from Ktunotes.in
Notation for grouping - Swimlane
● Swimlane and Partitions- A way to group activities performed by the same
actor on an activity diagram or to group activities in a single thread.
● Swimlanes are used for grouping related activities in one column/row
● Swimlanes can be vertical or horizontal, it adds modularity to the diagram.
Downloaded from Ktunotes.in
Activity diagram syntax
Downloaded from Ktunotes.in
Activity diagram - Student enrollment
An applicant wants to enroll in the university.
The applicant hands a filled out copy of Enrollment Form.
The registrar inspects the forms.
The registrar determines that the forms have been filled out properly.
The registrar informs student to attend in university overview presentation.
The registrar helps the student to enroll in seminars
The registrar asks the student to pay for the initial tuition.
Downloaded from Ktunotes.in
Activity diagram - Staff expense submission
Downloaded from Ktunotes.in
Statechart diagram
● It is used to capture the dynamic aspects of a system
● It is also called State Machine or State Transition diagram
● A state is a conditions or circumstances of an object.
○ Active - performs some activity
○ Inactive - waits for an event
● It defines different states of an object during its lifetime and
these states are getting changed by the events.
● Statechart diagram describes the transitions from one state
to another state in response to some event.
● Shows discrete behavior of a part of the designed system
through finite state transitions.
Downloaded from Ktunotes.in
Need for Statechart diagram
● The primary purpose of a state chart diagram is to model interactive systems and
define each and every state of an object.
● To represent the events responsible for change in state (we do not show what
processes cause those events).
● To understand the reaction of objects/classes to internal or external stimuli.
Downloaded from Ktunotes.in
Notations for State Machine
● Initial state - The initial state symbol is used to indicate the beginning
of a state machine diagram.
● Final state - This symbol is used to indicate the end of a state machine
diagram.
● State - a rounded rectangle to represent a state. A state represents the
conditions or circumstances of an object of a class at an instant of time.
It can be active or inactive. Simple state implies no nested substates.
● Transition – It is a a solid arrow which represents the path between
different states of an object. The arrow is labelled with the event which
causes the transition
Downloaded from Ktunotes.in
Notations for State Machine
● Composite state is state that has substates (nested
states). UML 2.4 defines composite state as the state
which contains one or more regions for substates.
● Orthogonal state - A composite state with two or more
regions is called orthogonal.
● History states is used to remember the previous state of
a state machine when it was interrupted.
Downloaded from Ktunotes.in
Notation and Symbol for State Machine
● Choice pseudostate - contains a condition. Depending upon the
result of an evaluated guard condition, a new path is taken for program
execution
● Fork pseudostate vertices serve to split an incoming transition into two
or more transitions terminating on orthogonal target vertices.
● Join pseudostate merges several transitions originating from source
vertices in different orthogonal regions
Downloaded from Ktunotes.in
Statechart diagram example - ATM
Downloaded from Ktunotes.in
Eg. University state Diagram
● The composite state “Enrollment” is made up of various sub states that will lead students through the
enrollment process.
● Once the student has enrolled, they will proceed to “Being taught” and finally to “Final exams.”
Downloaded from Ktunotes.in
UML Diagrams summary
Downloaded from Ktunotes.in
Case study : Library Management System
Downloaded from Ktunotes.in
Case study : Library Management System
Downloaded from Ktunotes.in
Case study : Library Management System
Downloaded from Ktunotes.in
Case study : Library
Management System
Downloaded from Ktunotes.in
Case study : Library Management System
Downloaded from Ktunotes.in
Module 1 - Introduction to Java
► Approaches to Software Design. Functional Oriented Design, Object
Oriented Design, Case Study of Automated Fire Alarm System
► Object Modeling Using Unified Modeling Language. Basic Object Oriented
concepts, UML diagrams, Use case model, Class diagram, Interaction diagram,
Activity diagram, State chart diagram
► Introduction to Java - Java programming Environment and Runtime
Environment, Development Platforms - Standard, Enterprise. Java Virtual
Machine, Java compiler, Bytecode, Java applet Java Buzzwords, Java program
structure, Comments, Garbage Collection, Lexical Issues
Downloaded from Ktunotes.in
History of Java
● Java is a general-purpose , Object Oriented Programming language
developed by Sun Micro System of USA in 1991.
● Developed by James Gosling and his team (Green Team) at Sun.
● First name of Java was “Oak,” later it was renamed “Java” in 1995.
● Initially designed for small, embedded systems in electronic appliances like
set-top boxes.
● The target of Java is to write a program once and then run this program on
multiple operating systems [PLATFORM INDEPENDENCE].
● Currently, Java is used in internet programming, mobile devices, games,
e-business solutions, etc.
Downloaded from Ktunotes.in
Platform dependency issue
● Platform dependency refers to case where
the applications run under only one
operating system in one series of
computers (platform => OS + H/w).
● C/C++ executable created for one platform
will not run on another, this is nothing but
platform dependence.
● Solution is platform independence which
describes a technology to implement
things on one platform and use them on
another platform without changes
Downloaded from Ktunotes.in
Java Compiler
● Compiler is a software which converts a program written in high level language
(Source Language) to low level language (Object/Target/Machine Language)
● Java compilers include the Java Programming Language Compiler (javac), the
GNU Compiler for Java (GCJ), the Eclipse Compiler for Java (ECJ) and Jikes.
● A Java compiler is a software that takes the java program file(.java) and compiles
it to produce a Java class file(.class).
● The content of class file is not machine code. It contains Java bytecode which
can be executed only on Java Virtual Machine (JVM).
●
● Syntax: javac HelloWorld.java
Downloaded from Ktunotes.in
Java Byte Code
● On compiling java program, we get class file that is nothing but bytecode.
Java bytecode is an intermediate representation of the java program which is
machine independent. ie, it is not the conventional Machine Code.
● Byte code cannot directly run on your machine like executable file from C/C++
program, it can run only on Java Virtual Machine.
● Java bytecode contains the instruction set for the Java Virtual Machine.
● JVM is responsible to convert bytecode to machine code and execute on your
machine.
● java interpreter is used to execute class file [ java ClassFileName ]
Downloaded from Ktunotes.in
Platform independence in Java
● Java compiler output is class file and it is different from machine
code. Only machine code can directly execute on your physical
machine.
● Class file contains byte code, which can execute only on Java
Virtual Machine(JVM).
● Java is platform independent because java class files can run on all
operating systems without any modifications.
● If JVM is available for a platform, then Java can run on that platform
Downloaded from Ktunotes.in
Java Programming Environment
● Java is a concurrent, class based, object oriented programming and runtime
environment, consisting of
1. A programming language (Java)
Used by programmers to write the application.
2. An API specification (Java Libraries)
Huge number of libraries and components for Java programming
3. A virtual machine specification (JVM)
It is a program which provides the runtime environment to execute
Java programs
Downloaded from Ktunotes.in
Java technology: Language specification
● The Java Language Specification (JLS) defines how a confirming Java
application must behave.
● JLS describes the technical details of how the language is implemented.
● Java is a high level (human-readable) language which is generally considered
easy to read and write.
● Java is class-based and strictly object-oriented in nature.
● Java is intended to be easy to learn and to teach.
● There are many different implementations of JLS available, both proprietary
and open source.
● Fulfils the goal Write Once, Run Anywhere (WORA). ie, the same program
can be highly portable and run on many different platforms
Downloaded from Ktunotes.in
Java technology: Library specification
● Specifies the standard libraries in Java language.
● The Java Class Library is a set of standard libraries that is available to any
application running on the JVM.
● This set of libraries is composed of classes that allow programs to handle
commons tasks like: network communication, collection manipulation, file
operations, user interface creation, etc.
Downloaded from Ktunotes.in
Java technology: Virtual Machine Specification
● 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.
Downloaded from Ktunotes.in
JVM Architecture
JVM is divided into three main
subsystems:
1. ClassLoader Subsystem
2. Runtime Data Area
3. Execution Engine
Downloaded from Ktunotes.in
JVM - ClassLoader Subsystem
ClassLoader subsystem loads, links. and initializes the class file when it refers to a class for
the first time at runtime, not compile time.
1.1 Loading - Classes will be loaded by this component. BootStrap ClassLoader, Extension
ClassLoader, and Application ClassLoader are the three
1.2 Linking - Performs verification , preparation
● Verify – Bytecode verifier will verify the generated bytecode
● Prepare – For all static variables memory will be allocated and assigned with defaults.
● Resolve – All symbolic memory references are replaced with the original references from
Method Area.
1.3 Initialization
This is the final phase of ClassLoading; here, all static variables will be
assigned with the original values, and the static block will be executed.
Downloaded from Ktunotes.in
JVM - Runtime
Data Area
These are storage areas needed during the execution of the program.
1. Method Area – Class-level data will be stored here, including static variables.
2. Heap Area – Objects and their corresponding instance variables and arrays
3. Stack Area – For every thread, a separate runtime stack will be created. For every
method call, one entry will be made in the stack memory which is called Stack Frame.
a. Local Variable Array – Related to the method, how many local variables are
involved and the corresponding values will be stored here.
b. Operand stack – acts as runtime workspace to perform operation.
c. Frame data – To store all symbols corresponding to the methods.
4. PC Registers – Each thread will have separate PC Registers.
5. Native Method stacks – holds native method information.
Downloaded from Ktunotes.in
JVM - Execution Engine
The bytecode, which is assigned to the Runtime Data Area, will be executed by the
Execution Engine(EE). It reads the bytecode and executes it piece by piece.
1. Interpreter – The interpreter interprets the bytecode faster but executes slowly.
2. JIT Compiler – When EE finds repeated code, it uses the JIT compiler, which compiles
the entire bytecode and changes it to native code. This native code will be used directly.
a. Intermediate Code Generator – Produces intermediate code
b. Code Optimizer – Responsible for optimizing the intermediate code.
c. Target Code Generator – Responsible for Generating Native Code
d. Profiler – Responsible for finding hotspots in the code.
3. Garbage Collector: Collects and removes unreferenced objects.
4. Java Native Interface (JNI): Interacts with the Native Method Libraries
5. Native Method Libraries: Native Libraries for the EE.
Downloaded from Ktunotes.in
Java Runtime Environment (JRE)
● JRE provides the minimum requirements for executing a Java application
programs.
● JRE is an installation package which provides environment to only run(not
develop) the java program(or application)onto your machine.
● JRE can be view as a subset of Java Development Kit.
● JRE contains Java Virtual Machine (JVM ),core classes, and supporting files
● JVM is a software implementation of a computer that executes programs like
a real machine.
Downloaded from Ktunotes.in
Java Development Kit (JDK)
● JDK is a software development environment used for developing and executing
Java applications and applets
● It includes the Java Runtime Environment (JRE), an interpreter/loader (Java), a
compiler (javac), an archiver (jar), a documentation generator (Javadoc) and
other tools needed in Java development.
● JDK is only used by Java Developers.
Downloaded from Ktunotes.in
Development Platforms
● All Java platforms consist of a Java Virtual Machine (JVM) and an application
programming interface (API).
● Allows applications written for that platform to run on any compatible system with all
the advantages of the Java. Major platforms are
1. Java Platform, Standard Edition (Java SE)
2. Java Platform, Enterprise Edition (Java EE)
3. Java Platform Micro Edition (Java ME)
Downloaded from Ktunotes.in
Java Platform, Standard Edition (Java SE)
● Java SE lets you develop and deploy Java applications on desktops and personal
computers. Latest version is 14.
● Java SE's API provides the core functionality of the Java programming language.
● It defines everything from the basic types and objects of the Java programming
language to high level classes that are used for networking, security, database
access, GUI development, and XML
● In addition to the core API, the Java SE platform consists of a
virtual machine, development tools, deployment technologies, and
other class libraries and toolkits commonly used in Java
technology applications.
Downloaded from Ktunotes.in
Java Platform, Standard Edition (Java SE)
For the development of following applications, Java SE is used
● Standalone Applications for desktop computers.
● Web supportive applications (Applets) (It is outdated and nobody is using)
● Database interaction Application (JDBC)
● Integrated Application (XML)
● Distributed Application (RMI)
Downloaded from Ktunotes.in
Java Platform, Enterprise Edition (Java EE)
● Java EE lets you develop and deploy Java applications on servers and enterprise
computers.
● Java EE provides an API and runtime environment for developing and running
large, multi-tiered, reliable, and secure enterprise applications that are portable
and scalable and that integrate easily with legacy applications and data.
● Java Platform, Enterprise Edition (Java EE) is the standard in community-driven
enterprise software.
● Java EE is developed using the Java Community Process(JCP), with
contributions from industry experts
● Enhancements to any Java technology or introduction of new ones
occur through Java Specification Requests (JSRs)
● Java EE platform is built on top of the Java SE platform.
Downloaded from Ktunotes.in
Java Platform, Enterprise Edition (Java EE)
For the development of following applications Java EE is used
● Web Application (Servlets/JSPs/JSF)
● Enterprise Application (EJB)
● Interoperable Application (Webservices)
Downloaded from Ktunotes.in
Java Platform, Micro Edition (Java ME)
● Java ME (Embedded) is designed for resource-constrained embedded devices
like wireless modules for M2M, industrial control, smart-grid infrastructure,
environmental sensors and tracking, and more.
● The JME Embedded API is a subset of the Java SE API, along with special class
libraries useful for small device application development.
● Java Card technology provides a secure environment for applications that run on
smart cards and other devices with very limited memory and processing
capabilities.
Downloaded from Ktunotes.in
Java FX
● 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
Downloaded from Ktunotes.in
Java Applet An applet is a Java
program that usually
runs a in a Web
browser.
To make interactive
web pages with
better GUI
Downloaded from Ktunotes.in
Java Applet
● An applet is a special kind of
Java program that is designed
to be transmitted over the
Internet and automatically
executed by a
Java-compatible web
browser.
● It runs inside the web browser
and works at client side
● Applets are used to make the
web pages more dynamic and
entertaining
Downloaded from Ktunotes.in
Java Applet security aspects.
● Applets are not stand-alone programs. Instead, they run within
a web browser or appletviewer tool.
● Java applets are loaded on a client when the user visits a
page containing an applet. To protecting the user from malicious
applets, several restrictions are imposed.
Applets are either sandbox applets or privileged applets.
● Sandbox applets are run in a security sandbox that restricts many operations.
● An applet cannot load libraries or define native methods.
● Ordinarily it cannot read or write files on the execution host.
● It cannot read certain system properties.
● It cannot make network connections except to the host from
where it came from.
● They cannot run any programs on the local computer.
● These restrictions are to provide security
Downloaded from Ktunotes.in
Applet Life Cycle
● When an applet is executed within the web browser or in an applet window, it goes
through the four stages of its life cycle: New Born, Run, Idle and Destroyed.
● Applets are sub-classes of java.applet.Applet class
● Major applet methods.
a. init( ) : first method to be called. This is where you should
initialize variables. This method is called only once.
b. start( ) : called after init( ). It is also called to restart an applet
after it has been stopped.
c. paint( ) : called each time to redraw the applet window.
paint( ) method has one parameter of type Graphics.
d. stop( ) : called when a web browser leaves the HTML
document containing the applet
e. destroy( ) : called when the environment determines that
your applet needs to be removed completely from memory.
Downloaded from Ktunotes.in
Java Applet vs Java Application
Downloaded from Ktunotes.in
Java Buzzwords Important features of Java language.
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
Downloaded from Ktunotes.in
Java features
1. Simple
● Java syntax is based on C/C++.
● If you already understand the basic concepts of object oriented programming,
learning Java will be even easier.
● Java has removed many complicated and rarely-used features, for example,
explicit pointers, operator overloading, etc.
● There is no need to remove unreferenced objects because there is an
Automatic Garbage Collection in Java.
2. Object-oriented
● Java is an object-oriented programming language.
● OOP means we organize our software as a combination of different
types of objects with both data and behavior.
● Basic concepts of OOPs are: Object, Class, Inheritance
Polymorphism, Abstraction, Encapsulation
Downloaded from Ktunotes.in
Java features
3. Platform Independent
● Java is platform independent because java bytecode (class file) can run on any
platform, just copy the class file to new platform and run using java interpreter
● Class file contains the platform independent bytecode which can run on any
platform with Java VM.
4. Robust
● Robustness is the property of being strong and healthy.
● Java is robust because:
1. There is automatic memory management (garbage collection) in java which runs on
the JVM to get rid of objects which are not being used anymore.
2. There is a lack of explicit pointers that avoids security problems.
3. There are exception handling and the type checking mechanism.
5. Interpreted
● Java programs are compiled into an intermediate representation called Java bytecode.
● The byte code is interpreted to any machine code so that it runs on the native machine.
Downloaded from Ktunotes.in
Java features
6. Secured
● Java is secure, we can develop virus-free systems. It is secured because,
● No explicit pointer, Java Programs run inside a virtual machine sandbox
● JVM has Classloader to load Java classes dynamically. It adds security by separating the
package for the classes of the local file system from those that are imported from network.
● Bytecode Verifier checks the code fragments for illegal code that can violate access right to
objects.
● Security Manager determines what resources a class can access.
● Java language provides these securities by default. Some security can also be provided by
an application developer explicitly through SSL, JAAS, Cryptography, etc.
Downloaded from Ktunotes.in
Java features
7. Architecture-neutral
● Java is architecture neutral because there are no implementation dependent features,
for example, the size of primitive types is fixed.
● In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and
4 bytes of memory for 64-bit architecture.
● However, it occupies 4 bytes of memory for both 32 and 64-bit architectures in Java.
8. Portable
● Java is portable because it facilitates you to carry the Java bytecode to any platform. It
doesn't require any implementation.
9. High-performance
● Java is faster than other traditional interpreted programming languages because Java
bytecode is "close" to native code.
● It is still a little bit slower than a compiled language (e.g., C++).
Downloaded from Ktunotes.in
Java features
10. Distributed
● Java is distributed because it facilitates users to create distributed applications in Java.
RMI and EJB are used for creating distributed applications. This feature of Java makes
us able to access files by calling the methods from any machine on the internet.
11. Multi-threaded
● A thread (light weight process) is a single sequential flow of control within a program.
● Java supports multiple concurrent threads with APIs to manage the thread states.
● We can write Java programs that deal with many tasks at once by defining multiple
threads.
12. Dynamic
● Java supports dynamic loading of classes.
● It means classes are loaded on demand at run time.
● Java supports dynamic compilation and automatic
memory management (garbage collection) at JVM level.
Downloaded from Ktunotes.in
Garbage Collection
● Memory leak is a type of resource leak that occurs when computer programs fails
to release the allocated memory after use. This is a common issue in C/C++
programs.
● Java’s answer to this issue is Automatic Garbage Collection
● When JVM starts up, it creates a heap area which is known as runtime data area.
This is where all the objects (instances of class) are stored
● The process of removing unused objects from heap memory is known as Garbage
collection and this is a part of memory management in Java.
● In java, garbage means unreferenced objects.
● In Java responsibility of releasing unused memory is with JVM.
● In C/C++.. Programmer is responsible for memory release and
it is the major reason for memory leaks and program crashes.
Downloaded from Ktunotes.in
Garbage Collection
● In java, garbage means unreferenced objects.
● Main objective of Garbage Collector is to free heap memory by destroying
unreachable objects.
● Unreachable objects : An object is said to be unreachable when there is no valid
references to that object exist.
● Eligibility for garbage collection : object must be unreachable.
● finalize() method – This method is invoked each time before the object is garbage
collected and it is intended to perform cleanup processing.
● Garbage collector releases only those objects that are created
by new keyword.
● So if we have created any object without new, we can use
finalize method to perform cleanup processing
Downloaded from Ktunotes.in
Request for Garbage Collection
● We can request to JVM for garbage collection
however, it is upto the JVM when to start the garbage
collector.
● gc() method is used to call garbage collector explicitly.
● It only request the JVM for garbage collection.
● However gc() method does not guarantee that JVM
will perform the garbage collection.
● This method is present in System and Runtime class,
functionally both are same.
Downloaded from Ktunotes.in
Comments
Downloaded from Ktunotes.in
Comments...
Downloaded from Ktunotes.in
Java program structure
Downloaded from Ktunotes.in
Java program structure
Document section (optional)
● Add comments describing the details of author, purpose, licence, etc
/**
* This file contains the implementation of sample program.
* @author Jinesh Jose
* @version 1.0
* @since 13-09-2020
*/
Package Statement (optional)
● You can create a package with any name to organize the classes of that file.
● A package is to group classes that are defined by a name.
● It is like a folder in which all the classes present in that file are kept.
● It is declared as: package package_name;
Downloaded from Ktunotes.in
Java program structure
Import Statement (optional)
● This line indicates that if you want to use a class of another package, then you
can do this by importing it directly into your program.
● E.g. import java.io.*; // importing all the classes from java.io package
Interface statement (optional)
● Interfaces are like a class that includes a group of method declarations.
● It's an optional section and can be used when programmers want to implement
multiple inheritances within a program.
Class Definition (optional)
● A Java program file may contain several class definitions.
● But only one public class is allowed in a file
● File name and the public class name should be same.
Downloaded from Ktunotes.in
Java program structure
Main Method Class
● Every Java stand alone program requires the main method as the starting point
of the program.
● There may be many classes in a Java program, but only one class defines the main
method .
public static void main(String args[])
● It is declared public , it means that it can also be used by code outside of its class.
● static indicates classified scope, ie we want to access a method without creating its
object, as we call the main method, before creating any class objects.
● void indicates that a method does not return a value.
● main is a method; this is a starting point of a Java program.
● String args[] - method receives an array of strings, it is used to receive
the command line arguments to your program.
Downloaded from Ktunotes.in
Sample Program
Downloaded from Ktunotes.in
Downloaded from Ktunotes.in
Java Lexical Issues or Java Lexeme or Java Tokens
● Tokens are the smallest
individual building block or
smallest unit of a program.
● Java compiler uses it for
constructing expressions and
statements.
● Java program is a collection of
different types of tokens,
comments, and white spaces.
Downloaded from Ktunotes.in
Tokens - Keywords
● A keyword is a reserved word. In Java there are 50 keywords.
● The meaning of the keywords has already been described to the java compiler.
These meaning cannot be changed.
● Thus, the keywords cannot be used as variable names because that would try to
change the existing meaning of the keyword, which is not allowed.
Downloaded from Ktunotes.in
Tokens - Identifiers
● Identifiers are the names of variables, methods, classes, packages and interfaces
● Allowed characters for identifiers are all alphanumeric characters([A-Z],[a-z],[0-9]),
‘$‘(dollar sign) and ‘_‘ (underscore).
● All identifiers must start with either a letter( a to z or A to Z ) or currency
character($) or an underscore.
● They must not begin with a digit
● After the first character, an identifier can have any combination of allowed
characters.
● Identifiers in Java are case sensitive, foo and Foo are different.
● A Java keywords cannot be used as an identifier.
● They can be any length
● Eg: int a; , char name;
Downloaded from Ktunotes.in
Tokens - Constants or Literals
● Constants are fixed values of a particular type of data,
which cannot be modified in a program.
● Java language specifies five major type of literals.
● In Java, a character preceded by a backslash (\) is an
escape sequence and has special meaning.
Downloaded from Ktunotes.in
Tokens - Separators
● There are few symbols in java that are used as separators.
● A separator is a sequence of one or more characters used to specify the boundary
between separate, independent regions in plain text or other data stream.
● The most commonly used separator in java is the semicolon ' ; '.
Downloaded from Ktunotes.in
Tokens - Operators
● An operator is a symbol that takes one or more arguments and operates on them to
produce a result.
1. Unary Operator
2. Arithmetic Operator
3. Shift Operator
4. Relational Operator
5. Bitwise Operator
6. Logical Operator
7. Ternary Operator
8. Assignment Operator
Downloaded from Ktunotes.in
Tokens - Comments & White space
White space
● Java is a free-form language. This means that you do not need to follow any
special indentation rules
● 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;
● White spaces are required in some places. For example between the int keyword
and the variable name.
● In java whitespace is a space, tab, or newline
Comments
● Java supports 3 types of comments.
Downloaded from Ktunotes.in
References
● Rajib Mall, Fundamentals of Software Engineering, 4th edition, PHI, 2014.
● UML Diagrams - www.uml-diagrams.org
● Visual Paradigm - www.visual-paradigm.com
● GeeksforGeeks - www.geeksforgeeks.org
● Wikipedia - www.wikipedia.org
● Tutorialspoint - www.tutorialspoint.com
● Java Zone - https://dzone.com
Disclaimer - This document contains images/texts from various internet sources. Copyright belongs to the
respective content creators. Document is compiled exclusively for study purpose and shall not be used for
commercial purpose.
Downloaded from Ktunotes.in