Is main a valid Java identifier?
Clash Royale CLAN TAG#URR8PPP
up vote
223
down vote
favorite
One of my kids is taking Java in high school and had this on one of his tests:
Which of the following is a valid identifier in Java?
a.
123java
b.main
c.java1234
d.{abce
e.)whoot
He answered b and got it wrong.
I looked at the question and argued that main
is a valid identifier and that it should have been right.
We took a look at the Java spec for identifiers and it reinforced that point. We also wrote a sample program that had a variable called main
, as well as a method. He created a written rebuttal that included the Java documentation reference, the test program and the teacher ignored it and says the answer is still incorrect.
Is main
a valid identifier?
java language-lawyer identifier
 |Â
show 10 more comments
up vote
223
down vote
favorite
One of my kids is taking Java in high school and had this on one of his tests:
Which of the following is a valid identifier in Java?
a.
123java
b.main
c.java1234
d.{abce
e.)whoot
He answered b and got it wrong.
I looked at the question and argued that main
is a valid identifier and that it should have been right.
We took a look at the Java spec for identifiers and it reinforced that point. We also wrote a sample program that had a variable called main
, as well as a method. He created a written rebuttal that included the Java documentation reference, the test program and the teacher ignored it and says the answer is still incorrect.
Is main
a valid identifier?
java language-lawyer identifier
1
Comments are not for extended discussion; this conversation has been moved to chat.
â Samuel Liewâ¦
Sep 11 at 23:33
18
Anecdotal: Your kid might be dealing with a rusted teacher. We recently reformed IT education here nation-wide, and pressure to use new programming languages and ideas lead to many teachers that have been teaching for many years (being rusted in their pre-2000 mindset of programming) simply not being up to the job of teaching modern programming (spreading misinformation such as main is not a valid identifier). I remember my embedded systems teacher trying to get us to sort 100.000 integers on an Arduino (which has 32kB memory). I also prepared a written rebuttal but it was simply ignored.
â Zimano
Sep 13 at 10:22
7
@Zimano, I think its the exact opposite. First year teacher who's major I don't think was CS.
â Gary Bak
Sep 13 at 11:17
15
Was it a single-choice or a multi-choice question? If it was a multi-choice question then b and c should be selected.
â md2perpe
Sep 13 at 21:40
11
@Zimano I can't for the life of me imagine why a "pre-2000 mindset of programming" would change the fact thatmain
is a perfectly valid identifier in Java since 1995.
â Tobia Tesan
Sep 14 at 22:36
 |Â
show 10 more comments
up vote
223
down vote
favorite
up vote
223
down vote
favorite
One of my kids is taking Java in high school and had this on one of his tests:
Which of the following is a valid identifier in Java?
a.
123java
b.main
c.java1234
d.{abce
e.)whoot
He answered b and got it wrong.
I looked at the question and argued that main
is a valid identifier and that it should have been right.
We took a look at the Java spec for identifiers and it reinforced that point. We also wrote a sample program that had a variable called main
, as well as a method. He created a written rebuttal that included the Java documentation reference, the test program and the teacher ignored it and says the answer is still incorrect.
Is main
a valid identifier?
java language-lawyer identifier
One of my kids is taking Java in high school and had this on one of his tests:
Which of the following is a valid identifier in Java?
a.
123java
b.main
c.java1234
d.{abce
e.)whoot
He answered b and got it wrong.
I looked at the question and argued that main
is a valid identifier and that it should have been right.
We took a look at the Java spec for identifiers and it reinforced that point. We also wrote a sample program that had a variable called main
, as well as a method. He created a written rebuttal that included the Java documentation reference, the test program and the teacher ignored it and says the answer is still incorrect.
Is main
a valid identifier?
java language-lawyer identifier
java language-lawyer identifier
edited yesterday
Andrew Tobilko
21.3k83875
21.3k83875
asked Sep 10 at 19:57
Gary Bak
2,69231126
2,69231126
1
Comments are not for extended discussion; this conversation has been moved to chat.
â Samuel Liewâ¦
Sep 11 at 23:33
18
Anecdotal: Your kid might be dealing with a rusted teacher. We recently reformed IT education here nation-wide, and pressure to use new programming languages and ideas lead to many teachers that have been teaching for many years (being rusted in their pre-2000 mindset of programming) simply not being up to the job of teaching modern programming (spreading misinformation such as main is not a valid identifier). I remember my embedded systems teacher trying to get us to sort 100.000 integers on an Arduino (which has 32kB memory). I also prepared a written rebuttal but it was simply ignored.
â Zimano
Sep 13 at 10:22
7
@Zimano, I think its the exact opposite. First year teacher who's major I don't think was CS.
â Gary Bak
Sep 13 at 11:17
15
Was it a single-choice or a multi-choice question? If it was a multi-choice question then b and c should be selected.
â md2perpe
Sep 13 at 21:40
11
@Zimano I can't for the life of me imagine why a "pre-2000 mindset of programming" would change the fact thatmain
is a perfectly valid identifier in Java since 1995.
â Tobia Tesan
Sep 14 at 22:36
 |Â
show 10 more comments
1
Comments are not for extended discussion; this conversation has been moved to chat.
â Samuel Liewâ¦
Sep 11 at 23:33
18
Anecdotal: Your kid might be dealing with a rusted teacher. We recently reformed IT education here nation-wide, and pressure to use new programming languages and ideas lead to many teachers that have been teaching for many years (being rusted in their pre-2000 mindset of programming) simply not being up to the job of teaching modern programming (spreading misinformation such as main is not a valid identifier). I remember my embedded systems teacher trying to get us to sort 100.000 integers on an Arduino (which has 32kB memory). I also prepared a written rebuttal but it was simply ignored.
â Zimano
Sep 13 at 10:22
7
@Zimano, I think its the exact opposite. First year teacher who's major I don't think was CS.
â Gary Bak
Sep 13 at 11:17
15
Was it a single-choice or a multi-choice question? If it was a multi-choice question then b and c should be selected.
â md2perpe
Sep 13 at 21:40
11
@Zimano I can't for the life of me imagine why a "pre-2000 mindset of programming" would change the fact thatmain
is a perfectly valid identifier in Java since 1995.
â Tobia Tesan
Sep 14 at 22:36
1
1
Comments are not for extended discussion; this conversation has been moved to chat.
â Samuel Liewâ¦
Sep 11 at 23:33
Comments are not for extended discussion; this conversation has been moved to chat.
â Samuel Liewâ¦
Sep 11 at 23:33
18
18
Anecdotal: Your kid might be dealing with a rusted teacher. We recently reformed IT education here nation-wide, and pressure to use new programming languages and ideas lead to many teachers that have been teaching for many years (being rusted in their pre-2000 mindset of programming) simply not being up to the job of teaching modern programming (spreading misinformation such as main is not a valid identifier). I remember my embedded systems teacher trying to get us to sort 100.000 integers on an Arduino (which has 32kB memory). I also prepared a written rebuttal but it was simply ignored.
â Zimano
Sep 13 at 10:22
Anecdotal: Your kid might be dealing with a rusted teacher. We recently reformed IT education here nation-wide, and pressure to use new programming languages and ideas lead to many teachers that have been teaching for many years (being rusted in their pre-2000 mindset of programming) simply not being up to the job of teaching modern programming (spreading misinformation such as main is not a valid identifier). I remember my embedded systems teacher trying to get us to sort 100.000 integers on an Arduino (which has 32kB memory). I also prepared a written rebuttal but it was simply ignored.
â Zimano
Sep 13 at 10:22
7
7
@Zimano, I think its the exact opposite. First year teacher who's major I don't think was CS.
â Gary Bak
Sep 13 at 11:17
@Zimano, I think its the exact opposite. First year teacher who's major I don't think was CS.
â Gary Bak
Sep 13 at 11:17
15
15
Was it a single-choice or a multi-choice question? If it was a multi-choice question then b and c should be selected.
â md2perpe
Sep 13 at 21:40
Was it a single-choice or a multi-choice question? If it was a multi-choice question then b and c should be selected.
â md2perpe
Sep 13 at 21:40
11
11
@Zimano I can't for the life of me imagine why a "pre-2000 mindset of programming" would change the fact that
main
is a perfectly valid identifier in Java since 1995.â Tobia Tesan
Sep 14 at 22:36
@Zimano I can't for the life of me imagine why a "pre-2000 mindset of programming" would change the fact that
main
is a perfectly valid identifier in Java since 1995.â Tobia Tesan
Sep 14 at 22:36
 |Â
show 10 more comments
11 Answers
11
active
oldest
votes
up vote
207
down vote
accepted
public class J
public static void main(String args)
String main = "The character sequence "main" is an identifier, not a keyword or reserved word.";
System.out.println(main);
This compiles, and when executed, emits this output:
The character sequence "main" is an identifier, not a keyword or reserved word.
The character sequence main
is an identifier, not a keyword or reserved word.
The relevant section of the JLS is 3.8:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
Identifier:
   IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
   JavaLetter JavaLetterOrDigit
JavaLetter:
   any Unicode character that is a "Java letter"
JavaLetterOrDigit:
   any Unicode character that is a "Java letter-or-digit"
