Skip to main content

Posts

click and get money <a href="https://www.vultr.com/?ref=7265462"><img src="https://www.vultr.com/media/banner_2.png" width="468" height="60"></a>

Abstraction

Abstraction means ignoring irrelevant features, properties, or functions and emphasizing the relevant ones...relevant to the given project (with an eye to future reuse in similar projects).

Encapsulation

You can take two views of an object: internal - the structure of its data, the algorithms used by its methods external - the interaction of the object with other objects in the program From the external view, an object is an encapsulated entity, providing services These services define the interface to the object An object should be self-governing Any changes to the object's state (its variables) should be accomplished by that object's methods We should make it difficult, if not impossible, for one object to "reach in" and alter another object's state The user, or client, of an object can request its services, but it should not have to be aware of how those services are accomplished (abstraction - hide details).

Polymorphism

Polymorphism Enables “programming in the general” The same invocation can produce “many forms” of results Interfaces Implemented by classes to assign common functionality to possibly unrelated classes  Polymorphism When a program invokes a method through a superclass variable, the correct subclass version of the method is called, based on the type of the reference stored in the superclass variable The same method name and signature can cause different actions to occur,  depending on the type of object on which the method is invoked Polymorphism enables programmers to deal in generalities and let the execution-time environment handle the specifics. Programmers can command objects to behave in manners appropriate to those objects, without knowing the types of the objects (as long as the objects belong to the same inheritance hierarchy).  Promotes extensibility New objects types can respond to existing method calls Can be incorporated into a system ...

inheritance in java

Inheritance allows a software developer to derive a new class from an existing one The existing class is called the parent class, or super class, or base class The derived class is called the child class or subclass. As the name implies, the child inherits characteristics of the parent That is, the child class inherits the methods and data defined for the parent class To tailor a derived class, the programmer can add new variables or methods, or can modify the inherited ones Software reuse is at the heart of inheritance By using existing software components to create new ones, we capitalize on all the effort that went into the design, implementation, and testing of the existing software Inheritance relationships often are shown graphically in a UML class diagram, with an arrow with an open arrowhead pointing to the parent class Examples  ex 1  ex 2

Java Platform Standard Edition 8 Documentation

Oracle has two products that implement Java Platform Standard Edition (Java SE) 8: Java SE Development Kit (JDK) 8 and Java SE Runtime Environment (JRE) 8. JDK 8 is a superset of JRE 8, and contains everything that is in JRE 8, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE 8 provides the libraries, the Java Virtual Machine (JVM), and other components to run applets and applications written in the Java programming language. Note that the JRE includes components not required by the Java SE specification, including both standard and non-standard Java components. The following conceptual diagram illustrates the components of Oracle's Java SE products: Description of Java Conceptual Diagram

History of Java

1990 Oak (interactive television, big failure) 1994 Java (for the Internet) Main feature: "Write Once, Run Any Where" => wrap the operating system so they all look the same Designed for A fresh start (no backward compatibility) “Pure” OOP: C++ Syntax, Smalltalk style Improvements over C++ much harder to write a bad program  Internet programming Very hard to create a virus  Run in a web browser (and at the server) There is a speed issue (from Java 1.3 and up much better) C# Microsoft's “Java-Killer” project release 2001 Language very similar to Java   Commen-Language Runtime (CLR) supports 30+ languages  

Java Program Structure

Code Example, Revisited

Polymorphism and Dynamic Binding

Polymorphism: One piece of code works with all shape objects. Dynamic binding: How polymorphism is implemented Take previous Shape class hierarchy  remove inheritance  remove general and abstract class Shape 

Generalization and Specialization

Generalization creates a concept with a broader scope. Specialization creates a concept with a narrower scope. Reusing the interface!  Inheritance: get the interface from the general class. Objects related by inheritance are all of the same type.

Aggregation and Decomposition

Idea: make new objects by combining existing objects. Reusing the implementation!  An aggregation consists of a number of (sub-)concepts which collectively is considered a new concept. A decomposition splits a single concept into a number of (sub-)concepts.

Phenomenon and Concept

A phenomenon is a thing in the “real” world that has individual existence. an object A concept is a generalization, derived from a set of phenomena and based on the common properties of these phenomena. a class Characteristics of a concept  A name Intension, the set of properties of the phenomenon  Extension, the set of phenomena covered by the concept  Classification and Exemplification, Examples • hat, 23, 34, mouse, telephone, book, 98, 45.34, hello numbers: 23, 34, 98, 45.34  words: hat, mouse, telephone, book, hello mouse, tyrannosaurus rex, allosaurus, elephant, velociraptor dinosaur: tyrannosaurus rex, allosaurus, velociraptor mammal: mouse, elephant A classification is a description of which phenomena that belongs to a concept. An exemplification is a phenomenon that covers the concept  

Encapsulation and Information Hiding

Data can be encapsulated such that it is invisible to the “outside world”. Data can only be accessed via methods. What the “outside world” cannot see it cannot depend on! The object is a “fire-wall” between the object and the “outside world”. The hidden data and methods can be changed without affecting the “outside world”. 

The Class Concept

A class is a collection of objects (or values) and a corresponding set of methods.  A class encapsulates the data representation and makes data access possible at a higher level of abstraction. Example 1: A set of vehicles with operations for starting, stopping, driving, get km/liter, etc. Example 2: A time interval, start time, end time, duration, overlapping intervals, etc. Example 3: A string, upper case, compare, lower case, etc.  str.equals(otherStr) – class/Java style   strcmp(str, otherStr) – C style

The Object Concept

An object is an encapsulation of data.  An object has identity (a unique reference)  social security number (cpr), employee number, passport number state, also called characteristics (variables)  hungry, sad, drunk, running, alive  behavior (methods) eat, drink, wave, smile, kiss  An object is an instance of an class   A class is often called an Abstract Data Type (ADT).

Introduction to Object-Oriented Programming

Objects and classes  Encapsulation and information hiding    Mental exercises            Classification and exemplification           Aggregation and decomposition           Generalization and specialization • Inheritance  • Polymorphism and dynamic binding  • Java an example of an object-oriented programming language          Program example         History of Java         Comparison to C/C+