Curso Java. Estructuras principales VI. Clase Math. Vídeo 9

pildorasinformaticas
19 May 201422:29

Summary

TLDREste curso de programación en Java, dirigido a principiantes, aborda conceptos fundamentales como las estructuras de datos y las clases. Se explica cómo realizar operaciones matemáticas avanzadas utilizando la clase Math, incluyendo raíces cuadradas, potencias y redondeo. Se introducen las clases predefinidas y personalizadas en Java, y se enfatiza la importancia de la API de Java para acceder a cientos de clases y métodos. El vídeo también explora cómo utilizar el método sqrt() para calcular raíces cuadradas y resalta la precisión de Java con tipos de datos, utilizando Eclipse para demostrar la creación y ejecución de un programa simple.

Takeaways

  • 😀 Este curso de programación en Java aborda la creación de programas desde cero.
  • 🔢 Se ha discutido cómo declarar variables y constantes, así como los diferentes tipos de datos en Java.
  • 🧮 Se exploraron los operadores aritméticos básicos como la suma, la resta, la multiplicación y la división.
  • 📚 Se avanzó en el conocimiento de las estructuras principales y se introdujeron cálculos numéricos más avanzados como raíces, elevado al cuadrado y redondeo de números.
  • 👨‍🏫 Se enfatizó la importancia de las clases en Java, tanto las propias como las predefinidas, y se explicó la diferencia entre ellas.
  • 📚 Se mencionaron clases predefinidas en Java, como String, Math, Array y System, que facilitan tareas comunes en la programación.
  • 🔍 Se presentó la API de Java (Java API) como una herramienta esencial para consultar clases y métodos predefinidos.
  • 💻 Se utilizó Eclipse para demostrar cómo se programa en Java y se abrió un nuevo espacio de trabajo para crear una clase llamada 'Calculations'.
  • 🛠️ Se explicó el uso del método sqrt() de la clase Math para calcular la raíz cuadrada de un número y se corrigió un error de tipo de datos.
  • 🔄 Se mencionó que se abordará el uso del método round() y la técnica de recast en futuras lecciones.

Q & A

  • ¿Qué temas se abordan en el curso de programación en Java mencionado en el guion?

    -El curso aborda la declaración de variables, tipos de datos en Java, operadores aritméticos, y avanza hacia el uso de la clase Math para realizar cálculos numéricos avanzados como raíces cuadradas, elevar a una potencia, redondeo de números, entre otros.

  • ¿Qué es una clase en el contexto de programación en Java?

    -Una clase en Java es una estructura de datos que actúa como una plantilla para objetos, puede contener métodos y variables, y es un concepto fundamental ya que todos los programas Java deben estar compuestos por al menos una clase.

  • ¿Cuáles son las dos tipos de clases que se pueden tener en Java según el guion?

    -Las dos tipos de clases en Java son las clases propias, que son aquellas que el programador crea, y las clases predefinidas, que vienen incorporadas en el lenguaje de programación Java.

  • ¿Qué es la clase Math en Java y qué propósito cumple?

    -La clase Math es una clase predefinida en Java que contiene métodos estáticos para realizar cálculos matemáticos como raíces cuadradas, potencias, redondeo, entre otros.

  • ¿Qué es la API de Java y cómo se relaciona con las clases predefinidas?

    -La API de Java es una biblioteca que contiene todas las clases del lenguaje de programación Java, y es una herramienta que los programadores consultan frecuentemente para usar las clases y métodos predefinidos en sus programas.

  • ¿Cómo se puede utilizar el método sqrt() de la clase Math para calcular la raíz cuadrada de un número?

    -El método sqrt() se utiliza pasando un número como argumento y devuelve la raíz cuadrada de ese número. El resultado es de tipo double, por lo que se debe almacenar en una variable de tipo double.

  • ¿Qué es un error de conversión de tipos en Java y cómo se presenta en el guion?

    -Un error de conversión de tipos ocurre cuando se intenta almacenar un dato de un tipo en una variable de otro tipo incompatible. En el guion, se presenta un ejemplo donde se intenta almacenar el resultado de sqrt(), que es un double, en una variable de tipo int, lo que causa un error.

  • ¿Qué herramienta de desarrollo se utiliza para ilustrar la creación y ejecución de código en el guion?

    -El guion utiliza Eclipse, un entorno de desarrollo integrado (IDE), para crear, editar, y ejecutar programas en Java.

  • ¿Qué métodos adicionales de la clase Math se mencionan en el guion para futuras sesiones?

    -Se mencionan métodos como round() para redondear números, pow() para elevar a una potencia, y la posibilidad de explorar el concepto de recast, que es el cambio de un tipo de dato a otro.

  • ¿Qué es un constante en Java y cómo se relaciona con la clase Math?

    -Una constante en Java es una variable cuyo valor no puede cambiar después de que se le asigne. La clase Math tiene constantes predefinidas, como PI, que almacenan valores fijos importantes para cálculos matemáticos.