The character sequence main
fits the above description and is not in the keyword list in Section 3.9.
(The character sequence java1234
is also an identifier, for the same reasons.)
Does it mean OP's child missed out 1 of the 2 good answers?
â Clockwork
Sep 13 at 20:19
15
@Clockwork The question was worded such that only one choice could be correct. However, both choices b and c satisfied the question's condition, inconsistent with the implied choice. This left the OP's child to choose between which correct answer was the one the only one that teacher thought was correct.
â rgettman
Sep 13 at 20:30
@rgettman I read "Which of the following..." as allowing more than once choice, to which "b and c" would be a valid response.
â TripeHound
Sep 14 at 14:38
2
@TripeHound "is a valid identifier" is singular and demands exactly 1 answer. Compare it to "are valid identifiers"
â Gimme the 411
Sep 15 at 22:46
You could have made the classmain
as well ;)
â Peter Lawrey
Sep 17 at 7:46
add a comment |Â
up vote
73
down vote
main
is a valid java identifier, and the teacher is wrong.
The relevant documentation is in the Java Language Specification, right here:
Chapter 3. "Lexical Structure", section 3.8. "Identifiers":
https://docs.oracle.com/javase/specs/jls/se10/html/jls-3.html#jls-3.8
It says:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter... An identifier cannot have the same spelling (Unicode character sequence) as a keyword (ç3.9), boolean literal (ç3.10.3), or the null literal (ç3.10.7), or a compile-time error occurs.
Which means that you can prove that it is a valid identifier by using it as an identifier and observing that no compile-time error occurs.
1
Could you quote and spell it out more explicitly?
â zero298
Sep 10 at 20:03
29
no, because it is an entire section. If the teacher thinks that this section makes some sort of exception for 'main', it is the teacher who must show where it says so.
â Mike Nakis
Sep 10 at 20:04
add a comment |Â
up vote
57
down vote
As the other answers state
main
is a valid Java identifier, as well as java1234
.
I guess the confusing comes from the fact that the main(String)
method is often used as entry point by the JVM1. However, that doesn't mean that the token main
itself cannot be used as identifier2.
The specs say so, and the following declarations are also valid:
A field:
private int main;
A local variable:
String main = "";
A method:
private void main() ...
A class (although a class name starting with lowercase is discouraged):
public class main ...
A package:
package main;
1: As noted in the comments, the JVM specification itself does not mandate any particular method as entry point, but the widely used java
tool often uses such a method as entry point.
2: I would generally avoid creating a main method other than main(String)
.
19
"I guess the confusing comes from the fact that the main(String) method is used as entry point for the JVM."main
isn't the entry point for the JVM. It's the entry point that thejava
tool uses to run applications. Other tools (servlet containers, for instance) use other entry points.
â T.J. Crowder
Sep 11 at 7:48
23
which is even more ironic, because even in the "entry-point-context" main ALREADY IS a valid identifier. So even the case you could hold against it actually proves OP right
â Hobbamok
Sep 11 at 11:42
@T.J.Crowder Thanks, I've included that in the answer.
â MC Emperor
Sep 11 at 14:21
1
@Hobbamok You seem confused about basic Java concepts, which probably explains why you teach it in a school and not practicing is the reply that comes to mind
â rath
Sep 12 at 9:58
2
Thejava
tool does not require amain(String)
method if the main class extends javafx.application.Application.
â VGR
Sep 12 at 18:27
 |Â
show 1 more comment
up vote
47
down vote
This compiles fine on Java 1.8...
public class main
public String main = "main";
public void main(String main)
System.out.println("This object is an instance of the class " + this.getClass().getCanonicalName());
System.out.println("The value of the argument "main" for this call to the method "main(String main)" is " + main);
System.out.println("The value of the field "main" is " + this.main);
public static void main(String args)
main main = new main();
main.main(main.main + main.main);
...and when executed produces the output:
This object is an instance of the class main
The value of the argument "main" for this call to the method "main(String main)" is mainmain
The value of the field "main" is main
4
Is it possible to add anotherstatic main
method with different parameters?
â jpmc26
Sep 13 at 1:50
3
@jpmc26 Try it out and tell us how it went. :)
â MichaelK
Sep 13 at 6:06
add a comment |Â
up vote
31
down vote
How main
could not be used as an identifier while it is used as identifier to declare the "main" method ?
For such a classic idiom :
public class Foo
public static void main(String args)
main
is not a keyword and it would probably never be a keyword in Java for obvious retro compatibility reasons.
About the question, is main
a good identifier ?
First : valid for a compiler doesn't mean necessarily good.
For example the java1234
option that is proposed is also a valid identifier but that should really be avoided.
main
has a very particularly and important meaning : it is used as the entry point method of classes and jars executed by the java
command line.
Using main
for a method name that doesn't fill the criteria to be used by the java
command line would be just misleading while using it as variable name or a class name could make sense.
For example defining the class representing the entry point of an application as the Main
class of the application is acceptable and so using it as variable name too such as :
public class Main
public static void main(String args)
Main main = new Main();
// ...
In a general way, in Java, multiple characters or "words" are considered valid identifiers for the compiler but are strongly discouraged to be used in the client code (but generated code may do that : nested classes for example) as not readable and/or really misleading.
For example this could be valid for the compiler :
public class Object // 1
public void foo()
...
public class BadChosenIdentifier
public static void main() // 2
new BadChosenIdentifier().toString(new Object());
public void toString(Object java1234) // 3, 4
String _result$ = java1234 + " -> to avoid"; // 4
System.out.println(_result$);
But we don't want :
- to name
Object
our class as this is defined injava.lang
(1). - to name a method
main()
if doesn't fill the criteria to be used by thejava
command line (2). - to overload the
Object.toString()
method (3). - to name our variables with
_
,$
or any surprising/unmeaningful characters that go against the shared naming conventions (4).
5
Just to note,main
could be a keyword that is only usable as a name for a static method with an appropriate signature (or whatever). Note that super class calls usesuper
in a way that makes it look like an identifier:super(foo);
andsuper.foo
, butsuper
IS a keyword (and before generics were added, this was the only way to use it (that I can remember)).
â jaxad0127
Sep 10 at 21:33
@jaxad0127 Interesting point but I don't agree completely. Actually it IS not and in the future it could probably not be for still compatibility reasons. If you definedmain
as a keyword in a new version of java, it means that any code that uses main as method name (or any member names) will not compile any longer. The usage ofsuper
in generics doesn't have any side effect in existing code as generics didn't exist at this time.
â davidxxx
Sep 10 at 21:50
2
I just meant that it COULD have been done as a keyword. Just because it looks like an identifier, doesn't mean it has to be.
â jaxad0127
Sep 10 at 22:01
@jaxad0127 Without going too deep into the JLS and for the two cases you mention I think it can be said thatsuper
is a special expression: It represents a reference to aClass
object to be used with the object's constructor and its members.
â Gerold Broser
Sep 12 at 0:57
2
I would argue thatmain
is still a better identifier thanjava1234
. Using it for a "regular" method would be misleading, but I'd have no problem naming a variablemain
, if it's actually the main something in my method.java1234
is just awful, names should be descriptive...
â AJPerez
Sep 12 at 12:56
 |Â
show 3 more comments
up vote
30
down vote
Is it a valid identifier? Yes.
Is it a good identifier? Not if you're using it for anything other than the method that starts at JVM launch.
Is another valid identifier listed? Yes.
Did the test instructions say to choose the best answer?
5
Agreed - multiple choice like this are about choosing the 'best' correct answer when there are multiple. However, that doesn't make this a good multiple choice question and I think talking to the teacher about it is the right thing to do.
â Shadow
Sep 12 at 3:22
15
@Shadow This is a programming course. Ambiguity on a question about something that's specified with formal mathematical grammar is intolerable. Speaking strictly against that standard (which is what's implied by "valid"), both answers are equally correct. I can imagine far more cases in whichmain
is a tolerable identifier than I can in whichjava1234
would be. Consider, for example, a code base working with water supply data (water mains).
â jpmc26
Sep 13 at 1:51
1
@Holger I'm not saying anything. Please note the quotes around the word better. But clearly this instructor thinks so.
â Shadow
Sep 13 at 1:55
3
On the other hand, java1234 stinketh to high heaven as an identifier.
â Joshua
Sep 13 at 20:13
2
"choose the best answer" doesn't mean "figure out when the teacher doesn't know what they're talking about and guess the bad answer they are thinking of." main is not only a valid identifier, it's a very important identifier because every Java application has a main method, and methods are named with identifiers.
â fluffysheap
Sep 15 at 10:21
 |Â
show 2 more comments
up vote
27
down vote
I threw everything I could at it, and it appears to work. I'd say main is a valid identifier.
package main;
public class main
static main main;
String Main;
main(String main)
Main = main;
main(main main)
System.out.println(main.Main);
main main(main main)
return new main(main);
public static void main(main...Main)
main:
for (main main : Main)
main = (main instanceof Main) ? new main(main): main.main(main);
break main;
public static void main(String args)
main = new main("main");
main.main(main, main);
main = main.new Main(main)
main main(main main)
return ((Main)main).main();
;
main.main(main);
main.main(main,main);
abstract class Main extends main
Main(main main)
super("main");
main main()
main.Main = "Main";
return main;
I like it. Try a 'grep -o main main.java | wc -l'
â Gary Bak
Sep 13 at 13:56
2
That code kinda reminds me of the programming language "ook" ^^ Almost every word in this code is "main" ...
â Florian Bach
Sep 14 at 7:50
public static void main(main...Main)
(missing a space) can't work, can it?
â Gerold Broser
Sep 14 at 12:50
2
I feel like I mainlined it.
â Ross Presser
Sep 15 at 0:56
add a comment |Â
up vote
20
down vote
main
is perfectly valid because it, from the docs:
- Is a "sequence of Java letters and Java digits, the first of which is a Java letter"
- Is not a keyword
- Is not a boolean literal i.e. "true" or "false"
- Is not null literal
add a comment |Â
up vote
20
down vote
public class Main
private static String main;
public static void main(String main)
Main.main = main[0];
new Main().main(Main.main);
private void main(String main)
System.out.println(main);
add a comment |Â
up vote
0
down vote
Both main
and java123
are valid identifiers, main isnâÂÂt a reserved keyword so itâÂÂs perfectly acceptable to use, as far as the test goes you shouldâÂÂve gotten a point or half a point at least.
add a comment |Â
up vote
0
down vote
You can use any word that not a Keyword, Boolean, Null or begins with Number as identifier, The word " main " is the most used identifier, but - in your case - you can use java1234.
add a comment |Â
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
207
down vote
accepted
public class J
public static void main(String args)
String main = "The character sequence "main" is an identifier, not a keyword or reserved word.";
System.out.println(main);
This compiles, and when executed, emits this output:
The character sequence "main" is an identifier, not a keyword or reserved word.
The character sequence main
is an identifier, not a keyword or reserved word.
The relevant section of the JLS is 3.8:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
Identifier:
   IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
   JavaLetter JavaLetterOrDigit
