OverviewAl finalizar la unidad, el alumno será capaz de:
- Identificar correctamente las características del lenguaje Java para concretizar la teoría de programación orientada a objetos
- Diseñar y desarrollar aplicaciones orientadas a objetos utilizando el lenguaje de programación Java
- Hacer uso de las librerías estándar de la plataforma Java
- Escribir código protegido (manejo de excepciones)
- Codificar de forma clara y concisa
- Reafirmar sus habilidades para modelar y diseñar sistemas utilizando los diagramas de UML más utilizados en aplicaciones Java
Object Oriented Programming (OOP) Concepts
We will explore What is OOP? Why is OOP important?Object-oriented programming (OOP) is a paradigm organized around objects rather than "actions" and data rather than logic. Currently is one of the most used paradigms.
Java LanguageJava was created by James Gosling and Sun Microsystems. Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.
UML DiagramsThe Unified Modeling Language (UML) is a general-purpose modeling language in the field of software engineering, which is designed to provide a standard way to visualize the design of a system
Object Oriented Programming (OOP) Concepts
IntroductionObject-oriented programming (OOP) is a paradigm organized around objects rather than "actions" and data rather than logic. The first step in OOP is to identify all the objects the programmer wants to manipulate and how they relate to each other, an exercise often known as data modeling. Once an object has been identified, it is generalized as a class of objects (think of Plato's concept of the "ideal" chair that stands for all chairs) which defines the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. Objects communicate with well-defined interfaces called messages.
What is class?
A class is the blueprint from which individual objects are created.Source
What is an object?
An object is an instance of class.
Objects are the key to understanding object-oriented technology
An object consists of a:
- Fields / Attributes: Used to store the state of an object.
- Methods: Used to expose the objects's behavior. They operate on an object's internal state and serve as the primary mechanism for object-to-object communication.
Benefits of OOP
- Code re-use
- Pluggability and debugging ease
InheritanceIn object-oriented programming (OOP), inheritance is when an object or class is based on another object or class, using the same implementation (inheriting from a class) specifying implementation to maintain the same behavior (realizing an interface; inheriting behavior). It is a mechanism for code reuse and to allow independent extensions of the original software via public classes and interfaces. The relationships of objects or classes through inheritance give rise to a hierarchy.
PolymorphismPolymorphism is the provision of a single interface to entities of different types.A polymorphic type is a type whose operations can also be applied to values of some other type, or types.
Encapsulation is the packing of data and functions into a single component. It allows selective hiding of properties and methods in an object by building an impenetrable wall to protect the code from accidental corruption.
Data encapsulation is a fundamental principle to OOP. It means hiding internal state and requiring all interaction to be performed through an object's methods.Read More
Java was created by James Gosling and Sun Microsystems and was released in 1995. Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA). Java is, as of 2015, one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers
When compiled Java programs create a compiled version of the source file (extension .class) which contains bytecode. Java Virtual Machine implementations are able to understand and run bytecode instructions (translate them into something that actual processors can understand).
Java was born as a need to have portable and compiled code. Sun microsystems main goal was to sell processors that run bytecode as native instructions with this Java programs run fast as C or C++ programs.References: More on this on Wikipedia
Java is a statically typed language. This means that the types are declared on variables and compilation will fail if an expected type is not received or declared. Java primitive types are:
- String (not really a primitive type but has a special place on the language)
VariablesVariables in Java can be
- Class variables
- Instance variables
- Local variables
OperatorsJava has many of the "standard" operators used on other languages with a few exceptions:
- instance of
Control StatementsJava has many of the standard control flow statements used on other languages including:
- if / else if / else
- do while
An abstract class is a class that is declared abstract. It may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
An abstract method is a method that is declared without an implementation.
If a class includes abstract methods, then the class itself must be declared abstract.
InterfacesAn interface is:
- A contract that should be fulfilled by those who implement it.
- Is the solution to multiple inheritance in Java.
CollectionsJava offers a wide range of collections as part of the standard including: