Guía Compuu

download Guía Compuu

of 8

Transcript of Guía Compuu

  • 8/13/2019 Gua Compuu

    1/8

  • 8/13/2019 Gua Compuu

    2/8

  • 8/13/2019 Gua Compuu

    3/8

    NOT: Is represented by the symbol: ! Affects only one condition and returns true ifit has the value of false and vice versa.

    XOR: Is represented by the symbol: ^ and returns the value true as long as onecondition is true and the other is false, else returns false.

    Topic 4: Developing and testing a Java ProgramStructure of the object: An object is made of methods, which define the behavior ofobjects (operations), and of attributes and fields, while define the state of theobject.

    Attributes: Define the state of the object

    Methods: Operations that define the behavior of an object

    Constructors: Part of the methods that allow an object to be created

    Destructors: Part of the methods that let you destroy an object

    Public: Is used so the method can be used anywhere in the program

    Static: No other object can be used in this method, it is independent from the rest.

    Void: The method, when ending its use, wont return any result.

    Statement to show a message on computers screen: (..)

    Topic 5: Declaration, initiation and use of variables

    Variables attributes: are declared outside of a method and their syntax is thefollowing:

    Modifier Data_type Name_variable

    Modifier: Public or private

    Data_type: Any primitive data type

    Name_variable: Must follow the mention characteristics

    Local variables: are declared inside a method and their syntax is the following:Data_type Name_variable

    Initiate variable. Both variable types can be initialize in the same line

    Topic 6: Use of operators and decision constructionsIfelse (use): The instruction if / else is a complement of the instruction if andallows certain condition to be executed in case the condition is met or if thecondition is not met.

    Example:

    if( age>=18)

  • 8/13/2019 Gua Compuu

    4/8

  • 8/13/2019 Gua Compuu

    5/8

    Topic 9: Implementation of encapsulations and constructors

    Encapsulation: refers to the action of hiding data in a class (a security capsule )and makes them available only through certain methods.

    Public modifier: makes the class, attributes and methods visible to any object.

    Private modifier: prevents that other objects can access the objects of a certainclass, such as attributes and methods.

    Constructor: is a special method that is executed at the moment you create a classobject. They can be reused.

    Topic 10: Implementation of inheritance

    Inheritance is one of the main concepts in object oriented programming.

    Inheritance: is the capacity of creating a class that will automatically acquire theattributes (methods), from other classes that already exist

    Superclass: is the class that contains methods and attributes that will be inherit tothe subclass.

    Subclass: receives the attributes and methods of the superclass.

    The subclass includes the word extends and the name of the class.

    Abstraction: creation of abstract classes.

    Abstract class: is a class in which objects cannot be created, is a class used to beinherited by others and is defined as a superclass since its creation.

    Java class packages:Package Description of the classes it contains

    ja va.aw t Contains classes that have tools to build and manage the graphic interfacethat includes the management of windows.

    ja va.ap p le t Contains classes that provide the management of the applets. Applets areobjects that allow programs created in Java to run from a web page.

    ja va.net Contains classes that allow you to perform network-related operations.

    ja va. io Contains classes that allow you to manipulate files, as well as reading andwriting operations from a disk.

    ja va.u ti l Contains classes for tasks such as generating random numbers, dateoperations and calendar functions.

    Word import: use it to make use of a package in a Java Program.

    Topic 11: Development and use of methods

    A method is declared inside a class.

  • 8/13/2019 Gua Compuu

    6/8

    To call a method, you need to write the name of the variable and the name of themethod separated by a point. housejavier.show_info();

    Worker method: is an execution method and it executes an action.

    Call method: is a method that calls another method to execute an action.

    The call method sends the worker to perform certain actions and waits until theworker finishes its action to proceed with the rest of the program.

    "Static" modifier: can be called without having to initialize a variable that refers toan objectand can also be called by more than one class, meaning, they are notspecific to a class in particular.

    Methods that use the "static" modifiercan be accessed by any method from anyother class in the program.

    Method overflow: methods in a class that have the same name but have differentarguments.

    Topic 12: Creation and use of matrixesMatrix: is an object in which you can store a set of data of the same type.

    Matrixes: are known as arrays.

    Matrix or array: is definedbased of thenumber of dimensions.

    uni-dimensional matrix: one dimension matrix

    Can be declared using the syntax:

    Data_type Matrixname[];

    You can then add the following instruction:

    Matrixname = new datatype[length];

    Example:int m[]; //Matrix with the name of m that stores integer values.m=new int[16]; // length of the matrix is 16.

  • 8/13/2019 Gua Compuu

    7/8

    bidimensional matrix: two dimensional matrix

    Bidimensional matrixes are initialized in the same way as unidimensional matrixeswith the difference that we add another pair of brackets.

    Example:int s[ ][ ]; //bidimensional matrix of infinitite size called s.

    s=new int[10] [15]; // length of 10 times 15

    tridimensional matrix: matrix with three dimensions

    Topic 13: Specific algorithmsRecursion: when a method is calling itself.

    A method calls itself to delimit the end of a call, with the intention of identifying themoment in which a function returns an expected result and to avoid that theprogram loops indefinitely with the same method.

    Methods to sort data:

    - bubble method:

    1. Compares the first element with the second one, the second one with thethird, and so on. When the result is higher (or lower) than the previous one,they exchange values. This way we can take the highest value (or lowest ifwe like) to the last position.

    a. The comparison of each element can be done by a logic operator,for example: to compare two variables we can make use of theinstruction:If (a>b).

    2. Repeats the point 1 for the n-1 first elements of the list.

  • 8/13/2019 Gua Compuu

    8/8

    3. Repeats the point 1 for the n-2 first elements of the list and so on until youfinish with all the elements.

    public static void bubble(int [] array){int aux;int i;

    int number_of_elements= array.length;boolean s=true;while ((s==true) && (--number_of_elements > 0)){

    s=false;for (i=1; iarray[i]){aux=array[i-1];array[i-1]=array[i];array[i]=aux;s=true;

    }}

    }

    }

    Insertion method:

    The first two elements of the array are ordered initially, and then the third elementis inserted in the correct position in respect to the previous ones, and so on. This isdone until the last element has been inserted.

    public static void insertion(int [] matriz){int array[40];

    double x;int i, k;int number_of_elements= array.length;for (i=1; i=0 && x< array[k]){

    array[k+1]= array[k];k=k-1;

    }m[k+1]=x;

    }}