JavaLetter:
   any Unicode character that is a "Java letter"
JavaLetterOrDigit:
   any Unicode character that is a "Java letter-or-digit"
The character sequence main
fits the above description and is not in the keyword list in Section 3.9.
(The character sequence java1234
is also an identifier, for the same reasons.)
Does it mean OP's child missed out 1 of the 2 good answers?
â Clockwork
Sep 13 at 20:19
15
@Clockwork The question was worded such that only one choice could be correct. However, both choices b and c satisfied the question's condition, inconsistent with the implied choice. This left the OP's child to choose between which correct answer was the one the only one that teacher thought was correct.
â rgettman
Sep 13 at 20:30
@rgettman I read "Which of the following..." as allowing more than once choice, to which "b and c" would be a valid response.
â TripeHound
Sep 14 at 14:38
2
@TripeHound "is a valid identifier" is singular and demands exactly 1 answer. Compare it to "are valid identifiers"
â Gimme the 411
Sep 15 at 22:46
You could have made the classmain
as well ;)
â Peter Lawrey
Sep 17 at 7:46
add a comment |Â
up vote
207
down vote
accepted
public class J
public static void main(String args)
String main = "The character sequence "main" is an identifier, not a keyword or reserved word.";
System.out.println(main);
This compiles, and when executed, emits this output:
The character sequence "main" is an identifier, not a keyword or reserved word.
The character sequence main
is an identifier, not a keyword or reserved word.
The relevant section of the JLS is 3.8:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
Identifier:
   IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
   JavaLetter JavaLetterOrDigit
JavaLetter:
   any Unicode character that is a "Java letter"
JavaLetterOrDigit:
   any Unicode character that is a "Java letter-or-digit"
The character sequence main
fits the above description and is not in the keyword list in Section 3.9.
(The character sequence java1234
is also an identifier, for the same reasons.)
Does it mean OP's child missed out 1 of the 2 good answers?
â Clockwork
Sep 13 at 20:19
15
@Clockwork The question was worded such that only one choice could be correct. However, both choices b and c satisfied the question's condition, inconsistent with the implied choice. This left the OP's child to choose between which correct answer was the one the only one that teacher thought was correct.
â rgettman
Sep 13 at 20:30
@rgettman I read "Which of the following..." as allowing more than once choice, to which "b and c" would be a valid response.
â TripeHound
Sep 14 at 14:38
2
@TripeHound "is a valid identifier" is singular and demands exactly 1 answer. Compare it to "are valid identifiers"
â Gimme the 411
Sep 15 at 22:46
You could have made the classmain
as well ;)
â Peter Lawrey
Sep 17 at 7:46
add a comment |Â
up vote
207
down vote
accepted
up vote
207
down vote
accepted
public class J
public static void main(String args)
String main = "The character sequence "main" is an identifier, not a keyword or reserved word.";
System.out.println(main);
This compiles, and when executed, emits this output:
The character sequence "main" is an identifier, not a keyword or reserved word.
The character sequence main
is an identifier, not a keyword or reserved word.
The relevant section of the JLS is 3.8:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
Identifier:
   IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
   JavaLetter JavaLetterOrDigit
JavaLetter:
   any Unicode character that is a "Java letter"
JavaLetterOrDigit:
   any Unicode character that is a "Java letter-or-digit"
The character sequence main
fits the above description and is not in the keyword list in Section 3.9.
(The character sequence java1234
is also an identifier, for the same reasons.)
public class J
public static void main(String args)
String main = "The character sequence "main" is an identifier, not a keyword or reserved word.";
System.out.println(main);
This compiles, and when executed, emits this output:
The character sequence "main" is an identifier, not a keyword or reserved word.
The character sequence main
is an identifier, not a keyword or reserved word.
The relevant section of the JLS is 3.8:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
Identifier:
   IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral
IdentifierChars:
   JavaLetter JavaLetterOrDigit
JavaLetter:
   any Unicode character that is a "Java letter"
JavaLetterOrDigit:
   any Unicode character that is a "Java letter-or-digit"
The character sequence main
fits the above description and is not in the keyword list in Section 3.9.
(The character sequence java1234
is also an identifier, for the same reasons.)
edited Sep 11 at 4:58
jeff6times7
1,522921
1,522921
answered Sep 10 at 20:08
rgettman
145k21198281
145k21198281
Does it mean OP's child missed out 1 of the 2 good answers?
â Clockwork
Sep 13 at 20:19
15
@Clockwork The question was worded such that only one choice could be correct. However, both choices b and c satisfied the question's condition, inconsistent with the implied choice. This left the OP's child to choose between which correct answer was the one the only one that teacher thought was correct.
â rgettman
Sep 13 at 20:30
@rgettman I read "Which of the following..." as allowing more than once choice, to which "b and c" would be a valid response.
â TripeHound
Sep 14 at 14:38
2
@TripeHound "is a valid identifier" is singular and demands exactly 1 answer. Compare it to "are valid identifiers"
â Gimme the 411
Sep 15 at 22:46
You could have made the classmain
as well ;)
â Peter Lawrey
Sep 17 at 7:46
add a comment |Â
Does it mean OP's child missed out 1 of the 2 good answers?
â Clockwork
Sep 13 at 20:19
15
@Clockwork The question was worded such that only one choice could be correct. However, both choices b and c satisfied the question's condition, inconsistent with the implied choice. This left the OP's child to choose between which correct answer was the one the only one that teacher thought was correct.
â rgettman
Sep 13 at 20:30
@rgettman I read "Which of the following..." as allowing more than once choice, to which "b and c" would be a valid response.
â TripeHound
Sep 14 at 14:38
2
@TripeHound "is a valid identifier" is singular and demands exactly 1 answer. Compare it to "are valid identifiers"
â Gimme the 411
Sep 15 at 22:46
You could have made the classmain
as well ;)
â Peter Lawrey
Sep 17 at 7:46
Does it mean OP's child missed out 1 of the 2 good answers?
â Clockwork
Sep 13 at 20:19
Does it mean OP's child missed out 1 of the 2 good answers?
â Clockwork
Sep 13 at 20:19
15
15
@Clockwork The question was worded such that only one choice could be correct. However, both choices b and c satisfied the question's condition, inconsistent with the implied choice. This left the OP's child to choose between which correct answer was the one the only one that teacher thought was correct.
â rgettman
Sep 13 at 20:30
@Clockwork The question was worded such that only one choice could be correct. However, both choices b and c satisfied the question's condition, inconsistent with the implied choice. This left the OP's child to choose between which correct answer was the one the only one that teacher thought was correct.
â rgettman
Sep 13 at 20:30
@rgettman I read "Which of the following..." as allowing more than once choice, to which "b and c" would be a valid response.
â TripeHound
Sep 14 at 14:38
@rgettman I read "Which of the following..." as allowing more than once choice, to which "b and c" would be a valid response.
â TripeHound
Sep 14 at 14:38
2
2
@TripeHound "is a valid identifier" is singular and demands exactly 1 answer. Compare it to "are valid identifiers"
â Gimme the 411
Sep 15 at 22:46
@TripeHound "is a valid identifier" is singular and demands exactly 1 answer. Compare it to "are valid identifiers"
â Gimme the 411
Sep 15 at 22:46
You could have made the class
main
as well ;)â Peter Lawrey
Sep 17 at 7:46
You could have made the class
main
as well ;)â Peter Lawrey
Sep 17 at 7:46
add a comment |Â
up vote
73
down vote
main
is a valid java identifier, and the teacher is wrong.
The relevant documentation is in the Java Language Specification, right here:
Chapter 3. "Lexical Structure", section 3.8. "Identifiers":
https://docs.oracle.com/javase/specs/jls/se10/html/jls-3.html#jls-3.8
It says:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter... An identifier cannot have the same spelling (Unicode character sequence) as a keyword (ç3.9), boolean literal (ç3.10.3), or the null literal (ç3.10.7), or a compile-time error occurs.
Which means that you can prove that it is a valid identifier by using it as an identifier and observing that no compile-time error occurs.
1
Could you quote and spell it out more explicitly?
â zero298
Sep 10 at 20:03
29
no, because it is an entire section. If the teacher thinks that this section makes some sort of exception for 'main', it is the teacher who must show where it says so.
â Mike Nakis
Sep 10 at 20:04
add a comment |Â
up vote
73
down vote
main
is a valid java identifier, and the teacher is wrong.
The relevant documentation is in the Java Language Specification, right here:
Chapter 3. "Lexical Structure", section 3.8. "Identifiers":
https://docs.oracle.com/javase/specs/jls/se10/html/jls-3.html#jls-3.8
It says:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter... An identifier cannot have the same spelling (Unicode character sequence) as a keyword (ç3.9), boolean literal (ç3.10.3), or the null literal (ç3.10.7), or a compile-time error occurs.
Which means that you can prove that it is a valid identifier by using it as an identifier and observing that no compile-time error occurs.
1
Could you quote and spell it out more explicitly?
â zero298
Sep 10 at 20:03
29
no, because it is an entire section. If the teacher thinks that this section makes some sort of exception for 'main', it is the teacher who must show where it says so.
â Mike Nakis
Sep 10 at 20:04
add a comment |Â
up vote
73
down vote
up vote
73
down vote
main
is a valid java identifier, and the teacher is wrong.
The relevant documentation is in the Java Language Specification, right here:
Chapter 3. "Lexical Structure", section 3.8. "Identifiers":
https://docs.oracle.com/javase/specs/jls/se10/html/jls-3.html#jls-3.8
It says:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter... An identifier cannot have the same spelling (Unicode character sequence) as a keyword (ç3.9), boolean literal (ç3.10.3), or the null literal (ç3.10.7), or a compile-time error occurs.
Which means that you can prove that it is a valid identifier by using it as an identifier and observing that no compile-time error occurs.
main
is a valid java identifier, and the teacher is wrong.
The relevant documentation is in the Java Language Specification, right here:
Chapter 3. "Lexical Structure", section 3.8. "Identifiers":
https://docs.oracle.com/javase/specs/jls/se10/html/jls-3.html#jls-3.8
It says:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter... An identifier cannot have the same spelling (Unicode character sequence) as a keyword (ç3.9), boolean literal (ç3.10.3), or the null literal (ç3.10.7), or a compile-time error occurs.
Which means that you can prove that it is a valid identifier by using it as an identifier and observing that no compile-time error occurs.
edited Sep 14 at 17:37
Robert Harveyâ¦
145k32264399
145k32264399
answered Sep 10 at 20:01
Mike Nakis
36k65389
36k65389
1
Could you quote and spell it out more explicitly?
â zero298
Sep 10 at 20:03
29
no, because it is an entire section. If the teacher thinks that this section makes some sort of exception for 'main', it is the teacher who must show where it says so.
â Mike Nakis
Sep 10 at 20:04
add a comment |Â
1
Could you quote and spell it out more explicitly?
â zero298
Sep 10 at 20:03
29
no, because it is an entire section. If the teacher thinks that this section makes some sort of exception for 'main', it is the teacher who must show where it says so.
â Mike Nakis
Sep 10 at 20:04
1
1
Could you quote and spell it out more explicitly?
â zero298
Sep 10 at 20:03
Could you quote and spell it out more explicitly?
â zero298
Sep 10 at 20:03
29
29
no, because it is an entire section. If the teacher thinks that this section makes some sort of exception for 'main', it is the teacher who must show where it says so.
â Mike Nakis
Sep 10 at 20:04
no, because it is an entire section. If the teacher thinks that this section makes some sort of exception for 'main', it is the teacher who must show where it says so.
â Mike Nakis
Sep 10 at 20:04
add a comment |Â
up vote
57
down vote
As the other answers state
main
is a valid Java identifier, as well as java1234
.
I guess the confusing comes from the fact that the main(String)
method is often used as entry point by the JVM1. However, that doesn't mean that the token main
itself cannot be used as identifier2.
The specs say so, and the following declarations are also valid:
A field:
private int main;
A local variable:
String main = "";
A method:
private void main() ...
A class (although a class name starting with lowercase is discouraged):
public class main ...
A package:
package main;
1: As noted in the comments, the JVM specification itself does not mandate any particular method as entry point, but the widely used java
tool often uses such a method as entry point.
2: I would generally avoid creating a main method other than main(String)
.
19
"I guess the confusing comes from the fact that the main(String) method is used as entry point for the JVM."main
isn't the entry point for the JVM. It's the entry point that thejava
tool uses to run applications. Other tools (servlet containers, for instance) use other entry points.
â T.J. Crowder
Sep 11 at 7:48
23
which is even more ironic, because even in the "entry-point-context" main ALREADY IS a valid identifier. So even the case you could hold against it actually proves OP right
â Hobbamok
Sep 11 at 11:42
@T.J.Crowder Thanks, I've included that in the answer.
â MC Emperor
Sep 11 at 14:21
1
@Hobbamok You seem confused about basic Java concepts, which probably explains why you teach it in a school and not practicing is the reply that comes to mind
â rath
Sep 12 at 9:58
2
Thejava
tool does not require amain(String)
method if the main class extends javafx.application.Application.
â VGR
Sep 12 at 18:27
 |Â
