Monday, June 15, 2009

Analyzing First Java program

Now, we will try to analyze the first Java program:

public class Hello
{
/ **
* My first java program
* /
public static void main (String [] args) {
/ / display the string "Hello world" on the screen
System.out.println ( "Hello world!");
}
}

The first line of code:

public class Hello

indicates the name of the Hello class. In Java, all code should be placed in declaration in the class. we do so by using the keyword class. As In addition, use the class access specifier public, which indicates that the class we have free access to the other class from another package that also (packagemerupakan collection of class-class). We will discuss more in the package and access specifier in the next session.
The next line which is made up of brackets brace (denotes the beginning of blocks. In the code this, we put the brace brackets on the next line after the class declaration, however, we can also put this brace brackets after the first line of code that we write. Thus, we can write our code as follows:

public class Hello
{
or
public class Hello {

Next three lines indicate the existence of a Java comment. Comment is used to document each section of code that is written. Comments not is part of the program itself, but used for the purpose of documentation. Comments can be added itself to the code you write as a guide can help the learning process is good programming.

/**
* My first java program
*/

Comments expressed with a "/ *" and "*/". Anything that is a sign of is ignored by the Java compiler, and they only considered as a comment.
Next line,

public static void main (String [] args) {

or can be also written as follows,

public static void main (String [] args)
{

the name of a method in the Hello class that acts as a method main. Main method is the starting point of a Java program. All programs except applet written in Java language starting with the main method. Be sure to follow the principle of the correct sign.
The line is also a further comment,

/ / Displays the string "Hello world" on the screen

Now we learn how to make 2 comments. The first way is to put in the comment / * and * /, and the other way is to write sign / / at the beginning of the comment
Next line,

System.out.println("Hello world!");

displays the text "Hello World!" on the screen. Command System.out.println (), display in side the text by double-pute marks ( "") on the screen. Last two lines that consist of two brace brackets used to cover method primary and each class respectively.

Comments on Java
Comments are notes written in code with the goal as documentation. The text is not part of the program and does not affect the way program.
Java supports three types of comments: C + + style single line comments, C style some line, and special javadoc comment.

Comment writing C + + Style
C + + comment style begins with the / /. All text after / / is considered a comment. As an example,

// This is a C++ style or single line comments


Writing Style Comments C
Comments or C-style comments also referred to some lines begin with / * and ends with * /. All text that is between two marks are considered as comment. No comments such as C + + style, this comment can reach a few lines. As example,

/* this is an example of a
C style or multiline comments */


Special javadoc comment
Comments javadoc used for special men-generate HTML documentation for the your Java program. You can create a javadoc comment with the start line with / ** and mengakhirinya with * /. Comments such as C_style, can also reach a few lines. Comments can also consist of tags for add more information on your comment. For example,

/**
This is an example of special java doc comments used for \n
generating an html documentation. It uses tags like:
@author Florence Balagtas
@version 1.2
*/


The statement in the Java and Blocks

The statement is one or more lines of code that end with a semicolon. As for example is a single statement

System.out.println(“Hello world”);

Block is one or more statements between the brackets and the open brace brace brackets, namely a set of statements closed as one unit unity. Block statements can be collected but will not exactly have any relevance function. Some of the permitted amount of empty space there is inside, as an example of a block is:

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


Java Identifier
Java Identifier is a sign that represents the names of variables, method, class, etc.. Example of Identifier is: Hello, play, System, out. Pendeklarasian Java is case-sensitive. This means that Identifier: Hello is not the same as the hello. Identifier must begin with a letter, underscore "_", or dollar sign "$". Letters can be uppercase or lowercase. Characters
can further use the number 0 smpai 9. Identifier can not use the keyword in Java, such as class, public, void, etc.. Next we will discuss more about the keyword in Java.

Keyword in Java
Keyword is the identifier that has to be defined previously by Java for a particular purpose. You can not use keywords as variable names, class, your method, etc.. The following is a list of keywords in Java (Java Keywords).


We will discuss all about the meaning of each keyword and how they are used in the process of writing Java programs.
Note: true, false, null, and not including the keyword akan but they include special words, so you can not use them as variable names in your program.

No comments:

Post a Comment