Outlines

00:00

📚 Introducción al curso de programación en Java

El primer párrafo presenta un curso de programación en Java, enfocándose en la explicación de las estructuras principales del lenguaje. Se menciona que se han cubierto temas como la declaración de variables y constantes, así como los tipos de datos en Java. También se recuerda que en el vídeo anterior se exploraron los operadores aritméticos básicos. El vídeo actual promueve avanzar en el conocimiento de estas estructuras, introduciendo cálculos numéricos más avanzados como raíces, elevación al cuadrado y redondeo de números. Se destaca la importancia de estas habilidades para los programadores principiantes y se anuncia la exploración de la clase Math en Java para realizar estos cálculos.

05:02

🏫 Importancia de las clases en Java y la biblioteca de clases (API)

El segundo párrafo profundiza en el concepto de clases en Java, explicando que todo programa en Java debe estar compuesto por al menos una clase y que los programas suelen estar compuestos por múltiples clases. Se diferencia entre clases propias, que son aquellas que el programador crea, y clases predefinidas que vienen incorporadas en el lenguaje. Se ilustra con ejemplos como la clase String para manejar cadenas de caracteres y la clase Math para realizar cálculos matemáticos. Además, se introduce la API de Java como una biblioteca de clases y métodos que el programador puede consultar y utilizar en sus programas.

10:03

🔢 Explorando la clase Math y sus métodos matemáticos

El tercer párrafo se centra en la clase Math y sus métodos para realizar cálculos matemáticos. Se mencionan métodos como sqrt para calcular raíces cuadradas, pow para elevar un número a una potencia y otros métodos para funciones trigonométricas como sin y tan. También se habla sobre el concepto de redondeo y la existencia de constantes predefinidas como PI y E. Se enfatiza la importancia de manejar la API de Java para aprender y utilizar estos métodos en la programación.

15:06

💻 Creación y errores en la programación con Java

El cuarto párrafo describe el proceso de creación de una clase en Java y la ejecución de un ejemplo simple para calcular la raíz cuadrada de un número. Se detalla cómo se declara una variable y se utiliza el método sqrt de la clase Math, pero se comete un error al intentar almacenar un valor decimal en una variable de tipo entero. Se explica la rigidez de Java con los tipos de datos y cómo el editor Eclipse ayuda a identificar y solucionar estos errores, proporcionando información sobre los métodos y sus tipos de datos esperados.

20:06

✅ Solución de errores y uso de la clase Math en Java

El último párrafo concluye con la corrección del error mencionado anteriormente, cambiando el tipo de la variable para almacenar el resultado decimal de la raíz cuadrada. Se muestra la ejecución del programa y el resultado esperado, que es el número 3.0. Además, se anuncia que en futuros vídeos se explorarán otros métodos de la clase Math, como el redondeo y el uso de métodos con dos parámetros, así como el concepto de recast para cambiar un tipo de datos a otro.

Mindmap

Keywords

💡Clases

Las clases son una de las estructuras fundamentales en la programación orientada a objetos, y en el vídeo se menciona que cada programa en Java debe estar compuesto por al menos una clase. Las clases en Java pueden ser propias, que son aquellas que el programador crea, o predefinidas, que son proporcionadas por el lenguaje de programación. En el vídeo, se utiliza la clase 'Math' como ejemplo de una clase predefinida para realizar cálculos matemáticos, destacando así la importancia de las clases en la estructura y funcionamiento de los programas Java.

💡Variables

Las variables son elementos utilizados en la programación para almacenar datos. En el guion, se habla sobre cómo se declaran variables y constantes, y se menciona que en Java se tienen diferentes tipos de datos para dichas variables. Las variables son fundamentales para almacenar y manipular información dentro de un programa, como se ve en el ejemplo donde se declara una variable para almacenar el resultado de la raíz cuadrada de un número.

💡Operadores aritméticos

Los operadores aritméticos son símbolos que representan operaciones matemáticas básicas como la suma, la resta, la multiplicación y la división. En el vídeo se menciona que en el vídeo anterior se vieron cómo usar estos operadores para realizar operaciones simples, lo que es esencial para el procesamiento de cálculos en cualquier programa.