show 1 more comment
up vote
57
down vote
As the other answers state
main
is a valid Java identifier, as well as java1234
.
I guess the confusing comes from the fact that the main(String)
method is often used as entry point by the JVM1. However, that doesn't mean that the token main
itself cannot be used as identifier2.
The specs say so, and the following declarations are also valid:
A field:
private int main;
A local variable:
String main = "";
A method:
private void main() ...
A class (although a class name starting with lowercase is discouraged):
public class main ...
A package:
package main;
1: As noted in the comments, the JVM specification itself does not mandate any particular method as entry point, but the widely used java
tool often uses such a method as entry point.
2: I would generally avoid creating a main method other than main(String)
.
19
"I guess the confusing comes from the fact that the main(String) method is used as entry point for the JVM."main
isn't the entry point for the JVM. It's the entry point that thejava
tool uses to run applications. Other tools (servlet containers, for instance) use other entry points.
â T.J. Crowder
Sep 11 at 7:48
23
which is even more ironic, because even in the "entry-point-context" main ALREADY IS a valid identifier. So even the case you could hold against it actually proves OP right
â Hobbamok
Sep 11 at 11:42
@T.J.Crowder Thanks, I've included that in the answer.
â MC Emperor
Sep 11 at 14:21
1
@Hobbamok You seem confused about basic Java concepts, which probably explains why you teach it in a school and not practicing is the reply that comes to mind
â rath
Sep 12 at 9:58
2
Thejava
tool does not require amain(String)
method if the main class extends javafx.application.Application.
â VGR
Sep 12 at 18:27
 |Â
show 1 more comment
up vote
57
down vote
up vote
57
down vote
As the other answers state
main
is a valid Java identifier, as well as java1234
.
I guess the confusing comes from the fact that the main(String)
method is often used as entry point by the JVM1. However, that doesn't mean that the token main
itself cannot be used as identifier2.
The specs say so, and the following declarations are also valid:
A field:
private int main;
A local variable:
String main = "";
A method:
private void main() ...
A class (although a class name starting with lowercase is discouraged):
public class main ...
A package:
package main;
1: As noted in the comments, the JVM specification itself does not mandate any particular method as entry point, but the widely used java
tool often uses such a method as entry point.
2: I would generally avoid creating a main method other than main(String)
.
As the other answers state
main
is a valid Java identifier, as well as java1234
.
I guess the confusing comes from the fact that the main(String)
method is often used as entry point by the JVM1. However, that doesn't mean that the token main
itself cannot be used as identifier2.
The specs say so, and the following declarations are also valid:
A field:
private int main;
A local variable:
String main = "";
A method:
private void main() ...
A class (although a class name starting with lowercase is discouraged):
public class main ...
A package:
package main;
1: As noted in the comments, the JVM specification itself does not mandate any particular method as entry point, but the widely used java
tool often uses such a method as entry point.
2: I would generally avoid creating a main method other than main(String)
.
edited Sep 13 at 18:43
answered Sep 10 at 20:10
MC Emperor
7,332115185
7,332115185
19
"I guess the confusing comes from the fact that the main(String) method is used as entry point for the JVM."main
isn't the entry point for the JVM. It's the entry point that thejava
tool uses to run applications. Other tools (servlet containers, for instance) use other entry points.
â T.J. Crowder
Sep 11 at 7:48
23
which is even more ironic, because even in the "entry-point-context" main ALREADY IS a valid identifier. So even the case you could hold against it actually proves OP right
â Hobbamok
Sep 11 at 11:42
@T.J.Crowder Thanks, I've included that in the answer.
â MC Emperor
Sep 11 at 14:21
1
@Hobbamok You seem confused about basic Java concepts, which probably explains why you teach it in a school and not practicing is the reply that comes to mind
â rath
Sep 12 at 9:58
2
Thejava
tool does not require amain(String)
method if the main class extends javafx.application.Application.
â VGR
Sep 12 at 18:27
 |Â
