0% found this document useful (0 votes)
12 views5 pages

Java

The document provides an overview of Java identifiers, including rules for their definition, such as allowed characters, case sensitivity, and restrictions on starting with digits or using reserved words. It also lists the 53 reserved words in Java, categorizing them into keywords for data types, flow control, modifiers, exception handling, class-related keywords, and object-related keywords. Additionally, it highlights the importance of using meaningful identifiers and avoiding reserved words to maintain code readability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Java

The document provides an overview of Java identifiers, including rules for their definition, such as allowed characters, case sensitivity, and restrictions on starting with digits or using reserved words. It also lists the 53 reserved words in Java, categorizing them into keywords for data types, flow control, modifiers, exception handling, class-related keywords, and object-related keywords. Additionally, it highlights the importance of using meaningful identifiers and avoiding reserved words to maintain code readability.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

NOTES FOR THE FIRST CLASS

1. A name is Java program is called Identifier


which can be used for identification purpose
it can be
method name
variable name
class name
label name
2. rules for defining java identifires
The only allowed characters in java identifiers are
a to z
A to Z
0 to 9
$
_

If you are using any other character we will get compile time error
example total_number (correct)
total= (compile error)
3. Identifiers cannot start with digits
example total123 (valid)
123total (invalid)
Java identifiers are case sensitive
ofcourse it is treated as case sensitive language

4. there is no length limit for java identifiers


but it is not recommended to take too lengthy identifiers

5. We cant use reserved words as identifires


example: int x = 10; (valid)
int if = 20:; (invalid)

6. All predefined java class names and interface name we can use as identidiers.
Even though it runs its not a good programming practice becoz it reduces
readability and creates confusion.

7. int - invalid identifier


Int - valid identifier

RESERVED WORDS
EX: English : crores of reserved words
cat
dog
apple
sleep
In Java some word are reserved words to represent some meaning or functionality
such type of words are called reserved words.

Total 53 reserved words:


keyword (50) reserved lliterals(3)
- used keywords(48) = true
if, else...... = false
- unused keywords(2) = null
goto
const

@LittleKidsZone.
3 months ago
IDENTIFIERS
NOTES FOR THE FIRST CLASS

1. A name is Java program is called Identifier


which can be used for identification purpose
it can be
method name
variable name
class name
label name
2. rules for defining java identifires
The only allowed characters in java identifiers are
a to z
A to Z
0 to 9
$
_

If you are using any other character we will get compile time error
example total_number (correct)
total= (compile error)
3. Identifiers cannot start with digits
example total123 (valid)
123total (invalid)
Java identifiers are case sensitive
ofcourse it is treated as case sensitive language

4. there is no length limit for java identifiers


but it is not recommended to take too lengthy identifiers

5. We cant use reserved words as identifires


example: int x = 10; (valid)
int if = 20:; (invalid)

6. All predefined java class names and interface name we can use as identidiers.
Even though it runs its not a good programming practice becoz it reduces
readability and creates confusion.

7. int - invalid identifier


Int - valid identifier

RESERVED WORDS
EX: English : crores of reserved words
cat
dog
apple
sleep

In Java some word are reserved words to represent some meaning or functionality
such type of words are called reserved words.

Total 53 reserved words:


keyword (50) reserved lliterals(3)
- used keywords(48) = true
if, else...... = false
- unused keywords(2) = null
goto
const
Keywords for Data Types: (8)
byte
short
int
long
float
double
boolean
char

Keywords for flow control: (11)


if
else
switch
- case
- default
while
do
for
break
continue
return
Keywords for Modifiers: (11)
Public
private
protected
static
final
abstract
synchronized
native
strict fp
transient
volatile

Keywords for Exception Handling: (6)


try
catch
finally
throw
throws
assert

Class Related Keywords: (6)


class
interface
extends
implements
package
import

Object Related Keywords: (4)


new
instanceof
super
- this

Delete keyword is not there in Java


Void is a Return type keyword(1)

IN JAVA RETURN TYPE IS MANDATORY


If a method wont return anything than we have to declare that method with Void
Return type

But in C language return type is optional and default return type is int.

UNUSED KEYWORDS: (2) these keywords created several problems in old languages
and hence sun people banned this keyword in java.
goto
const
- use final insted of const
Note : goto and const are unused keywords and if we are trying to use we will get
compile time error.

RESERVED LITERALS:
true these are values for boolean data types
false
null - default value for object reference

enum(1) keyword:
we can use enum to define a group of named constants.
enum month
{
jan, feb........dec;
}

enum beer
{
KF, KO, RC, FO;
}

Conclusions:
All 53 reserved words contain only alphabets
All 53 reserved words contain only lower case alphabets
In java we have only new keyword and there is no delete keyword becoz destruction
of useless objects is the responsibility of garbage collector
the following are new keywords in java
- strictfp - 1.2v
- assert - 1.4v
- enum - 1.5v
strictfp but not strictFp
insatnceof but not instanceOf
synchronized but not synchronize
extends but not extend
implements but not implement
import but not imports
const but not constant

QUESTIONS for the exam:


1. which of the following list contains only java reserved words?
new, delete
goto, constant
break, continue, return, exit
final, finally, finalize
throw, throws, thrown
notify, notifyall
implements, extends, imports
sizeof, instanceof
instanceOf, strictFp
byte, short, Int
None of the above

Answer: None of the above


Bold words are java reserved words

2. Which of the following are java reserved words?


public
static
void
main - name of the method
String - its a predefined class
args - name of the variable

Answer: Bold words are java reserved words.

You might also like