Program Comment
Program comment is part of the program code that will not be executed during program compilation process. This means that the presence of program comment will not affect the course of the program. Program comment is usually used to write information about the program code, for example: creator, version, program description, and others. Program comment also frequently written to write the flow or algorithm of the program.
As explained earlier when we write Hello World program code, in Java, program comments are divided into three. Two of them are adopted from C++ language. Those three comments are as follows:
- Comment for one line
Just as in C++, Java also uses the // sign to make a comment that applies only to a single line of code. Here is an example of its use:
// this is a Java comment
If the // sign applied for comment more than one line, it will cause error when compiling the program, as shown in the following code sample:
// this is
a Java comment (FALSE)
In the code above, the second line will be considered as an unknown identifier that will cause error in the compilation process. -
Comment for more than one line
In Java, comment that has more than one line is made by using the /* and */ sign. Here is an example of its use:
/* This is one line comment */
/* This is
two lines comment */
As you can see in the example above, the type of comments that use /* and */ can also be applied to one line comment. This comment is a C/C++ comment style. -
Comment for documentation purpose
Besides these two types of the comments above, Java has a special kind of comment that is used for documentation purpose, using /** and */ sign. This type of comment will be used by javadoc program to generate an HTML file. To make the comment, we also need to use special tags that have been provided, for example: @author, @version, @param, and so on. Here is an example of its use:
/**
* "Hello World" program
* @author Aula Muttaqin
* @version 1.0
*/
Program Block
Java allows us to group one or more statements in a program block. In Java, a program block begins with { and end with }. By the time we write code, we will be a lot of work with program block. In Java, a program block can be applied to the definition of the class, method, loop structure, decision making, and others. Here is an example of making the program block in Java:
//program block in class definition class ClassSample { //begin of program block ... } //end of program block //program block in loop structure for (int i=0; i<7; i++) { //begin of program block System.out.println(i); System.out.println((i+1)); } //end of program block //program block in decision making if (a < b) { //begin of program block System.out.println("Bigger value: " + b); } //end of program block //program block in method definition public int getValue() { //begin of program block return value; } //end of program block
To a single statement in the loop and decision making block, we actually do not need to use a program block. Consider the following example:
if (p == null) { exit; } for (int i=0; i<7; i++) { System.out.println(i); }The code above can also be written as follows:
if (p == null) exit; for (int i=0; i<7; i++) System.out.println(i);
Separator
Separator is used to separate one part of the program with other parts. The most often used separator in any program code is semicolon, which is used to separate statements with each other. Here is the list separator that is contained in the Java:
-
Braces: { }
Used to make the program block (class, method, decision making, and loop control) and to fill in the initial value in array declaration.
Example:
Class MyClass { ... } int[] a = {1, 2, 3};
-
Parentheses: ( )
Used to fill in the list of parameters in the method, to flank an expression in certain operations (e.g. arithmetic operatios), flanking the expression in control statement, and to do typecast.
Example:
public int add(int a, int b) { return a + b; } int value = (1 * 2) + 3; if (result = 7) { ... } for (int i=0; i<3; i++) { ... } byte b = (byte) value;
-
Bracket: [ ]
Used to declare an array and to take/fill value of array element.
Example:
int[] c = new int[5]; c[0] = 7;
-
Semicolon: ;
Used to separate statements.
Example:
c = a; a = b; b = c;
-
Comma: ,
Used to separate the variables during the declaration process.
Example:
int a, b, c;
-
Period: .
Used to separate the package name, sub package, and class. Also used to separate data or method of an object reference.
Example:
import java.io.IOException; obj.x = 4; obj.getX();
Keyword
Keywords are words that have been defined by the compiler and have a specific meaning and purpose. Java does not allow us to create an identifier (variable name, constant, class, or method) by using keywords. Here is a list of keywords that are contained in Java:
abstract | continue | for | new | switch |
assert | default | goto * | package | synchronized |
boolean | do | if | private | this |
break | double | implements | protected | throw |
byte | else | import | public | throws |
case | enum | instanceof | return | transient |
catch | extends | int | short | try |
char | final | interface | static | void |
class | finally | long | strictfp | volatile |
const * | float | native | super | while |
* Although provided, the const and goto keywords are not used.
Thanks a lot! You made a new blog entry to answer my question; I really appreciate your time and effort.
ReplyDeletebest java institute in chennai |
Core java training in chennai
Python Training with Django
ReplyDeleteDeep Learning with TensorFlow (Python)
Embedded System and Robotics with IOT
IOT & Cloud with RaspberryPi
Android App Development with Java
ChatBot-Game Development, Image Processing, Face Detection, Browser Automation, and Data Visualisation
Call: 9893762256
Thank you so much for the valuable info
ReplyDeleteHere am sharing some information about Best Training Institutes java training in hyderabad |java course in hyderabad | java institutes in hyderabad | software training institutes in hyderabad |selenium training in hyderabad | software training institutes in hyderabad with placements |python training in hyderabad | python course in hyderabad | python institutes in hyderabad
Python Training in Bhopal
ReplyDeleteThanks for sharing.
ReplyDeleteJava developer job available in Chennai
Thank you for sharing valuable information with us.
ReplyDeleteJava web application is a type of free programming language used to develop applications and software that are becoming highly in demand on the internet. The software engineer can provide the web application or software in the form of windows, Linux, and MAC OS. There are various types of systems that can not work without java and it is getting necessary day by day even the world’s no.1 application depends on java. Java has become a most popular feature in android smartphone applications that's why Aptech learning provides java training in Dwarka, Janakpuri, and in Gurgaon also. Java training helps to get you complete knowledge about web frameworks, Java testing tools, and design patterns in java.
Let's get learn about the PHP training course
PHP is a type of programming language that is most commonly used in dynamic functions such as modifying, collecting, and deleting all types of databases It also helps to encrypt all types of data in the form of HTML and XML file. Aptech learning provides you with a complete PHP training course at a reasonable cost that will help you to grow more in the era of the software industry.
For more details please visit our website : Aptech Dwarka