Chitika

Tuesday, October 26, 2010

Fundemantals

Source code of the java program is first written in plain text files ending with the .java extension. When you compile the java program Those source files are then converted into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead contains bytecodes

Figure showing MyProgram.java, compiler, MyProgram.class, Java VM, and My Program running on a computer.
Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris TM Operating System (Solaris OS), Linux, or Mac OS.


Identifiers and Keywords

The rules the compiler uses to determine whether a name is legal. 
  • Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
  • After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
  • In practice, there is no limit to the number of characters an identifier can contain.
  • You can't use a Java keyword as an identifier.
  • Identifiers in Java are case-sensitive; foo and FOO are two different identifiers
Examples:
The following identifiers are legal

int _a;  //starting with underscore
int $c;  //starting with $ sign
int ______2_w;  //starting with underscore
int _$;       //starting with underscore
int this_is_a_very_detailed_name_for_an_identifier; // starting with a letter

The following identifiers are illegal

int :b; // starting letter is not valid
int -d; // starting letter is not valid
int e#; // special charactor # is not legal
int .f; // starting (.) is not valid
int 7g; //starting with number not allowed.

Java Keywords

You cannot use any of the following as identifiers in your programs

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

* not used 
** added in 1.2 *** added in 1.4 **** added in 5.0

Through the Java VM, the same application is capable of running on multiple platforms.

Figure showing source code, compiler, and Java VM's for Win32, Solaris OS/Linux, and Mac OS

Legal Identifiers

Technically, legal identifiers must be composed of only Unicode characters, numbers, currency symbols, and connecting characters (like underscores).

All the Java components —classes, variables, and methods—need names. In Java these names are called
there are rules for what constitutes a legal Java identifier.

1 comment:

  1. @Java Keywords. "forn" is not a keyword I think it is "for" keyword.

    ReplyDelete