SlideShare ist ein Scribd-Unternehmen logo
1 von 32
OOPS, ENUMS, 
Inner Classes, 
GarbageCollection 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
1
ASSOCIATION 
 Association is a relationship between two objects. 
 Objects might not be completely dependent on each 
other. 
 One-to-many, many-to-one, many-to-many all these 
words define an association between objects 
 Example: A Student and a Faculty are having an 
association. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
2
AGGREGATION 
 A directional association between objects. 
 Aggregation can be considered as a “has-a” 
relationship. 
 Child object can also survive or exist without the 
enclosing class. 
 For Example, Room has a table, but the table can 
exist without the room. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
3
COMPOSITION 
 A restricted aggregation is called composition. 
 The member object (part) cannot exist without the 
containing class. 
 For example, A class contains students. A student 
cannot exist without a class. There exists composition 
between class and students. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
4
UML Diagrams of 
Relationships 
 Association 
Association is denoted by simple 
arrow 
 Aggregation 
aggregation is denoted by empty 
diamond head arrow 
 Composition 
composition is denoted by filled 
diamond head arrow 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
5
Difference Between 
Composition And Aggregation 
 When there is a composition between two objects, the 
composed object cannot exist without the other object. 
 In case of Aggregation, 
Though one object can contain the other object, 
there is no condition that the composed object must 
exist. 
 For Ex: Facebook has-a-User i.e. Aggregation 
Every User has a different Session i.e. 
Composition. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
6
METHODS OVERRIDING 
 Overriding is a feature of OOP languages like 
Java that is related to run-time polymorphism. 
 Method overriding is when a child class 
redefines the same method as a parent class, 
with the same parameters. 
 The key benefit of overriding is the ability to 
define behavior that is specific to a particular 
subclass type. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
7
The rules for overriding a method 
are as follows: 
 The argument list must exactly match that of the 
overridden method. 
 Overriding method CAN throw any unchecked 
runtime exception. 
 You cannot override a method marked final. 
 You cannot override a method marked static. 
 If a method can't be inherited, you cannot 
override it. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
8
METHOD OVERLOADING 
 Overloading is also a feature of OOP languages like 
Java that is related to compile time (or static) 
polymorphism. 
 Method overloading is defining several methods in 
the same class, that accept different numbers and 
types of parameters. 
 In this case, the actual method called is decided at 
compile-time, based on the number and types of 
arguments. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
9
Overloading Rules 
 Overloaded methods MUST change the argument 
list. 
 Overloaded methods CAN change the return type. 
 Overloaded methods CAN change the access 
modifier. 
 Overloaded methods CAN declare new or broader 
checked exceptions. 
 A method can be overloaded in the same class or 
in a subclass. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
10
ENUM, 
INNER CLASSES 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
11
Enum 
 An enumeration, or “enum” is simply a set of 
constants to represent various values. 
 An enum type is a special data type that enables for 
a variable to be a set of predefined constants. 
 The variable must be equal to one of the values that 
have been predefined for it. 
 enums extend java.lang.Enum and implement 
java.lang.Comparable. 
 Hence, enums can be sorted. 
 Enums override toString() and provide valueOf(). 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
12
Defining Enum 
 Old way of doing it: 
public final int SPRING = 0; 
public final int SUMMER = 1; 
public final int FALL = 2; 
public final int WINTER = 3; 
 New way of doing it: 
enum <enumname>{} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
13
Advantages 
 Enums provide compile-time type safety. 
 Enums provide a proper name space for the 
enumerated type. 
 Enums are robust. 
 Enum printed values are informative 
 Because enums are objects, you can put them in 
collections. 
 Because enums are classes, you can add fields and 
methods. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
14
Inner Class 
 The class defined inside another class or interface is 
called inner class 
 We can also create an interface in another class or 
interface. 
 For example 
class Example{ 
class Sample{} 
} 
class Example{ 
interface Sample{} 
} 
interface Example{ 
class Sample{} 
} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
15
Need of Inner Class 
 Inner class is used for creating an object logically 
inside another object with clear separation of 
properties region. 
 A inner class has access to the variables and methods 
of the outer class, even if they are declared private. 
 Nested classes can be hidden from other classes in 
the same package. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
16
Nested class (static inner class) 
 The inner class defined at class level with static 
