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

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...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
describe the mechanism that supports random file access in Java.
describe the mechanism that supports random file access in Java.
Can you provide source code in Java that 1. accepts a two-way acceptor via file; 2....
Can you provide source code in Java that 1. accepts a two-way acceptor via file; 2. and validate if the input string is part of the language
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.
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called  Dog that contains instance data that represent the dog's name and age.   define the Dog constructor to accept and initialize instance data.   create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age).   Include a toString...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT