SCJP Language Fundamentals Lecture Notes
Agenda for Language Fundamentals
- Identifiers
- Reserved Words
- Data Types
- Literals
- Arrays
- Types of Variables
- Methods
- Main Method
- Command Line Arguments
- Java Coding Standards
1. Identifiers
- Definition:
- An identifier is a name used for identification purposes in Java programming.
- Examples: class names, method names, variable names, and label names.
Example of Identifiers
class Test {
public static void main(String[] args) {
int x = 10;
System.out.println("Hello");
}
}
- Identifiers in Example:
Test
(class name)
main
(method name)
String
(predefined class name)
args
(array name)
x
(variable name)
Rules for Defining Java Identifiers
- Allowed Characters:
- Only letters (a-z, A-Z), digits (0-9), dollar sign ($), and underscore (_) are allowed.
- E.g.,
total_number
is valid but total#number
is invalid.
- Cannot Start with a Digit:
- Identifiers cannot start with a digit.
- E.g.,
1abc
is invalid, while abc1
is valid.
- Case Sensitivity:
- Java is case-sensitive.
variable
and Variable
are different identifiers.
- Length Limit:
- There is no limit on the length of identifiers, but it is not recommended to use excessively long names for readability.
- Reserved Words:
- Cannot use reserved words as identifiers (e.g.,
if
, else
, for
).
- Predefined Class Names:
- Using predefined class names (e.g.,
String
, Runnable
) as identifiers is possible but not recommended.
2. Reserved Words
- Definition:
- Reserved words are specific words in Java that have special meaning and cannot be used as identifiers.
- Total Reserved Words in Java:
- 53 reserved words
- Keywords: 50
- 48 user-defined and 2 unused.
- Reserved Literals: 3 (true, false, null)
List of Keywords and Reserved Words
- Keywords for Data Types:
byte
, short
, int
, long
, float
, double
, boolean
, char
- Control Flow Keywords:
if
, else
, switch
, case
, default
, while
, do
, for
, break
, continue
, return
- Modifiers:
public
, private
, protected
, static
, final
, abstract
, synchronized
, native
, strictfp
, transient
, volatile
- Exception Handling:
try
, catch
, finally
, throw
, throws
, assert
- Class Related Keywords:
class
, interface
, extends
, implements
, package
, import
- Object Related Keywords:
new
, instanceof
, super
, this
- Return Type Keyword:
Unused Keywords
- List of Unused Keywords:
goto
, const
- Reason: They were banned due to issues in other programming languages.
Reserved Literals
- Values:
- Purpose:
- Used to represent boolean values and default value for object references.
3. Important Conclusions
- All reserved words contain only alphabet symbols.
- Java does not have a
delete
keyword; garbage collection handles object destruction.
- New keywords introduced in Java:
strictfp
(Java 1.2), assert
(Java 1.4), enum
(Java 1.5).
Exam Preparation Tips
- Know the 53 reserved words and their classifications.
- Understand rules for defining identifiers.
- Familiarize yourself with keywords related to data types, control flow, modifiers, exception handling, and class-related keywords.