Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the valid characters for a Java method name?

I read about the naming of Java variables. It says that Java variables cannot start with any numbers and special characters except for $ and _.

Some valid examples:

int count;
int _count;
int $count;

And some invalid examples:

int %count;
int 4count;
int #count;

Do the same rules apply to method names?

like image 710
kon Avatar asked Apr 18 '12 14:04

kon


2 Answers

Yes, method names and variable names are what's called "identifiers". Identifiers all share the same rules regarding accepted characters. Take a look at §3.8 from the Java Language Specification to find out exactly what an identifier may contain, and §6.2 for an explanation about how identifiers are used.

like image 83
rid Avatar answered Oct 07 '22 03:10

rid


You might be surprised when having unusual characters for method, such as:

public void mój_brzuch_zacznie_burczeć()

and it works pretty nice. Take a look at this blog to see more fancy examples.

like image 34
Damian Avatar answered Oct 07 '22 01:10

Damian