Question

In: Computer Science

Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide...

Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide three examples of different kinds of invalid identifiers.

Java

Solutions

Expert Solution

Java identifiers are in java programming language are used for the indenfication propose.in java programming language the identifiers are contains the a class name,method name,variable name,or label.we will discuss the rules governing identifiers this mainly maid for valid java identifier.there need tobe followed else it getting the compile time error.

Identifiers can have only alphanumeric characters like a-z,A-Z and 0-9 digits and underscore that is _.for example "welcome@" is not valid java identifier as it conatin the @ sign.

The first character of an identifier is conatin the only alphabet that is a-z and A-Z.or underscore _.for example "123example" it is not valid java identifier.

Identifiers are also contain sensitive.that is welcome and Welcome  are two different identifiers.

There is no limit for length of identifiers but in case ot contain the optimal length that 4 to 15 letters.

Reverse word can not used as identifier.example int while=10;it is invalid statement because it contain while is reverse word.

Keyword are not allowed to ne used as identifiers.

No special characters such as semicolon ,space and comma are permitted to be used or as identifier.

Can identifiers be re-used in the same Java class file the answer is no because in program the it conatin uniqueness.it can used for identification process identifies conatin method name,class name or a variable name.in the java program conatin unique identifier .also you can not create as same class name.also it applicable for method and variable.for example  

Public class addition

{

Public static void main(String args[ ])

{

int num1=10;// this is valid identifier.

int num1=30//In this line num1 variable is used allready used you cannot reuse it will provide generate an error as a duplicate variable.

}

}

Three example of invalid identifiers

1.add number- this is invalid identifier because you can not keep space if you going to run the program with this identifier this will generate error.

2.123add -this is invalid identifier you can not use identifier which begin with the digit.

3. A+B this is invalid identifier because + sign is not an alphanumeric character.


Related Solutions

Write the RE for identifiers that can consist of any sequence of letters (l) or digit...
Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_" (10)
Write the RE for identifiers that can consist of any sequence of letters (l) or digit...
Write the RE for identifiers that can consist of any sequence of letters (l) or digit (d) or "_" but the first char must be a letter and the last char cannot be a "_"
Write a program that reads a Java source file and produces an index of all identifiers...
Write a program that reads a Java source file and produces an index of all identifiers in the file. For each identifier, print all lines in which it occurs. For simplicity, we will consider each string consisting only of letters, numbers, and underscores an identifer. Declare a Scanner in for reading from the source file and call in.useDelimiter("[^AZa-z0-9_]+"). Then each call to next returns an identifier. Java. Explain logic used lease.
Create an ID table class that maps identifiers to memory addresses for a Parser java program....
Create an ID table class that maps identifiers to memory addresses for a Parser java program. The first identifier will be at address 0, the second at address 1, and so on. I am working on a Lexer/Parser project for java. I've completed the lexer and parser portion of the program but I'm looking for some assistance in creating a ID table class. That has specific methods that add token identifiers into a hashmap. Here are the specifications that I'm...
Create a Java class file for a Car class. In the File menu select New File......
Create a Java class file for a Car class. In the File menu select New File... Under Categories: make sure that Java is selected. Under File Types: make sure that Java Class is selected. Click Next. For Class Name: type Car. For Package: select csci2011.lab7. Click Finish. A text editor window should pop up with the following source code (except with your actual name): csci1011.lab7; /** * * @author Your Name */ public class Car { } Implement the Car...
Create a Java class file for an Account class. In the File menu select New File......
Create a Java class file for an Account class. In the File menu select New File... Under Categories: make sure that Java is selected. Under File Types: make sure that Java Class is selected. Click Next. For Class Name: type Account. For Package: select csci1011.lab8. Click Finish. A text editor window should pop up with the following source code (except with your actual name): csci1011.lab8; /** * * @author Your Name */ public class Account { } Implement the Account...
JAVA Assignement In the same file, create two classes: a public class Module1 and a non-public...
JAVA Assignement In the same file, create two classes: a public class Module1 and a non-public (i.e. default visibility) class Module1Data. These classes should have the following data fields and methods: 1) Module1 data fields: a. an object of type Module1Data named m1d b. an object of type Scanner named scanner c. a double named input 2) Module1Data methods: a. a method named square that returns an int, accepts an int parameter named number, and returns the value of number...
Java Write a class called Triangle that can be used to represent a triangle. Write a...
Java Write a class called Triangle that can be used to represent a triangle. Write a class called Describe that will interface with the Triangle class The Server • A Triangle will have 3 sides. It will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. • It will allow a client to create a Triangle, passing in integer values for the...
in java: Write a class responsible for storing data in a text file. The class should...
in java: Write a class responsible for storing data in a text file. The class should include a method that accepts a string and appends it to a file.
In this problem, we provide you with a Java file called Question2.java. Suppose that there is...
In this problem, we provide you with a Java file called Question2.java. Suppose that there is an array and let us call this array, items. The array items contains n integers. These n integers are in a completely random order in the array. What you are asked to do is to reorder the items in the array such that all the negative integers come before all the zeros and all the positive integers appear at the end. Note, this question...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT