You are on page 1of 12

This subject is designed to orient them to you into the world of computer programming in the Java programming language.

Language that is used from the programming of basic electronic devices such as calculators, microwaves, washing machines, smartphones, among others. The important thing is that the Java application that is used for any operating system is installed the JVM (Java Virtual Machine). For programming Java applications we will use the JDK (Java Development Kit) and the NetBeans IDE, the same that will be provided. Without further ado I make available their course waiting III programming that reflects the interest in researching and learning new things.

Buffered Initializes

Reader space

is for

within

Seller reading

import.java.io. keyboard

*; work

The Scanner is more user directly reads the data and returns the corresponding type used Bookseller java.util.Scanner;

Repetition structures are used to repeat a section of code block or program a number of times specified or unspecified .... Loop. - Is used when you know the number of times it will be a cycle, its syntax is for(declaration/inicialization;condition;cont){ instruction/s; } for example for(int i = 0; i<10; i++){ system.out.println(i); }

do-while loop.- is used when no one knows the number of repetitions of the cycle but is expected to perform at least once, the syntax is:

do{ instruction/s; }while(condition); for example int i=0; do{ i++; system.out.println(i); }while(i<10);

while loop.- is used when no one knows the number of repetitions of the cycle and is expected to evaluate the expression if true to run your code, the syntax is:
while(condition){ instruction/s; } for example int i=0; while(i<10){ i++; system.out.println(i); }

In both structures as both do-while while you have to be extremely cautious to place a mechanism that at some point leave the repeat structure, in our example we increase the variable i in every execution cycle, if the cycle was not would be endless.

The vectors provide the functionality of a single variable grouped into different values of the same type, that is, assigning a large memory space for storing the elements of a single data type at a time, his declaration is based on: type vector [] = new type [size]; is basically the form of declaration and initialization, remember to use repetition structures to traverse the vector containing the elements for any type of operation, such as reading, assignment, or sample data. Matrices as vectors are allocated memory spaces identified by a variable in which case the option covers two rows, the first for the rows and the second for columns. the statement is maintained with the following exception: type name [] [] = new type [size row] [column size]

Methods are known in another language (C, C + +) as procedures and functions. One method is: A block of code that has a name, receives some parameters or arguments (optionally) contains statements or instructions to make something (optionally) and returns a value of any known type (optionally).

The overall syntax is: ambito_Tipo_Valor_devuelto nombre_mtodo (lista_argumentos) { bloque_de_codigo;} and the list of arguments is expressed by stating the type and name of the same (as in variable declarations). If more than one are separated by commas. For example:

int sumaEnteros ( int a, int b ) { int c = a + b; return c; }


In the example the return clause is used to finalize the method returning the value of the variable c. The fact that a method returns a value or not is optional. If that returns a value is declared return type. But if you do not need a value, is declared return type, the keyword void. For example:

void haceAlgo() { ... }


When not return a value, the return clause is not necessary. Note that in this example the method also does not receive any parameters haceAlgo. However parentheses are mandatory.

Lenght. - Returns the size of the object and travels up to that amount

In this unit we explore the object-oriented programming in java, characteristics such as inheritance, polymorphism, overloading, among others. with examples that can help the understanding ...

As a class is initialized?. If a builder cant pass values.

But besides this compositional technique is possible to think of cases where a class is an extension of another. That is, a class is like another and also has some sort of characteristic that distinguishes it. For example we might think of the Employee class and define it as:

class Empleado { String nombre; int numEmpleado , sueldo; static private int contador = 0; Empleado(String this.nombre this.sueldo numEmpleado } nombre, int sueldo) { = nombre; = sueldo; = ++contador;

public void aumentarSueldo(int porcentaje) { sueldo += (int)(sueldo * aumento / 100); } public String toString() { return "Num. empleado " + numEmpleado + " Nombre: " + nombre + " Sueldo: " + sueldo; } }

