SlideShare a Scribd company logo
1 of 12
Download to read offline
Universidad Técnica de Manabí
Facultad de Ciencias Informáticas
  Carrera Ingeniera en Sistema
           Asignatura
             Ingles

       Project of English:

         Docente tutor:
         Danny Jarred

          Integrantes:
  Mastarreno Macías Luis Miguel

        3ero Semestre “C”

Periodo: Septiembre 2012-Frebrero
               2013
UNIVERSIDAD TÉCNICA DE MANABÌ
                                    Misión:
Formar académicos, científicos y profesionales responsables, humanistas,
éticos y solidarios, comprometidos con los objetivos del desarrollo nacional,
que contribuyan a la solución de los problemas del país como universidad de
docencia con investigación, capaces de generar y aplicar nuevos
conocimientos, fomentando la promoción y difusión de los saberes y las
culturas, previstos en la Constitución de la República del Ecuador.

                                    Visión:
Ser institución universitaria, líder y referente de la educación superior en
el Ecuador, promoviendo la creación, desarrollo, transmisión y difusión de la
ciencia, la técnica y la cultura, con reconocimiento social y proyección
regional y mundial.




               FACULTAD DE CIENCIAS INFORMÀTICAS
                             Misión:

Ser una unidad con alto prestigio académico, con eficiencia, transparencia y
calidad en la educación, organizada en sus actividades, protagonistas del
progreso regional y nacional.

                                   Visión:
 Formar profesionales eficientes e innovadores en el campo de las ciencias
informáticas, que con honestidad, equidad y solidaridad, den respuestas a
las necesidades de la sociedad elevando su nivel de vida.
PROGRAMMING IN JAVA
Java language is a general purpose development, and as such is valid for all

kinds of professional applications.

Language Features.
· It is inherently object-oriented.

· Works great networking.
· Leverage features of most modern languages avoiding drawbacks. In
particular, the C + +.
· It has great functionality with its libraries (classes).
The Java language can be seen as an evolution of C + +. The syntax is similar
to this language, so that in this book will refer to the language frequently.


The Java Virtual Machine (JVM)
The Java virtual machine is the idea of language revolucionaria4. It is the
entity that provides platform independence for Java programs "Compiled"
into byte-code.


