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 "_"
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...
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 Searching and Sorting In An Integer List File IntegerList contains a Java class representing...
IN JAVA Searching and Sorting In An Integer List File IntegerList contains a Java class representing a list of integers. The following public methods are provided: ? IntegerList(int size)—creates a new list of size elements. Elements are initialized to 0. ? void randomize()—fills the list with random integers between 1 and 100, inclusive. ? void print()—prints the array elements and indices ? int search(int target)—looks for value target in the list using a linear (also called sequential) search algorithm. Returns...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called...
android studio -Starting with a basic activity, create a new Java class (use File->New->Java class) called DataBaseManager as in Lecture 5 and create a database table in SQLite, called StudentInfo. The fields for the StudentInfo table include StudentID, FirstName, LastName, YearOfBirth and Gender. Include functions for adding a row to the table and for retrieving all rows, similar to that shown in lecture 5. No user interface is required for this question, t -Continuing from , follow the example in...
IF–THEN rules can be used for classification. What are some performance measures that can be used...
IF–THEN rules can be used for classification. What are some performance measures that can be used to evaluate the accuracy of the rule, and how do these measures differ? What are the advantages and limitations of each performance measure? You should compare at least two performance measures for evaluating the performance of an IF–THEN rule.
JAVA Start with the SelectionSort class in the zip file attached to this item. Keep the...
JAVA Start with the SelectionSort class in the zip file attached to this item. Keep the name SelectionSort, and add a main method to it. Modify the selectionSort method to have two counters, one for the number of comparisons, and one for the number of data swaps. Each time two data elements are compared (regardless of whether the items are in the correct order—we're interested in that a comparison is being done at all), increment the comparison counter. Each time...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT