0

I am getting an "Invalid Character" error message for these identifiers. I think it is because of the apostrophe. How can I get them to work?

Double Semester’s_End;
Double Stonebinder’s_Familiar;
Double Mavinda,_Students'_Advocate;
Nathan
  • 29
  • 1
  • 3
    You don't. There's no magic trick here. You name your variables with alphanumerics and underscores. Some languages will let you do funny quoting shenanigans to get unusual identifier names, but Java is not one of those – Silvio Mayolo May 18 '21 at 23:00
  • 2
    See the Naming section at [Java Tutorial: Variables](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html). – jarmod May 18 '21 at 23:04

2 Answers2

0

Because of the syntax definitions of the language, the only way to use an apostrophe in a java identifier is like this:

SemestersApostrophs_End
EndOfSemester
Semester_s_End

or similar, you get the idea.
I.e. in short, you can't.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
-1

In short: You can't. Use underscores to separate words if you want.

Also, in Java we use camelCase, where the first letter is small and the first letter of the next word is capitalized (unless it's a class, for which we use Regular).

Example:

double semestersEnd;
double stonebinder_s_Familiar;
double mavinda_StudentsAdvocate;

Also, when initializing/declaring, it's double, not Double (so it's a lower case d). Use: What is the difference between "Double" and "double" in Java?

As @jarmod provided, use this link for more info: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html.

TheSj
  • 376
  • 1
  • 11