JDK (Java Developer's Kit)
The basic tool to start developing Java applications or applets is the JDK
(Java Developer's Kit) or Java Development Kit, which consists basically, in
a compiler and an interpreter (JVM) for the command line. It has an
integrated development environment (IDE), but it is enough to learn
language and develop small applications.


                         Object Oriented Programming
The object-oriented programming is a natural evolution of programming
structured, in which the concept of variables local to a procedure or
function, which are not accessible to other procedures and functions, it is
extensible to own applets that access to these variables. But OOP goes far
beyond.
In object-oriented programming, objects are defined that make up a
application. These objects are formed by a series of features and
operations that can be performed on them.
Object
An object is a person, animal or thing. It is distinguished from other
objects by having certain characteristics and "serves" to something, or put
another way, can perform various operations with / on that object.
For example: A house is an object.
FEATURES: Number of floors, Total height in meters Color the facade,
number of windows, door number, city, street and number where it is
located, etc..
OPERATIONS: Build, destroy, painted facade, modify some features, for
example, open a new window, etc.
In terminology of object-oriented programming, the characteristics of
object are called attributes and operations METHODS. Everyone of these
methods is a procedure or a function belonging to an object.


                          Classes and Objects
In OOP we must distinguish between two closely related concepts, the class
and object.
The way to declare objects in Java is:

Ccasa casa1, house2;

In this case, house2 casa1 and variables are effectively but somewhat
special, are objects. Furthermore, the type of objects is Ccasa.
This type is the kind of object.


Properties must meet a language to be Object Oriented considered.
· Encapsulation.
· HERITAGE.
· Polymorphism.

Encapsulation
Encapsulation is the property possessed objects hide their attributes, and
even methods to other parts of the program or other objects. The natural
way to build a class is to define a set of attributes, in general, are not
accessible outside of the same object, but can only modified through
methods that are defined as available from outside of that class.
class Ccasa {
int nPuertas, nVentanas;
String color;
public Ccasa(int np, int nv, String co) {
nPuertas=np;
nVentanas=nv;
color=co;
}
public void pintar(String co) {
color=co;
}
public void abrirVentanas(int n) {
nVentanas=nVentanas+n;
}
public void cerrarVentanas(int n) {
nVentanas=nVentanas-n;
if (nVentanas<0)
nVentanas=0;
}
public void abrirPuertas(int n) {
nPuertas=nPuertas+n;
}
public void cerrarPuertas(int n) {
nPuertas=nPuertas-n;
if (nPuertas<0)
nPuertas=0;
}
}
…
Ccasa casa1,casa2;
…

Heredity

One of the main advantages of OOP. This property allows you to define
descendants of other classes, such that the new class (class descendant)
predecessor class inherits all its attributes and methods. the new class can
define new attributes and methods or attributes can redefine and existing
methods (for example, change the type of an attribute or operations
performed by a particular method).
This property enables code reuse and is very easy to grasp the existing
class code, modifying them to suit the minimally new specifications.

Example: Suppose you have built and want Ccasa class define a new class
that represents the chalets. In this case it may be convenient to define a
new attribute that represents the square footage of garden. Instead of
redefining a new class "from scratch", can written to exploit the class code
as follows Ccasa.
Ccasa Cchalet class extends {
mJardin int;
public Cchalet (int np, int nv, co String, int nj) {
super (np, nv, co);
mJardin = nj;
}
}
...
Cchalet chalet1, chalet2;
...
Class Ccasa
nPuertas
nVentanas
color
...
abrirVentanas ()
cerrarVentanas ()
paint ()
abrirPuertas ()
cerrarPuertas ()


class Cchalet
nPuertas
nVentanas
color
mJardin
...
abrirVentanas ()
cerrarVentanas ()
paint ()
abrirPuertas ()
cerrarPuertas ()



As can be seen, only have to declare the new class Cchalet is descended
from Ccasa (extends Ccasa) and declare the new attribute. Clearly, the
method must constructor to redefine initialize the new attribute mJardin.
But methods to open / close doors or windows is not necessary .The
constructor is a special method with the same name as the class and whose
function is to initialize the attributes of each object (instance).
Defining, are inherited from class Ccasa and can be used, for example of
the follows:
chalet1.pintar ("White");


Polymorphism
Polymorphism allows a single message sent to class objects different then
these also behave differently (different objects can have methods with
the same name or the same object can methods have identical names but
different parameters).

class Ccasa {
…
public Ccasa(int np, int nv, String co) {
nPuertas=np;
nVentanas=nv;
color=co;
}
public Ccasa() {
nPuertas=0;
nVentanas=0;
color=””;
}
You have two methods with the same name but different parameters. In he
first If attributes are initialized object method parameters and the
second case is initialized to zero, for example. Also, if you have two objects
and chalet1 casa1 and calls the method chalet1.abrirVentanas (2) will run
the procedure code abrirVentanas Cchalet class and not Ccasa class.


                               Hello, world.
First, let's see what structure should have the typical program which
starts in any programming language that provides a first view of the
language syntax and begins transmitting a series of feelings of acceptance
or rejection by the programmer. the program simply will display the
message "Hello, world" and terminates.
class Hello {
public static void main (String args []) {
System.out.println ("hello, world");
}
}


Everything written in Java alone program starts running (as in C) from the
main () method. Classes may be compiled not have main () method, but can
not run Java interpreter initially, but they can run if called from another
running method. We will see in later chapters how creating applets is
different and does not declare this method.


Statement of the main () method:

· Public: indicates that the method main () is public and therefore can be
called from other classes. All main () method must be public to run from
the Java interpreter (JVM).
· Static: indicates that the class does not need to be instantiated use the
method that qualifies. (Not create any instance or Hello class object). It
also indicates that the method is the same for all instances that may be
created.
· Void: indicates that the main function returns no value.
· The main method must always accept, as a parameter, a vector strings
that contain the possible arguments that are passed to program on the
command line, but as in our case, no is used.
The main () method is always declared in the same way:

                   public static void main (String args [])

Data Types
In Java there are two main types of data:
1) Simple Data Types.
2) References to objects.
The data types are those that can be used directly in a program, without
the use of classes (OOP). These types are:
Byte, short, int, long, float, double, char, Boolean.
Data Types reference
All other data types that are not simple, are considered benchmarks.
These guys are basically the classes, which is based programming
object oriented.


Scope of a variable
The scope of a variable is the portion of the program where the variable is
visible to the program code and, therefore, referenceable.
The scope of a variable depends on the location of the program where it is
declared, may belong to four different categories.
· Local Variable.
· Attribute.
· A method parameter.
· Parameter of an exception handler.


Local Variable
A local variable is declared within the body of a method of a class and is
visible only within that method.
Attributes
The attributes of a class are the features to be taken into account on an
object and hence its area is limited, in principle, within the class to which
characterize.


Alternative structures
Alternative structures are structures that allow you to alter the flow
a sequential program so that depending on a condition or value
of an expression, the same can be diverted in either alternative
code.


if-else
Simple:
if (expression)
Block instructions
The statement block is executed if, and only if, the expression (which must
be logic) evaluates to true, ie a certain condition is met.
Switch
Simple:
switch (expression) {
case value1: instrucciones1;
case value2: instrucciones2;
...
valueN case: instruccionesN;
}
In this case, unlike the above, whether or instrucciones2 or instrucciones1
instruccionesN are formed by a single block of instructions, it is
parentizarlas required by the braces ({...}).


Loops
Loops are repeat structures. Blocks of instructions that repeat a number
of times while a condition is met or until enforcing a condition.


Loop for
for (initialization, condition, increment)
block instructions
· The initialization clause is a statement that executes a single After the
start of the loop, typically to initialize a counter.
The condition clause is a logical expression that evaluates to top each new
iteration of the loop.
The increase clause is a statement that is executed in each iteration of the
loop as if it were the last statement in the statement block.


Do-while loop.
do
block instructions
while (Expression);
In this type of loop instruction block is executed once so long less, and that
block of instruction will be executed while expression evaluates to true.


While loop
while (Expression)
block instructions
As in do-while loop in the previous section, the statement block is executed
while a condition is met (while expression evaluates to true), but in this
case, the condition is checked before start first run loop, so if expression
evaluates to false in the first iteration, then the statement block will not
execute any time.


Vectors
To handle collections of objects of the same type in a single structured
vectores12 variable is used. In Java, the vectors are actually objects and
therefore it can call its methods (as discussed in the next chapter).
There are two equivalent ways to declare vectors in Java:
1) type nombreDelVector [];
2) type [] nombreDelVector;


