« Previous Page Next Page »

Introduction to Java Syntax.



The syntax of the Java programming language is the set of rules defining how a Java program is written and interpreted. The syntax is mostly derived from C and C++. Unlike C++, in Java there are no global functions or variables, but there are data members which are also regarded as global variables. All code belongs to classes and all values are objects.

Java Identifier:

Identifiers in java language are the names of Java packages, Java classes and objects, interfaces, methods, and variables in Java. They are basically the name of any element. For example, in the program above, String, main, args and println are Java identifiers.

Identifiers in Java are case-sensitive, there are some basic conventions that are to be followed while naming any identifier, they can contain:

• Any Unicode character, which is a letter or a digit
• Special signs such as an underscore
• A $ sign ( a currency sign)
• Java identifiers cannot start with a digit or be same as a reserved word.

Java Keywords:

The following list shows the reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names.

abstract continue for new
switch assert default goto
package synchronized boolean do
if private this protected
throw break double implements
byte else import public
throws case enum instanceof
return transient catch extends
int short try char
final interface static var
class finally long strictfp
void const float native
super volatile while

Java Comments

There are 3 types of comments in Java language:

• Single Line Comment in Java:

The single line comment is used to comment only one line.

// This is an end-of-line comment

• Java Multi Line Comment:

The multi line comment is used to comment multiple lines of code.

/* This is a multi-line comment.
It may occupy more than one line. */

• Java Documentation Comment:

The documentation comment is used to create documentation API. To create documentation API, you need to use javadoc tool.

 * This is a documentation comment.
 * @author Varun Singh

Java Modifiers

Like other languages, it is possible to modify classes, methods by using modifiers. There are two categories of modifiers:
• Access Modifiers - default, public , protected, private
• Non-access Modifiers - final, abstract, strictfp

Java Variables

Following are the types of variables in Java:
• Local Variables
• Class Variables (Static Variables)
• Instance Variables (Non-static Variables)

The End:

Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section. We will be very happy to hear that.

If you like my tutorial, please follow us on facebook, Google + and Twitter. I need your support to continue.

« Previous Page Next Page »