You are on page 1of 12

c 


    
 

OOP is a method of programming in which programs are organised as cooperative
collections of objects. Each object is an instance of a class and each class belong to a
hierarchy.

 
Class is a template for a set of objects that share a common structure and a common
behaviour.

 
  
Object is an instance of a class. It has state,behaviour and identity. It is also called as an
instance of a class.

 


 
An instance has state, behaviour and identity. The structure and behaviour of similar
classes are defined in their common class. An instance is also called as an object.

     


 
Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP¶s
concepts.

  
  

Abstraction defines the essential characteristics of an object that distinguish it from all
other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative
to the perspective of the viewer. Its the process of focussing on the essential characteristics
of an object. Abstraction is one of the fundamental elements of the object model.

 
 !
"

Encapsulation is the process of compartmentalising the elements of an abtraction that
defines the structure and behaviour. Encapsulation helps to separate the contractual
interface of an abstraction and implementation.

 
 
 
 
Inheritance is a relationship among classes, wherein one class shares the structure or
behaviour defined in another class. This is called Single Inheritance. If a class shares the
structure or behaviour from multiple classes, then it is called Multiple Inheritance.
Inheritance defines ³is-a´ hierarchy among classes in which one subclass inherits from one
or more generalised superclasses.

#  
  
Polymorphism literally means taking more than one form. Polymorphism is a
characteristic of being able to assign a different behavior or value in a subclass, to
something that was declared in a parent class.

c$ 
% 
Abstract class is a class that has no instances. An abstract class is written with the
expectation that its concrete subclasses will add to its structure and behaviour, typically by
implementing its abstract operations.

cc 

 & 
Interface is an outside view of a class or object which emphaizes its abstraction while
hiding its structure and secrets of its behaviour.

c   
Base class is the most generalised class in a class structure. Most applications have such
root classes. In Java, Object is the base class for all classes.

c " 
Subclass is a class that inherits from one or more classes

c " 
superclass is a class from which another class inherits.

c 
"
Constructor is an operation that creates an object and/or initialises its state.

c  "
Destructor is an operation that frees the state of an object and/or destroys the object
itself. In Java, there is no concept of destructors. Its taken care by the JVM.

c  
 '


Binding denotes association of a name with a class.

c(  
  


Static binding is a binding in which the class association is made during compile time.
This is also called as Early binding.

c#  
 )
 


Dynamic binding is a binding in which the class association is not made until the object
is created at execution time. It is also called as Late binding.

$ ) &
*" 
Modularity is the property of a system that has been decomposed into a set of cohesive
and loosely coupled modules.

c  
  
 
Persistence is the property of an object by which its existence transcends space and time.

  

Colloboration is a process whereby several objects cooperate to provide some higher
level behaviour.
 
+,-./0 
     
" 
All the instance variables should be declared as private and public getter and setter
methods should be provided for accessing the instance variables.

 ./  , 


,
Inheritance, Overloading and Overriding are used to acheive Polymorphism in java.


r 


Ê  
 
° 
  
    
 
   

 
  
 p   
  
 

     
  
 
   
 
  

      
 
 
     



&-

 & "&   /    1%
  2 ,-& & 

 & - &/3

p p 
 

 p  p  


p p 

 p p  


 pp p  

 p
p  

ï    
  
    
 

   

    ° !p 
    p
 !
     
 "

° !p 
p  p 
 

p  p
p
 " 


r     
    

 

  

 r 
 
 
      
   
 
 
   
r
        
   
   
 
   
 
       


 

ï

 
    
  
   
 
  

 




 
  
 
 
 #
  
 

  !   

   
 $ 
 
!  p 
  
 

l 4 -


&""  /  " 5
  


 "  /""
 1%"  
"&" / 
&/ 6+,-&"    "  7--   -"
 &-

&1%
 
""-  
"
 
"

"&" -0 " 
    , 8968 

9   

/  

&
&&


" 
&
,  1

: "
"&" "" 

" 5

 &  "
 /
 
 
,0 0  , 6
-&

"&"  1: "
 

"&" 

/ &/ 
,0     
 
 & 

 1;  
""
0
/   "2&/ 
 
 1
&- "
 &/    
  ,  
& 
 -


"    "  
 & 1

Interfaces in Java

r %

     p  

    
     

      
      ï

    r 
  
   &  p       
  
 
 #   
    
     

) &



 &  

/3

"
pp # 

  
p $p 

 p 
p  %pp pp $°  p 
&'()$*!+)
 "
p$ "
,$ "
 ,