Declaration of the superclass (inheritance)
The superclass is the class from which another class inherits all the
attributes and methods. The way to declare that a class inherits from
another is:
class ClassName extends NombreSuperclase
example:
Nif class extends Dni
Declares a class that inherits Nif all attributes and
Dni class methods.


Abstract


Abstract classes can not be instanciadas17. These are for declare
subclasses should override those methods that have been declared
abstract. This does not mean that all methods of an abstract class
abstractos18 should be even possible that none of them is. Even in this
latter case, the class is considered abstract and not be declared Objects
of this class.
When any of the methods of a class is declared abstract class must
abstract necessarily be, otherwise, the compiler generates a message
error.
Proyecto

More Related Content

What's hot

CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONLalitkumar_98
 
Python Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismPython Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismRanel Padon
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in JavaKurapati Vishwak
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPTAjay Chimmani
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming conceptsrahuld115
 
How would you implement multiple inheritance in java
How would you implement multiple inheritance in javaHow would you implement multiple inheritance in java
How would you implement multiple inheritance in javaTyagi2636
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingNithyaN19
 
Seminar on java
Seminar on javaSeminar on java
Seminar on javashathika
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: InheritanceTareq Hasan
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritanceadil raja
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented ProgrammingAida Ramlan II
 