💡Raíz cuadrada

La raíz cuadrada es una operación matemática que se utiliza para encontrar un número que, multiplicado por sí mismo, resulte en el número original. En el vídeo, se utiliza el método 'sqrt' de la clase 'Math' para calcular la raíz cuadrada de un número, mostrando cómo se puede realizar este cálculo en Java y resaltando la precisión de los tipos de datos al almacenar el resultado en una variable de tipo double.

💡Tipos de datos

Los tipos de datos son categorías predefinidas de valores que una variable puede almacenar. En el vídeo se discute la importancia de los tipos de datos en Java, como enteros (int) y dobles (double), y cómo se deben utilizar correctamente para evitar errores de conversión, como el intento de almacenar un resultado decimal en una variable de tipo entero.

💡Métodos

Los métodos son bloques de código que realizan una tarea específica y se pueden reutilizar en diferentes partes de un programa. En el vídeo, se mencionan varios métodos de la clase 'Math', como 'sqrt' para calcular raíces cuadradas y 'round' para redondear números, demostrando cómo estos métodos facilitan el desarrollo de programas al encapsular funcionalidades comunes.

💡API de Java

La API de Java es una biblioteca de clases y métodos predefinidos que permite a los programadores utilizar funcionalidades avanzadas sin tener que programarlas desde cero. En el vídeo, se hace referencia a la API de Java como una herramienta esencial para los programadores, ya que incluye cientos de clases y métodos que pueden ser consultados y utilizados en los programas.

💡Eclipse

Eclipse es un entorno de desarrollo integrado (IDE) ampliamente utilizado para la programación en Java. En el vídeo, se utiliza Eclipse para crear y ejecutar un programa que utiliza la clase 'Math', mostrando cómo los IDEs facilitan la escritura, la compilación y la depuración de código, y cómo proporcionan ayuda para la programación, como sugerencias de métodos y autocompletado.

💡Errores de conversión de tipos

Los errores de conversión de tipos ocurren cuando se intenta almacenar un tipo de dato en una variable que no es compatible con ese tipo. En el vídeo, se muestra un ejemplo de este error cuando se intenta almacenar el resultado de la función 'sqrt', que devuelve un double, en una variable de tipo int, lo que provoca un error hasta que se corrige el tipo de la variable a double.

💡Constantes

Las constantes son variables cuyos valores no pueden cambiar una vez que se han asignado. En el vídeo, se menciona la constante 'PI' de la clase 'Math', que almacena el valor de pi, una cifra matemática fundamental en la trigonometría. Las constantes son útiles para mantener valores inmutables que se utilizan a lo largo de un programa.

Highlights

Bienvenido a otro entrega de curso de programación en Java.

Se discute la importancia de las estructuras principales en Java.

Se explica cómo declarar variables y constantes en Java.

Se exploran los tipos de datos en Java.

Se enseña el uso de operadores aritméticos para realizar operaciones básicas.

Se avanza en el conocimiento de las estructuras principales y se mencionan otros cálculos numéricos.

Se mencionan cálculos como raíces, elevados al poder y redondeo de números.

Se habla sobre la necesidad de conocer el manejo de la clase Math para realizar cálculos en Java.

Se aclara la diferencia entre clases propias y clases predefinidas en Java.

Se explica que cada programa en Java debe estar compuesto por al menos una clase.

Se menciona la importancia de la clase Math para realizar cálculos matemáticos en Java.

Se presentan ejemplos de clases predefinidas en Java, como String, Math, Array y Thread.

Se habla sobre la imposibilidad de memorizar todas las clases y métodos predefinidos y la necesidad del API de Java.

Se muestra cómo se puede consultar la biblioteca de clases de Java (API) en línea.

Se discute la importancia de las clases y sus métodos en la programación en Java.

Se explica cómo se pueden utilizar métodos de la clase Math, como sqrt para calcular raíces cuadradas.

Se menciona el uso de la constante pi en la clase Math para cálculos trigonométricos.

Se ilustra cómo se puede encontrar y utilizar métodos de la clase Math con la ayuda del IDE Eclipse.

Se da un ejemplo práctico de cómo se declara una variable y se le asigna el resultado de una operación matemática utilizando la clase Math.

Se explica el error de tipo de conversión y cómo solucionarlo al utilizar métodos que devuelven un tipo de datos específico.

Se muestra cómo ejecutar un programa simple en Eclipse que utiliza la clase Math para calcular la raíz cuadrada de un número.

