Java SE Programming 1 - "Hello World"
Let's see our first Java code.
As you can see this is the simplest Java code. We can see three components here. There is a class, in here you can see it's name as Test. The class's scope is defined using the curly braces. Test class's opening curly brace is in line 5 and ending curly brace is in line 9.
Inside that Test class (Test is just a class name) you can see the Main method, as the name "Main" it is the method that doing and/or starting all functionalities in the Java program. We just skip the detailed description about the main method for another post. As you thought the main method's scope is starting from curly brace in line 6 and it ends with line 8.
Inside the curly braces of main method there is a print statement. It prints things. In here it prints Hello World. And the print statement ends with a semi colon. In Java every statement should ends with a semi colon, otherwise program doesn't know your statement is over. There are two types of print statements in Java. One type is,
System.out.println("hello world");
Above example we used this type. Other type is,
System.out.print("hello world");
Did you see? "ls" letters are missing in the second type.
Wanna know the difference? see the below images.
Inside that Test class (Test is just a class name) you can see the Main method, as the name "Main" it is the method that doing and/or starting all functionalities in the Java program. We just skip the detailed description about the main method for another post. As you thought the main method's scope is starting from curly brace in line 6 and it ends with line 8.
Inside the curly braces of main method there is a print statement. It prints things. In here it prints Hello World. And the print statement ends with a semi colon. In Java every statement should ends with a semi colon, otherwise program doesn't know your statement is over. There are two types of print statements in Java. One type is,
System.out.println("hello world");
Above example we used this type. Other type is,
System.out.print("hello world");
Did you see? "ls" letters are missing in the second type.
Wanna know the difference? see the below images.
| Different types of Print Statements |
| Code output |
In 'println' type the cursor goes to next line and stop. Therefore next print statement will print in next line. But 'print' type the cursor don't go to next line, it stops where the string is over. Therefore next print statement will print very next to the previous print.
And we use curly braces as mentioned above to define scope over code indentation. (In python we use indentation to define scopes.)
Okay. That's enough for the first Java post. Feel free to comment any suggestions and wait for the next post of Java.
Post a Comment