SlideShare a Scribd company logo
2
Constructors
 A special type of method that enables an object to initialize itself when it is
created
 Constructors have the same name as the class itself
 They do not specify a return type, not even void because they return the
instance of the class itself.
 It is called constructor because it constructs the values at the time of object
creation
Most read
11
Java Garbage Collection
 Java garbage collection is the process by which Java programs perform
automatic memory management.
 Java programs compile to bytecode that can be run on a Java Virtual
Machine, or JVM for short.
 When Java programs run on the JVM, objects are created on the heap,
which is a portion of memory dedicated to the program.
 Eventually, some objects will no longer be needed. The garbage collector
finds these unused objects and deletes them to free up memory.
Most read
18
 The strings are objects in java of the class ‘String’.
System.out.println(“Welcome to java”);
The string “welcome to java” is automatically converted into a string
object by java.
 A string in java is not a character array and it is not terminated with
“NULL”.
Most read
object oriented programming using java, second sem BCA,UoM
Constructors
 A special type of method that enables an object to initialize itself when it is
created
 Constructors have the same name as the class itself
 They do not specify a return type, not even void because they return the
instance of the class itself.
 It is called constructor because it constructs the values at the time of object
creation
Example:
class Rectangle
{
int length;
int width;
Rectangle (int x, int y) // Defining constructor
{
length=x;
width=y;
}
int rectArea()
{
return (length * width);
}
}
Class RectangleArea
{
public static void main(string a[ ])
{
Rectangle rect1=new Rectangle(15,10); //calling constructors
int area1=rect1.rectArea( );
System.out.println(“Area1= ” +area1);
}
}
Types of Constructor
 In Java, constructors can be divided into three types:
1. No-Arg Constructor
 If a constructor does not accept any parameters, it is known as
a no-argument constructor.
 Ex: class Data
{
Data()
{
System.out.println("No-Args Constructor");
}
public static void main(String[] args)
{
Data d = new Data();
}
}
2. Parameterized Constructor
 A Java constructor can also accept one or more parameters. Such
constructors are known as parameterized constructors (constructors
with parameters).
class Data
{
int num1, num2;
Data(int m,int n)
{
num1=m;
num2=n;
}
public static void main(String[] args)
{
Data d = new Data(10,20)
}
}
3. Default Constructor
 If we do not create any constructor, the Java compiler automatically creates a no-arg
constructor during the execution of the program.
 This constructor is called the default constructor.
 Ex: class Data
{
public static void main(String[] args)
{
Data d = new Data();
}
}
 Default constructor only role is to initialize the object and return it to the calling code.
 Default constructor is always without argument and provided by java compiler only
when there is no existing constructor defined.
Overloaded constructor
 Two or more constructors having different parameters is called overloaded
constructor.
 Ex:
class Demo
{
int a,b,c;
Demo()
{
a=1; b=2; c=3;
}
Demo(int x, int y)
{
a=x; b=y; c=20;
}
Demo(int x, int y, int z)
{
a=x; b=y; c=z;
}
}
class Main
{
public static void main(String args[])
{
Demo obj1=new Demo();
Demo obj2=new Demo(10,20);
Demo obj3=new Demo(10,20,30);
}
}
object oriented programming using java, second sem BCA,UoM
Java Garbage Collection
 Java garbage collection is the process by which Java programs perform
automatic memory management.
 Java programs compile to bytecode that can be run on a Java Virtual
Machine, or JVM for short.
 When Java programs run on the JVM, objects are created on the heap,
which is a portion of memory dedicated to the program.
 Eventually, some objects will no longer be needed. The garbage collector
finds these unused objects and deletes them to free up memory.
Finalizer
• Finalizer methods are almost the opposite of constructor methods.
• A constructor method is used to initialize an object, while finalizer methods
are called just before the object is garbage-collected and its memory
reclaimed.
• The syntax of the finalizer method is simply finalize().
• The Object class defines a default finalizer method.
• To create a finalizer method, override the finalize() method using the
following signature:
 The body of finalize() method can include several objects including
