PIC20A Lecture 2: A simple program

In the section, we will learn how to
You must read the textbook p32-36 or A Closer Look at HelloWorld.
 1. // name this file HelloWorld.java  
2.
3. /* Usage :
4. type java HelloWorld
5. at Dos Command prompt */
6.
7. /** Written by Charles Li */
8.
9. public class HelloWorld {
10. public static void main(String[] args) {
11. System.out.println("Hello World !!!");
12. }
13.}
Line 1
// name this file HelloWorld.java
Explanation:
Same as C++, words after // are comments. Every words on the same line after // will be ignored by the compiler
Syntax :
//your comments

Line 3-5  
/*.... */
Explanation :
As in C++, all the words between /* and */ will be ignored. /* and */ can be on one single line or on different lines.
Syntax :
/* your comment */
or
         
/* comment 1 
   comment 2 
   comment 3 */
Line 7
/**....*/
Explanation:
This is very simple to /* comments */. Everything between /** and */ will be ignored. Again, the comments can be on either one single line or on multiple lines. The difference between the these 2 types of comments is that the comment between the /** and */ will appear in the documentation generated by the Java tools (javadoc, you will learn this later).
Syntax :
/** your comment */
or
/** comment 1 
    comment 2 
    comment 3 */
Line 9
public class HelloWorld
Explanation:
HelloWorld is the name of the class. You must name the file HelloWorld.java. This is the only possible name of this file.
Syntax :
public class classname {
.........
}
Line 10
public static void main(String[] args)
Explanation:
Syntax :
public static void main(String[] args) {
        // your codes 
}
Detail Explanation for PIC10B students(don't worry if you don't understand it now)
Line 11.
System.out.println("Hello World !!!");
Explanation: Syntax :
     System.out.println("print something with a return at the end"); 
System.out.print("print something without return");
Detail Explanation for PIC10B students(don't worry if you don't understand it now)
/*  Usage :
type java HelloWho Charles
at Dos Command prompt
The output will be
Hello Charles
*/

public  class HelloWho {
    public static void main(String[] args) {
             System.out.println("Hello " + args[0] );
       }
}

Explanation:


Question :
What is the output of

System.out.println


Summary

After this lecture, you should know