INTRODUCTION TO OOP Flashcards
Describe object-oriented programming
A method of programming based on a hierarchy of classes with well defined and cooperating objects.
What is an object?
An object is an executable copy of a class. It can also be referred to as an instance
What are states and behaviors, give real world examples
For a dog:
states (breed, color, age, hungry) - nouns and adjectives
behaviors (barking, eating, fetching) -verbs
What are fields and methods?
- An object stores its state in fields and exposes its behavior through methods.
- Methods operate on an object’s internal state and IMPLEMENT object-to-object communication.
What is a class?
A blueprint from which objects are created. It defines the data and the methods to work on the data
What is a package and what is its importance?
- A package is a namespace that organizes a set of related classes and interfaces. (It is like different folders on our personal computer.)
- Packages are important for organization.
Where can one find a complete listing of all packages, interfaces, classes, fields, and methods supplied by the Java SE platform.
The Java Platform API Specification
*application programming interface
What is an interface?
- An interface is a group of related methods with empty bodies.
- Methods form the object’s interface with the outside world; e.g remote buttons, computer keyboards, e.t.c.
What are some characteristics of OOP?
- Encapsulation
- Inheritance
- Abstraction
- Polymorphism
- Message passing
- Garbage collection
Define encapsulation
- This is a concept that enables the hiding unnecessary details in classes and only providing a clear and simple interface for working with them.
- It is also called information hiding.
- An object must provide its users only with the essential information for manipulation, without the internal details.
What is inheritance
- Inheritance is a concept in OOP that enables new objects to take on the properties of existing objects.
- Object-oriented programming allows classes to ASSUME commonly used state and behavior from other classes.
- Inheritance is an “is a” relationship eg a dog is a animal; therefore it inherits the characteristics common to animals
What are the names of classes involved in inheritance?
- A class that is used as the basis for inheritance is called a superclass or base class.
- A class that inherits from a superclass is called a subclass or derived class.
- In Java, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses
What is abstraction?
The process of representing essential features without including background details or explanations / The process of defining the essential concepts while
ignoring the inessential details.
What are the types of abstraction?
- Data Abstraction
- Functional Abstraction
- Object Abstraction
What is polymorphism?
This is the ability to present the same interface for differing underlying forms.
What are the different types of polymorphism?
- Method overloading
* Method overriding
Describe garbage collection in OOP
This is a form of automatic memory management whereby the garbage collector attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program.
What is a variable?
A variable is a container that holds values that are used in a Java program
What are the different types of variables?
- Instance variables (non-static fields)
- Class variables (static fields)
- Local variables
- Parameters
Describe an instance variable (non-static field)
• Objects store their individual states in “non-static fields” (fields declared without the static keyword.)
• Non-static fields are also known as instance variables because their values are unique to each instance of a class (object)
• E.g., the different ages of new objects in a Registration system.
*immediately after class
Describe a class variable (static fields)
• A class variable is any field declared with the static modifier. • There is exactly one copy of this variable in existence in a class regardless of how many times the class has been instantiated. • The key word static is usually used to indicate static variables. *immediately after class EG static int data = 30;
Describe local variables
• These are variables that store temporary states.
• There is no special keyword designating a variable as local.
• Local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.
*Found within a method
What are parameters and where are they found?
• These are variables found within the parenthesis of different structs within a program.
• Examples of the structs where parameters are found include:
• Methods
• Constructors
*Found within ()
Give example (source code) showing the different types of variables
public class A { static int m=100;/static variable void method() { int n=90;/local variable } public static void main(String args[]) { int data=50;/instance variable } }//end of class
What are the rules for naming variables?
- Variable names are case-sensitive.
- Can begin with a letter, underscore or $
- Subsequent characters for a variable may be letters, digits, dollar signs, or underscore characters.
- When choosing a name for your variables, use full words instead of cryptic abbreviations
(self-documentation) - Variable names consisting of more than one word should be named, e.g. carSpeed or car_speed
What are the eight primitive data types in java?
- Byte
- Short
- Integer
- Long
- Float
- Double
- Boolean
- Character
What do data types determine?
the values it may contain, their sizes plus the operations that may be performed on it.
Define states and behaviors
States/attributes- built in characteristics of an object
behaviors- predefined functions
Briefly explain at least 4 object-oriented design concepts.
encapsulation, abstraction, inheritance, and polymorphism
why is java suitable for studying advanced OOP / What are the advantages of java?
- Java is simple. It is easy to learn, understand and debug.
- It makes it possible to write reusable and modular code
- Java reduces security threats and risks by avoiding the use of explicit pointers
- Java programs are cheap to develop and maintain as these programs are dependent on a specific hardware infrastructure to run. We can easily execute them on any machine that reduces the extra cost to maintain.
- Java offers a very effective boon to its users by providing the feature of platform independence that is Write Once Run Anywhere(WORA) feature.
- Java provides Automatic Garbage Collection run by the java virtual machine
What are the disadvantages of java?
- Java is slow and has a poor performance due to the extra level of compilation and abstraction by the JVM.
- Java provides no backup facility. Java mainly works on storage and not focuses on the backup of data
- Java requires a significant or major amount of memory space as compared to other languages like C and C++
- Java codes are verbose, meaning that there are many words in it and there are many long and complex sentences that are difficult to read and understand. This can reduce the readability of the code.