Mastering OOP Fundamentals: Objects, Classes, and Java Terms
Classified in Computers
Written on in
English with a size of 2.57 KB
Core Concepts of Object-Oriented Programming (OOP)
Object Characteristics: State and Behavior
Objects in real life possess two primary characteristics: state and behavior.
- State: Defined by a set of parameters that define and distinguish an object from others of the same type.
- Behavior: Allows distinguishing objects of different types (e.g., a dog object behaves differently than a cat object).
Class Structure and Components
A class is a template or prototype that defines a particular object type. A class defines the attributes and methods that an object will possess.
Defining Object Components
- Attributes or Member Variables
- The parameters or variables that define the state of an object.
- Methods or Member Functions
- Actions that objects can perform.
- Accessing Attributes
- Attributes of an object are accessed using Methods.
- Object Communication
- Objects communicate with each other via messages.
- Methods in OOP
- Actions that can be performed with objects.
Key OOP Mechanisms
Method Overloading
When a class has methods with the same name but differing either in the number or type of parameters, this is called Method Overloading.
Encapsulation (Information Hiding)
An object normally has a public part used by other objects for interaction, and a hidden part to conceal implementation details. This concept is known as Encapsulation.
Inheritance
A fundamental OOP mechanism defined as the transmission of characteristics (methods and attributes) from parent classes to child classes is Inheritance.
Java Specific Concepts
Java Servlets
A Java Servlet is a Java application that runs on a server, handling requests (pleas) from a client (typically a web browser), and lacks a graphical interface.
Java Applets
Java Applets are dynamic and interactive programs that run within a web page loaded by a web browser.
Garbage Collection
The Java procedure that automatically locates and removes memory that is no longer needed. This process is performed without the need for explicit calls: Garbage Collector.
Variable Initialization in the Main Class
The correct approach is to declare variables in the class scope and assign values or initialize them within the constructor.