Se invita a los espectadores a seguir el curso para aprender más sobre el uso de la clase Math y otros conceptos en futuros videos.

Transcripts

play00:01

hello that such welcome to another delivery

play00:03

this java programming course from

play00:05

zero we were watching in videos

play00:08

previous main structures

play00:09

of language we have already seen how

play00:12

declare variables like declare

play00:14

constant we talked about the types of

play00:16

data in java and in the last video if

play00:18

you remember, we were seeing how

play00:20

use the arithmetic operators to

play00:23

do simple operations such as

play00:25

sums subtraction multiplications and

play00:27

divisions in this video we follow

play00:29

advancing in the knowledge of

play00:31

main structures and let's see

play00:33

how to perform other numerical calculations

play00:35

in java

play00:36

when we say other numerical calculations

play00:38

we refer for example to roots

play00:40

square we mean to raise a

play00:42

number to a power rounding of

play00:44

numbers and so on

play00:46

and to do these calculations that are

play00:48

essential when programming

play00:50

maybe those who are starting in the

play00:53

world of programming because you can not

play00:55

see the need to learn to do

play00:57

all this when creating a program

play00:59

but I already anticipate that it is

play01:00

essential and to be able to do these

play01:03

calculations in java we have to know the

play01:05

handling of the class more and that is it turns out

play01:09

that to make these calculations we must

play01:10

use in java this class the term

play01:13

of class because maybe we still find

play01:16

everything familiar maybe serves us a little

play01:17

because we are starting to program in

play01:19

java we are not in the beginning yet

play01:21

that we know about the classes that we know

play01:24

of the class concept as we said in

play01:27

previous videos all java program

play01:30

must be composed of at least one

play01:32

class as usual is that a program in

play01:34

java is composed of more than one class

play01:36

but at least it has to be formed of

play01:37

a class and we the examples that

play01:40

We have been doing so far

play01:42

they have been composed of a class not

play01:43

we have to keep moving forward in this

play01:46

class concept although not yet

play01:48

we are in a position to deepen

play01:50

everything you need but

play01:53

we have to know at least two things

play01:55

and is that besides that every program

play01:57

java has to be composed at least

play01:58

of a class the classes in java can

play02:01

be of two types we can have in java

play02:03

own classes and we have in java classes

play02:07

predefined what is the difference between

play02:09

one and the other

play02:10

own classes are what we create

play02:13

us as we have done then in

play02:15

previous videos for example now

play02:18

we have one of the classes on screen

play02:20

what we did in the last good video

play02:21

because this would be a class of its own is a

play02:24

class that we have created very

play02:26

simple and this class has a unique

play02:29

method another term that still does not

play02:31

we control completely the method that has

play02:34

this class is the main all class method

play02:36

in java all program in java must have

play02:39

at least one main method unless it is

play02:42

a play program that we already talked about

play02:44

it at the time in the applets it

play02:47

replace the main with the line method

play02:49

but good for the moment this is not us

play02:50

worry we'll see later

play02:52

these are the classes that we have

play02:54

gone so far very simple

play02:56

Well, these are our own classes

play02:58

classes developed by us

play02:59

however we also have another kind of

play03:02

classes that are the predefined ones and these

play03:04

they are classes are already built inside

play03:07

of the java programming language are

play03:10

classes that are supplied with the

play03:12

programming language so that

play03:14

we can use in our programs

play03:16

in the case that we need them and here

play03:19

in this little graphic I have put you

play03:21

four examples of predefined classes

play03:23

that come in java and I tell you that I have

play03:26

put only four examples but

play03:28

come hundreds and hundreds that is to say to the

play03:31

time to program in java us

play03:33

we have hundreds and hundreds of classes

play03:35

predefined that is already built

play03:37

so that we can use them in

play03:40

our programs if we need them

play03:41

the examples that I have put in this

play03:44

screen are the string class that

play03:47

we have not seen it yet, it's good for

play03:49

handle character strings strings

play03:51

text the class more that is then the one that

play03:54

let's see a little bit above in this

play03:56

video which allows us to make the

play03:59

mathematical calculations square roots

play04:00

round powers and so on

play04:03

the array class which is another one of those

play04:05

we will manage throughout the course

play04:07

the array class allows you to manipulate

play04:09

handle arrays

play04:13

arrays and then then we have the class

play04:16

create that is another class that is used

play04:18

quite when it comes to programming in java

play04:20

and that allows

play04:21

the concurrent programming that is called

