Merged
Merged
Encapsulation: Related data & procedures are clubbed together within an encapsulated structure known as class
and every entity forms a classification with data members representing the properties or attributes and the
operations on these data are treated as entity behaviour.
STUDENT
-Int roll; STUDENT
-Float marks; Roll=123;
-Char grade; Marks=70;
+Void put_data(); Char grade=’A’;
+Void show_data(); +Void put_data();
+void compute(); +Void show_data();
student s1→ +void compute();
2. Abstraction:
i. Complexity of internal representation is to be hidden form the end user.
ii. Behaviour of the new data type is similar to the basic one i.e new user defined data type treated as abstracted
data type (ADT) will work just like the traditional data type and their operations.
Complex
Int real;
Int img;
+Void addition(complex c1, complex c2);
Complex c1, c2, c3;
C3=c1+c2;
3 Data protection/hiding:
i. Attribute specific:
STUDENT
-Int roll; Private data
-Float marks;
-Char grade;
+Void put_data();
+Void show_data(); Public data
+void compute();
Student s1;
S1.roll; x
S1.put_data(); √
A
Data1;
+ operation1();
B
-Data2;
+operation2();
A cannot access any private B properties directly and it has to be via the public properties of B.
B can access both public and private properties of A.
A MODULE-1
B M
public
Private Private
C MODULE-2
D E
public
Private Private
1. Code reusability:
i. Incorporation of previously developed code/properties into another entity or module. This process reduces
redundant code development.
ii. Can selectively choose properties form the original structure to be reused in the new structure.
STUDENT
+Int roll;
+Float marks;
-Char Report;
+Void put_data();
+Void show_data();
UG_STUDENT
PG_STUDENT -int JEE score;
-int Gate_ score;
1. Monolytic Prog. Language:
i. Subroutine concept is missing
ii. Data & codes are scattered throughout the prog. (i.e no data organization)
iii. Lack of data security
iv. Not suitable for large codes or real life programming.
1. Data1
2. Data2
3. Instruction with data1 & data2 codes
4. Instruction with data1 & data2
5. Data3
6. Instruction data2 & data3
Ex: Assembly Language
2. Procedural prog. languages
The primary focus is on functions, and the overall structure follows hierarchical decomposition.
Main programme
Function-2 (with local data)
Serious drawback of procedural approach is that they does not model the real life prog. very well . This is because
functions are action oriented and not focused on elements.
i. Everything is procedure based i.e for every operation specific procedure or algorithm is defined.
ii. Subroutine concept is introduced
iii. Data organization is not taken care of within the procedure.
iv. Data move around openly from function to function.
v. Lack of data security as global data concept prevails.
In a multi-function prog. many vital data items are placed as global data which are always vulnerable. Also in a
large programme it is very difficult to identify what data is used by which function.
Data1 Data2 Data3
Global data
Proc1 Proc2 Proc3
3. Structured Prog. Language (Ex: C)
i. It follows procedural prog. Concept.
ii. Data organization taken care of and all the related data are clubbed in a structure. Instance of that structure
basically representing all those individual data. Also each such instance can be treated as a new user defined
data type variable.
iii. Data security issue still lacking Teacher
STUDENT Teacher Name=”AMIT DAS”;
Int roll; String name; Id=1234;
Float marks; Int id; Subject=DBMS;
Char grade; String subject;
UG_STUDENT PG_STUDENT
-int JEE score; -int Gate_ score;
2. Nested Structuring
3. Importing Modules
POLYMORPHISM
1. Ad-Hoc Polymorphism at compile time-
Functions that behave differently with different sets of arguments i.e same
function with different types or numbers of arguments. (Function overloading)
ADD FUNCTION
UG_STUDENT PG_STUDENT
getAttendence() getAttendence()
Student stud_ptr;
(as reference)
MESSAGE PASSING
• A set of objects communicate with each other by sending & receiving
information and it helps in modeling the real world scenario. In this case
functions of one object can access the functions of other object.
• A message is a request for the execution of a procedure call that involves
name of the object, name of the function (message), and the information to
be sent. Ex: employee.salary(Allownace)
• object message information
• Communication between objects are possible when they are alive.
EMP Allowance
-string emp_name; -int DA;
-int basic; -int HRA;
+void show_data(); +void put_allowance();
+int salary(allowance); +void get_allowance_data();
Striking Features of OOP
1. Emphasis given on data rather than procedures and maintains global view
or data abstraction.
2. Programms are divided into objects that employs real life data structure.
3. Attributes and behaviors of the object are tied together within the object
structure.
4. Data is hidden and can not be accessed by the outside world.
5. Objects may communicate with each other through specific interface
functions.
6. Previously developed data & code can be reutilized in various forms while
new data & code can be easily added whenever necessary.
7. Modular programming concept can be implemented in a better way and
hence more suitable for real life software development.
8. Software complexity can be easily managed.
1. OBJECT BASED PROGRAMMING LANGUAGE
It is the style of programming that primarily supports encapsulation and object
identity. The major features are-
(i) Encapsulation
(ii) Data hiding & accessibility mechanism
(iii) Automatic initialization and clear up of objects
(iv) operator overloading
2. Object Oriented Programming Language
It supports the features of object based language plus the additional features of
inheritance & dynamic binding.
What is Modeling
➢ A model is an abstraction for the purpose of understanding the system before building it.
➢ A model hides the non-essential characteristics of a system and highlights those which are
pertinent for understanding.
➢ A model provides a means for conceptualization and communication of ideas in a precise
and unambiguous form.
➢ Modelling enables us to cope with the complexity of the system
➢ Modelling is used frequently, during many of the phases of the software life cycle such as
analysis, design and implementation.
Abstract view of TV remote & call handling procedure for a mobile phone
Why do we model?
➢To evaluate the outcome of a physical entity before actually building it.
➢ To set the stage for communication between customers and developers.
➢ For visualization i.e. for finding alternative representations.
➢ For reduction of complexity in order to understand it.
OBJECT MODELING TECHNIQUE (OMT)
➢ This concept introduces a methodology for analysis, design and implementation
of a system with object-oriented software development techniques/process.
➢It is a fast, intuitive approach for identifying and modelling all the objects of a
system.
➢It focuses three different viewpoints i.e. the static, dynamic and functional
behaviours of the system.
➢These are described by object model, dynamic model and functional model of
the OMT.
Different Viewpoints of OMT
1. Object Model- It describes the static, structural and data aspects of a system in terms of
objects and their relationships.
2. Dynamic model-It describes the temporal, behavioural and control aspects of the system. It
actually focuses on state changes for the various objects with respect to the event.
3. Functional model- It focuses on process perspective of the system and mainly defines the
critical functional parts with the help of Data Flow Diagrams (DFDs).
LANGUAGE
LINK ATTRIBUTES
Some times, an attribute(s) cannot be associated with either of the two classes.
In such cases, the attribute(s) is associated with the association and is called as
link attribute. It is the property of the link and not any of the individual class.
SALESMAN Works for COMPANY
SALARY
Date-of-Join
It is also possible to model link attributes as a class and such class is called as link
class. Each link becomes one instance of the class. The notation for this kind of an
association is the same as for a link attribute. FILE Accessibly by USER
Authorization
Access-permission
ROLE NAMES
➢A role is one end of an association.
➢A binary association can have two roles, each of which may have a role name.
➢A role name is a name uniquely identifies one end of an association.
➢Role provides a way of viewing a binary association as a traversal from one
object to a set of associated objects.
employee employer
SALESMAN COMPANY
Works for
➢Role names are necessary for associations between two objects of the same class.
➢They are also useful to distinguish between two associations between the same pair of classes
➢All role names on the far end of associations attached to a class must be unique.
Ordering
Usually the objects on the "many" side of an association have no explicit order,
and can be regarded as a set. Writing {ordered} next to the multiplicity dot
indicates an ordered set of objects of an association.
WINDOW {ordered} SCREEN
visible on
Qualification
➢A qualifier is a special association attribute that reduces the effective multiplicity
of an association.
➢One-to-many and many-to-many associations may be qualified.
➢The advantage of qualification is that it improves the semantic accuracy and also
increases the visibility of navigation paths.
BANK ACOUNT NUMBER PERSON
Aggregation
➢Aggregation is another form of relationship between classes. It is a tightly
coupled form of association with some extra semantics.
➢It is “part-whole” or “a-part-of” relationship in which one object is part of other.
TEAM maintains PLAYER
Aggregation can be fixed, variable or recursive.
➢In a fixed aggregation number and subtypes are fixed i.e. predefined.
➢In variable aggregation number of parts may vary but number of levels is finite.
DOCUMENT PARAGRAPH SENTENCE WORD
➢ A recursive aggregate contains, directly or indirectly, an instance of the same
aggregate. The number of levels is unlimited here.
PROGRAMME BLOCK
MODULARITY-
➢ Partitioning a programme into individual components for managing the complexity.
➢ Modules compile separately or together.
➢ They are Connected with other modules.
ADVANTAGES-
➢ Decomposition of the problem into individual components.
➢ Enable reuse of existing components.
➢ Understanding module as a unit and hence easy to change.
➢ Errors are localized and local modification is possible.
Main Focus Points of Modularity
➢ Group logically related abstraction
➢ Minimize dependency among modules
➢ Simple enough to understand fully.
Hierarchy – It is a ranking or ordering of abstractions and mainly used to share the common
functionalities between objects or entities. It is of two types
A. IS–A hierarchy B. PART–OF hierarchy
Minor Elements- Each one of these following elements are useful but not essential.
1. Typing 2.Concurrency and 3. Persistence
1.Typing- A typing is the enforcement of the class to an object, such that objects of different
types- (i) may not be interchanged or at the most (ii) they are interchanged only in very
restricted ways.
2. Concurrency- It is the property that distinguishes an active object form the inactive one. It
allows multiple task to execute, interact and collaborate at the same time.
3. Persistence- It is the property of an object through which its existence transcends time. It
decides the fate of objects over time and space.
Time- Object continues to exist after its creator destroys it.
Space- Object’s location moves form the address space in which it was created.
Class to class relationships
EMP Project
-string emp_name; -int proj_number;
-int basic; -string p_name;
-int p_id; -string p_duration;
+void show_data(); -int p_budget;
+int salary(allowance); +void put_data(emp e);
+void get_data();
Project
EMP -int proj_number;
-string emp_name; -string p_name;
-int basic; -string p_duration;
+void show_data(); -int p_budget;
+int salary(allowance); EMP e[];
+void put_data();
+void get_data();
STRING HANDLING METHODS
Java string class container package – java.lang.String
The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as
instances of this class.
String str = "abc"; is equivalent to:
char data[] = {'a', 'b', 'c'};
String str1 = new String(data);
String str2=new String(“abc”);
class string_concat
{
public static void main(String args[]){
String str="HELLO";
char data[]={'H','E','L','L','O'};
String s=new String(data);
System.out.println(str);
System.out.println(data);
System.out.println(s);
System.out.println(str+" AND "+s);
}
}
SUBSTRING CUTTING FROM THE MOTHER STRING
1. String substring (int began, int end) -> cuts a substring form the method invocation string
with starting index at began and the ending index at end-1.
2. String substring (int began) -> cuts the substring form the method invocation string with
starting index at began and upto the last index of the string.
Example-
class remove_char
{
static String remove_charAt(String str, int pos){
return str.substring(0, pos)+str.substring(pos+1);
}
public static void main(String args[])
{ String str="GOOD IS JAVA";
System.out.println(remove_charAt(str,2));
}
}
COMMAND LINE ARGUMENTS
class command_line_argument
{
public static void main(String args[]){
for (int i=0; i<args.length;i++)
System.out.print(args[i]+" ");
System.out.println();
System.out.println("LENGTH OF THE FIRST ARGUMENT:-"+args[0].length());
//int length()-> returns the length of the invoked string object
System.out.println("EQUALITY OF THE FIRST TWO ARGUMENTS:-
"+args[0].equals(args[1]));
// boolean equals(String str) -> compares invoked string with the passed argument string
System.out.println("CHARACTER AT INDEX POSITION 2 FOR THE FIRST ARGUMENTS:-
"+args[0].charAt(2));
//char charAt(int index) -> returns the character at the specified index position
}
}
KEYBOARD INPUT
import java.io.*;
class input{
public static void main(String args[]) throws IOException
{
int a=0; String str=" "; int b=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n");
System.out.print("ENTER YOUR NAME:-");
str=br.readLine();
System.out.println("\n");
System.out.println("YOUR NAME:-"+str);
System.out.println("\n");
System.out.print("ENTER A NUMBER:-");
a=Integer.parseInt(br.readLine());
System.out.println("\n");
System.out.println("YOUR ENTERED NUMBER:-"+a);
}
}
LEXIOGRAPHICAL COMPARISON WITH EXAMPLE
import java.io.*;
class string_compare
{ public static void main(String args[])throws IOException
{ String s1=""; String s2="";
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("ENTER FIRST STRING:-"); s1=br.readLine();
System.out.print("ENTER SECOND STRING:-"); s2=br.readLine();
int a=s1.compareTo(s2);
if(a==0) System.out.println("THE TWO STRINGS ARE EQUAL");
else if(a<0) System.out.println("FIRST STRING IS SMALLER");
else System.out.println("FIRST STRING IS LARGER");
System.out.println("THE VALUE OF A:-"+a);
}
}
SUB STRING PATTERN SEARCHING WITH CONTAINS METHOD
• The contains() method checks whether the specified substring (i.e sequence of
characters) is present in the mother string or not.
• Syntax of contains()
• string.contains(String str) and the return type is boolean (i.e true/false)
class string_contain
{
public static void main(String[] args) {
String str = "GCECT IS A GOOD COLLEGE";
System.out.println(str.contains("GCECT"));
System.out.println(str.contains("GOOD"));
System.out.println(str.contains("KGEC"));
}
}
STRING OBJECT CREATION CONCEPT
• There are two ways to create a String object:
• By string literal : using double quotes. For Example: String s=“Welcome”;
• By new keyword : Java String is created by using a keyword “new”.
• For example: String s=new String(“Welcome”);
• Java String Pool: refers to collection of Strings which are stored in heap memory.
whenever a new object is created, String pool first checks whether the object is
already present in the pool or not. If it is present, then same reference is
returned to the variable else new object will be created in the String pool.
Reversing a String by Reading It In a Reverse Manner
class reverse_first
{
public static void main(String args[]){
String s1="";
for (int i=args[0].length()-1; i>=0;i--)
s1=s1+args[0].charAt(i);
System.out.println(s1);
System.out.println("First String Palindrome:-"+args[0].equals(s1));
}
}
Java Architecture
1
Agenda
Evolution of Java
Java Architecture
2
Evolution of Java
3
Key Founders
Java was the brainchild of:
• James Gosling
• Patrick Naughton
• Mike Sheridan
The origin of Java can be traced back to the fall of 1991, and was
initially called Greentalk later renamed to Oak.
Oak was renamed as Java in 1995
4
Design Goal
Java was originally meant to be a platform-neutral language for
embedded software in devices.
The goal was to move away from platform and OS-specific compilers
that would compile source for a particular target platform to a language
that would be portable, and platform-independent.
5
Java Architecture
6
Java Architecture
Compile-time Run-time Environment
step3
Environment step1
Class Java
Class
Java
Source Loader Libraries
(.java)
Bytecode
Verifier step4
step2 Java
Bytecodes
Java Compiler move locally Java
Just in
Time
step5
or through Interpreter
Compiler Java
network
Virtual
machine
Runtime System
Java
Bytecode
(.class ) Operating System
Hardware
7
Java Architecture (Contd.).
Step1:
Create a java source code with .java extension
Step2:
Compile the source code using java compiler, which will create bytecode file with .class
extension
Step3:
Class loader reads both the user defined and library classes into the memory for execution
8
Java Architecture (Contd.).
Step4:
Bytecode verifier validates all the bytecodes are valid and do not violate Java’s security
restrictions
Step5:
JVM reads bytecodes and translates into machine code for execution. While execution of the
program the code will interact to the operating system and hardware
9
The 5 phases of Java Programs
Java programs can typically be developed in five stages:
1. Edit
Use an editor to type Java program (Welcome.java)
2. Compile
• Use a compiler to translate Java program into an intermediate language called
bytecodes, understood by Java interpreter (javac Welcome.java)
10
The 5 phases of Java Programs (Contd.).
4. Verify
Use a Bytecode verifier to make sure bytecodes are valid and do not violate security
restrictions
5. Execute
• Java Virtual Machine (JVM) uses a combination of interpretation and just-in-time
compilation to translate bytecodes into machine language
• Applications are run on user's machine, i.e. executed by interpreter with java command
(java Welcome)
11
Java Virtual Machine
12
The Java Architecture – The JVM (Contd.).
Most modern languages are designed to be compiled
Interpreting a Java program into byte code facilitates its execution in a wide variety of
environments
13
The Java Architecture – The JVM (Contd.).
Only the Java Virtual Machine (JVM) needs to be implemented for each platform
Once the Java runtime package exists for a given system, any Java program can run on it
The JVM will differ from platform to platform, and is, platform-specific
14
The Java Architecture – The JVM (Contd.).
Interpreted code runs much slower compared to executable code
The use of bytecode enables the Java runtime system to execute programs much faster
15
The Java Architecture – The Adaptive optimizer
Another type of execution engine is an adaptive optimizer
It also keeps a tab on the code that is running and identifies only the heavily used areas
The JVM compiles these heavily used areas of code into native code
The rest of the code, which is not heavily used continues to be interpreted and executed
16
The Java Architecture - The Class Loader
The class loader is that part of the VM that is important from:
A security standpoint
Network mobility
The class loader loads a compiled Java source file (.class files represented as bytecode) into
the Java Virtual Machine (JVM)
The bootstrap class loader is responsible for loading the classes, programmer defined classes
as well as Java's API classes
17
The Java Architecture - The Java .class file
The Java class file is designed for
platform independence
network mobility
The class file is compiled to a target JVM, but independent of underlying host platforms
The Java class file is a binary file that has the capability to run on any platform
18
Quiz
1. Write the correct order of the Java program execution.
A. Class Loader
B. Interpretation
C. Compilation
D. Byte Code Verification
E. Java Source Code
F. Execution
4. The JDK is a superset of the JRE, and contains everything that is in the JRE, plus
tools such as the compilers and debuggers necessary for developing applets and
applications.
A. TRUE
B. FALSE
20
Summary
21
Thank You
22
CODE REUABILITY WITH INHERITANCE
Class A
Int x;
A(int i){} A(){}
Void show(){}
Class B Class B
Int x;
Int y; Int y;
B(int I, int j){} B(){} B(int I, int j){} B(){}
Void display(){} Void show(){}
Void display(){}
➢ Whenever child object is created, at first the parent data members are initialized either
explicitly or implicitly. It means immediate parent class constructor is called first inside the
child class constructor.
➢ Private members & constructors of the parent class never inherited.
Types of Inheritance