p  * %pp pp $ "
,$ "
 ,
p p 
) %pp pp $"
 p 
# 
p &+  "
p ) $ "
#
p && "
p ) $ "
#
------
  p 

š   
  
  

     

:" 

 & - "/ p   
 & 1



  
 


 & -,    & &    
 

 & 1l 4 -
"
p
# ./01pp
 # 

# p $pp
 p 22
 3
4
p p 
) %pp pp $"
 p 
#  
    .5*!+) p p 
p 
    .5*!+) p p 
p 
    .5&'() p p 
p 
    .5&'() p p 
p 


 "$ 22 3
$


  pp"
 
p  p 


r 

     

    

'
           
 
ï 
 
 

  
  
ï   


   
 
       $()  
      
  



r            ! 
 "
 
  
!  
   


Interfaces as APIs

ï

     
       
  
° pp 
 p  °°(r 
   
  

  ï  
    
!     
     
   

 °   !  
   

   !  * 

 

 ï
   
     
    
 !    
ï
    ! 

       
  

      
+ 

    °(r     
    °(r !
    
  
&  
     
     
     
   
  

   

Interfaces and Multiple Inheritance

r 
  


 
  %

   r 
 
 

  

  
!      ï%

   
  
   
  
       
      
 
 
  



+,-

 &
 
 "
 
 


 & 1
:  & -  
, "   3   & /

   & 

 &   
1: 
&,        &


 & -," 
 & 
 
  

 &
 

 
 & 1:"  
 
-
  
 <=


 & 
:  1<
° 
  
°        
 "&
     
 
° 
            

%
| |     /"
 

6/"  -

&/   
-0 3

" p )  "



6$ "

7
r       
        
 "   "
"
p"
p#"8 

p


 2" 
" p

+   
            
     
 
 
   
   ,
           
 
"

š °    p  '   
p pp
 
  
" 
     
  &     
 


Abstract Classes versus Interfaces

' ! 
  
       
 p p 
  
      ) 
   
  
 
 
 

              r  
  
  
 
   
     
    
  

*" 
 & 
  
   
/  
   -/  

    



 

/ 1:
0& "

"
-& 4 1

' 
-   
 "     &
 

1%
  "    , 


6  
 &   - ",  && 
 6 
   1

Thread
9 "- |2& 4 "
1*/
 "


  -"
  /
"  ,


"   1
> 2 -& 4 -
  &/
" /  
0 0 1
: ", &"

 0 
"0
   
  


 ,
 1:  "
      4 "
&/
  
&   1: /"1
*"  
 ,  
/  "



 
"
 
/

 1l
&, /-" 
 
" 
&

 
  4 "    -/ , -
  

/ 
 
   " 
& 
 4 "   
 1
 -  
   
 /  


  1=
 =
4-&0
    /&& 
  
&  
1./ , -   &,  &  
  -
0
,  =5

,  
1' 
 
 -
 &&
&
4 "
  / 
 
 & 
1:  &

  ,  
&- " 
"  &
 
/ 2" 1

Creating threads

+,2 , "  


// & 
 3 



 & 

 4

1!4

 / +,
  
,  &

1
 -


  4

 &
 
1:

/
+,
 ,    


 & -/ 

/    16;  &
 
   /  "

 1"  4 "
- 1 


 & , / &   "
/0&1:  " 
 
  ?" 
& &  
1: 
 &   ,  
"-

   
 
 &  /01: && 
 & 
 
 
 & , &/  " 1

:   & /&& 


  /



 & 1l-

 & 

 


  
@&
,  6

 1 -
  
-

 
 


,   


19 
-

 & 


 

 1% 


 & " 
 
 &


 & 1%

 &     4
& 
 & -
6"
0 
  
 4
&" 
 & 1l"  -

 & 

 

 
/ 
/ A& 4 -& "
9 & "

/ 1

: & & 


   4
& )1)
 &
  "
 4 "   
 , 
  4
 &
 1
: ) &

 0 ,1
-/
  "
  / & &

1

p 8 -
 -:
"
p
  3 )

"
p p 
 
----



:  ,  4   
/   4
 )
,   
)-  &/
 

1:   /   /0&
    
1:  
     

B"

  3

p 8 -
 -:
"
p
  p
 & "


))
"
p p 
 
----




.  -     &



 B"

  
 & 
 
 
 1
; / , 


 & ),  &   1: 
 
&& 
  /
 /   

B"

  -    & 4  



  
&   1
  ,  4 - "
  4 4

   -&
 1:  &   
 "
 /
 
B"

  
       4

  &"

 &
 