play04:23

but I've put four examples

play04:25

of four of the most used classes

play04:27

but as I say there are hundreds

play04:30

so many are the classes that there are for

play04:32

a programmer is impossible to memorize

play04:35

all and not just memorize the

play04:36

classes keep in mind that each class

play04:39

predefined that comes with the language

play04:40

java brings with it a number of methods

play04:44

who perform different tasks with what

play04:46

what if it is impossible to memorize all the

play04:49

classes is even more impossible is to memorize

play04:51

the methods that come with those classes

play04:53

so that we can use them is because

play04:56

what exists in java what is known

play04:59

as a class library or

play05:02

called api de java which is the pija

play05:06

well, the blackboard is a library

play05:08

where all the classes of the

play05:11

java programming language and that all

play05:14

programmer should consult with

play05:16

often when preparing a

play05:18

program since it is very likely that

play05:20

example if you frequently use the

play05:22

class more you forget it then some of

play05:24

the methods that come within that

play05:26

class you know that they exist but you do not

play05:29

remember its syntax do not remember

play05:31

of the arguments that come in that

play05:33

method and you'll have to consult the

play05:34

library

play05:36

this library is very easy to use

play05:39

to her and let's see an example I'll

play05:42

open a browser for example firefox

play05:44

previously

play05:46

and once we open firefox firefox

play05:49

sorry if you go to the google page

play05:51

Well, in any search engine if you

play05:54

you say to fix to fix that I do not

play05:56

I have purple because the consultation with

play05:58

often the first link that we

play06:00

it offers then it is a link to the java app and

play06:05

here it left library of classes not

play06:07

so if we click on that link then

play06:09

right now we have open what is the

play06:11

java class library not yet

play06:14

we are in a position to handle this

play06:17

class library because this

play06:18

class library you also have to

play06:20

learn to manage it is composed of

play06:22

different panels or parts that

play06:24

we will talk about them at the time without

play06:27

However good in this panel that

play06:29

we have here below to the left then

play06:30

they come in alphabetical order all the

play06:32

classes that we currently have in the

play06:35

java programming language and fixes

play06:37

that as I told you there are one hundred 600 there is no

play06:39

human person able to memorize all

play06:42

these predefined classes that come with

play06:44

the language so that we can

play06:45

use

play06:46

As I said before, there are classes that

play06:48

commission calculations

play06:49

mathematicians like most there are classes that

play06:51

They are in charge of carrying out operations with

play06:54

strings of characters like string there

play06:56

classes because they are dedicated to work

play06:58

with networks there are classes that are dedicated

play07:01

to the graphic part for example having

play07:03

here then green bay the youth good

play07:05

all this refers to work

play07:07

java graphic is to say if you want

play07:10

create the graphical interface as you will have

play07:12

that working with these classes here is

play07:14

the same graphics class serves to

play07:16

work with graphics in java graphics

play07:18

from finally hundreds and hundreds of classes

play07:21

Each class as I say has its own

play07:23

methods and you will find out right now

play07:25

those who did not know it before the

play07:28

dimension of the programming language

play07:30

java is to say the number of classes

play07:33

predefined methods packages that already

play07:37

We will see at the time what it is that

play07:38

they come with this programming language

play07:41

as of today, May 19, 2014 that

play07:45

is when I'm recording this video the

play07:47

app and it goes by version 7 what do you want

play07:51

say this

play07:53

well, it means that we

play07:54

When installing a machine

play07:55

virtual of the java

play07:56

we've talked about it in videos

play07:57

previous we are installing us the

play07:59

version 7 with time then surely

play08:02

that instead of installing version 7

play08:03

we have to install version 8 and

play08:05

in a couple of years with surely

play08:07

let's be by version 9 by the version

play08:08

10 is not to say the virtual machine of

play08:10

java that we have installed in this course

play08:12

It updates what the

play08:15

update of the virtual machine

play08:18

java because it consists of several things and a

play08:20

of them is that more classes are included

play08:23

that is, in this class library

play08:25

right now the classes that exist are

play08:27

these are the classes with which

play08:30

We currently have to program in

play08:32

Java

play08:33

but over time new

play08:35

you already know that information technology

play08:37

evolves constantly and

play08:39

programming languages also with what

play08:41

what if a need arises

play08:44

which requires the use of a calculation of a

play08:48

class or whatever it is that right now

play08:50

What you do is update the

play08:53

java virtual machine instead of the

play08:55

version 7 as they update it to 8 as

play08:58

consequence the library is updated