show 1 more comment
19
"I guess the confusing comes from the fact that the main(String) method is used as entry point for the JVM."main
isn't the entry point for the JVM. It's the entry point that thejava
tool uses to run applications. Other tools (servlet containers, for instance) use other entry points.
â T.J. Crowder
Sep 11 at 7:48
23
which is even more ironic, because even in the "entry-point-context" main ALREADY IS a valid identifier. So even the case you could hold against it actually proves OP right
â Hobbamok
Sep 11 at 11:42
@T.J.Crowder Thanks, I've included that in the answer.
â MC Emperor
Sep 11 at 14:21
1
@Hobbamok You seem confused about basic Java concepts, which probably explains why you teach it in a school and not practicing is the reply that comes to mind
â rath
Sep 12 at 9:58
2
Thejava
tool does not require amain(String)
method if the main class extends javafx.application.Application.
â VGR
Sep 12 at 18:27
19
19
"I guess the confusing comes from the fact that the main(String) method is used as entry point for the JVM."
main
isn't the entry point for the JVM. It's the entry point that the java
tool uses to run applications. Other tools (servlet containers, for instance) use other entry points.â T.J. Crowder
Sep 11 at 7:48
"I guess the confusing comes from the fact that the main(String) method is used as entry point for the JVM."
main
isn't the entry point for the JVM. It's the entry point that the java
tool uses to run applications. Other tools (servlet containers, for instance) use other entry points.â T.J. Crowder
Sep 11 at 7:48
23
23
which is even more ironic, because even in the "entry-point-context" main ALREADY IS a valid identifier. So even the case you could hold against it actually proves OP right
â Hobbamok
Sep 11 at 11:42
which is even more ironic, because even in the "entry-point-context" main ALREADY IS a valid identifier. So even the case you could hold against it actually proves OP right
â Hobbamok
Sep 11 at 11:42
@T.J.Crowder Thanks, I've included that in the answer.
â MC Emperor
Sep 11 at 14:21
@T.J.Crowder Thanks, I've included that in the answer.
â MC Emperor
Sep 11 at 14:21
1
1
@Hobbamok You seem confused about basic Java concepts, which probably explains why you teach it in a school and not practicing is the reply that comes to mind
â rath
Sep 12 at 9:58
@Hobbamok You seem confused about basic Java concepts, which probably explains why you teach it in a school and not practicing is the reply that comes to mind
â rath
Sep 12 at 9:58
2
2
The
java
tool does not require a main(String)
method if the main class extends javafx.application.Application.â VGR
Sep 12 at 18:27
The
java
tool does not require a main(String)
method if the main class extends javafx.application.Application.â VGR
Sep 12 at 18:27
 |Â
show 1 more comment
up vote
47
down vote
This compiles fine on Java 1.8...
public class main
public String main = "main";
public void main(String main)
System.out.println("This object is an instance of the class " + this.getClass().getCanonicalName());
System.out.println("The value of the argument "main" for this call to the method "main(String main)" is " + main);
System.out.println("The value of the field "main" is " + this.main);
public static void main(String args)
main main = new main();
main.main(main.main + main.main);
...and when executed produces the output:
This object is an instance of the class main
The value of the argument "main" for this call to the method "main(String main)" is mainmain
The value of the field "main" is main
4
Is it possible to add anotherstatic main
method with different parameters?
â jpmc26
Sep 13 at 1:50
3
@jpmc26 Try it out and tell us how it went. :)
â MichaelK
Sep 13 at 6:06
add a comment |Â
up vote
47
down vote
This compiles fine on Java 1.8...
public class main
public String main = "main";
public void main(String main)
System.out.println("This object is an instance of the class " + this.getClass().getCanonicalName());
System.out.println("The value of the argument "main" for this call to the method "main(String main)" is " + main);
System.out.println("The value of the field "main" is " + this.main);
public static void main(String args)
main main = new main();
main.main(main.main + main.main);
...and when executed produces the output:
This object is an instance of the class main
The value of the argument "main" for this call to the method "main(String main)" is mainmain
The value of the field "main" is main
4
Is it possible to add anotherstatic main
method with different parameters?
â jpmc26
Sep 13 at 1:50
3
@jpmc26 Try it out and tell us how it went. :)
â MichaelK
Sep 13 at 6:06
add a comment |Â
up vote
47
down vote
up vote
47
down vote
This compiles fine on Java 1.8...
public class main
public String main = "main";
public void main(String main)
System.out.println("This object is an instance of the class " + this.getClass().getCanonicalName());
System.out.println("The value of the argument "main" for this call to the method "main(String main)" is " + main);
System.out.println("The value of the field "main" is " + this.main);
public static void main(String args)
main main = new main();
main.main(main.main + main.main);
...and when executed produces the output:
This object is an instance of the class main
The value of the argument "main" for this call to the method "main(String main)" is mainmain
The value of the field "main" is main
This compiles fine on Java 1.8...
public class main
public String main = "main";
public void main(String main)
System.out.println("This object is an instance of the class " + this.getClass().getCanonicalName());
System.out.println("The value of the argument "main" for this call to the method "main(String main)" is " + main);
System.out.println("The value of the field "main" is " + this.main);
public static void main(String args)
main main = new main();
main.main(main.main + main.main);
...and when executed produces the output:
This object is an instance of the class main
The value of the argument "main" for this call to the method "main(String main)" is mainmain
The value of the field "main" is main
edited Sep 11 at 14:24
answered Sep 11 at 12:11
MichaelK
1,590914
1,590914
4
Is it possible to add anotherstatic main
method with different parameters?
â jpmc26
Sep 13 at 1:50
3
@jpmc26 Try it out and tell us how it went. :)
â MichaelK
Sep 13 at 6:06
add a comment |Â
4
Is it possible to add anotherstatic main
method with different parameters?
â jpmc26
Sep 13 at 1:50
3
@jpmc26 Try it out and tell us how it went. :)
â MichaelK
Sep 13 at 6:06
4
4
Is it possible to add another
static main
method with different parameters?â jpmc26
Sep 13 at 1:50
Is it possible to add another
static main
method with different parameters?â jpmc26
Sep 13 at 1:50
3
3
@jpmc26 Try it out and tell us how it went. :)
â MichaelK
Sep 13 at 6:06
@jpmc26 Try it out and tell us how it went. :)
â MichaelK
Sep 13 at 6:06
add a comment |Â
up vote
31
down vote
How main
could not be used as an identifier while it is used as identifier to declare the "main" method ?
For such a classic idiom :
public class Foo
public static void main(String args)
main
is not a keyword and it would probably never be a keyword in Java for obvious retro compatibility reasons.
About the question, is main
a good identifier ?
First : valid for a compiler doesn't mean necessarily good.
For example the java1234
option that is proposed is also a valid identifier but that should really be avoided.
main
has a very particularly and important meaning : it is used as the entry point method of classes and jars executed by the java
command line.
Using main
for a method name that doesn't fill the criteria to be used by the java
command line would be just misleading while using it as variable name or a class name could make sense.
For example defining the class representing the entry point of an application as the Main
class of the application is acceptable and so using it as variable name too such as :
public class Main
public static void main(String args)
Main main = new Main();
// ...
In a general way, in Java, multiple characters or "words" are considered valid identifiers for the compiler but are strongly discouraged to be used in the client code (but generated code may do that : nested classes for example) as not readable and/or really misleading.
For example this could be valid for the compiler :
public class Object // 1
public void foo()
...
public class BadChosenIdentifier
public static void main() // 2
new BadChosenIdentifier().toString(new Object());
public void toString(Object java1234) // 3, 4
String _result$ = java1234 + " -> to avoid"; // 4
System.out.println(_result$);
But we don't want :
- to name
Object
our class as this is defined injava.lang
(1). - to name a method
main()
if doesn't fill the criteria to be used by thejava
command line (2). - to overload the
Object.toString()
method (3). - to name our variables with
_
,$
or any surprising/unmeaningful characters that go against the shared naming conventions (4).
5
Just to note,main
could be a keyword that is only usable as a name for a static method with an appropriate signature (or whatever). Note that super class calls usesuper
in a way that makes it look like an identifier:super(foo);
andsuper.foo
, butsuper
IS a keyword (and before generics were added, this was the only way to use it (that I can remember)).
â jaxad0127
Sep 10 at 21:33
@jaxad0127 Interesting point but I don't agree completely. Actually it IS not and in the future it could probably not be for still compatibility reasons. If you definedmain
as a keyword in a new version of java, it means that any code that uses main as method name (or any member names) will not compile any longer. The usage ofsuper
in generics doesn't have any side effect in existing code as generics didn't exist at this time.
â davidxxx
Sep 10 at 21:50
2
I just meant that it COULD have been done as a keyword. Just because it looks like an identifier, doesn't mean it has to be.
â jaxad0127
Sep 10 at 22:01
@jaxad0127 Without going too deep into the JLS and for the two cases you mention I think it can be said thatsuper
is a special expression: It represents a reference to aClass
object to be used with the object's constructor and its members.
â Gerold Broser
Sep 12 at 0:57
2
I would argue thatmain
is still a better identifier thanjava1234
. Using it for a "regular" method would be misleading, but I'd have no problem naming a variablemain
, if it's actually the main something in my method.java1234
is just awful, names should be descriptive...
â AJPerez
Sep 12 at 12:56
 |Â