super.finalize(). This object allows the parent class to finalize an object, if
necessary.
 The finalize() method can be called at any time; however, calling finalize()
does not trigger an object to be garbage-collected. Only removing all
references to an object will cause it to be marked for deleting.
 Finalizer methods are best used for optimizing the removal of an object
(for example, by removing references to other objects) by releasing
external resources that have been acquired (for example, external files), or
for other behaviors that may make it easier for that object to be removed .
Visibility modifiers
 Java provides entities called “Access Modifiers or access specifiers” that help
us to restrict the scope or visibility of a package, class, constructor, methods,
variables, or other data members. These access modifiers are also
called “Visibility Specifiers”.
 The access specifiers also determine which data members (methods or fields)
of a class can be accessed by other data members of classes or packages etc.
 To ensure encapsulation and reusability, these access specifiers/modifiers are
an integral part of object-oriented programming.
Visibility modifiers in Java
1. Default: Whenever a specific access level is not specified, then it is assumed
to be ‘default’. The scope of the default level is within the package.
2. Public: This is the most common access level and whenever the public
access specifier is used with an entity, that particular entity is accessible
throughout from within or outside the class, within or outside the package,
etc.
3. Protected: The protected access level has a scope that is within the package.
A protected entity is also accessible outside the package through inherited
class or child class.
4. Private: When an entity is private, then this entity cannot be accessed
outside the class. A private entity can only be accessible from within the class.
object oriented programming using java, second sem BCA,UoM
Inbuilt classes - String
 The String is a built-in class in Java to store a sequence of characters between
double-quotes.
 It’s under java.lang package so we don’t have to import, it will be imported
automatically for every class.
 Example: class Main
{
public static void main(String[] args)
{
String str = "apple";
System.out.println(str); // apple
String name = new String("John");
System.out.println(name); // John
}
}
 The strings are objects in java of the class ‘String’.
System.out.println(“Welcome to java”);
The string “welcome to java” is automatically converted into a string
object by java.
 A string in java is not a character array and it is not terminated with
“NULL”.

More Related Content

What's hot (20)

Pasif Bilgi Toplama
Pasif Bilgi ToplamaPasif Bilgi Toplama
Pasif Bilgi Toplama
Melek Nurten Yavuz
 
Input Space Partitioning
Input Space PartitioningInput Space Partitioning
Input Space Partitioning
Riyad Parvez
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
BG Java EE Course
 
Support Vector Machines ( SVM )
Support Vector Machines ( SVM ) Support Vector Machines ( SVM )
Support Vector Machines ( SVM )
Mohammad Junaid Khan
 
Java Final Keyword
Java Final KeywordJava Final Keyword
Java Final Keyword
Ducat India
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
JDK,JRE,JVM
JDK,JRE,JVMJDK,JRE,JVM
JDK,JRE,JVM
Cognizant
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
Somya Bagai
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
yugandhar vadlamudi
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Interface in java
Interface in javaInterface in java
Interface in java
Kavitha713564
 
Java Notes
Java Notes Java Notes
Java Notes
Sreedhar Chowdam
 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static Keyword
Dhrumil Panchal
 
Accessing Hardware on Android
Accessing Hardware on AndroidAccessing Hardware on Android
Accessing Hardware on Android
Gary Bisson
 
Main method in java
Main method in javaMain method in java
Main method in java
Hitesh Kumar
 
Intro to GemStone/S
Intro to GemStone/SIntro to GemStone/S
Intro to GemStone/S
ESUG
 
Prototype Pattern
Prototype PatternPrototype Pattern
Prototype Pattern
Ider Zheng
 
Android Storage - StorageManager & OBB
Android Storage - StorageManager & OBBAndroid Storage - StorageManager & OBB
Android Storage - StorageManager & OBB
William Lee
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
Mark Niebergall
 