What's hot (20)

04 inheritance
04 inheritance04 inheritance
04 inheritance
 
CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
 
Java pdf
Java   pdfJava   pdf
Java pdf
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Python Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and PolymorphismPython Programming - VIII. Inheritance and Polymorphism
Python Programming - VIII. Inheritance and Polymorphism
 
OOP
OOPOOP
OOP
 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
 
4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Object oriented programming concepts
Object oriented programming conceptsObject oriented programming concepts
Object oriented programming concepts
 
How would you implement multiple inheritance in java
How would you implement multiple inheritance in javaHow would you implement multiple inheritance in java
How would you implement multiple inheritance in java
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Python OOPs
Python OOPsPython OOPs
Python OOPs
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
concept of oops
concept of oopsconcept of oops
concept of oops
 
the Concept of Object-Oriented Programming
the Concept of Object-Oriented Programmingthe Concept of Object-Oriented Programming
the Concept of Object-Oriented Programming
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 

Viewers also liked (12)

Miguel portafolioingles
Miguel portafolioinglesMiguel portafolioingles
Miguel portafolioingles
 
Portafolio kenia original 2 a
Portafolio kenia original 2 aPortafolio kenia original 2 a
Portafolio kenia original 2 a
 
Class 1 y 2 2ciclo
Class 1 y 2 2cicloClass 1 y 2 2ciclo
Class 1 y 2 2ciclo
 
Class 3 2ciclo
Class 3 2cicloClass 3 2ciclo
Class 3 2ciclo
 
Folder
FolderFolder
Folder
 
Folder aby
Folder abyFolder aby
Folder aby
 
Kenia
KeniaKenia
Kenia
 
Mata
MataMata
Mata
 
Gisella bravo portafolio
Gisella bravo portafolioGisella bravo portafolio
Gisella bravo portafolio
 
Cultura empresarial en estudiantes universitarios
Cultura empresarial en estudiantes universitariosCultura empresarial en estudiantes universitarios
Cultura empresarial en estudiantes universitarios
 
Cultura empresarial en estudiantes universitarios
Cultura empresarial en estudiantes universitariosCultura empresarial en estudiantes universitarios
Cultura empresarial en estudiantes universitarios
 
Portafolio estudiantil
Portafolio estudiantilPortafolio estudiantil
Portafolio estudiantil
 

Similar to Proyecto (20)

Proyecto de ingles
Proyecto de inglesProyecto de ingles
Proyecto de ingles
 
Class 6
Class 6Class 6
Class 6
 
Java notes jkuat it
Java notes jkuat itJava notes jkuat it
Java notes jkuat it
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
 
Ingles proyecto traducido
Ingles proyecto traducidoIngles proyecto traducido
Ingles proyecto traducido
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
 
Proyect of english
Proyect of englishProyect of english
Proyect of english
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
INTRODUCTION TO JAVA
INTRODUCTION TO JAVAINTRODUCTION TO JAVA
INTRODUCTION TO JAVA
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Oops
OopsOops
Oops
 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
 
Java notes
Java notesJava notes
Java notes
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
Mca2030 object oriented programming – c++
Mca2030  object oriented programming – c++Mca2030  object oriented programming – c++
Mca2030 object oriented programming – c++
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Oop basic concepts
Oop basic conceptsOop basic concepts
Oop basic concepts
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 

More from Miguel Mastarreno Macías (20)

Proyecto de ingles traducido
Proyecto de ingles traducidoProyecto de ingles traducido
Proyecto de ingles traducido
 
Class 5
Class 5Class 5
Class 5
 
Class 4
Class 4Class 4
Class 4
 
Class 3
Class 3Class 3
Class 3
 
Class 2
Class 2Class 2
Class 2
 
Class 1
Class 1Class 1
Class 1
 
Kenii
KeniiKenii
Kenii
 
Gissy
GissyGissy
Gissy
 
Aby
AbyAby
Aby
 
