Tuesday, March 27, 2007

HOW YOUR TEXTUAL CODE IS READ(2)

HOW YOUR TEXTUAL CODE IS READ(2):

(continued from 1)

COMMENTS:
There are two types of comments in the java programming language:

  1. The traditional comment, /* text */
  2. The end-of-line comment, // text

Note: a. that the text is ignored in both type of comments.
Also, b. Comments do not nest.

/* /* */ */ will give syntax error.

  1. If comments occur in other comments, the special meaning is lost.

/* // */ the EOL(//) comment will lose its special meaning.

package examples;

class CommentsExamples {

public static void main(String[] args) {

// Simple example: comments do not nest.
//Try writing the below and your compiler should give
//an error

/*/* */ */
//traditional comments have no special meaning in comments
//that are end-of-line, example:

// /* */

//also // has no special meaning in traditional comments

/*// */

//have a nice day!
}

}

IDENTIFIERS:

An identifier is an unlimited-length sequence of java letters or java digits, which letters or digits are in the Unicode character set. The beginning of an identifier must be a java letter.

No identifier should be Unicode character sequence equivalent with a keyword, boolean literal or the number literal.

The following method, Character.isJavaIdentifierStart(int), will return true if a character is a java letter while, Character.isJavaIdentifierPart(int), will return true if a character is a java letter or digit.

The java letters: ASCII A-Z(\u0041-\u0059), ASCII a-z(\u0061-\u0079), underscore _(\u005f), dollar sign, &(\u0024), although the dollar sign should be used rarely.

The java digits are the ASCII digits 0-9(\u0030-\u0039).

package examples;

class JavaLettersExample {

public static void main(String[] args) {
// I want to use the letter below as an identifier
//beginning letter being french
char frenchletter = '\u00C7';

if (Character.isJavaIdentifierStart(frenchletter)){

System.out.println("Valid. Can use "+frenchletter+" as start of identifier.");

}else {

System.out.println("Sorry, not first letter of identifier.");

}

//Can the trademark be a valid java identifier?
char trademark = '\u0099';

System.out.println(Character.isJavaIdentifierPart(trademark));

//yes, true!
//To check for identifier sameness.
char bigs = '\u0053', smalls = '\u0073';
System.out.print("If the two s are the same identifiers");
System.out.println(" our compiler should return true.");

//now checking
if (bigs == smalls){

System.out.println("True");

}else {System.out.println("Sorry, big and small s are

different.");}

}

}

KEYWORDS:

The keywords in java are:

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

const and goto are reserved in java for making a check on their appearance in code as against C++ code.

(Continued at 3)

1 comment:

Anonymous said...

Good words.