CLASS XI: CHAPTER 4:Programming Fundamentals

Programming Fundamentals
Token :
The smallest individual unit in a program is known as Token. Java has the following types of tokens: keyword, Identifier, literal, punctuators and operators.
Keywords :
Keywords are words that have a specific predefined meaning in Java. They cannot be used as variable names. They are also known as reserve words. Eg. void, private, if, while etc.
Literals:
Items having fixed data values are referred to as Literals. They are also known as Constants. Various types of literals available in Java are :
1.    Integer literals
2.    Floating literals
3.    Boolean literals
4.    Character literals
5.    String literals
6.    Null literals

Integer Literals:
An integer literal is of type long if it ends with the letter L or l; otherwise it is of type int. It is recommended that you use the upper case letter  L because the lower case letter l is hard to distinguish from the digit 1.
Values of the integral types byte, short, int, and long can be created from int literals. Values of type long that exceed the range of int can be created from long literals. Integer literals can be expressed by these number systems:
  • Decimal: Base 10, whose digits consists of the numbers 0 through 9; this is the number system you use every day
  • Hexadecimal: Base 16, whose digits consist of the numbers 0 through 9 and the letters A through F
  • Binary: Base 2, whose digits consists of the numbers 0 and 1 (you can create binary literals in Java SE 7 and later)
For general-purpose programming, the decimal system is likely to be the only number system you'll ever use. However, if you need to use another number system, the following example shows the correct syntax. The prefix 0x indicates hexadecimal and 0b indicates binary:
// The number 26, in decimal
int decVal = 26;
//  The number 26, in hexadecimal
int hexVal = 0x1a;
// The number 26, in binary
int binVal = 0b11010;

Floating-Point Literals:
A floating-point literal is of type float if it ends with the letter F or f; otherwise its type is double and it can optionally end with the letter D or d.
The floating point types (float and double) can also be expressed using E or e (for scientific notation), F or f (32-bit float literal) and D or d (64-bit double literal; this is the default and by convention is omitted).
double d1 = 123.4;
// same value as d1, but in scientific notation
double d2 = 1.234e2;
float f1  = 123.4f;

Character and String Literals:

Literals of types char and String may contain any Unicode (UTF-16) characters. Always use 'single quotes' for char literals and "double quotes" for String literals. Unicode escape sequences may be used elsewhere in a program (such as in field names, for example), not just in char or String literals.
The Java programming language also supports a few special escape sequences for  char  and  String  literals:  \b (backspace), \t (tab), \n (line feed), \f (form feed), \r(carriage return), \" (double quote), \' (single quote), and \\ (backslash).
There's also a special null literal that can be used as a value for any reference type. null may be assigned to any variable, except variables of primitive types. There's little you can do with a null value beyond testing for its presence. Therefore, null is often used in programs as a marker to indicate that some object is unavailable.


Java Identifiers:
All java components require names. Names used for classes, variables and methods are called identifiers.
In java there are several points to remember about identifiers. They are as follows:
·                     All identifiers should begin with a letter (A to Z or a to z ), currency character ($) or an underscore (-).
·                     After the first character identifiers can have any combination of characters.
·                     A key word cannot be used as an identifier.
·                     Most importantly identifiers are case sensitive.
                 
                Examples of legal identifiers:
                age, $salary, _value, __1_value
                Examples of illegal identifiers : 123abc, -salary

Variable :
                        Variable is a named storage location in computer memory whose contents can change during a program run.
The characteristics of a variable are:
  • It has a name.  
  • It is capable of storing values.
  • It provides temporary storage.
  • It is capable of changing its value during program execution. 

1 comment:

  1. Thank you for sharing this amazing post. Looking forward to reading more.

    Visit us: Java Online Training Hyderabad
    Visit us: Java Training

    ReplyDelete