My
understanding of the code in class
2:
1. class hello
2. {
3. public static void main(String[]
args)
4. {
5. System.out.println("Hello!
It is me, JAVA boy!");
6. }
7. }
Line 1 tells me to create a class named hello. In my JAVA language,
everything is inside a class. Line 2 and line 7 are two curvy braces.
All you want me to do must reside
inside these 2 braces.
Line 3 is main method.
It is a special method in my language. It tells me where to start
to find all the commands you give me. When run a program, I always
look for a class with a main method
and start from there. Line 4 and line 6 are 2 braces belong to this
method.
Remember: braces should be paired!
Left brace { pairs
with right brace },
always.
Line 5 is little something new. System is
a class. out is one
field of System (output to the command prompt). println is
a method in out. This
line tells me to write out a sentence "Hello! It is me, JAVA
boy!" in command prompt. println means
print line. Why you don't say printline? Well,
I don't say that way. I say println.
Also, did you see that semicolon ; ? Every
command(computer guru say statement,
whatever..) must ended with ;.
Did you notice that not every line ended with ;. That
is because not every line is a statement. Some lines are defining
class (Line 1), defining method(line 3).
Home work
1. Imitate what you learn, create a helloDoggy class and print a
line says: Hello Doggy.
2. Modify hello.java and print 3 lines greeting.
You may print out anything you want to say. Be creative. |