In the example the Employee is characterized by a name (String) and an employee number and salary (integer). The class defines a constructor that assigns the values of name and salary and

employee number calculated from a counter (always static variable will increase), and two methods, one to calculate the new salary when a pay rise (aumentarSueldo method) and a second that returns a representation of employee data in a String. (toString). With this representation we can think of another class that has all the characteristics of Employee and add some own. For example, the executive class. The objects of this kind might be given all the data and methods of the Employee class and add some, such as the fact that an executive has a budget. So we would say that the class extends Executive or Employee class inherits. This is done in Java extends clause which is incorporated in the class definition, as follows:
class Ejecutivo extends Empleado { int presupuesto; void asignarPresupuesto(int p) { presupuesto = p; } }

Redefining methods. The use of super. Also we could consider redefining some methods of the base class but making methods with the same name and features behave differently. For example we could think of redesigning the toString method of the Employee class by adding the characteristics of the executive class. This could be:
class Ejecutivo extends Empleado { int presupuesto; void asignarPresupuesto(int p) { presupuesto = p; } public String toString() { String s = super.toString(); s = s + " Presupuesto: " + presupuesto; return s; }

} Thus when invoked jefe.toString () will use the toString method of the class instead of the existing Executive in the Employee class. Note in the example the use of super, which is implicit internal reference to the base class (superclass). By super.toString () method is invoked toString Employee class Initialization of derived classes When you create an object of a derived class implicitly creates an object of the base class constructor is initialized with its corresponding. If the object creation using the no-args constructor, then an implicit call to the no-args constructor for the base class. But used other builders must explicitly invoke. In our example, since the class defines a constructor method, we also need a constructor for executive class, we can complete this:

class Ejecutivo extends Empleado { int presupuesto; Ejecutivo (String n, int s) { super(n,s); } void asignarPresupuesto(int p) { presupuesto = p; } public String toString() { String s = super.toString(); s = s + " Presupuesto: " + presupuesto; return s; } }

The protected access modifier The protected access modifier is a combination of the approaches that provide public and private modifiers. protected provides public access to derived classes and private access (forbidden) for all other classes. For example:
class Empleado { protected int sueldo; . . . }

Then from the Executive class can access the data member salary, while if not declaring private. Java implanted another mechanism is similar to that of multiple inheritance is the interfaces that will be discussed below.

The concept of polymorphism is one of the foundations for any object-oriented language, the very roots of the word can be a strong clue to its meaning: Poli = Multiple, = Forms morphism, this implies that the same object can take various forms. Through the concept of Inheritance ("Inheritance") may illustrate this behavior:

Sometimes, when developing a class hierarchy that some behavior is present in all but materializes differently for each. For example, consider a class structure to manipulate geometric figures. We could think of having a generic class, you might call FiguraGeometrica and a series of classes that extend to above that could be circle, polygon, etc.. There could be a draw method as on all the figures can be carried out this action, but specific operations to carry out depend on the specific figure (of its kind). Moreover draw action is meaningless for FiguraGeometrica generic class, because this class represents an abstraction of all possible shapes. To solve this problem Java provides classes and abstract methods. An abstract method is a method declared in a class for which the class provides no implementation (code). An abstract class is a class that has at least one abstract method. A class that extends an abstract class must implement the abstract methods (write code) or return them to declare as abstract, which itself also becomes abstract class.

abstract class FiguraGeometrica { . . . abstract void dibujar(); . . . } class Circulo extends FiguraGeometrica { . . . void dibujar() { // codigo para dibujar Circulo . . . } }

The abstract class is declared with the abstract modifier just in his statement.

To create an interface, use the interface keyword instead of class. The interface can be defined public or no access modifier, and has the same meaning as for classes. All methods that declares an interface are always public. To indicate that a class implements an interface method uses the implements keyword. The compiler will verify that the class actually declare and implement all methods of the interface. A class can implement more than one interface.