OOP design Flashcards
Scanner
The scanner begins the analysis of the source
program by reading the input, character by
character, and grouping characters into
individual words and symbols (tokens)
Parser
Given a formal syntax specification (typically
as a context-free grammar [CFG] ), the
parser reads tokens and groups them into
units as specified by the productions of the
CFG being used.
➢As syntactic structure is recognized, the
parser either calls corresponding semantic
routines directly or builds a syntax tree.
Semantic Routines
Perform two functions
◼ Check the static semantics of each
construct
◼ Do the actual translation
◼ Intermediate representation is the representation
of the program in a language internal to the compiler
Optimizer
The IR code generated by the semantic routines is
analyzed and transformed into functionally equivalent
but improved IR code
This phase can be very complex and slow
->loop optimization, register allocation, code scheduling
Code Generator
➢Interpretive Code Generation
➢Grammar-Based Code Generator
Primitive vs Non-primitive (Object)
- Primitive types are predefined in Java.
- Non-primitive types are created by the programmer
and is not defined by Java (except for String). - Non-primitive types can be used to call methods to
perform certain operations, while primitive types
cannot. - A primitive type has always a value, while non-
primitive types can be null.
A collection is a unit
that contains a group of objects, e.g.,
a list of students …
* Java defines a collections framework since JDK 1.2,
which is a unified architecture for representing and
manipulating collections, allowing them to be
manipulated independent of the details of their
representation.
* Java collections framework contains:
* Interfaces
* Implementations
* Algorithms
Benefits of Java Collections Framework
- Reduced Development Effort – It comes with
almost all common types of collections and
useful methods to iterate and manipulate the
data. - Increased Quality – Using core collection
classes that are well tested increases our
program quality rather than using any home
developed data structure. - Reusability and Interoperability
public interface Iterable<T></T>
- T - the type of elements returned by the iterator
- Implementing this interface allows an object to be the
target of the “for-each loop” statement, i.e., allows it
to be iterated
Iterators
An Iterator is an object that enables you to traverse
through a collection and to remove elements from the
collection selectively, if desired. You get an Iterator for
a collection by calling its iterator() method. The
following is the Iterator interface.
Overriding (via inheritance)
Replacing an inherited method with another having the same signature
Overloading
Two or more methods with different signatures
Inheritance is transitive
An instance of class Parrot is also an instance of Bird, an instance
of Animal, …, and an instance of class Object
Overriding by Replacement
Defining Methods in the Child Class:
Overriding by Replacement
* A child class can override the definition of an inherited method in
favor of its own
* that is, a child can redefine a method that it inherits from its parent
* the new method must have the same signature as the parent’s method,
but can have different code in the body
* In java, all methods except of constructors override the methods of
their ancestor class by replacement. E.g.:
* the Animal class has method eat()
* the Bird class has method eat() and Bird extends Animal
* variable b is of class Bird, i.e. Bird b = …
* b.eat() simply invokes the eat() method of the Bird class
* If a method is declared with the final modifier, it cannot be
overridden
Overloading vs. Overriding
- Overloading deals with
multiple methods in the
same class with the same
name but different
signatures - Overloading lets you
define a similar operation
in different ways for
different data - Overriding deals with two
methods, one in a parent
class and one in a child
class, that have the same
signature - Overriding lets you define
a similar operation in
different ways for
different object types