Input Space Partitioning
Input Space PartitioningInput Space Partitioning
Input Space Partitioning
Riyad Parvez
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Java Final Keyword
Java Final KeywordJava Final Keyword
Java Final Keyword
Ducat India
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
Somya Bagai
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Accessing Hardware on Android
Accessing Hardware on AndroidAccessing Hardware on Android
Accessing Hardware on Android
Gary Bisson
 
Main method in java
Main method in javaMain method in java
Main method in java
Hitesh Kumar
 
Intro to GemStone/S
Intro to GemStone/SIntro to GemStone/S
Intro to GemStone/S
ESUG
 
Prototype Pattern
Prototype PatternPrototype Pattern
Prototype Pattern
Ider Zheng
 
Android Storage - StorageManager & OBB
Android Storage - StorageManager & OBBAndroid Storage - StorageManager & OBB
Android Storage - StorageManager & OBB
William Lee
 

Similar to object oriented programming using java, second sem BCA,UoM (20)

UNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptxUNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
chetanpatilcp783
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
CJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxCJP Unit-1 contd.pptx
CJP Unit-1 contd.pptx
RAJASEKHARV10
 
unit 2 java.pptx
unit 2 java.pptxunit 2 java.pptx
unit 2 java.pptx
AshokKumar587867
 
Java
JavaJava
Java
nirbhayverma8
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java II
Ghadeer AlHasan
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
Kavindu Sachinthe
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Constructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object CreationConstructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object Creation
Geekster
 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
Ahmad sohail Kakar
 
Module 1.pptx
Module 1.pptxModule 1.pptx
Module 1.pptx
YakaviBalakrishnan
 
Lecture11.docx
Lecture11.docxLecture11.docx
Lecture11.docx
ASADAHMAD811380
 
Java - Basic Concepts
Java - Basic ConceptsJava - Basic Concepts
Java - Basic Concepts
Victer Paul
 
Class and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdfClass and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdf
sameer2543ynr
 
Class and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece departmentClass and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece department
om2348023vats
 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
UNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptxUNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
chetanpatilcp783
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
CJP Unit-1 contd.pptx
CJP Unit-1 contd.pptxCJP Unit-1 contd.pptx
CJP Unit-1 contd.pptx
RAJASEKHARV10
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java II
Ghadeer AlHasan
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
NitishChaulagai
 
Constructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object CreationConstructors In Java – Unveiling Object Creation
Constructors In Java – Unveiling Object Creation
Geekster
 
Java - Basic Concepts
Java - Basic ConceptsJava - Basic Concepts
Java - Basic Concepts
Victer Paul
 
Class and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdfClass and Object JAVA PROGRAMMING LANG .pdf
Class and Object JAVA PROGRAMMING LANG .pdf
sameer2543ynr
 
Class and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece departmentClass and Object.pptx from nit patna ece department
Class and Object.pptx from nit patna ece department
om2348023vats
 
Ad

More from ambikavenkatesh2 (19)

CN(BCS502) Module-4 _Transport Layer.pptx
CN(BCS502) Module-4 _Transport Layer.pptxCN(BCS502) Module-4 _Transport Layer.pptx
CN(BCS502) Module-4 _Transport Layer.pptx
ambikavenkatesh2
 
Module-3 Deadlocks.pptx BCS303 Operating system
Module-3 Deadlocks.pptx BCS303 Operating systemModule-3 Deadlocks.pptx BCS303 Operating system
Module-3 Deadlocks.pptx BCS303 Operating system
ambikavenkatesh2
 
V semester, computer networks BCS502 Module-2_DataLinkLayer
V semester, computer networks BCS502 Module-2_DataLinkLayerV semester, computer networks BCS502 Module-2_DataLinkLayer
V semester, computer networks BCS502 Module-2_DataLinkLayer
ambikavenkatesh2
 