show 3 more comments
up vote
31
down vote
How main
could not be used as an identifier while it is used as identifier to declare the "main" method ?
For such a classic idiom :
public class Foo
public static void main(String args)
main
is not a keyword and it would probably never be a keyword in Java for obvious retro compatibility reasons.
About the question, is main
a good identifier ?
First : valid for a compiler doesn't mean necessarily good.
For example the java1234
option that is proposed is also a valid identifier but that should really be avoided.
main
has a very particularly and important meaning : it is used as the entry point method of classes and jars executed by the java
command line.
Using main
for a method name that doesn't fill the criteria to be used by the java
command line would be just misleading while using it as variable name or a class name could make sense.
For example defining the class representing the entry point of an application as the Main
class of the application is acceptable and so using it as variable name too such as :
public class Main
public static void main(String args)
Main main = new Main();
// ...
In a general way, in Java, multiple characters or "words" are considered valid identifiers for the compiler but are strongly discouraged to be used in the client code (but generated code may do that : nested classes for example) as not readable and/or really misleading.
For example this could be valid for the compiler :
public class Object // 1
public void foo()
...
public class BadChosenIdentifier
public static void main() // 2
new BadChosenIdentifier().toString(new Object());
public void toString(Object java1234) // 3, 4
String _result$ = java1234 + " -> to avoid"; // 4
System.out.println(_result$);
But we don't want :
- to name
Object
our class as this is defined injava.lang
(1). - to name a method
main()
if doesn't fill the criteria to be used by thejava
command line (2). - to overload the
Object.toString()
method (3). - to name our variables with
_
,$
or any surprising/unmeaningful characters that go against the shared naming conventions (4).
5
Just to note,main
could be a keyword that is only usable as a name for a static method with an appropriate signature (or whatever). Note that super class calls usesuper
in a way that makes it look like an identifier:super(foo);
andsuper.foo
, butsuper
IS a keyword (and before generics were added, this was the only way to use it (that I can remember)).
â jaxad0127
Sep 10 at 21:33
@jaxad0127 Interesting point but I don't agree completely. Actually it IS not and in the future it could probably not be for still compatibility reasons. If you definedmain
as a keyword in a new version of java, it means that any code that uses main as method name (or any member names) will not compile any longer. The usage ofsuper
in generics doesn't have any side effect in existing code as generics didn't exist at this time.
â davidxxx
Sep 10 at 21:50
2
I just meant that it COULD have been done as a keyword. Just because it looks like an identifier, doesn't mean it has to be.
â jaxad0127
Sep 10 at 22:01
@jaxad0127 Without going too deep into the JLS and for the two cases you mention I think it can be said thatsuper
is a special expression: It represents a reference to aClass
object to be used with the object's constructor and its members.
â Gerold Broser
Sep 12 at 0:57
2
I would argue thatmain
is still a better identifier thanjava1234
. Using it for a "regular" method would be misleading, but I'd have no problem naming a variablemain
, if it's actually the main something in my method.java1234
is just awful, names should be descriptive...
â AJPerez
Sep 12 at 12:56
 |Â
show 3 more comments
up vote
31
down vote
up vote
31
down vote
How main
could not be used as an identifier while it is used as identifier to declare the "main" method ?
For such a classic idiom :
public class Foo
public static void main(String args)
main
is not a keyword and it would probably never be a keyword in Java for obvious retro compatibility reasons.
About the question, is main
a good identifier ?
First : valid for a compiler doesn't mean necessarily good.
For example the java1234
option that is proposed is also a valid identifier but that should really be avoided.
main
has a very particularly and important meaning : it is used as the entry point method of classes and jars executed by the java
command line.
Using main
for a method name that doesn't fill the criteria to be used by the java
command line would be just misleading while using it as variable name or a class name could make sense.
For example defining the class representing the entry point of an application as the Main
class of the application is acceptable and so using it as variable name too such as :
public class Main
public static void main(String args)
Main main = new Main();
// ...
In a general way, in Java, multiple characters or "words" are considered valid identifiers for the compiler but are strongly discouraged to be used in the client code (but generated code may do that : nested classes for example) as not readable and/or really misleading.
For example this could be valid for the compiler :
public class Object // 1
public void foo()
...
public class BadChosenIdentifier
public static void main() // 2
new BadChosenIdentifier().toString(new Object());
public void toString(Object java1234) // 3, 4
String _result$ = java1234 + " -> to avoid"; // 4
System.out.println(_result$);
But we don't want :
- to name
Object
our class as this is defined injava.lang
(1). - to name a method
main()
if doesn't fill the criteria to be used by thejava
command line (2). - to overload the
Object.toString()
method (3). - to name our variables with
_
,$
or any surprising/unmeaningful characters that go against the shared naming conventions (4).
How main
could not be used as an identifier while it is used as identifier to declare the "main" method ?
For such a classic idiom :
public class Foo
public static void main(String args)
main
is not a keyword and it would probably never be a keyword in Java for obvious retro compatibility reasons.
About the question, is main
a good identifier ?
First : valid for a compiler doesn't mean necessarily good.
For example the java1234
option that is proposed is also a valid identifier but that should really be avoided.
main
has a very particularly and important meaning : it is used as the entry point method of classes and jars executed by the java
command line.
Using main
for a method name that doesn't fill the criteria to be used by the java
command line would be just misleading while using it as variable name or a class name could make sense.
For example defining the class representing the entry point of an application as the Main
class of the application is acceptable and so using it as variable name too such as :
public class Main
public static void main(String args)
Main main = new Main();
// ...
In a general way, in Java, multiple characters or "words" are considered valid identifiers for the compiler but are strongly discouraged to be used in the client code (but generated code may do that : nested classes for example) as not readable and/or really misleading.
For example this could be valid for the compiler :
public class Object // 1
public void foo()
...
public class BadChosenIdentifier
public static void main() // 2
new BadChosenIdentifier().toString(new Object());
public void toString(Object java1234) // 3, 4
String _result$ = java1234 + " -> to avoid"; // 4
System.out.println(_result$);
But we don't want :
- to name
Object
our class as this is defined injava.lang
(1). - to name a method
main()
if doesn't fill the criteria to be used by thejava
command line (2). - to overload the
Object.toString()
method (3). - to name our variables with
_
,$
or any surprising/unmeaningful characters that go against the shared naming conventions (4).
edited Sep 17 at 7:52
answered Sep 10 at 20:10
davidxxx
57.2k54278
57.2k54278
5
Just to note,main
could be a keyword that is only usable as a name for a static method with an appropriate signature (or whatever). Note that super class calls usesuper
in a way that makes it look like an identifier:super(foo);
andsuper.foo
, butsuper
IS a keyword (and before generics were added, this was the only way to use it (that I can remember)).
â jaxad0127
Sep 10 at 21:33
@jaxad0127 Interesting point but I don't agree completely. Actually it IS not and in the future it could probably not be for still compatibility reasons. If you definedmain
as a keyword in a new version of java, it means that any code that uses main as method name (or any member names) will not compile any longer. The usage ofsuper
in generics doesn't have any side effect in existing code as generics didn't exist at this time.
â davidxxx
Sep 10 at 21:50
2
I just meant that it COULD have been done as a keyword. Just because it looks like an identifier, doesn't mean it has to be.
â jaxad0127
Sep 10 at 22:01
@jaxad0127 Without going too deep into the JLS and for the two cases you mention I think it can be said thatsuper
is a special expression: It represents a reference to aClass
object to be used with the object's constructor and its members.
â Gerold Broser
Sep 12 at 0:57
2
I would argue thatmain
is still a better identifier thanjava1234
. Using it for a "regular" method would be misleading, but I'd have no problem naming a variablemain
, if it's actually the main something in my method.java1234
is just awful, names should be descriptive...
â AJPerez
Sep 12 at 12:56
 |Â
show 3 more comments
5
Just to note,main
could be a keyword that is only usable as a name for a static method with an appropriate signature (or whatever). Note that super class calls usesuper
in a way that makes it look like an identifier:super(foo);
andsuper.foo
, butsuper
IS a keyword (and before generics were added, this was the only way to use it (that I can remember)).
â jaxad0127
Sep 10 at 21:33
@jaxad0127 Interesting point but I don't agree completely. Actually it IS not and in the future it could probably not be for still compatibility reasons. If you definedmain
as a keyword in a new version of java, it means that any code that uses main as method name (or any member names) will not compile any longer. The usage ofsuper
in generics doesn't have any side effect in existing code as generics didn't exist at this time.
â davidxxx
Sep 10 at 21:50
2
I just meant that it COULD have been done as a keyword. Just because it looks like an identifier, doesn't mean it has to be.
â jaxad0127
Sep 10 at 22:01
@jaxad0127 Without going too deep into the JLS and for the two cases you mention I think it can be said thatsuper
is a special expression: It represents a reference to aClass
object to be used with the object's constructor and its members.
â Gerold Broser
Sep 12 at 0:57
2
I would argue thatmain
is still a better identifier thanjava1234
. Using it for a "regular" method would be misleading, but I'd have no problem naming a variablemain
, if it's actually the main something in my method.java1234
is just awful, names should be descriptive...
â AJPerez
Sep 12 at 12:56
5
5
Just to note,
main
could be a keyword that is only usable as a name for a static method with an appropriate signature (or whatever). Note that super class calls use super
in a way that makes it look like an identifier: super(foo);
and super.foo
, but super
IS a keyword (and before generics were added, this was the only way to use it (that I can remember)).â jaxad0127
Sep 10 at 21:33
Just to note,
main
could be a keyword that is only usable as a name for a static method with an appropriate signature (or whatever). Note that super class calls use super
in a way that makes it look like an identifier: super(foo);
and super.foo
, but super
IS a keyword (and before generics were added, this was the only way to use it (that I can remember)).â jaxad0127
Sep 10 at 21:33
@jaxad0127 Interesting point but I don't agree completely. Actually it IS not and in the future it could probably not be for still compatibility reasons. If you defined
main
as a keyword in a new version of java, it means that any code that uses main as method name (or any member names) will not compile any longer. The usage of super
in generics doesn't have any side effect in existing code as generics didn't exist at this time.â davidxxx
Sep 10 at 21:50
@jaxad0127 Interesting point but I don't agree completely. Actually it IS not and in the future it could probably not be for still compatibility reasons. If you defined
main
as a keyword in a new version of java, it means that any code that uses main as method name (or any member names) will not compile any longer. The usage of super
in generics doesn't have any side effect in existing code as generics didn't exist at this time.â davidxxx
Sep 10 at 21:50
2
2
I just meant that it COULD have been done as a keyword. Just because it looks like an identifier, doesn't mean it has to be.
â jaxad0127
Sep 10 at 22:01
I just meant that it COULD have been done as a keyword. Just because it looks like an identifier, doesn't mean it has to be.
â jaxad0127
Sep 10 at 22:01
@jaxad0127 Without going too deep into the JLS and for the two cases you mention I think it can be said that
super
is a special expression: It represents a reference to a Class
object to be used with the object's constructor and its members.â Gerold Broser
Sep 12 at 0:57
@jaxad0127 Without going too deep into the JLS and for the two cases you mention I think it can be said that
super
is a special expression: It represents a reference to a Class
object to be used with the object's constructor and its members.â Gerold Broser
Sep 12 at 0:57
2
2
I would argue that
main
is still a better identifier than java1234
. Using it for a "regular" method would be misleading, but I'd have no problem naming a variable main
, if it's actually the main something in my method. java1234
is just awful, names should be descriptive...â AJPerez
Sep 12 at 12:56
I would argue that
main
is still a better identifier than java1234
. Using it for a "regular" method would be misleading, but I'd have no problem naming a variable main
, if it's actually the main something in my method. java1234
is just awful, names should be descriptive...â AJPerez
Sep 12 at 12:56
 |Â
