Continued
1)Token
- Tokens are the smallest elements of a program
- They are fundamental building blocks of the program.
2)Keywords
- Reserved words with predefined meanings.
- Each keyword perform a specific function in a program.
- Keywords cannot be used as variable names
These are some keywords which is in Java....
3)Identifiers:
- Identifiers in Java are the names used to various elements in a program like variables,methods,classes,interfaces and Packages.
- They make the code more readable way.
Examples:
Variable names: age, totalSum
Class names: Student, Employee
Method names: calculateArea(), displayDetails().
Rules for Naming Identifiers:
1.Must begin with a letter (A-Z or a-z), a dollar sign ($), or an underscore (_).
2.Cannot start with a digit (e.g., 1variable is invalid).
3.Can contain letters, digits (0-9), underscores, and dollar signs.
4.Cannot use Java reserved keywords (e.g., class, int, if).
5.Identifiers are case-sensitive (MyVariable and myvariable are different).
4)Literals:
- literals are constant values that are directly assigned to variables
- Literals may belong to any of the data type.
- They represent fixed values of various data types, such as numbers, characters, strings, or boolean values. Types:
1.Integer Literals:
These are whole numbers without a fractional part.
Decimal (Base 10): Default format.
Octal (Base 8): Prefix with 0.
Hexadecimal (Base 16): Prefix with 0x or 0X.
Binary (Base 2): Prefix with 0b or 0B.
Example:
int decimal = 100; // Decimal literal
int octal = 0144; // Octal literal (equivalent to 100 in decimal)
int hex = 0x64; // Hexadecimal literal (equivalent to 100 in decimal)
int binary = 0b1100100; // Binary literal (equivalent to 100 in decimal)
2.Floating-Point Literals
These represent decimal numbers with a fractional part
Example:
double pi = 3.14159; // Standard notation
float gravity = 9.8f; // 'f' indicates a float literal
double exp = 1.5e2; // Scientific notation (150.0)
3.Character Literals:
A single character enclosed in single quotes (').
Example:
char letter = 'A'; // Character literal
char digit = '7'; // Character literal
char symbol = '$'; // Character literal
4.String Literals:
A sequence of characters enclosed in double quotes (").
Example:
String greeting = "Hello, World!"; // String literal
String empty = ""; // Empty string literal
5.Boolean Literals:
These represent true or false.
Example:
boolean isJavaFun = true; // Boolean literal
boolean isFishTasty = false; // Boolean literal
5)ASCII(American Standard Code for Information Interchange)
- standardized system that assigns numeric codes to letters, digits, punctuation marks.
- Each character is represented by a unique 7-bit binary number.
- allows computers to store and communicate text data efficiently.
6)UNICODE(Universal character encoding standard)
- Unicode is the most fundamental and universal character encoding standard
- For every character, there is a unique 4 to 6-digit unique hexadecimal number.
Top comments (0)