Curso Java. Estructuras principales III. Declaración variables Eclipse Vídeo 6
Summary
TLDREste vídeo tutorial de programación en Java desde cero guía a los estudiantes a través de la creación de una nueva clase en Eclipse. Se repasan conceptos básicos como tipos de datos primitivos, variables y la importancia de la declaración de variables. Se muestra cómo escribir comentarios en el código, declarar variables en una sola línea y cómo cambiar sus valores durante la ejecución del programa. Además, se destaca la utilidad de los comentarios para comprender mejor el código y se enfatiza la orientación a objetos en Java, donde todo es considerado un objeto con propiedades y métodos.
Takeaways
- 😀 Se da la bienvenida a un nuevo video de curso de programación en Java desde cero.
- 🔍 Se repasan conceptos vistos en videos anteriores, como tipos de datos primitivos y la declaración de variables.
- 💻 Se instruye sobre cómo abrir y utilizar Eclipse para crear una nueva clase y repasar conceptos.
- 📂 Se explica la estructura de carpetas en un proyecto de Eclipse, incluyendo 'src' y 'bin'.
- 🛠️ Se detallan los pasos para crear una nueva clase en Eclipse y la importancia de la opción 'main method'.
- 📝 Se discute la inclusión de comentarios en el código para facilitar la comprensión y colaboración en proyectos.
- 🔢 Se ejemplifica la declaración y asignación de variables, y se explora la diferencia entre tipos de datos como 'byte', 'short' e 'int'.
- 📡 Se ilustra cómo se utiliza la variable 'age' para almacenar y mostrar valores en la consola.
- 🔁 Se menciona la capacidad de modificar el valor de una variable durante la ejecución de un programa.
- 💬 Se enfatiza la importancia de los comentarios en el código y cómo se escriben en Java.
Q & A
¿Qué tipo de datos primitivos se mencionan en el video?
-En el video se mencionan los tipos de datos primitivos como enteros y decimales.
¿Qué concepto se explicó en relación a las variables en el video?
-Se explicó cómo se declaran las variables y los tipos de datos que pueden manejar, como los enteros y los decimales.
¿Qué herramienta se utiliza para crear y gestionar los proyectos de código en el video?
-Se utiliza Eclipse como herramienta de desarrollo para crear y gestionar proyectos de código en Java.
¿Cómo se crea una nueva clase en Eclipse según el video?
-Se puede crear una nueva clase en Eclipse a través del menú 'File' y seleccionando la opción 'New' o utilizando el atajo de teclado correspondiente.
¿Qué es un 'package' en el contexto de Java y cómo se menciona en el video?
-Un 'package' en Java es una división en la estructura de directorios que se utiliza para organizar el código fuente. En el video, se menciona que el 'package' debería estar en blanco cuando se crea una nueva clase.
¿Qué método es esencial en todos los programas de Java según el video?
-El método 'main' es esencial en todos los programas de Java, ya que es el punto de entrada del programa.
¿Qué se hace al seleccionar la opción de crear el método 'main' en Eclipse?
-Al seleccionar la opción de crear el método 'main', Eclipse genera un marco básico del método main, que es necesario para ejecutar el programa.
¿Qué son los comentarios en Java y cómo se mencionan en el video?
-Los comentarios en Java son anotaciones que no afectan la ejecución del código y se utilizan para proporcionar información adicional al código. Se mencionan en el video como una práctica útil para ayudar a otros programadores a entender el código.
¿Cómo se declara y se inicia una variable en una sola línea en Java según el video?
-Se puede declarar e iniciar una variable en una sola línea en Java utilizando la siguiente sintaxis: 'tipoDeDatos nombreVariable = valor;'.
¿Qué tipo de datos se recomienda para almacenar la edad de una persona según lo discutido en el video?
-El video sugiere que se puede utilizar el tipo de datos 'byte' para almacenar la edad de una persona, ya que el rango de un byte (-128 a 127) es adecuado para representar la edad.
¿Qué significa la advertencia amarilla en Eclipse y cómo se menciona en el video?
-La advertencia amarilla en Eclipse indica una nota o advertencia, pero no un error. En el video, se menciona que una advertencia amarilla puede aparecer si se declara una variable pero no se utiliza en el código.
Outlines
💻 Introducción al Curso de Programación en Java
Este primer párrafo introduce un nuevo video del curso de programación en Java desde cero. Se menciona que en el video anterior se discutieron las estructuras de control y los tipos de datos primitivos en Java, como los enteros y decimales. El objetivo de este video es aplicar el conocimiento adquirido en Eclipse, un entorno de desarrollo integrado (IDE), creando una nueva clase para repasar los conceptos vistos. Se describe el proceso de abrir Eclipse, recordar la estructura de carpetas y cómo se guardan los archivos de código, y se explica cómo abrir el proyecto y crear una nueva clase llamada 'variables'. También se detalla cómo se configura la clase con un método principal (main), que es esencial en todos los programas de Java, y se menciona la utilidad de los comentarios en el código para ayudar a otros programadores a comprender mejor el programa.
📝 Creando y Utilizando Variables en Java
En este segundo párrafo, se profundiza en la creación y uso de variables en Java. Se explica cómo declarar una variable para almacenar un valor, como la edad de una persona, y se discute el rango adecuado para el tipo de dato 'byte'. Se muestra cómo se escribe la declaración de la variable, cómo se le asigna un valor y cómo se utiliza en una impresión en la consola. Además, se aborda la importancia de utilizar variables que ya han sido inicializadas y cómo Eclipse ayuda al programador mediante avisos y sugerencias visuales. Se menciona la corrección de errores y la ejecución del programa, destacando la diferencia entre los avisos amarillos y rojos en Eclipse, y se enfatiza la práctica de utilizar comentarios para mejorar la comprensión del código.
🔢 Declaración y Asignación de Variables en Java
El tercer párrafo se centra en la declaración y asignación de variables en una sola línea de código en Java. Se ilustra cómo se puede declarar y asignar un valor a una variable en el mismo momento, y se compara con la declaración y asignación en líneas separadas. Se discute la flexibilidad de Java para manejar diferentes tipos de datos, como 'byte', 'short' e 'int', y cómo estos afectan la optimización de recursos. Se muestra cómo cambiar el valor de una variable después de su declaración y cómo estos cambios se reflejan en la salida del programa. Se subraya la secuencia de ejecución del código en el método main y cómo los cambios en los valores de las variables se procesan y se muestran en la consola.
📝 Comentarios y Espacios en la Programación Java
Este cuarto párrafo aborda el uso de comentarios en el código fuente de Java, explicando cómo se insertan y su función en la programación. Se describen los comentarios de una sola línea, marcados con '//', y los comentarios multilínea, marcados con '/*' y '*/'. Se enfatiza la utilidad de los comentarios para aclarar el código y facilitar la comprensión, especialmente en proyectos grandes con múltiples programadores. Se discute cómo los espacios verticales en el código no afectan la ejecución del programa, pero son útiles para organizar y mejorar la legibilidad del código. Se sugiere la práctica de incluir comentarios en el código para mejorar la comprensión y se muestra cómo se pueden escribir comentarios en varias líneas en Eclipse.
🔚 Conclusión del Vídeo y Perspectivas Futuras
El último párrafo del guion del video cierra el tema actual y establece expectativas para futuras lecciones. Se menciona que Java es un lenguaje de programación orientado a objetos, donde todo se considera un objeto, incluyendo la consola. Se explica brevemente la noción de que los objetos tienen propiedades y métodos, y se da un ejemplo de cómo la consola, considerada un objeto, tiene un método 'print'. Se anima a los espectadores a seguir el curso para aprender más sobre estos conceptos. Se sugiere que los programadores principiantes acostumbren a incluir comentarios en su código y se cierra el video con la promesa de más contenido en futuras entregas.
Mindmap
Keywords
💡Eclipse
💡Clase
💡Variable
💡Tipos de datos
💡Método main
💡Comentarios
💡Consola
💡Sintaxis
💡Objeto
💡Programación orientada a objetos
Highlights
Bienvenida al curso de programación en Java desde cero.
Revisión de conceptos vistos en videos anteriores, como estructuras de datos y tipos primitivos en Java.
Introducción al concepto de variables en Java.
Demostración de cómo abrir y usar Eclipse para la programación en Java.
Creación de una nueva clase en Eclipse para repasar conceptos.
Explicación de la estructura de carpetas en un proyecto de Eclipse.
Cómo crear una clase con un método main en Eclipse.
Importancia del método main en la ejecución de un programa Java.
Uso de comentarios en el código Java para ayudar a otros programadores a entender el código.
Declaración y uso de variables de tipo byte para almacenar valores enteros.
Ejemplo práctico de cómo declarar y asignar valores a variables en Java.
Cómo utilizar el sistema de ayuda de Eclipse para aprender sobre errores y advertencias.
Diferencia entre declarar una variable y asignarle un valor en Java.
Ejemplo de cómo cambiar el valor de una variable durante la ejecución de un programa.
Importancia de la ejecución secuencial de código en Java y cómo afecta a las variables.
Cómo incluir comentarios de varias líneas en el código Java.
Conclusión del video y invitación a seguir el curso para aprender más sobre Java.
Transcripts
hello that such welcome everyone to another
delivery of this programming course in
java from scratch we were seeing
in the previous video the structures
main language we saw the types
of primitive data that are handled in
java the data of integer type decimals
etcetera we also saw the concept of
variable we saw how the
variables what we are going to do in this
video is to transfer all these
knowledge acquired at eclipse
let's open eclipse let's create another
class to review concepts seen in
previous videos and declare we have
variables we will handle data types like this
that we are going to close the presentation and
we open eclipse
we remember that we had two folders and
specifically on the desk you
then you will probably have them in another
site one that was called eclipse with the
program and another one that we had created
to save these codes
initials of this course
we call that java course folder if
we open the java course folder
we found the first folder
steps that corresponds to the project that
we created the first time we opened
eclipse and within this folder
project because there were two folders
main src which is where it is stored
the java file and the bean folder that is
where they are assembled where the
witte code file is the file
compiled with java extension if we open
src here we have the java if we open it well
here we have in class said this we are going to
open the program again then
we open the eclipse folder double click on
the executable
and we wait for the program to load
once the program finished
load then opens the project that
we had built the previous video
Well, let's create a new class
within this project if you have opened
the class that we create in videos
previous in the in the work area
We can close it from your
corresponding x without any problem
then we close it and what we are going to
do as I say is to create another class
more then then several options in
eclipse if we remember good so let's
use another option more
to get to know the little program to
little if you look at the bar
tools then we should have a
button that I'm going to point out right now in
screen this has as well as a
small c whose goal is to build
good classes because this is another way
of building classes then we click on
that button and the window of
creation of classes on the one hand has us
that indicate the project folder is
right on the other hand the package that
we still do not know what it is should
be blank and then we have the
cursor blinking in the name box
which corresponds to the name of the class
let's call this class
for example variables what then you
we call variables and we're going to use
an option that we did not see in videos
earlier we go little by little that is in
this window tell you a little bit more
downwards so that we build the
make method we already mentioned in videos
previous that every java program should
have at least one main method that is the
method from which everything is executed
the code is for this poor reason that
eclipse in this window offers us the
creation of the main method then then
we select this check to tell you
that we are going to create a main method and
click on the finish button
I've done these and everything went well
you have to create then within what is
our project within what is the
src folder and within what is the
default package that we do not have yet
very clear then what does this mean?
do you worry two classes the video
previous and the class that we just
create now that is called variables
notice that it already gives you the java extension and
if you look at the work area
because he has created the class with us
name that we have
specified access modifier
public word reserved class for
specify that you are inside a class
opening key closing key and
it has also built us is already a
comfort then what is the main method
no and from here we will have to
start programming all java application
begins to run always from a
main method
what you see inside the main method and
that created us eclipse is what it
called in java comments and the only thing
what does he do then is tell us this
comment that all the code then has
to start from here not the
comments the program does not have them in
account at all is to say at the time of
run a program or is the comment
as if the comments were not
they are small annotations that serve
of help or warning code
to the programmer to whom you are applying
not code and above all they are very useful
when in the same project they participate
several programmers when in a
project involved several programmers
it is more than advisable to go including
comments that help then those
programmers that go behind you to
examine the same good code well that
help them to understand a little better the
code because this instruction exists
here because you put this instruction
there's etcetera so they do not bother and not
I'm going to confuse them
comments we can delete them
quietly and so I will explain
now after how to include comments
us manually
Well, what we have to do is
get inside the main method and go
to start declaring variables in a
line in two lines let's start
variables and we're going to use variables
For example, let's imagine that we are going to
declare a variable to store
because the age of a person because in a
future we will need to have it in
the program
Well, we have several options if
remember then the age of a person
it has to be more or less between 0
and 100 percent and little if not more than
a hundred and a little and to be lucky then
then we can put that age
within a variable of type byte if
you remember in the previous video the byd
went from the minus 128 negative to 127
positive declaration of variables good
then bites that is to say data type name
of the variable for example age
and here, well, we can choose
close the sentence with a semicolon
with which we have already declared the
variable and then later in the
code so we can start the is to say
name of the variable age equal and the
corresponding value semicolon no
eclipse as one goes programming
Well, it includes a lot of help with
which we have to go
familiarizing for example if you look
to the left of what is the
statement of the variable they offer us
a kind of balloon or bulb well
these are these bulbs that appear here
yellow are notices
warnings but in no case these
yellow warnings means that
there is an error if it is the mouse
over this warning you will see that
eclipse tells you that the value of the
local variable age has not been used
it means that we have declared the
variable we have also started it but
at no time of this variable has
used that means it's used
well then if we now
we say that we print the value that there is
stored in the age variable in the
console should remove this
yellow warning that we have both
the left as underlining the name
of the variable age because already the
we will be using something for
example system point out point print ln
we open parentheses and within the
parentheses we put the name of the
variable and do not forget to finish the
sentence with a semicolon
with this instruction we are already
using the variable and for that reason
x we are already removed the warning
yellow because effectively
we are using the variable
if you remember the previous video os
I commented that it can not be used in java
a variable that has not been started in
our case we have started the
variable was equal to 35 but if by
any reason this instruction
this sentence was not I'm going to
eliminate good then in that case fixos
as soon as the eclipse is not
warns with a red balloon or with a
bulb in red and that is to these icons
He usually calls them balloons, well
warns us that there is an error and
when the warnings are red
then yes that implies an error of
syntax not if we place the mouse over
of that warning, yes, it is going to
launch a description like that I get it
stop a description that to us that
We are starting to program, as
better we find it difficult to
interpret but when we have a
little bit of practice and we know a little
more the language these warnings yes
that are going to be very clarifying here
Well, you are telling me more or less
that especially this last line is the
that gives us the clue that the variable
locality then
has been started for that good reason
It is also underlining us the
variable age telling me good then that
there is a problem to solve it and it is
that this variable is not started if
pulse control z to undo the last
which says good as you can see
and so it takes away the warning and the
program works perfectly
remembering concepts that we saw in the
video past us in this line what
what we have done has been to book a
space in memory to store the
number 35 this what we have done that
we do not see it we are consuming
x resources to store that value and
Later we are telling you that
we reflect on the console system point to
point print l n the value of the variable
age if we press the play to execute
this program I remember that in the bar
of tools you have a good play
well, here eclipse can make two
things if you have not saved the button
save this code when you click on the
play you will get a window
intermediate to save the changes
if you save the changes and then press
the play that intermediate window is omitted
notice that I have not saved changes yet
because in the name of the file that I
da eclipse appears an asterisk is this
disk as we saw in videos
previous indicates that you have not saved
the latest changes made with what
which will take pulse in this play
Well, as you can see, this is the
intermediate window that comes out and this comes out
Well, because we have not saved
fixed changes that tells me that
select resources to save or more or
unless you select the program where
you want to save the changes of the
check activities click on ok
automatically saves the changes and in
the console so look how
effectively we already get the value that
there is stored in the age variable
this variable that we have declared as
byte then we could have declared it
how short is perfectly saying
as the value that we are going to store in
its interior is a good 35 because
we tell you how old you are and then
age equal to 35 as this works
Exactly the same thing that happens is
that while declaring it as byte
We are reserving a space in the
memory to store the 35 when the
We declare what we are
doing is to reserve a larger space
to store the same value with what
which the optimization of resources is not
so good if instead of declaring it as
short then declared it as int
Well, the program also works
perfectly what happens then I will
can you imagine this would be a
byte statement this would be a
statement of sun and this would be a
statement of a and so we can follow it
and in all cases so we're
storing inside is the number
35 in short then we would have
served perfectly with a data of
type b and a byte variable for
do the test and you see that this
it works effectively because we go back to
press on the play as we have not saved
changes we get the intermediate window
click on ok
effectively the program works
exactly the same
if we want to make a statement in the
same line as we saw in your
moment is to say instead of starting the
variable and then sorry instead of
declare the variable and then start it
we can do everything in the same line
that is, if we do without the
initiation of variable and together with the
statement we say fifth age equal
to 35 semicolon, well, this is
valid perfectly we are doing
an initiation and declaration
initiation of variables in it
line many times then you can do it
well to simplify the code but
other times not because he declares is a
variable and you do not know for sure what
value will take that variable in the
future
the variable name says it all and it is
that the value stored inside
it can vary and there comes the name of
variable can change is to say that if
after declaring a variable and
after starting it as we have
we in this code later on will
we changed the value saying it was
equal to 75 as this is perfectly
valid because it is a variable and
in the definition that we saw in the video
earlier we said that a variable
memory space where it is stored
a value that can change during the
execution of a program if we execute
this code then what will come out of us
console is number 75 because all the
java programs start to run by
the main method right now is very
simple because we have nothing nothing is
that a main method when we create
more complex applications you will discover
that we have applications formed by
several classes formed with a lot of
methods but there's always going to be a
main method in one of those classes
because the code of that application always
begins to run within the method
main and once the code
the compiler or interpreter better said
once the interpreter when he is
running the program enters the
main method this code starts at
run from top to bottom then
then the first line that interprets
is to try equal to 35 but
immediately after crushing on
write the value saying that it is equal to
75 and finally print
with which good let's try it on
this time I'm going to save changes with
controls or by pressing the floppy disk and
now if I press on the window
intermediate should not go out and does not come out
but fix as in the console as the
value that gives me is 75 not if we
this initiation this change of value what
we do behind the point-to-point system
print then this program works
perfectly just that as the code
inside the main method is executed from
top to bottom first declares and starts
the age variable then prints on the
console the value that has age but the
value that you have at this height of
program that is 35 and after having
taken out by console the 35 returns to
assign a value that we do not see because it does not
We are telling you to go back to
include if we execute this code
pressing on the play
Well, we see that the value is really
the 35 we could do to see the
new value of the variable then another
system point out point print remember
that java is case sensitive what then
must respect uppercase and lowercase
well, once we've done this
what is going to come out now in
code console is executed from above
down well, we are going to get the
messages in console 1 and 2 because I have
two instructions system point to point
pin
the first message would take away the value of
the variable given this height of
program the second as the value that
age at that height of the program and
just before we gave it a value
different we have varied the value of the
variable then then if we click on
the play
we have that effectively gives us both
values the two system point out point
print l
to understand a little better the
code although we still need a lot to
understand it perfectly so I'll tell you
that java is a programming language
object oriented that means that
in java everything is considered an object
absolutely everything the console where
we are seeing the results
it is also considered by java a
object and the objects and we'll talk about
this carefully have properties and
they have methods like in real life they do not
the objects of real life a car a
table
a chair have properties of a table
because it has a width a height a weight a
color even a temperature all that
they would be properties and also objects
have methods is able to make a
object that would be a method not
for example a car the method that can
have a car can be start braking
turn to the left is turn to the
right is to teach the methods of
car object while the
properties could be with dry the red
with se blue color car width three
meters high in 90 centimeters and so on
well as the console is considered
also an object has its properties
and its methods is to say this little window and
is what we are doing with this
instruction that we have here what
we are doing is neither more nor less
that accessing or executing a method is
say something that console window
can do and one of the things that can
do just like a car can turn
start or stop one of the things that
can do is print it or what you
we are saying is that this object
belonging to the system ie the
console out of the system prints the age
basically is this do not worry that
this will be explained in detail in
its moment
as for the spaces that we can
leave vertically as you can see
they have no influence when it comes to
execute a program that is to say the
vertical spaces that we can leave
between instructions well they do not have
importance and in terms of
comments this is extremely useful
when we learn to program when
we learn to program and we start
build our first codes
it helps a lot to go inserting
comments throughout the code that
help us understand a little more
Well, everything we are doing for
example would be a good practice since
this is the first statement of
variable that we have done include a
comment to the right good so that
indicate that that is a statement of
initiation in the same line as
include comments in java if the
comments these personal notes
they will be from a single line the
comment has to be preceded by
two slanted bars the symbol of
divide and then the message that
you want to put
If the comment is going to be composed of
several lines because it must start with
disc bars
the expression the comment you want
put and end with asterisk bar
in our case as we are going to include a
comment of a single line just to
continuation of the declaration
initiation of the age variable
we put two inverted bars and
then we can put what we
fancy as long as it occupies a
single line declaration and initiation
of variable in a single line not os
you fear because the eclipse underlines us
then some terms of these messages
because when we go to execute
interpreting the program will not have it in
account since it is a comment then
then here we have included our
first comment more comments than
we can include good because imagine that
Now I want to include a message
several lines just before the
system instruction point by point print
well disc bars and a
then we would write the message and
I'm going to do it in several lines because
example we could put the following
instruction
in the console
and we can put here in parentheses to
sister 1 out is the system console
the message
of the variable or better the value
directly the value of the variable
and since said that I'm going to put several
lines of the variable age set as
the
comments because as soon as he has given
enter to do it in several lines
here, the eclipse alone has already
built the comment close the
intermediate asterisk really is not
necessary although eclipse builds it is
say this intermediate asterisk if not
we want to erase does not happen absolutely
nothing I do not know exactly why
builds eclipse but good if it gets
It does not bother you either and at the time of
execute the program I keep changes then
these comments do not affect at all
to the good functioning of the program that
the program continues to function as it should
then then remember accustomed
especially now that we are starting
to program then include comments on
all the lines that you want there is no
limits in terms of putting comments and
This does not imply that the program is going to
go slower or weigh much more because it
it's about text so good, so let's go
to leave this video at the point where
we meet and we will continue advancing
in future deliveries so I invite you to
Stay tuned until then
Ver Más Videos Relacionados
📀 DATOS PRIMITIVOS JAVA | DECLARACIÓN, INICIALIZACIÓN y ASIGNACIÓN Variables ◀️
🔴Curso de Python #02 - Variables y Tipos de Datos
Variables Numéricas en MATLAB - Curso Básico de MATLAB #DesdeCero. Resolviendo ecuación cuadrática.
Curso Java. Estructuras principales VI. Clase Math. Vídeo 9
2_2 II: Comenzando a Programar - Ejecución Condicional y Repetitiva
Programación en Java | Windows | S3-1 Variables y Constantes
5.0 / 5 (0 votes)