play09:01

of java classes is to say the api of

play09:03

java is updated and include those classes

play09:06

new ones that allow you to do these

play09:09

news

play09:10

that have been emerging over time is

play09:14

the library of the left was fixed

play09:16

constantly updated with which

play09:20

There are many people who download it

play09:21

because it is possible to download the

play09:23

java library in local to have it

play09:25

on your hard drive and well this download

play09:27

Well, he's consulting it but I'm going

play09:30

I recommend if you have an internet connection

play09:31

it is to consult the online route because

play09:34

If you consult online, you can be sure

play09:36

that you're always updated

play09:38

you know that java belongs to oracle with

play09:40

which is good as the download or the

play09:42

consultation is done from the page of

play09:44

prayer said this

play09:47

well then we go back to our

play09:48

power Point presentation

play09:51

and we already have a slight emotion of what

play09:53

which is a predefined class not

play09:55

worry that we will go deeper

play09:56

course in the use of the sabín apa

play09:59

api sorry or library of classes and in

play10:01

this video what we are going to do is see

play10:03

a little a little bit more the class more

play10:05

because the class has a lot more

play10:07

methods for doing mathematical calculations

play10:08

and I'm just going to mention the

play10:12

main calculations obviously if

play10:15

you learn to use the class more for

play10:17

do basic or usual calculations and

play10:21

you also learn how to handle the api

play10:23

java that we will see in future videos and

play10:24

also already shortly

play10:26

you will know how to use any method

play10:28

belonging to the class plus or

play10:29

belonging to any other kind of

play10:32

java what methods are we going to see us from

play10:35

the best class because the methods that

play10:38

let's see from the matt class are more

play10:40

point s qr t is to say the method s cub rt

play10:45

what he does then is to return us a

play10:48

decimal number

play10:50

is the square root of the parameter

play10:53

specified in parentheses in

play10:55

definitive

play10:56

point that is what is allowed

play10:58

calculate the square root of a number

play11:00

the method for what it does is calculate the

play11:03

power of a number this method receives

play11:05

two parameters or arguments a base and

play11:08

an exponent

play11:10

we are also going to use good this is not

play11:13

we are going to use drinks or mentioned

play11:14

more points and what it does is calculate the

play11:17

sine of an angle plus a total what

play11:19

does is calculate the tangent to so

play11:21

the tangent arc is to say as you can

play11:23

observe the class more

play11:25

what it brings inside are diverse

play11:28

srt methods all without cause so tan and

play11:33

many others to do calculations not

play11:35

round method what it does is round a

play11:37

this number is used a lot is not

play11:39

very frequent that the need arises

play11:41

round one figure at the time of

play11:43

work then in a java program and not

play11:46

there is also the concept of constants

play11:48

of class then we have already

play11:51

seen what is a constant but we have

play11:53

seen what is a constant itself is

play11:55

say we have learned to declare a

play11:57

constant in our own

play11:59

we know that the value of a constant does not

play12:00

can change as we have classes

play12:03

own and predefined classes as per

play12:05

example more we also have constants

play12:07

own those that we have seen in videos

play12:09

previous and predefined constants or

play12:13

class constants

play12:15

the constant predefined constants

play12:17

of class are those that accompany the

play12:20

class is to say they come with the class and what

play12:22

what they do then is store in their

play12:24

internal values that can not be

play12:25

modified for example is very common

play12:28

than to do trigonometry calculations

play12:30

you need to use the number and then

play12:33

the pi number because everyone I think we know

play12:35

which is equal to 3 1416 rounding off

play12:38

well, this is a fixed value

play12:40

value of the number pi can not change

play12:42

under no circumstances the number that

play12:44

it has to be always the same is because

play12:46

this reason why it is stored in

play12:49

a constant constant that has

play12:51

called and and as a consequence of this

play12:55

we can use it and the type value

play12:57

you can not change it a constant of

play12:59

class

play13:00

and all this as it translates to the

play13:02

good practice then let's open

play13:03

eclipse below and let's see

play13:05

how to use the map class to perform

play13:08

this series of basic calculations so

play13:10

as always because we are going to close the

play13:11

presentation of power point and we are going to

play13:13

open the eclipse program

play13:15

then then we go to the folder

play13:17

where we have stored the program

play13:19

we double click on the executable and

play13:22

we wait for the program to load

play13:24

you know it takes a few moments once

play13:27

that the program loads well since it

play13:29

usually open for the class you left

play13:31

open is to say if at the time of closing

play13:32

eclipse you left an open class like