show 3 more comments
up vote
30
down vote
Is it a valid identifier? Yes.
Is it a good identifier? Not if you're using it for anything other than the method that starts at JVM launch.
Is another valid identifier listed? Yes.
Did the test instructions say to choose the best answer?
5
Agreed - multiple choice like this are about choosing the 'best' correct answer when there are multiple. However, that doesn't make this a good multiple choice question and I think talking to the teacher about it is the right thing to do.
â Shadow
Sep 12 at 3:22
15
@Shadow This is a programming course. Ambiguity on a question about something that's specified with formal mathematical grammar is intolerable. Speaking strictly against that standard (which is what's implied by "valid"), both answers are equally correct. I can imagine far more cases in whichmain
is a tolerable identifier than I can in whichjava1234
would be. Consider, for example, a code base working with water supply data (water mains).
â jpmc26
Sep 13 at 1:51
1
@Holger I'm not saying anything. Please note the quotes around the word better. But clearly this instructor thinks so.
â Shadow
Sep 13 at 1:55
3
On the other hand, java1234 stinketh to high heaven as an identifier.
â Joshua
Sep 13 at 20:13
2
"choose the best answer" doesn't mean "figure out when the teacher doesn't know what they're talking about and guess the bad answer they are thinking of." main is not only a valid identifier, it's a very important identifier because every Java application has a main method, and methods are named with identifiers.
â fluffysheap
Sep 15 at 10:21
 |Â
show 2 more comments
up vote
30
down vote
Is it a valid identifier? Yes.
Is it a good identifier? Not if you're using it for anything other than the method that starts at JVM launch.
Is another valid identifier listed? Yes.
Did the test instructions say to choose the best answer?
5
Agreed - multiple choice like this are about choosing the 'best' correct answer when there are multiple. However, that doesn't make this a good multiple choice question and I think talking to the teacher about it is the right thing to do.
â Shadow
Sep 12 at 3:22
15
@Shadow This is a programming course. Ambiguity on a question about something that's specified with formal mathematical grammar is intolerable. Speaking strictly against that standard (which is what's implied by "valid"), both answers are equally correct. I can imagine far more cases in whichmain
is a tolerable identifier than I can in whichjava1234
would be. Consider, for example, a code base working with water supply data (water mains).
â jpmc26
Sep 13 at 1:51
1
@Holger I'm not saying anything. Please note the quotes around the word better. But clearly this instructor thinks so.
â Shadow
Sep 13 at 1:55
3
On the other hand, java1234 stinketh to high heaven as an identifier.
â Joshua
Sep 13 at 20:13
2
"choose the best answer" doesn't mean "figure out when the teacher doesn't know what they're talking about and guess the bad answer they are thinking of." main is not only a valid identifier, it's a very important identifier because every Java application has a main method, and methods are named with identifiers.
â fluffysheap
Sep 15 at 10:21
 |Â
show 2 more comments
up vote
30
down vote
up vote
30
down vote
Is it a valid identifier? Yes.
Is it a good identifier? Not if you're using it for anything other than the method that starts at JVM launch.
Is another valid identifier listed? Yes.
Did the test instructions say to choose the best answer?
Is it a valid identifier? Yes.
Is it a good identifier? Not if you're using it for anything other than the method that starts at JVM launch.
Is another valid identifier listed? Yes.
Did the test instructions say to choose the best answer?
answered Sep 11 at 16:38
user1423956
34922
34922
5
Agreed - multiple choice like this are about choosing the 'best' correct answer when there are multiple. However, that doesn't make this a good multiple choice question and I think talking to the teacher about it is the right thing to do.
â Shadow
Sep 12 at 3:22
15
@Shadow This is a programming course. Ambiguity on a question about something that's specified with formal mathematical grammar is intolerable. Speaking strictly against that standard (which is what's implied by "valid"), both answers are equally correct. I can imagine far more cases in whichmain
is a tolerable identifier than I can in whichjava1234
would be. Consider, for example, a code base working with water supply data (water mains).
â jpmc26
Sep 13 at 1:51
1
@Holger I'm not saying anything. Please note the quotes around the word better. But clearly this instructor thinks so.
â Shadow
Sep 13 at 1:55
3
On the other hand, java1234 stinketh to high heaven as an identifier.
â Joshua
Sep 13 at 20:13
2
"choose the best answer" doesn't mean "figure out when the teacher doesn't know what they're talking about and guess the bad answer they are thinking of." main is not only a valid identifier, it's a very important identifier because every Java application has a main method, and methods are named with identifiers.
â fluffysheap
Sep 15 at 10:21
 |Â
show 2 more comments
5
Agreed - multiple choice like this are about choosing the 'best' correct answer when there are multiple. However, that doesn't make this a good multiple choice question and I think talking to the teacher about it is the right thing to do.
â Shadow
Sep 12 at 3:22
15
@Shadow This is a programming course. Ambiguity on a question about something that's specified with formal mathematical grammar is intolerable. Speaking strictly against that standard (which is what's implied by "valid"), both answers are equally correct. I can imagine far more cases in whichmain
is a tolerable identifier than I can in whichjava1234
would be. Consider, for example, a code base working with water supply data (water mains).
â jpmc26
Sep 13 at 1:51
1
@Holger I'm not saying anything. Please note the quotes around the word better. But clearly this instructor thinks so.
â Shadow
Sep 13 at 1:55
3
On the other hand, java1234 stinketh to high heaven as an identifier.
â Joshua
Sep 13 at 20:13
2
"choose the best answer" doesn't mean "figure out when the teacher doesn't know what they're talking about and guess the bad answer they are thinking of." main is not only a valid identifier, it's a very important identifier because every Java application has a main method, and methods are named with identifiers.
â fluffysheap
Sep 15 at 10:21
5
5
Agreed - multiple choice like this are about choosing the 'best' correct answer when there are multiple. However, that doesn't make this a good multiple choice question and I think talking to the teacher about it is the right thing to do.
â Shadow
Sep 12 at 3:22
Agreed - multiple choice like this are about choosing the 'best' correct answer when there are multiple. However, that doesn't make this a good multiple choice question and I think talking to the teacher about it is the right thing to do.
â Shadow
Sep 12 at 3:22
15
15
@Shadow This is a programming course. Ambiguity on a question about something that's specified with formal mathematical grammar is intolerable. Speaking strictly against that standard (which is what's implied by "valid"), both answers are equally correct. I can imagine far more cases in which
main
is a tolerable identifier than I can in which java1234
would be. Consider, for example, a code base working with water supply data (water mains).â jpmc26
Sep 13 at 1:51
@Shadow This is a programming course. Ambiguity on a question about something that's specified with formal mathematical grammar is intolerable. Speaking strictly against that standard (which is what's implied by "valid"), both answers are equally correct. I can imagine far more cases in which
main
is a tolerable identifier than I can in which java1234
would be. Consider, for example, a code base working with water supply data (water mains).â jpmc26
Sep 13 at 1:51
1
1
@Holger I'm not saying anything. Please note the quotes around the word better. But clearly this instructor thinks so.
â Shadow
Sep 13 at 1:55
@Holger I'm not saying anything. Please note the quotes around the word better. But clearly this instructor thinks so.
â Shadow
Sep 13 at 1:55
3
3
On the other hand, java1234 stinketh to high heaven as an identifier.
â Joshua
Sep 13 at 20:13
On the other hand, java1234 stinketh to high heaven as an identifier.
â Joshua
Sep 13 at 20:13
2
2
"choose the best answer" doesn't mean "figure out when the teacher doesn't know what they're talking about and guess the bad answer they are thinking of." main is not only a valid identifier, it's a very important identifier because every Java application has a main method, and methods are named with identifiers.
â fluffysheap
Sep 15 at 10:21
"choose the best answer" doesn't mean "figure out when the teacher doesn't know what they're talking about and guess the bad answer they are thinking of." main is not only a valid identifier, it's a very important identifier because every Java application has a main method, and methods are named with identifiers.
â fluffysheap
Sep 15 at 10:21
 |Â