Module-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptxModule-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptx
ambikavenkatesh2
 
computer networks lab program Bellman Ford.pptx
computer networks lab program Bellman Ford.pptxcomputer networks lab program Bellman Ford.pptx
computer networks lab program Bellman Ford.pptx
ambikavenkatesh2
 
Module-1.pptx Computer Networks BCS502 module-1 ppt
Module-1.pptx Computer Networks BCS502 module-1 pptModule-1.pptx Computer Networks BCS502 module-1 ppt
Module-1.pptx Computer Networks BCS502 module-1 ppt
ambikavenkatesh2
 
Module-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptxModule-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptx
ambikavenkatesh2
 
Concurrency Control in Databases.Database management systems
Concurrency Control in Databases.Database management systemsConcurrency Control in Databases.Database management systems
Concurrency Control in Databases.Database management systems
ambikavenkatesh2
 
Operating systems Lab program: to develop C program to implement process mana...
Operating systems Lab program: to develop C program to implement process mana...Operating systems Lab program: to develop C program to implement process mana...
Operating systems Lab program: to develop C program to implement process mana...
ambikavenkatesh2
 
MODULE-1_Operating System Services - ppt
MODULE-1_Operating System Services - pptMODULE-1_Operating System Services - ppt
MODULE-1_Operating System Services - ppt
ambikavenkatesh2
 
Module1_Decision Support and Business Intelligence.pptx
Module1_Decision Support and Business Intelligence.pptxModule1_Decision Support and Business Intelligence.pptx
Module1_Decision Support and Business Intelligence.pptx
ambikavenkatesh2
 
Transactions and concurrency control mechanisms in database management system
Transactions and concurrency control mechanisms in  database management systemTransactions and concurrency control mechanisms in  database management system
Transactions and concurrency control mechanisms in database management system
ambikavenkatesh2
 
data base management system notes on concurrency control
data base management system notes on concurrency controldata base management system notes on concurrency control
data base management system notes on concurrency control
ambikavenkatesh2
 
Unit1_Fundamentals of Information Technlogy
Unit1_Fundamentals of Information TechnlogyUnit1_Fundamentals of Information Technlogy
Unit1_Fundamentals of Information Technlogy
ambikavenkatesh2
 
Module-1 Data base management systems chap1-Introduction to database.pptx
Module-1 Data base management systems chap1-Introduction to database.pptxModule-1 Data base management systems chap1-Introduction to database.pptx
Module-1 Data base management systems chap1-Introduction to database.pptx
ambikavenkatesh2
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
ambikavenkatesh2
 
Tableau.pptx
Tableau.pptxTableau.pptx
Tableau.pptx
ambikavenkatesh2
 
ICT.pptx
ICT.pptxICT.pptx
ICT.pptx
ambikavenkatesh2
 
unit-1_Introduction to e-commerce.pptx
unit-1_Introduction to e-commerce.pptxunit-1_Introduction to e-commerce.pptx
unit-1_Introduction to e-commerce.pptx
ambikavenkatesh2
 
CN(BCS502) Module-4 _Transport Layer.pptx
CN(BCS502) Module-4 _Transport Layer.pptxCN(BCS502) Module-4 _Transport Layer.pptx
CN(BCS502) Module-4 _Transport Layer.pptx
ambikavenkatesh2
 
Module-3 Deadlocks.pptx BCS303 Operating system
Module-3 Deadlocks.pptx BCS303 Operating systemModule-3 Deadlocks.pptx BCS303 Operating system
Module-3 Deadlocks.pptx BCS303 Operating system
ambikavenkatesh2
 
V semester, computer networks BCS502 Module-2_DataLinkLayer
V semester, computer networks BCS502 Module-2_DataLinkLayerV semester, computer networks BCS502 Module-2_DataLinkLayer
V semester, computer networks BCS502 Module-2_DataLinkLayer
ambikavenkatesh2
 