1

)

0 B"

  
 & 

 /0/
   

4 " 1     , 
 
  
& )1
&-
,  



 
  1.    &

& B"

  

 &   & +," 3

8 -
 
"
pp & "
 
"
p" p 



:   B"

  
 & 1%

 & 
 ,  
"
/
 "  
 1
  & B"

  
 & -&   &

&

    1:  & -& /0

 )1% 0
 

  &

& )/, 
 &/  

3

"
p
)p
 & "
 
---
"
p p  
p;9 

 
- 


---


l  ,  
  ,
 :  
 B"

  

 & 1)1  00 "   6 
 
"
  
 ?"
"-

 4 "    &  1


-   &  / "


/
 1

Starting and stopping

9
  && 
/   


 &  
/
-/ /" 
 

&  


/ / ,  
 "

 


 "   
3

"
 : !4 
9"  

:  ,  /"

&$ 
""  

 

 1%?"0
 ,   
 /"



  ,  
" - "
  1%  4

&  4 "
&
 / , " 
 1

ß ršr r
š

 
ï
    

  %(

   °
   -   
  

° 
      
  

 
  


  

c1 Overview of Thread


: 

 ,  

+,

" 1% 
 ?"
&  4 "
/
1%
  /

,  -"
 
&  1

1 Life Cycle of A Thread
>&   &: 

&& 
 5; / -B"

  -B"


 -
)  -;
5B"

   1

1 Thread Creation 


: 
  

 
&// 5!4

 ,1
1: -
 

 ,1
1B"

  
 & 1

1 Thread Constructors
9 , 
" ,  & 

/: 

 0 : 6 -
: 69
 -: 6B"

   1111

1 Introduction to Multithreading
*" 
 
?" /  4 " 
0

"
 6   
  1/ "
0
 
 

    1

1 Creation of Multiple Threads


>0  
&
  -C"
   

 6"  

"
Thread  


 & Runnable1

1 Thread Priorities and Scheduler



+,-  " 
"   priorities
 &&integer value 
&   
  4 "
 " & 1:   ready-
to-run 
  1

(1 Deadlock
%"
/   /
&
  0  
 -

 
 /
&
  0 & -"

0
/
) 01

#1 Lock and Synchronized Threads


+," monitor0
/
?semaphore? ,
& 
"  
"   0 /synchronized

D  

 "
 
  1Lock  &   
 " 
 
   " 1

c$1Inter-Thread Communication
% /  - " / "



 


  
/ 
 60 
   
  4 " 1: 
?" 
0
/
Inter-Thread communication

cc1Daemon Thread
) 
   , , &    "



  
   
 1) 
  " & 0"
"
0

 
 
 / 
   4 "

c .Êhat Is an Exception?
c1%
 4 

 ,
""
  4 "
&" 

&/&
"
1








÷ ÷ 
  



 ÷÷ 
ï  
   
 


 
 
   

  
   
 
 

    
  
 
    

  !
  
        

 "#"$"# "$
     $%&'# 

  

  
   
     
  
  

 

    
 
  
( 
 
 
  

 )   
*
  
 
  +   
 $
   
 

        $


 ,+

 

 
 
 
 
   
 
÷÷ 
- 
.
V 
V /
V   
V 0
  

V !
 
*

V !
 

V  
O   


 

     
  1

$

   $2''
  "#"$"# "$
 


 


!
 3 $  


    $ 4
#   

   
      
  
 
   
   
 
!

       
 
  
!   
   

 


   
  !
 3 
 
   
$$

O  O  

÷÷ 
0
  


 

   



ï 

 
 (     
 
"  
 "$" 
"
     $ 5$ *
  

 
   


$ 
!
  

 $  
     
 


    

 ï  
 

  
     
 
 
   
ï  


 
 
 
  


 
   
 
 
 
 ÷÷ 
!
 


   (  3  


 
$  
  
ï

 
( $ 
  
 $
"

"
  
6


  
 
 



  ( ! 
  
$ 
   
 

  

 
!
 

 



( 

!
 
  

 
 ï 
 

  
   
 
( 

 
   


 
    
 
  
ï   

O   

 
 
    


  

(   
  
 


ï     

  
  
   

 ÷
 

 

 
 
(   
 

 
  
( $  
 
#  
 " #"
" "
O  ÷ 

 


 

    
  

   !      ""

7
  $     "" ï   
""
7
 
 
 
     
÷÷ 



     
÷÷ !

V ! 
  $



V !

    
 ( 
 


V 8
      
 ( 


V 
 
    

You might also like