0% found this document useful (0 votes)
19 views5 pages

Dcit50 Reviewer

Uploaded by

dinglasnella01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

Dcit50 Reviewer

Uploaded by

dinglasnella01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

DCIT50 – REVIEWER  The process of creating and manipulating

objects through code, applying the


BASIC JAVA OOP CONCEPTS principles of OOP (encapsulation,
inheritance, polymorphism, and
OBJECT-ORIENTED PROGRAMMING
abstraction).
 is a computer programming model that
organizes software design around data, or OBJECT ORIENTED PROGRAMMING
objects, rather than functions and logic. An STRUCTURE
object can be defined as a data field that
has unique attributes and behavior. OOP CLASSES
models real-world entities and relationships  are user-defined data types that act as the
through objects, which represent things with blueprint for individual objects, attributes
attributes (properties) and behaviors and methods.
(methods).
 The first step in OOP is to collect all of the OBJECTS
objects a programmer wants to manipulate  are instances of a class created with
and identify how they relate to each other -- specifically defined data. Objects can
an exercise known as data modeling. correspond to real-world objects or an
abstract entity. When class is defined
OBJECT initially, the description is the only object
 is a self-contained entity that contains that is defined.
Attributes (data) and Methods (functions). It
is also an instance of a class which is a METHODS
blueprint that defines what attributes and  are functions that objects can perform.
behaviors the objects of that type will have. They are defined inside a class that
 Represents a real-world entity or concept in describe the behaviors of an object. Each
the system, with data (attributes) and method contained in class definitions starts
behaviors (methods). with a reference to an instance object.
Additionally, the subroutines contained in
ORIENTED an object are called instance methods.
 means the programming is focused or Programmers use methods for reusability or
organized around objects. Instead of keeping functionality encapsulated inside
structuring a program around procedures or one object at a time.
functions, as in procedural programming,
OOP organizes software development ATTRIBUTES
around objects and the relationships  represents the state of an object. In other
between them. words, they are the characteristics that
 The program is organized around objects distinguish classes. Objects have data
and their interactions, rather than stored in the attributes field. Class attributes
procedures or functions. belong to the class itself and are defined in
the class template.
PROGRAMMING
 refers to the actual process of writing code. FOUR PILLARS OF OOP:
In Object-Oriented Programming, you write  ENCAPSULATION
code that defines objects and how they  ABSTRACTION
interact. It uses OOP principles  INHERITANCE
(encapsulation, inheritance, polymorphism,  POLYMORPHISM
and abstraction) to solve problems.
ENCAPSULATION  OOPs provide code reusability so that a
 is a process of binding data members programmer can reuse an existing code.
(attributes) and methods together. The  OOPs help us to keep the important data
encapsulation restricts direct access to hidden.
important data.
JAVA NAMING CONVENTIONS
ABSTRACTION
 is a technique of hiding internal details and NAMING CONVENTIONS
showing functionalities. The abstract  are a set of guidelines that developers
classes and interfaces are used to achieve follow to write clear and readable code.
abstraction in Java. While they are not enforced by the
compiler, following these conventions
INHERITANCE improves code readability and
 is a process by which we can reuse the maintainability.
functionalities of existing classes to new
classes. In the concept of inheritance, there ADVANTAGED OF NAMING CONVENTIONS
are two terms base (parent) class and IN JAVA
derived (child) class. When a class is
inherited from another class (base class), it READABILITY
(derived class) obtains all the properties  Consistent naming makes it easier for
and behaviors of the base class. developers to read and understand code.

POLYMORPHISM MAINTAINABILITY
 The term "polymorphism" means "many  Teams can work more effectively together
forms". In object-oriented programming, when they follow common conventions.
polymorphism is useful when you want to
create multiple forms with the same name AVOIDING AMBIGUITY
of a single entity. To implement  Clear, descriptive names reduce confusion
polymorphism in Java, we use two about what a class, method, or variable
concepts method overloading and method does
overriding.
 METHOD OVERLOADING - is INDUSTRY STANDARDS
performed in the same class where we  Following widely accepted conventions
have multiple methods with the same ensures that your code can be easily
name but different parameters understood by other developers familiar
 METHOD OVERRIDING - is performed with Java.
by using the inheritance where we can
have multiple methods with the same OBJECT AND CLASSES IN JAVA
name in parent and child classes.
CLASSES AND OBJECTS
ADVANTAGES OF OOP OVER  are basic concepts of Object Oriented
PROCEDURE-ORIENTED PROGRAMMING Programming (OOPs) that are used to
LANGUAGE represent real-world concepts and entities.
 The implementations of OOPs concepts are  The class represents a group of objects
easier. having similar properties and behavior.
 The execution of the OOPs is faster than
procedural-oriented programming. JAVA CLASSES
 A class in Java is a set of objects which  PUBLIC - Accessible from any other
shares common characteristics/ behavior class.
and common properties/ attributes. It is a  PRIVATE - Accessible only within the
user-defined blueprint or prototype from same class
which objects are created.  PROTECTED - Accessible within the
same package or subclasses.
PROPERTIES OF JAVA CLASSES
 A class does not take any byte of memory. class <class_name>
 A class is just like a real-world entity, but it  - is the name you give to the class, which
