Sunday, September 10, 2017

Hello World



Challenge: Write a program that prints a greeting of your choice, perhaps in a language other than English.
Solution: 






public class lab1_01 {

  public static void main(String[] args) {
  System.out.println("Hello World");

     }
}

Let's examine the program line by line: 
To insert comments in Java we can do it in two ways, the first one is by typing // and the second one by typing /* */. The difference is that with the first one we can only insert comments in the line where we are using it, and with the second one we can comment as many lines we want (see the video for comments).

In our first line (public class <class name>), we have what is know as class header, and it marks the beginning of a class definition. A class functions as a container for an application but also it could has other functions that we will cover latter. After out name class we have the sentence (public static void main(String[] args) ) and this is known as the method header and it mark the beginning of a method. Methods could be defined as one of more programming statements under the same name.

To print an statement in java we can use:
System.out.println("message goes here")
and if you noticed in the video when we type System.out and we hit dot, Netbeans provides us a list of possible combinations we could use and a brief description. 

System.out.println() vs System.out.print()
By using System.out.println() we are going to print a message and the next output we print it is going to appear in the next line. By using System.out.print() print the next message after the previous one.






No comments:

Post a Comment