keyword is called static inner class. 
 Syntax: 
 Allowed Modifiers: 
class Example{ 
static class A{} 
} 
private, protected, public, final, abstract, strictfp 
 Types of Members allowed: 
* static variable * non-static variable 
* static block * non-static block 
* static method * non-static method 
* main method * constructor 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
17
Inner class (non-static inner class) 
 The inner class defined at class level without static 
keyword is called non-static inner class. 
 Syntax: 
 Allowed Modifiers: 
private, protected, public, final, abstract, strictfp 
 Types of Members allowed: 
* non-static variable 
* non-static block 
* non-static method 
* constructor 
class Example{ 
class A{} 
} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
18
Method Local class (local inner class) 
 The inner class defined inside a method of outer 
class called method inner class. 
 Syntax: 
 Allowed Modifiers: 
final, abstract, strictfp 
 Types of Members allowed: 
* non-static variable 
* non-static block 
* non-static method 
* constructor 
class A{ 
void m1(){ 
class B{} 
} 
} 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
19
Anonymous class (argument inner class) 
 It is a nameless subclass of some other existed 
class/interface. 
 Like other inner classes it is not individual class. 
 Using anonymous class we can do 3 things at a time- 
1. Inner class creation as a subclass of outer class. 
2. Overriding outer class method. 
3. Creating and sending its object as argument or 
return type to another method. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
20
 Syntax: 
new outerclassname(){ 
//overriding outer class methods 
} 
 Allowed Modifiers: 
no modifier is allowed 
 Types of Members allowed: 
* non-static variables 
* non-static blocks 
* non-static methods 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
21
Cohesion,Coupling 
And Garbage Collection 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
22
Cohesion 
Defintion:- 
Cohesion means that a certain class performs a set of 
closely related actions. Cohesion focuses on how 
single class is designed. 
Types of Cohesion:- 
 High Cohesion 
 Low Cohesion 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
23
High cohesion:- 
High cohesion is when you have a class that does a 
well defined job. 
Low cohesion:- 
Low cohesion is when a class does a lot of jobs that 
don't have much in common. 
Higher the cohesiveness of the class, better is the OO 
design. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
24
 Example:- 
 You have a class that adds two numbers, but the 
same class creates a window displaying the result. 
 This is a low cohesive class because the window 
and the adding operation don't have much in 
common. 
 The window is the visual part of the program and 
the adding function is the logic behind it. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
25
What is Coupling? 
Coupling:- 
 Coupling is the degree to which one class knows 
about another class. 
 It refers to how related are two classes / modules 
and how dependent they are on each other. 
Types of Coupling:- 
 Tight coupling 
 Loose coupling 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
26
Tight coupling:- 
Tight coupling is when a group of classes are 
highly dependent on one another. 
Loose coupling:- 
 Loose coupling would mean that changing 
something major in one class should not affect the 
other. 
 Generally, good OO design should be loosely 
coupled and highly cohesive. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
27
What is Garbage Collection ? 
 Garbage collection is the process of identifying 
which objects are in use and which are not, and 
deleting the unused objects. 
 In Java, process of deallocating memory is handled 
automatically by the garbage collector. 
 This enables faster development with less code, 
eliminate memory leaks and other memory-related 
problems. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
28
The ways to make an Object 
eligible for GC:- 
Even though the programmer is not responsible for 
distruction of Object. It is a good programming 
practice to make our object is eligible for the 
Garbage Collection, if it is no longer required. 
 Nullifying the reference variable :- 
 Re-assigning the reference variable:- 
 The Object created inside a method… are by 
default eligible for GC. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
29
When the Garbage Collector Runs? 
 The garbage collector is under the control of the JVM. 
 The JVM will typically run the garbage collector when it 
senses that memory is running low. 
 User can request the JVM for garbage Collection 
by Calling “System.gc()”. 
 User can rely on ‘System.gc()’ to free up enough memory 
without worrying for running out of memory. 
 But the garbage collector will run before it throws an 
OutOfMemoryException. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
30
Role of finalize() method in GC 
 Java has a mechanism to run some code just before 
your object is deleted by the garbage collector. 
 This code is located in a method named finalize() 
that all classes inherit from class Object. 
 For any given object, finalize() will be called only 
once (at most) by the garbage collector. 
 Calling finalize() can actually result in saving an 
