we will try to analyze your first java program:
public class Hello
{
/ **
* My first java program
* /
public static void main (String [] args) {
/ / display the string "Hello world" on screen
System.out.println ("Hello world!");
}
}
public class Helloindicate the class name is Hello. In java all the code should be placed inside the class declaration. We do this by using the keyword class. In addition, the class uses a special public access, which indicates that our class will have free access to another class from another package anyway (package is a collection of classes). We will discuss more deeply about the package and special access to a further discussion.The next line is composed of curly braces {indicates the beginning of the block. In this code, we put the brace on the next line after the declaration of class, however, we can also put a brace after the first line of code we write. So, we can write our code as follows:public class Hello{orpublic class Hello {The next three lines indicate a comment in the java language. Comment is something that is used to document each section of code written. Comments are not part of the program itself, but it is used for documentation purposes. The comments themselves can be added to the code you write as a guide that can help the process of learning good programming./ *** My first java program* /Comments are indicated by the sign "/ *" and "*/". Everything that exists between these markers is ignored by the java compiler, and they are only considered as a comment.The next line,public static void main (String [] args) {or can also be written as follows,public static void main (String [] args){indicate the name of a method in a class in acting as the main method. The main method is the starting point of a Java program. All proram except applet written in Java language starting with the main method. Be sure to
The next line is also a commentary,/ / Prints the string "Hello world" on screenNow we learn two ways to make a comment. The first way is by placing a comment in / * and * /, and another way is to write the sign / / at the beginning of the commentsThe next line,System.out.print ("Hello world!");displays the text "Hello World!" on the screen. Command System.out.println (), displays a text enclosed by double Pute marks ("") on the screen.The last two lines consisting of two brackets used to close the main method and each class in sequence.
10:40 PM
Wardana
Posted in: 

0 comments:
Post a Comment