Gestor proyectocalculo
Gestor proyectocalculoGestor proyectocalculo
Gestor proyectocalculo
 
Diapositivas avance calculo
Diapositivas avance calculoDiapositivas avance calculo
Diapositivas avance calculo
 
Proyecto kenia gisse miguel aby
Proyecto kenia gisse miguel abyProyecto kenia gisse miguel aby
Proyecto kenia gisse miguel aby
 
Calculo mastarreno
Calculo mastarrenoCalculo mastarreno
Calculo mastarreno
 
Calculo folder gisy.editado
Calculo folder gisy.editadoCalculo folder gisy.editado
Calculo folder gisy.editado
 
Keniia fold calculo original
Keniia fold calculo originalKeniia fold calculo original
Keniia fold calculo original
 
Keniia fold calculo original
Keniia fold calculo originalKeniia fold calculo original
Keniia fold calculo original
 
Ciencias astronimicas
Ciencias astronimicasCiencias astronimicas
Ciencias astronimicas
 
Proyecto avance 1 matlab
Proyecto avance 1 matlab Proyecto avance 1 matlab
Proyecto avance 1 matlab
 
Prontuario
ProntuarioProntuario
Prontuario
 
Materiales relacionados con clase
Materiales relacionados con claseMateriales relacionados con clase
Materiales relacionados con clase
 