object from deletion. 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
31
“Thank You” 
Satyam Shrivastav 
http://programmingpoints.blogspot.in/ 
32

Weitere ähnliche Inhalte

Was ist angesagt?

Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming languageVasavi College of Engg
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.netsuraj pandey
 
9781285852744 ppt ch14
9781285852744 ppt ch149781285852744 ppt ch14
9781285852744 ppt ch14Terry Yoast
 
Java and its features
Java and its featuresJava and its features
Java and its featuresPydi Nikhil
 
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...Edureka!
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Javaparag
 
Compiler.design.in.c.docs
Compiler.design.in.c.docsCompiler.design.in.c.docs
Compiler.design.in.c.docsAbid Syed
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz SAurabh PRajapati
 
INTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONINTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONAjit Yadav
 

Was ist angesagt? (20)

Introduction to java programming part 2
Introduction to java programming  part 2Introduction to java programming  part 2
Introduction to java programming part 2
 
Java chapter 1
Java   chapter 1Java   chapter 1
Java chapter 1
 
Java swing 1
Java swing 1Java swing 1
Java swing 1
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
 
9781285852744 ppt ch14
9781285852744 ppt ch149781285852744 ppt ch14
9781285852744 ppt ch14
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 
Spring IO 2015 Spock Workshop
Spring IO 2015 Spock WorkshopSpring IO 2015 Spock Workshop
Spring IO 2015 Spock Workshop
 
Java and its features
Java and its featuresJava and its features
Java and its features
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
java token
java tokenjava token
java token
 
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
 
JVM
JVMJVM
JVM
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Java
 
Java essential notes
Java essential notesJava essential notes
Java essential notes
 
Compiler.design.in.c.docs
Compiler.design.in.c.docsCompiler.design.in.c.docs
Compiler.design.in.c.docs
 
Features of java
Features of javaFeatures of java
Features of java
 
3. jvm
3. jvm3. jvm
3. jvm
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
 
INTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONINTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATION
 

Ähnlich wie Oops and enums

116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 eehomeworkping9
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and oodthan sare
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAhmed Nobi
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2Usman Mehmood
 
25 java interview questions
25 java interview questions25 java interview questions
25 java interview questionsMehtaacademy
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfbca23189c
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitishChaulagai
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+javaYe Win
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesSujit Majety
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptxmrxyz19
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdfParvizMirzayev2
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Ayes Chinmay
 

Ähnlich wie Oops and enums (20)

Core java questions
Core java questionsCore java questions
Core java questions
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 
Java basics
Java basicsJava basics
Java basics
 
Review oop and ood
Review oop and oodReview oop and ood
Review oop and ood
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
25 java interview questions
25 java interview questions25 java interview questions
25 java interview questions
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Java scjp-part1
Java scjp-part1Java scjp-part1
Java scjp-part1
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Suga java training_with_footer
Suga java training_with_footerSuga java training_with_footer
Suga java training_with_footer
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdf
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Java mcq
Java mcqJava mcq
Java mcq
 

Kürzlich hochgeladen

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxsomshekarkn64
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 