Module-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptxModule-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptx
ambikavenkatesh2
 
computer networks lab program Bellman Ford.pptx
computer networks lab program Bellman Ford.pptxcomputer networks lab program Bellman Ford.pptx
computer networks lab program Bellman Ford.pptx
ambikavenkatesh2
 
Module-1.pptx Computer Networks BCS502 module-1 ppt
Module-1.pptx Computer Networks BCS502 module-1 pptModule-1.pptx Computer Networks BCS502 module-1 ppt
Module-1.pptx Computer Networks BCS502 module-1 ppt
ambikavenkatesh2
 
Module-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptxModule-1_Introduction to Data Communications.pptx
Module-1_Introduction to Data Communications.pptx
ambikavenkatesh2
 
Concurrency Control in Databases.Database management systems
Concurrency Control in Databases.Database management systemsConcurrency Control in Databases.Database management systems
Concurrency Control in Databases.Database management systems
ambikavenkatesh2
 
Operating systems Lab program: to develop C program to implement process mana...
Operating systems Lab program: to develop C program to implement process mana...Operating systems Lab program: to develop C program to implement process mana...
Operating systems Lab program: to develop C program to implement process mana...
ambikavenkatesh2
 
MODULE-1_Operating System Services - ppt
MODULE-1_Operating System Services - pptMODULE-1_Operating System Services - ppt
MODULE-1_Operating System Services - ppt
ambikavenkatesh2
 
Module1_Decision Support and Business Intelligence.pptx
Module1_Decision Support and Business Intelligence.pptxModule1_Decision Support and Business Intelligence.pptx
Module1_Decision Support and Business Intelligence.pptx
ambikavenkatesh2
 
Transactions and concurrency control mechanisms in database management system
Transactions and concurrency control mechanisms in  database management systemTransactions and concurrency control mechanisms in  database management system
Transactions and concurrency control mechanisms in database management system
ambikavenkatesh2
 
data base management system notes on concurrency control
data base management system notes on concurrency controldata base management system notes on concurrency control
data base management system notes on concurrency control
ambikavenkatesh2
 
Unit1_Fundamentals of Information Technlogy
Unit1_Fundamentals of Information TechnlogyUnit1_Fundamentals of Information Technlogy
Unit1_Fundamentals of Information Technlogy
ambikavenkatesh2
 
Module-1 Data base management systems chap1-Introduction to database.pptx
Module-1 Data base management systems chap1-Introduction to database.pptxModule-1 Data base management systems chap1-Introduction to database.pptx
Module-1 Data base management systems chap1-Introduction to database.pptx
ambikavenkatesh2
 
data structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysoredata structures using C 2 sem BCA univeristy of mysore
data structures using C 2 sem BCA univeristy of mysore
ambikavenkatesh2
 
unit-1_Introduction to e-commerce.pptx
unit-1_Introduction to e-commerce.pptxunit-1_Introduction to e-commerce.pptx
unit-1_Introduction to e-commerce.pptx
ambikavenkatesh2
 
Ad

Recently uploaded (20)

Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ FINALS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 