Proyecto

  • 1. Universidad Técnica de Manabí Facultad de Ciencias Informáticas Carrera Ingeniera en Sistema Asignatura Ingles Project of English: Docente tutor: Danny Jarred Integrantes: Mastarreno Macías Luis Miguel 3ero Semestre “C” Periodo: Septiembre 2012-Frebrero 2013
  • 2. UNIVERSIDAD TÉCNICA DE MANABÌ Misión: Formar académicos, científicos y profesionales responsables, humanistas, éticos y solidarios, comprometidos con los objetivos del desarrollo nacional, que contribuyan a la solución de los problemas del país como universidad de docencia con investigación, capaces de generar y aplicar nuevos conocimientos, fomentando la promoción y difusión de los saberes y las culturas, previstos en la Constitución de la República del Ecuador. Visión: Ser institución universitaria, líder y referente de la educación superior en el Ecuador, promoviendo la creación, desarrollo, transmisión y difusión de la ciencia, la técnica y la cultura, con reconocimiento social y proyección regional y mundial. FACULTAD DE CIENCIAS INFORMÀTICAS Misión: Ser una unidad con alto prestigio académico, con eficiencia, transparencia y calidad en la educación, organizada en sus actividades, protagonistas del progreso regional y nacional. Visión: Formar profesionales eficientes e innovadores en el campo de las ciencias informáticas, que con honestidad, equidad y solidaridad, den respuestas a las necesidades de la sociedad elevando su nivel de vida.
  • 3. PROGRAMMING IN JAVA Java language is a general purpose development, and as such is valid for all kinds of professional applications. Language Features. · It is inherently object-oriented. · Works great networking. · Leverage features of most modern languages avoiding drawbacks. In particular, the C + +. · It has great functionality with its libraries (classes). The Java language can be seen as an evolution of C + +. The syntax is similar to this language, so that in this book will refer to the language frequently. The Java Virtual Machine (JVM) The Java virtual machine is the idea of language revolucionaria4. It is the entity that provides platform independence for Java programs "Compiled" into byte-code. JDK (Java Developer's Kit) The basic tool to start developing Java applications or applets is the JDK (Java Developer's Kit) or Java Development Kit, which consists basically, in a compiler and an interpreter (JVM) for the command line. It has an integrated development environment (IDE), but it is enough to learn language and develop small applications. Object Oriented Programming The object-oriented programming is a natural evolution of programming structured, in which the concept of variables local to a procedure or function, which are not accessible to other procedures and functions, it is extensible to own applets that access to these variables. But OOP goes far beyond. In object-oriented programming, objects are defined that make up a application. These objects are formed by a series of features and operations that can be performed on them.
  • 4. Object An object is a person, animal or thing. It is distinguished from other objects by having certain characteristics and "serves" to something, or put another way, can perform various operations with / on that object. For example: A house is an object. FEATURES: Number of floors, Total height in meters Color the facade, number of windows, door number, city, street and number where it is located, etc.. OPERATIONS: Build, destroy, painted facade, modify some features, for example, open a new window, etc. In terminology of object-oriented programming, the characteristics of object are called attributes and operations METHODS. Everyone of these methods is a procedure or a function belonging to an object. Classes and Objects In OOP we must distinguish between two closely related concepts, the class and object. The way to declare objects in Java is: Ccasa casa1, house2; In this case, house2 casa1 and variables are effectively but somewhat special, are objects. Furthermore, the type of objects is Ccasa. This type is the kind of object. Properties must meet a language to be Object Oriented considered. · Encapsulation. · HERITAGE. · Polymorphism. Encapsulation Encapsulation is the property possessed objects hide their attributes, and even methods to other parts of the program or other objects. The natural way to build a class is to define a set of attributes, in general, are not accessible outside of the same object, but can only modified through methods that are defined as available from outside of that class. class Ccasa { int nPuertas, nVentanas;
  • 5. String color; public Ccasa(int np, int nv, String co) { nPuertas=np; nVentanas=nv; color=co; } public void pintar(String co) { color=co; } public void abrirVentanas(int n) { nVentanas=nVentanas+n; } public void cerrarVentanas(int n) { nVentanas=nVentanas-n; if (nVentanas<0) nVentanas=0; } public void abrirPuertas(int n) { nPuertas=nPuertas+n; } public void cerrarPuertas(int n) { nPuertas=nPuertas-n; if (nPuertas<0) nPuertas=0; } } … Ccasa casa1,casa2; … Heredity One of the main advantages of OOP. This property allows you to define descendants of other classes, such that the new class (class descendant) predecessor class inherits all its attributes and methods. the new class can define new attributes and methods or attributes can redefine and existing methods (for example, change the type of an attribute or operations performed by a particular method). This property enables code reuse and is very easy to grasp the existing class code, modifying them to suit the minimally new specifications. Example: Suppose you have built and want Ccasa class define a new class that represents the chalets. In this case it may be convenient to define a new attribute that represents the square footage of garden. Instead of redefining a new class "from scratch", can written to exploit the class code as follows Ccasa.
  • 6. Ccasa Cchalet class extends { mJardin int; public Cchalet (int np, int nv, co String, int nj) { super (np, nv, co); mJardin = nj; } } ... Cchalet chalet1, chalet2; ... Class Ccasa nPuertas nVentanas color ... abrirVentanas () cerrarVentanas () paint () abrirPuertas () cerrarPuertas () class Cchalet nPuertas nVentanas color mJardin ... abrirVentanas () cerrarVentanas () paint () abrirPuertas () cerrarPuertas () As can be seen, only have to declare the new class Cchalet is descended from Ccasa (extends Ccasa) and declare the new attribute. Clearly, the
  • 7. method must constructor to redefine initialize the new attribute mJardin. But methods to open / close doors or windows is not necessary .The constructor is a special method with the same name as the class and whose function is to initialize the attributes of each object (instance). Defining, are inherited from class Ccasa and can be used, for example of the follows: chalet1.pintar ("White"); Polymorphism Polymorphism allows a single message sent to class objects different then these also behave differently (different objects can have methods with the same name or the same object can methods have identical names but different parameters). class Ccasa { … public Ccasa(int np, int nv, String co) { nPuertas=np; nVentanas=nv; color=co; } public Ccasa() { nPuertas=0; nVentanas=0; color=””; } You have two methods with the same name but different parameters. In he first If attributes are initialized object method parameters and the second case is initialized to zero, for example. Also, if you have two objects and chalet1 casa1 and calls the method chalet1.abrirVentanas (2) will run the procedure code abrirVentanas Cchalet class and not Ccasa class. Hello, world. First, let's see what structure should have the typical program which starts in any programming language that provides a first view of the language syntax and begins transmitting a series of feelings of acceptance or rejection by the programmer. the program simply will display the message "Hello, world" and terminates.
  • 8. class Hello { public static void main (String args []) { System.out.println ("hello, world"); } } Everything written in Java alone program starts running (as in C) from the main () method. Classes may be compiled not have main () method, but can not run Java interpreter initially, but they can run if called from another running method. We will see in later chapters how creating applets is different and does not declare this method. Statement of the main () method: · Public: indicates that the method main () is public and therefore can be called from other classes. All main () method must be public to run from the Java interpreter (JVM). · Static: indicates that the class does not need to be instantiated use the method that qualifies. (Not create any instance or Hello class object). It also indicates that the method is the same for all instances that may be created. · Void: indicates that the main function returns no value. · The main method must always accept, as a parameter, a vector strings that contain the possible arguments that are passed to program on the command line, but as in our case, no is used. The main () method is always declared in the same way: public static void main (String args []) Data Types In Java there are two main types of data: 1) Simple Data Types. 2) References to objects. The data types are those that can be used directly in a program, without the use of classes (OOP). These types are: Byte, short, int, long, float, double, char, Boolean.
  • 9. Data Types reference All other data types that are not simple, are considered benchmarks. These guys are basically the classes, which is based programming object oriented. Scope of a variable The scope of a variable is the portion of the program where the variable is visible to the program code and, therefore, referenceable. The scope of a variable depends on the location of the program where it is declared, may belong to four different categories. · Local Variable. · Attribute. · A method parameter. · Parameter of an exception handler. Local Variable A local variable is declared within the body of a method of a class and is visible only within that method. Attributes The attributes of a class are the features to be taken into account on an object and hence its area is limited, in principle, within the class to which characterize. Alternative structures Alternative structures are structures that allow you to alter the flow a sequential program so that depending on a condition or value of an expression, the same can be diverted in either alternative code. if-else Simple: if (expression) Block instructions The statement block is executed if, and only if, the expression (which must be logic) evaluates to true, ie a certain condition is met.
  • 10. Switch Simple: switch (expression) { case value1: instrucciones1; case value2: instrucciones2; ... valueN case: instruccionesN; } In this case, unlike the above, whether or instrucciones2 or instrucciones1 instruccionesN are formed by a single block of instructions, it is parentizarlas required by the braces ({...}). Loops Loops are repeat structures. Blocks of instructions that repeat a number of times while a condition is met or until enforcing a condition. Loop for for (initialization, condition, increment) block instructions · The initialization clause is a statement that executes a single After the start of the loop, typically to initialize a counter. The condition clause is a logical expression that evaluates to top each new iteration of the loop. The increase clause is a statement that is executed in each iteration of the loop as if it were the last statement in the statement block. Do-while loop. do block instructions while (Expression); In this type of loop instruction block is executed once so long less, and that block of instruction will be executed while expression evaluates to true. While loop while (Expression) block instructions
  • 11. As in do-while loop in the previous section, the statement block is executed while a condition is met (while expression evaluates to true), but in this case, the condition is checked before start first run loop, so if expression evaluates to false in the first iteration, then the statement block will not execute any time. Vectors To handle collections of objects of the same type in a single structured vectores12 variable is used. In Java, the vectors are actually objects and therefore it can call its methods (as discussed in the next chapter). There are two equivalent ways to declare vectors in Java: 1) type nombreDelVector []; 2) type [] nombreDelVector; Declaration of the superclass (inheritance) The superclass is the class from which another class inherits all the attributes and methods. The way to declare that a class inherits from another is: class ClassName extends NombreSuperclase example: Nif class extends Dni Declares a class that inherits Nif all attributes and Dni class methods. Abstract Abstract classes can not be instanciadas17. These are for declare subclasses should override those methods that have been declared abstract. This does not mean that all methods of an abstract class abstractos18 should be even possible that none of them is. Even in this latter case, the class is considered abstract and not be declared Objects of this class. When any of the methods of a class is declared abstract class must abstract necessarily be, otherwise, the compiler generates a message error.