Kürzlich hochgeladen (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptx
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 

Oops and enums

  • 1. OOPS, ENUMS, Inner Classes, GarbageCollection Satyam Shrivastav http://programmingpoints.blogspot.in/ 1
  • 2. ASSOCIATION  Association is a relationship between two objects.  Objects might not be completely dependent on each other.  One-to-many, many-to-one, many-to-many all these words define an association between objects  Example: A Student and a Faculty are having an association. Satyam Shrivastav http://programmingpoints.blogspot.in/ 2
  • 3. AGGREGATION  A directional association between objects.  Aggregation can be considered as a “has-a” relationship.  Child object can also survive or exist without the enclosing class.  For Example, Room has a table, but the table can exist without the room. Satyam Shrivastav http://programmingpoints.blogspot.in/ 3
  • 4. COMPOSITION  A restricted aggregation is called composition.  The member object (part) cannot exist without the containing class.  For example, A class contains students. A student cannot exist without a class. There exists composition between class and students. Satyam Shrivastav http://programmingpoints.blogspot.in/ 4
  • 5. UML Diagrams of Relationships  Association Association is denoted by simple arrow  Aggregation aggregation is denoted by empty diamond head arrow  Composition composition is denoted by filled diamond head arrow Satyam Shrivastav http://programmingpoints.blogspot.in/ 5
  • 6. Difference Between Composition And Aggregation  When there is a composition between two objects, the composed object cannot exist without the other object.  In case of Aggregation, Though one object can contain the other object, there is no condition that the composed object must exist.  For Ex: Facebook has-a-User i.e. Aggregation Every User has a different Session i.e. Composition. Satyam Shrivastav http://programmingpoints.blogspot.in/ 6
  • 7. METHODS OVERRIDING  Overriding is a feature of OOP languages like Java that is related to run-time polymorphism.  Method overriding is when a child class redefines the same method as a parent class, with the same parameters.  The key benefit of overriding is the ability to define behavior that is specific to a particular subclass type. Satyam Shrivastav http://programmingpoints.blogspot.in/ 7
  • 8. The rules for overriding a method are as follows:  The argument list must exactly match that of the overridden method.  Overriding method CAN throw any unchecked runtime exception.  You cannot override a method marked final.  You cannot override a method marked static.  If a method can't be inherited, you cannot override it. Satyam Shrivastav http://programmingpoints.blogspot.in/ 8
  • 9. METHOD OVERLOADING  Overloading is also a feature of OOP languages like Java that is related to compile time (or static) polymorphism.  Method overloading is defining several methods in the same class, that accept different numbers and types of parameters.  In this case, the actual method called is decided at compile-time, based on the number and types of arguments. Satyam Shrivastav http://programmingpoints.blogspot.in/ 9
  • 10. Overloading Rules  Overloaded methods MUST change the argument list.  Overloaded methods CAN change the return type.  Overloaded methods CAN change the access modifier.  Overloaded methods CAN declare new or broader checked exceptions.  A method can be overloaded in the same class or in a subclass. Satyam Shrivastav http://programmingpoints.blogspot.in/ 10
  • 11. ENUM, INNER CLASSES Satyam Shrivastav http://programmingpoints.blogspot.in/ 11
  • 12. Enum  An enumeration, or “enum” is simply a set of constants to represent various values.  An enum type is a special data type that enables for a variable to be a set of predefined constants.  The variable must be equal to one of the values that have been predefined for it.  enums extend java.lang.Enum and implement java.lang.Comparable.  Hence, enums can be sorted.  Enums override toString() and provide valueOf(). Satyam Shrivastav http://programmingpoints.blogspot.in/ 12
  • 13. Defining Enum  Old way of doing it: public final int SPRING = 0; public final int SUMMER = 1; public final int FALL = 2; public final int WINTER = 3;  New way of doing it: enum <enumname>{} Satyam Shrivastav http://programmingpoints.blogspot.in/ 13
  • 14. Advantages  Enums provide compile-time type safety.  Enums provide a proper name space for the enumerated type.  Enums are robust.  Enum printed values are informative  Because enums are objects, you can put them in collections.  Because enums are classes, you can add fields and methods. Satyam Shrivastav http://programmingpoints.blogspot.in/ 14
  • 15. Inner Class  The class defined inside another class or interface is called inner class  We can also create an interface in another class or interface.  For example class Example{ class Sample{} } class Example{ interface Sample{} } interface Example{ class Sample{} } Satyam Shrivastav http://programmingpoints.blogspot.in/ 15
  • 16. Need of Inner Class  Inner class is used for creating an object logically inside another object with clear separation of properties region.  A inner class has access to the variables and methods of the outer class, even if they are declared private.  Nested classes can be hidden from other classes in the same package. Satyam Shrivastav http://programmingpoints.blogspot.in/ 16
  • 17. Nested class (static inner class)  The inner class defined at class level with static keyword is called static inner class.  Syntax:  Allowed Modifiers: class Example{ static class A{} } private, protected, public, final, abstract, strictfp  Types of Members allowed: * static variable * non-static variable * static block * non-static block * static method * non-static method * main method * constructor Satyam Shrivastav http://programmingpoints.blogspot.in/ 17
  • 18. Inner class (non-static inner class)  The inner class defined at class level without static keyword is called non-static inner class.  Syntax:  Allowed Modifiers: private, protected, public, final, abstract, strictfp  Types of Members allowed: * non-static variable * non-static block * non-static method * constructor class Example{ class A{} } Satyam Shrivastav http://programmingpoints.blogspot.in/ 18
  • 19. Method Local class (local inner class)  The inner class defined inside a method of outer class called method inner class.  Syntax:  Allowed Modifiers: final, abstract, strictfp  Types of Members allowed: * non-static variable * non-static block * non-static method * constructor class A{ void m1(){ class B{} } } Satyam Shrivastav http://programmingpoints.blogspot.in/ 19
  • 20. Anonymous class (argument inner class)  It is a nameless subclass of some other existed class/interface.  Like other inner classes it is not individual class.  Using anonymous class we can do 3 things at a time- 1. Inner class creation as a subclass of outer class. 2. Overriding outer class method. 3. Creating and sending its object as argument or return type to another method. Satyam Shrivastav http://programmingpoints.blogspot.in/ 20
  • 21.  Syntax: new outerclassname(){ //overriding outer class methods }  Allowed Modifiers: no modifier is allowed  Types of Members allowed: * non-static variables * non-static blocks * non-static methods Satyam Shrivastav http://programmingpoints.blogspot.in/ 21
  • 22. Cohesion,Coupling And Garbage Collection Satyam Shrivastav http://programmingpoints.blogspot.in/ 22
  • 23. Cohesion Defintion:- Cohesion means that a certain class performs a set of closely related actions. Cohesion focuses on how single class is designed. Types of Cohesion:-  High Cohesion  Low Cohesion Satyam Shrivastav http://programmingpoints.blogspot.in/ 23
  • 24. High cohesion:- High cohesion is when you have a class that does a well defined job. Low cohesion:- Low cohesion is when a class does a lot of jobs that don't have much in common. Higher the cohesiveness of the class, better is the OO design. Satyam Shrivastav http://programmingpoints.blogspot.in/ 24
  • 25.  Example:-  You have a class that adds two numbers, but the same class creates a window displaying the result.  This is a low cohesive class because the window and the adding operation don't have much in common.  The window is the visual part of the program and the adding function is the logic behind it. Satyam Shrivastav http://programmingpoints.blogspot.in/ 25
  • 26. What is Coupling? Coupling:-  Coupling is the degree to which one class knows about another class.  It refers to how related are two classes / modules and how dependent they are on each other. Types of Coupling:-  Tight coupling  Loose coupling Satyam Shrivastav http://programmingpoints.blogspot.in/ 26
  • 27. Tight coupling:- Tight coupling is when a group of classes are highly dependent on one another. Loose coupling:-  Loose coupling would mean that changing something major in one class should not affect the other.  Generally, good OO design should be loosely coupled and highly cohesive. Satyam Shrivastav http://programmingpoints.blogspot.in/ 27
  • 28. What is Garbage Collection ?  Garbage collection is the process of identifying which objects are in use and which are not, and deleting the unused objects.  In Java, process of deallocating memory is handled automatically by the garbage collector.  This enables faster development with less code, eliminate memory leaks and other memory-related problems. Satyam Shrivastav http://programmingpoints.blogspot.in/ 28
  • 29. The ways to make an Object eligible for GC:- Even though the programmer is not responsible for distruction of Object. It is a good programming practice to make our object is eligible for the Garbage Collection, if it is no longer required.  Nullifying the reference variable :-  Re-assigning the reference variable:-  The Object created inside a method… are by default eligible for GC. Satyam Shrivastav http://programmingpoints.blogspot.in/ 29
  • 30. When the Garbage Collector Runs?  The garbage collector is under the control of the JVM.  The JVM will typically run the garbage collector when it senses that memory is running low.  User can request the JVM for garbage Collection by Calling “System.gc()”.  User can rely on ‘System.gc()’ to free up enough memory without worrying for running out of memory.  But the garbage collector will run before it throws an OutOfMemoryException. Satyam Shrivastav http://programmingpoints.blogspot.in/ 30
  • 31. Role of finalize() method in GC  Java has a mechanism to run some code just before your object is deleted by the garbage collector.  This code is located in a method named finalize() that all classes inherit from class Object.  For any given object, finalize() will be called only once (at most) by the garbage collector.  Calling finalize() can actually result in saving an object from deletion. Satyam Shrivastav http://programmingpoints.blogspot.in/ 31
  • 32. “Thank You” Satyam Shrivastav http://programmingpoints.blogspot.in/ 32