In this first entry I'll talk a little about what I am learning the basics of programming classes about the basic structure of a program written in Java.
The following example prints a message on the screen and terminates.
- / / Saludo.java
- public class Greeting
- {public static
- void main (String [] args) {
- System.out.print ("Hello world!");
- System.exit ( 0);}
What makes this program?
In line 1 we are putting a single line comment is specified by the two diagonals (/ /) and followed by a message which will be ignored by the compiler when error checking. Not visible on the screen. Its utility is to present messages to those who wish to read our code.
Line number 3 says
public class Greeting {public
and class are Java reserved words and thus we are telling the compiler that we will write a main class within our Saludo.java file whose name is healthy. For convenience the main class name should match the name of the file. What is also good programming practice is to have the following considerations:
- The class names are written with the first letter capitalized.
- The names of the members and methods are written with the first letter in lowercase.
- must follow the rules for writing the names of identifiers in Java (of which I will not talk).
On line # 5 are:
public static void main (String [] args) {
We are declaring the main method of our program and where it begins execution. public words, static void and Java language are reserved, meaning that we can not use as names of members, methods or classes. The keyword public indicates that the main method is known externally to the class, also static and may be referenced without the need to create an instance of the class externally to its scope, whereas void indicate that the function will return unsuccessful. The parameter passed to the main method is an array of strings, a series of arguments that we send to the function to perform a particular action is with them. In this case are not used. Finally the left key that defines the area of \u200b\u200bprimary function. In line
:
System.out.print ("Hello world!");
we are using the Java standard output when using the System. The print () method of System class can receive as parameters of data type integer, float, double, character, boolean or string to display them as messages to the screen.
With instruction System.exit (0); indicate that our program is completed with error code 0, ie, without error.
Finally finished the main scope of the class and the class greet with the right brace (}).
If we run our program in the Windows console gives a result like this:
0 comments:
Post a Comment