Curso Java desde cero  #2 | Indentado, Compilación y Ejecución del código

Curso Java desde cero #2 | Indentado, Compilación y Ejecución del código

Introduction to Java Programming

Course Overview

  • The video welcomes viewers to the second part of a Java programming course, providing a link in the description for newcomers to access the first part.
  • Viewers are instructed to open both Notepad and Command Prompt, tools previously covered in the last video.

Understanding Classes in Java

  • A class in Java is defined as a template where code is written; it serves as a structure for creating programs.
  • Emphasis on reading code from top to bottom and left to right, which is crucial for understanding how computers interpret code.

Writing Your First Class

  • The first line of code must declare the class name; this example uses "public class" followed by the chosen name (e.g., "Ernesto").
  • After naming the class, an opening brace should be added, highlighting that every opening brace must have a corresponding closing brace.

Structuring Code Properly

Indentation and Readability

  • The importance of indentation is discussed; it helps maintain clean and readable code.
  • The main method (public static void main(String[] args)) is introduced as essential for starting any Java program.

Implementing Indentation

  • Indentation allows programmers to create visually appealing and organized code. It involves adding spaces after opening braces.
  • When writing subsequent lines of code after an opening brace, two spaces should be added for proper indentation.

Creating the Main Method

Syntax of Main Method

  • The syntax for declaring the main method includes specific keywords: public, static, void, followed by main with parameters (String[] args) enclosed in parentheses.
  • After writing this line, another opening brace `` should follow, indicating where the main method's body begins.

Understanding the Java Main Method and Program Structure

The Importance of the Main Method

  • The Main method is essential for starting a Java program; without it, the code cannot be executed.
  • The class name and Main method are defined to identify and initiate the program's execution.

Writing Instructions in Java

  • Indentation in Java begins after the nearest opening brace, which helps structure the code visually.
  • To print messages to the screen, use System.out.printLn() with text enclosed in double quotes.

Syntax Rules for Java Code

  • Each instruction must end with a semicolon (;) to signify completion.
  • Text strings must always be enclosed in quotes when outputting messages.

Creating Your First Program

  • A common first message printed in programming is "Hello World," serving as a standard introduction to coding.
  • After writing your code, it's crucial to save your work to prevent data loss.

Saving and Naming Your Java File

  • Save your file with a .txt extension initially but remember that this does not make it a runnable Java program yet.
  • To create an executable Java file, save it with a .java extension using the same name as your class (e.g., Ernesto.java).

Navigating Windows Command Line

  • Understanding how to navigate through directories using command line commands like dir is vital for accessing files on your system.

How to Compile and Run a Java Program

Navigating the Desktop and Listing Files

  • The process begins by accessing the desktop folder, where the command dir is used to list all files present.
  • The user identifies two key files: a Java file named Ernesto.java and a text file containing code snippets called práctica 1.txt.

Understanding Java Compilation

  • It’s crucial to note that Java requires a compiler for communication; this compiler is known as javac.
  • The compilation process translates human-readable code into bytecode, which can be understood by the computer.

Compiling the Java File

  • To compile, the command javac Ernesto.java is executed. If successful, it generates an additional file named Ernesto.class.
  • In case of errors during compilation, it indicates issues in the written code that need correction before proceeding.

Executing the Compiled Program

  • Once compiled without errors, execution of the program is done using the command java Ernesto, which runs the program.
  • The output of this simple program displays "Hola mundo," confirming successful execution.

Troubleshooting Compilation Errors

  • If errors occur during compilation, users should compare their code with provided examples to identify discrepancies.
  • After correcting any mistakes, recompile using javac Ernesto.java, followed by executing with java Ernesto to see results.

Conclusion and Encouragement

Video description

Curso JAVA, en este vídeo aprenderemos a realizar el correcto indentando del código fuente de un programa, compilaremos y ejecutaremos un programa desde consola, crearemos nuestro primer programa y entenderemos la función de las primeras lineas de código. ¡¡Ayúdame a seguir creciendo, te invito a suscribirte!! La Geekipedia de Ernesto ➞ Facebook https://www.facebook.com/LaGeekipediaDeErnesto/ ➞ Instagram https://www.instagram.com/lageekipedia/ ➞ Twitter https://twitter.com/LaGeekipedia ═════════════════════════════════════════ Link de descarga de la practica: https://goo.gl/VYp3jD Enlace a la primera parte de este curso: https://www.youtube.com/watch?v=L1oMLsiMusQ ═════════════════════════════════════════ Música: 1. Kasger - Reflections [NCS Release] https://www.youtube.com/watch?v=M4_ivwYfWFo Kasger • https://soundcloud.com/kaspergerlif • https://www.youtube.com/c/kasger • https://www.facebook.com/Kasger • https://twitter.com/Kasger ═════════════════════════════════════════ Vídeo Final: 1. Mount Bromo HD Timelapse Movie by Justin Ng https://www.youtube.com/watch?v=UNs7TkFvK-4 Follow Facebook: justinngphoto.com/facebook Follow Twitter: twitter.com/justinngphoto Follow Google+: plus.google.com/116998818067074636759 To join my photography community: mopsg.com