object oriented programming using java, second sem BCA,UoM

  • 2. Constructors  A special type of method that enables an object to initialize itself when it is created  Constructors have the same name as the class itself  They do not specify a return type, not even void because they return the instance of the class itself.  It is called constructor because it constructs the values at the time of object creation
  • 3. Example: class Rectangle { int length; int width; Rectangle (int x, int y) // Defining constructor { length=x; width=y; } int rectArea() { return (length * width); } }
  • 4. Class RectangleArea { public static void main(string a[ ]) { Rectangle rect1=new Rectangle(15,10); //calling constructors int area1=rect1.rectArea( ); System.out.println(“Area1= ” +area1); } }
  • 5. Types of Constructor  In Java, constructors can be divided into three types: 1. No-Arg Constructor  If a constructor does not accept any parameters, it is known as a no-argument constructor.  Ex: class Data { Data() { System.out.println("No-Args Constructor"); } public static void main(String[] args) { Data d = new Data(); } }
  • 6. 2. Parameterized Constructor  A Java constructor can also accept one or more parameters. Such constructors are known as parameterized constructors (constructors with parameters). class Data { int num1, num2; Data(int m,int n) { num1=m; num2=n; } public static void main(String[] args) { Data d = new Data(10,20) } }
  • 7. 3. Default Constructor  If we do not create any constructor, the Java compiler automatically creates a no-arg constructor during the execution of the program.  This constructor is called the default constructor.  Ex: class Data { public static void main(String[] args) { Data d = new Data(); } }  Default constructor only role is to initialize the object and return it to the calling code.  Default constructor is always without argument and provided by java compiler only when there is no existing constructor defined.
  • 8. Overloaded constructor  Two or more constructors having different parameters is called overloaded constructor.  Ex: class Demo { int a,b,c; Demo() { a=1; b=2; c=3; } Demo(int x, int y) { a=x; b=y; c=20; }
  • 9. Demo(int x, int y, int z) { a=x; b=y; c=z; } } class Main { public static void main(String args[]) { Demo obj1=new Demo(); Demo obj2=new Demo(10,20); Demo obj3=new Demo(10,20,30); } }
  • 11. Java Garbage Collection  Java garbage collection is the process by which Java programs perform automatic memory management.  Java programs compile to bytecode that can be run on a Java Virtual Machine, or JVM for short.  When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program.  Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory.
  • 12. Finalizer • Finalizer methods are almost the opposite of constructor methods. • A constructor method is used to initialize an object, while finalizer methods are called just before the object is garbage-collected and its memory reclaimed. • The syntax of the finalizer method is simply finalize(). • The Object class defines a default finalizer method. • To create a finalizer method, override the finalize() method using the following signature:
  • 13.  The body of finalize() method can include several objects including super.finalize(). This object allows the parent class to finalize an object, if necessary.  The finalize() method can be called at any time; however, calling finalize() does not trigger an object to be garbage-collected. Only removing all references to an object will cause it to be marked for deleting.  Finalizer methods are best used for optimizing the removal of an object (for example, by removing references to other objects) by releasing external resources that have been acquired (for example, external files), or for other behaviors that may make it easier for that object to be removed .
  • 14. Visibility modifiers  Java provides entities called “Access Modifiers or access specifiers” that help us to restrict the scope or visibility of a package, class, constructor, methods, variables, or other data members. These access modifiers are also called “Visibility Specifiers”.  The access specifiers also determine which data members (methods or fields) of a class can be accessed by other data members of classes or packages etc.  To ensure encapsulation and reusability, these access specifiers/modifiers are an integral part of object-oriented programming.
  • 15. Visibility modifiers in Java 1. Default: Whenever a specific access level is not specified, then it is assumed to be ‘default’. The scope of the default level is within the package. 2. Public: This is the most common access level and whenever the public access specifier is used with an entity, that particular entity is accessible throughout from within or outside the class, within or outside the package, etc. 3. Protected: The protected access level has a scope that is within the package. A protected entity is also accessible outside the package through inherited class or child class. 4. Private: When an entity is private, then this entity cannot be accessed outside the class. A private entity can only be accessible from within the class.
  • 17. Inbuilt classes - String  The String is a built-in class in Java to store a sequence of characters between double-quotes.  It’s under java.lang package so we don’t have to import, it will be imported automatically for every class.  Example: class Main { public static void main(String[] args) { String str = "apple"; System.out.println(str); // apple String name = new String("John"); System.out.println(name); // John } }
  • 18.  The strings are objects in java of the class ‘String’. System.out.println(“Welcome to java”); The string “welcome to java” is automatically converted into a string object by java.  A string in java is not a character array and it is not terminated with “NULL”.