play13:35

is my case saved changes but

play13:37

open is to say on the screen well

play13:39

Eclipse is usually opened by that class

play13:41

we remember that in the browser

play13:43

packages because we have our project

play13:45

which we call first steps

play13:46

Within our project we have the

play13:48

source src folder and inside we have

play13:51

the default package something that is not yet

play13:54

we know very well what is our

play13:56

package and we have built at the moment

play13:57

three classes well then let's build

play14:00

a fourth class where we use the

play14:02

best class because you know you can

play14:04

leave open if you have the same as me

play14:07

open class you can leave it open

play14:08

because eclipse what it does is work

play14:10

by tabs that is to say as you go

play14:12

creating classes and leaving them

play14:14

open as they appear

play14:15

continuation of the previous

play14:17

and if you want to work more

play14:18

comfortable you can close the class from your

play14:20

corresponding X and create a new

play14:22

is to create a new class you know

play14:24

what can be done from different

play14:26

menus and buttons I'm going to use the

play14:28

button on the toolbar and you

play14:30

I'm going to say that this class is going to

play14:31

call for example

play14:33

calculations and a bass with more and I'm going to

play14:39

say already to the creation window of

play14:41

classes that create the main method and so

play14:44

Well, we already have part of the work

play14:46

done and then as always since we're going to

play14:49

enter within the mail method no

play14:51

this would be an example of the class itself

play14:54

because it is a class that we have created

play14:55

us right now and it's called

play14:57

calculations commas well let's go to

play15:00

use the sea class so you can see

play15:02

what would be the mechanics

play15:06

let's create a simple instruction

play15:08

that allows us to find out the root

play15:11

square of a number but I'm going to

play15:13

do to start badly and I'm going to do it

play15:15

bad so that you can see where the

play15:17

error and see also how strict it is

play15:19

the java programming language with the

play15:21

data types then I will declare

play15:23

an integer variable where

play15:25

I intend to store the result of

play15:29

the square root of a number then

play15:30

Well I say int

play15:32

then name of the variable

play15:33

Well, I'm going to call you, for example, the root

play15:36

we can call as we want and tell him

play15:37

that this will be equal to more

play15:42

point and then the method would come

play15:44

but before putting the method that

play15:46

we remember that to find the root it was s

play15:48

qr t fix that eclipse it helps us

play15:51

quite at the time of writing with these

play15:53

menus of which we have spoken in

play15:55

previous videos the behavior

play15:56

smart when we put more

play15:59

point a menu is displayed in which

play16:01

all methods appear

play16:03

that belong to the class plus all the

play16:07

methods and also look at the impossible that

play16:11

is to memorize this in addition to the methods

play16:12

the constants also appear

play16:14

predefined that come with marc and here

play16:16

appears for example the constant and the

play16:19

that we talked about a moment ago but

play16:20

another number also appears

play16:23

constant that is the number e that also

play16:24

has a fixed value not good when

play16:26

I put and I remove the zoom I'm going

play16:28

but also notice that eclipse

play16:30

offers us another help and is that

play16:32

example if we are going to use that

play16:34

qr t if now after the point

play16:37

we write an s this menu is going to all

play16:40

the methods that start with that and already

play16:42

we are seeing in this menu well where

play16:45

you find that q rte not

play16:49

Well, if in addition to one you put a quota

play16:51

we already have only the srt method and

play16:54

here we are given a lot of information and

play16:56

this makes it eclipse look at us

play16:59

saying eclipse in this submenu that

play17:01

appears on the right that you press the

play17:03

Tab key to put the focus on

play17:07

this window

play17:08

what is the use of that window that we

play17:11

informs this window good because this

play17:12

window informs us of what it is that

play17:15

does the method that does not have what

play17:17

what to work with an editor of these

play17:20

features like eclipse netbeans

play17:21

etc. helps a lot at the time of

play17:23

program it is also convenient

play17:26

convenient I do not consider it

play17:28

fundamental that when programming

play17:30

in java you have always, although not what

play17:32

we know use still minimized the

play17:35

app and left the class library

play17:37

a whole programmer java then

play17:39

normally normally works with the

play17:42

app and minimized because in this app and

play17:44

also in the lower left window

play17:47

we can arrive are ordered by order

play17:49

alphabetical to the class more and when

play17:52

let's see the class more notice that the

play17:54

I'm seeing here if we click on it in

play17:56

the window on the right so what we

play17:59

appears from to press as it is a

play18:02

very exhaustive information of what is it

play18:04