is not a real-world entity. It's a blueprint should start with a capital letter as per Java
where we specify the functionalities. naming conventions.
 A class contains mainly two things:
Methods and Data Members. data member
 A class can also be a nested class.  - These are variables declared inside the
 Classes follow all of the rules of OOPs such class that represent the attributes or
as inheritance, encapsulation, abstraction, properties of the objects created from the
etc. class.

TYPES OF CLASS VARIABLES Method


 – it define behaviors or actions that objects
LOCAL VARIABLES of the class can perform. Methods contain
 Variables defined inside methods, code that can be called or invoked to
constructors or blocks are called local perform certain tasks.
variables. The variable will be declared and
initialized within the method and the Constructor
variable will be destroyed when the method  - A constructor is a special method used to
has completed. initialize objects. It has the same name as
the class and no return type. When an
INSTANCE VARIABLES object is created, the constructor is called to
 - Instance variables are variables within a set up initial values for the object's data
class but outside any method. These members.
variables are initialized when the class is
instantiated. Instance variables can be Nested class
accessed from inside any method,  - is a class defined within another class. It
constructor or blocks of that particular class can be useful for logically grouping classes
that are only used in one place or
CLASS VARIABLES enhancing encapsulation.
 Class variables are variables declared  Static Nested Class - A static class
within a class, outside any method, with the inside another class. It doesn’t need an
static keyword. instance of the outer class to be
created.
STRUCTURE OF CLASS DECLARATION IN  Inner Class: A non-static class inside
JAVA another class. It requires an instance of
the outer class to be created.
ACCESS MODIFIER
 control the visibility of classes, methods, Interface
and variables.  - is a reference type that contains only
abstract methods (methods without a body)
and constants. It is a way to define a
contract that implementing classes must STRUCTURE OF OBJECT DECLARATION
follow. IN JAVA

JAVA OBJECTS Class_name


 An object in Java is a basic unit of Object-  This is the name of the class from which
Oriented Programming and represents real- you are creating an object. It represents the
life entities. Objects are the instances of a blueprint or template for the object.
class that are created to use the attributes
and methods of a class. A typical Java object_name
program creates many objects, which as  This is the name you are giving to the
you know, interact by invoking methods. object you are creating. It acts as a
reference to the object in memory, allowing
CHARACTERISTICS OF AN OBJECT you to interact with the object's data
members and methods.
State
 It is represented by attributes of an object. It new keyword
also reflects the properties of an object.  is used to allocate memory and initialize a
new object of the class.
Behavior
 It is represented by the methods of an Class_name([parameters])
object. It also reflects the response of an  This is a call to the constructor of the class
object with other objects.
JAVA CONSTRUCTOR
Identity  Java Constructors are special types of
 It gives a unique name to an object and methods that are used to initialize an object
enables one object to interact with other when it is created. It has the same name as
objects. its class and is syntactically similar to a
method. However, constructors have no
WAYS OF INITIALIZING OBJECT IN JAVA explicit return type (no void).

Using new keyword TYPES OF JAVA CONSTRUCTORS


 - It is the most common and general way to  Default Constructor
create an object in Java.  No-Args Constructor
 Parameterized Constructor
Using Class.forName(String className)
method DEFAULT CONSTRUCTOR
 - returns the Class object associated with  If we do not create any constructor, the
the class with the given string name Java compiler automatically creates a no-
arg constructor during the execution of the
Using clone() method program. This constructor is called the
 - clone() method is present in the Object default constructor.
class. It creates and returns a copy of the Takeaways:
object.  Does not take any arguments.
 Java automatically inserts a default
Deserialization constructor behind the scenes.
 - De-serialization is a technique of reading
an object from the saved state in a file NO-ARGS CONSTRUCTOR
 Similar to methods, a Java constructor may
or may not have any parameters
(arguments). If a constructor does not
accept any parameters, it is known as a no-
argument constructor. By using the No-Args
constructor you can initialize the class data
members and perform various activities that
you want on object creation.
Takeaways:
 It does not accept any arguments
 It initializes the object, typically setting
default or predefined values for the
instance variables.

PARAMETERIZED CONSTRUCTOR
 A Java constructor can also accept one or
more parameters. Such constructors are
known as parameterized constructors
(constructors with parameters).
Takeaways:
 It accepts arguments (or parameters) to
initialize an object's instance variables. JAVA COPY CONSTRUCTOR
 It allows you to initialize an object with  Copy constructor is a special type of
specific values, making the object more constructor that creates a new object as a
flexible and dynamic. copy of an existing object. The copy
 You can have multiple parameterized constructor takes an object of the same
constructors in the same class (this is class as a parameter and duplicates its field
called constructor overloading) as long values into the new object. Java doesn’t
as each has a unique set of parameters. provide a built-in copy constructor like some
other programming languages (e.g., C++),
CONSTRUCTOR OVERLOADING but you can manually define one in your
 Constructor overloading in Java is a feature class.
that allows a class to have more than one
constructor, each with a different parameter
list (number or type of parameters). It
enables objects to be created in multiple
ways by providing different sets of data at
the time of object creation.

DIFFERENCE BETWEEN METHOD AND


CONSTRUCTOR

You might also like