0% found this document useful (0 votes)
36 views8 pages

C4-Data types&NamingConventions

The document outlines the rules for defining identifiers in Java, including allowed characters, case sensitivity, and restrictions on starting characters and reserved words. It also lists various reserved words categorized by their functionality, such as data types, flow control, and modifiers. Additionally, it emphasizes that Java is a strongly typed language, requiring type compatibility for variable assignments.

Uploaded by

dinesh 0337
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views8 pages

C4-Data types&NamingConventions

The document outlines the rules for defining identifiers in Java, including allowed characters, case sensitivity, and restrictions on starting characters and reserved words. It also lists various reserved words categorized by their functionality, such as data types, flow control, and modifiers. Additionally, it emphasizes that Java is a strongly typed language, requiring type compatibility for variable assignments.

Uploaded by

dinesh 0337
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Identifier :

 A name in java program is called identifier. It may be class name, method


name, and variable name.

Example:

Rules to define java identifiers:


Rule 1: The only allowed characters in java identifiers are:

 a to z
 A to Z
 0 to 9
 _ (underscore)
 $

Rule 2: If we are using any other character we will get compile time error.

Example:

 total_number------->valid
 Total#------------------>invalid.

Rule 3: identifiers are not allowed to starts with digit.

Example:

 ABC123--------->valid
 123ABC--------->Invalid

Rule 4: java identifiers are case sensitive , java language itself treated as case
sensitive language.

Example:

class Test{

int number=10;
int Number=20;

int NUMBER=20; we can differentiate with case.

int NuMbEr=30;

Rule 5: There is no length limit for java identifiers but it is not recommended to
take more than 15 length.

Rule 6: We can't use reserved words as identifiers.

Example:

int if=10; --------------invalid

Rule 7: All predefined java class names and interface names we use as
identifiers but not suggested.

Example 1:

class Test

public static void main(String[] args){

int String=10;

[Link](String);

}}

Output:

10

Example 2:

class Test
{

public static void main(String[] args){

int Runnable=10;

[Link](Runnable);

}}

Output:

10

 Even though it is legal to use class names and interface names as identifiers
but it is not a good programming practice.

Reserved words:

In java some identifiers are reserved to associate some functionality or meaning


such type of reserved identifiers are called reserved words.

Reserved words for data types: (8)

1) byte

2) short

3) int

4) long

5) float

6) double

7) char

8) boolean.
Reserved words for flow control:(11)

1) if

2) else

3) switch

4) case

5) default

6) for

7) do

8) while

9) break

10) continue

11) return

Keywords for modifiers:(11)

1) public

2) private

3) protected

4) static

5) final

6) abstract

7) synchronized

8) native

9) strictfp(1.2 version)
10) transient

11) volatile

Keywords for exception handling:(6)

1) try

2) catch

3) finally

4) throw

5) throws

6) assert(1.4 version)

Class related keywords:(6)

1) class

2) package

3) import

4) extends

5) implements

6) interface

Object related keywords:(4)

1) new

2) instanceof

3) super

4) this
Void return type keyword:

If a method won't return anything compulsory that method should be declared


with the void return type in java .

Unused keywords:

goto: Create several problems in old languages and hence it is banned in java.

Const: Use final instead of this.

By mistake if we are using these keywords in our program we will get compile
time error.

Reserved literals:

1) true values for boolean data type.

2) false

3) null----------------- default value for object reference.

Conclusions :

1. All reserved words in java contain only lowercase alphabet symbols.

2. New keywords in java are:

3. strictfp-----------1.2v

4. assert-------------1.4v

5. enum--------------1.5v

6. In java we have only new keyword but not delete because destruction of
useless objects is the responsibility of Garbage Collection.

7. instanceof but not instanceOf

8. strictfp but not strictFp


9. const but not Constant

10. syncronized but not syncronize

11. extends but not extend

12. implements but not implement

13. import but not imports

Data Types in Java


Every variable has a type, every expression has a type and all types are strictly define
more over every assignment should be checked by the compiler by the type
compatibility hence java language is considered as strongly typed programming
language.

You might also like