who does this class and what is it for and

play18:06

in addition all the methods belonging

play18:08

to the class and well then what kind of

play18:12

data returns how it is built

play18:15

etcetera we are not yet in

play18:17

willingness to understand this at all

play18:19

you worry we will be working with it

play18:21

little by little but well we also have

play18:23

the help of the eclipse as we have seen

play18:25

a moment ago if you look at this

play18:27

menu that comes out in eclipse is us

play18:29

saying that this method that q rt

play18:32

receives a parameter or argument that

play18:34

it has to be double type and this

play18:37

appears here below informs us

play18:40

of the type of data returned by this

play18:42

method is to say this method what does

play18:45

is to find the square root of a number

play18:47

well that square root what

play18:51

it has to be double it is to say it's a

play18:53

double type data however if you

play18:56

you see, I'm telling you that I

play18:58

store the square root because still

play19:00

we do not even have it done that we

play19:02

store it in a whole type number

play19:04

this is going to give an error because the method

play19:06

s qr returns a double a decimal if

play19:10

we tell you to keep it a whole not

play19:11

it is possible with which if we finish

play19:13

to complete

play19:15

the square root for example 9

play19:20

Well, this has to give us a

play19:22

error notice that in this case eclipse

play19:24

it will also do it to any other editor

play19:26

Java programming does not emphasize the

play19:29

red the instruction and we see a

play19:32

information balloon to the left if

play19:34

you place the mouse on top of that balloon

play19:36

information because it tells us that there is a

play19:39

Type conversion error and the case

play19:42

is that you can not convert from double to

play19:46

whole and that's because the method s qr you

play19:49

what it does is return an integer if

play19:51

you also set the internal parameter

play19:54

It must be a double and we

play19:56

however we have introduced an integer is

play19:58

say in the help he told us the method

play20:01

srt had to have here a double this

play20:04

what the help told us and yet

play20:06

the number that we have entered inside

play20:08

of the arguments of this function is not

play20:10

a double is an integer really what

play20:13

is doing hub although we do not

play20:14

let's see is to consider that number as

play20:17

you see now on screen 90

play20:20

we can also put for example the

play20:22

square root of 952 this is

play20:24

perfectly valid is a double the

play20:26

error is that we can not

play20:28

store it within a whole solution

play20:31

I'm going to leave the 9 again, well, the

play20:33

solution is to change the data type to

play20:36

corresponding type is to say do not tell me

play20:38

warehouses in a whole number but

play20:41

they store it in a variable forgiveness or

play20:44

in a number he stores it in a

play20:45

variable of double type fixes that in

play20:47

how much do we change the type of the variable

play20:49

where we are storing the result

play20:51

that you already know is 3

play20:53

Well, automatically disappears

play20:55

underlined red and the only thing that appears

play20:57

now it is the information in yellow that

play20:58

we have seen on other occasions for

play21:00

tell us that that variable is not yet

play21:02

used the only thing we would have to

play21:04

do now it is because of the instruction

play21:06

system or print

play21:08

well print

play21:11

root in the console and our program already

play21:15

would be finished that is to say statement

play21:18

variable initiation we are

play21:20

starting at the square root of 9 and

play21:22

then we tell him to print us in

play21:24

the console the value you have stored

play21:26

in the root variable if we execute this

play21:29

program then in the console you have to

play21:30

exit 3.0 and have to exit 3.0 the root

play21:36

square of 9 stress because the result

play21:38

that always returns this method is

play21:40

a double with which if we click on the

play21:42

play then look like in the console

play21:44

after compiling it will take a

play21:46

little does it effectively return a

play21:48

3.0

play21:50

Well, here you see the use of the class

play21:53

plus

play21:54

specifically with the srt method

play21:58

let's leave this video at the point in

play22:00

the one that we meet and in the next

play22:02

video then we'll see how to use the

play22:04

round method to round up we'll see how

play22:07

also use the pop method

play22:09

example to see then an example of

play22:10

method that needs two parameters and

play22:14

let's look at also see a concept

play22:15

which is the recast concept is

play22:18

change one type of data to another for that

play22:21

as I say we will see in the next

play22:22

delivery so as always I invite you to

play22:24

Stay tuned for the next video

play22:26

until then it goes well

Rate This

5.0 / 5 (0 votes)

相关标签
Programación JavaClase MathCálculos MatemáticosProgramación BásicaEclipse IDEConstantes MatemáticasMétodos de ClaseTipos de DatosAPI de JavaDesarrollo de Software
您是否需要英文摘要?