show 2 more comments
up vote
27
down vote
I threw everything I could at it, and it appears to work. I'd say main is a valid identifier.
package main;
public class main
static main main;
String Main;
main(String main)
Main = main;
main(main main)
System.out.println(main.Main);
main main(main main)
return new main(main);
public static void main(main...Main)
main:
for (main main : Main)
main = (main instanceof Main) ? new main(main): main.main(main);
break main;
public static void main(String args)
main = new main("main");
main.main(main, main);
main = main.new Main(main)
main main(main main)
return ((Main)main).main();
;
main.main(main);
main.main(main,main);
abstract class Main extends main
Main(main main)
super("main");
main main()
main.Main = "Main";
return main;
I like it. Try a 'grep -o main main.java | wc -l'
â Gary Bak
Sep 13 at 13:56
2
That code kinda reminds me of the programming language "ook" ^^ Almost every word in this code is "main" ...
â Florian Bach
Sep 14 at 7:50
public static void main(main...Main)
(missing a space) can't work, can it?
â Gerold Broser
Sep 14 at 12:50
2
I feel like I mainlined it.
â Ross Presser
Sep 15 at 0:56
add a comment |Â
up vote
27
down vote
I threw everything I could at it, and it appears to work. I'd say main is a valid identifier.
package main;
public class main
static main main;
String Main;
main(String main)
Main = main;
main(main main)
System.out.println(main.Main);
main main(main main)
return new main(main);
public static void main(main...Main)
main:
for (main main : Main)
main = (main instanceof Main) ? new main(main): main.main(main);
break main;
public static void main(String args)
main = new main("main");
main.main(main, main);
main = main.new Main(main)
main main(main main)
return ((Main)main).main();
;
main.main(main);
main.main(main,main);
abstract class Main extends main
Main(main main)
super("main");
main main()
main.Main = "Main";
return main;
I like it. Try a 'grep -o main main.java | wc -l'
â Gary Bak
Sep 13 at 13:56
2
That code kinda reminds me of the programming language "ook" ^^ Almost every word in this code is "main" ...
â Florian Bach
Sep 14 at 7:50
public static void main(main...Main)
(missing a space) can't work, can it?
â Gerold Broser
Sep 14 at 12:50
2
I feel like I mainlined it.
â Ross Presser
Sep 15 at 0:56
add a comment |Â
up vote
27
down vote
up vote
27
down vote
I threw everything I could at it, and it appears to work. I'd say main is a valid identifier.
package main;
public class main
static main main;
String Main;
main(String main)
Main = main;
main(main main)
System.out.println(main.Main);
main main(main main)
return new main(main);
public static void main(main...Main)
main:
for (main main : Main)
main = (main instanceof Main) ? new main(main): main.main(main);
break main;
public static void main(String args)
main = new main("main");
main.main(main, main);
main = main.new Main(main)
main main(main main)
return ((Main)main).main();
;
main.main(main);
main.main(main,main);
abstract class Main extends main
Main(main main)
super("main");
main main()
main.Main = "Main";
return main;
I threw everything I could at it, and it appears to work. I'd say main is a valid identifier.
package main;
public class main
static main main;
String Main;
main(String main)
Main = main;
main(main main)
System.out.println(main.Main);
main main(main main)
return new main(main);
public static void main(main...Main)
main:
for (main main : Main)
main = (main instanceof Main) ? new main(main): main.main(main);
break main;
public static void main(String args)
main = new main("main");
main.main(main, main);
main = main.new Main(main)
main main(main main)
return ((Main)main).main();
;
main.main(main);
main.main(main,main);
abstract class Main extends main
Main(main main)
super("main");
main main()
main.Main = "Main";
return main;
answered Sep 13 at 13:22
18107
41838
41838
I like it. Try a 'grep -o main main.java | wc -l'
â Gary Bak
Sep 13 at 13:56
2
That code kinda reminds me of the programming language "ook" ^^ Almost every word in this code is "main" ...
â Florian Bach
Sep 14 at 7:50
public static void main(main...Main)
(missing a space) can't work, can it?
â Gerold Broser
Sep 14 at 12:50
2
I feel like I mainlined it.
â Ross Presser
Sep 15 at 0:56
add a comment |Â
I like it. Try a 'grep -o main main.java | wc -l'
â Gary Bak
Sep 13 at 13:56
2
That code kinda reminds me of the programming language "ook" ^^ Almost every word in this code is "main" ...
â Florian Bach
Sep 14 at 7:50
public static void main(main...Main)
(missing a space) can't work, can it?
â Gerold Broser
Sep 14 at 12:50
2
I feel like I mainlined it.
â Ross Presser
Sep 15 at 0:56
I like it. Try a 'grep -o main main.java | wc -l'
â Gary Bak
Sep 13 at 13:56
I like it. Try a 'grep -o main main.java | wc -l'
â Gary Bak
Sep 13 at 13:56
2
2
That code kinda reminds me of the programming language "ook" ^^ Almost every word in this code is "main" ...
â Florian Bach
Sep 14 at 7:50
That code kinda reminds me of the programming language "ook" ^^ Almost every word in this code is "main" ...
â Florian Bach
Sep 14 at 7:50
public static void main(main...Main)
(missing a space) can't work, can it?â Gerold Broser
Sep 14 at 12:50
public static void main(main...Main)
(missing a space) can't work, can it?â Gerold Broser
Sep 14 at 12:50
2
2
I feel like I mainlined it.
â Ross Presser
Sep 15 at 0:56
I feel like I mainlined it.
â Ross Presser
Sep 15 at 0:56
add a comment |Â
up vote
20
down vote
main
is perfectly valid because it, from the docs:
- Is a "sequence of Java letters and Java digits, the first of which is a Java letter"
- Is not a keyword
- Is not a boolean literal i.e. "true" or "false"
- Is not null literal
add a comment |Â
up vote
20
down vote
main
is perfectly valid because it, from the docs:
- Is a "sequence of Java letters and Java digits, the first of which is a Java letter"
- Is not a keyword
- Is not a boolean literal i.e. "true" or "false"
- Is not null literal
add a comment |Â
up vote
20
down vote
up vote
20
down vote
main
is perfectly valid because it, from the docs:
- Is a "sequence of Java letters and Java digits, the first of which is a Java letter"
- Is not a keyword
- Is not a boolean literal i.e. "true" or "false"
- Is not null literal
main
is perfectly valid because it, from the docs:
- Is a "sequence of Java letters and Java digits, the first of which is a Java letter"
- Is not a keyword
- Is not a boolean literal i.e. "true" or "false"
- Is not null literal
answered Sep 10 at 20:07
zero298
10.9k32854
10.9k32854
add a comment |Â
add a comment |Â
up vote
20
down vote
public class Main
private static String main;
public static void main(String main)
Main.main = main[0];
new Main().main(Main.main);
private void main(String main)
System.out.println(main);
add a comment |Â
up vote
20
down vote
public class Main
private static String main;
public static void main(String main)
Main.main = main[0];
new Main().main(Main.main);
private void main(String main)
System.out.println(main);
add a comment |Â
up vote
20
down vote
up vote
20
down vote
public class Main
private static String main;
public static void main(String main)
Main.main = main[0];
new Main().main(Main.main);
private void main(String main)
System.out.println(main);
public class Main
private static String main;
public static void main(String main)
Main.main = main[0];
new Main().main(Main.main);
private void main(String main)
System.out.println(main);
answered Sep 11 at 10:41
kabra.dabar
9071815
9071815
add a comment |Â
add a comment |Â
up vote
0
down vote
Both main
and java123
are valid identifiers, main isnâÂÂt a reserved keyword so itâÂÂs perfectly acceptable to use, as far as the test goes you shouldâÂÂve gotten a point or half a point at least.
add a comment |Â
up vote
0
down vote
Both main
and java123
are valid identifiers, main isnâÂÂt a reserved keyword so itâÂÂs perfectly acceptable to use, as far as the test goes you shouldâÂÂve gotten a point or half a point at least.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Both main
and java123
are valid identifiers, main isnâÂÂt a reserved keyword so itâÂÂs perfectly acceptable to use, as far as the test goes you shouldâÂÂve gotten a point or half a point at least.
Both main
and java123
are valid identifiers, main isnâÂÂt a reserved keyword so itâÂÂs perfectly acceptable to use, as far as the test goes you shouldâÂÂve gotten a point or half a point at least.
edited Sep 16 at 11:12
Chirag Jain
451119
451119
answered Sep 14 at 15:11
shavar
14
14
add a comment |Â
add a comment |Â
up vote
0
down vote
You can use any word that not a Keyword, Boolean, Null or begins with Number as identifier, The word " main " is the most used identifier, but - in your case - you can use java1234.
add a comment |Â
up vote
0
down vote
You can use any word that not a Keyword, Boolean, Null or begins with Number as identifier, The word " main " is the most used identifier, but - in your case - you can use java1234.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You can use any word that not a Keyword, Boolean, Null or begins with Number as identifier, The word " main " is the most used identifier, but - in your case - you can use java1234.
You can use any word that not a Keyword, Boolean, Null or begins with Number as identifier, The word " main " is the most used identifier, but - in your case - you can use java1234.
answered Sep 17 at 9:24
Ahmed Tag Amer
96
96
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52264638%2fis-main-a-valid-java-identifier%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Comments are not for extended discussion; this conversation has been moved to chat.
â Samuel Liewâ¦
Sep 11 at 23:33
18
Anecdotal: Your kid might be dealing with a rusted teacher. We recently reformed IT education here nation-wide, and pressure to use new programming languages and ideas lead to many teachers that have been teaching for many years (being rusted in their pre-2000 mindset of programming) simply not being up to the job of teaching modern programming (spreading misinformation such as main is not a valid identifier). I remember my embedded systems teacher trying to get us to sort 100.000 integers on an Arduino (which has 32kB memory). I also prepared a written rebuttal but it was simply ignored.
â Zimano
Sep 13 at 10:22
7
@Zimano, I think its the exact opposite. First year teacher who's major I don't think was CS.
â Gary Bak
Sep 13 at 11:17
15
Was it a single-choice or a multi-choice question? If it was a multi-choice question then b and c should be selected.
â md2perpe
Sep 13 at 21:40
11
@Zimano I can't for the life of me imagine why a "pre-2000 mindset of programming" would change the fact that
main
is a perfectly valid identifier in Java since 1995.â Tobia Tesan
Sep 14 at 22:36