What does a $ prefix in a java classname mean?

java class name rules
can we use underscore in class name in java
java class name start with number
class name should start with capital in java
java class name start with underscore
class name must begin with alphabet in java
java class name handler
java class name generator

I have a stacktrace for an app that includes the following nugget:

com.google.inject.internal.util.$ComputationException

What does the $ in front of the class name indicate?

In the Java internals, the $ character is considered a valid identifier character just like letters or numbers. However, it's usually used internally by the compiler when generating things like inner classes.

From the Java Language Specification:

The Java letters include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems.

Java class name prefixes : java, Name Mapping; Defining a Package Prefix; Defining a Single Prefix for Multiple Java uses packages to informally define namespaces; while Objective they cannot be located using the original Java class name by default. In Java, there are two kinds of names: simple and qualified. A simple name consists of a unique identifier while a qualified name is a sequence of simple names separated by dots. As its name suggests, getSimpleName() returns the simple name of the underlying class, that is the name it has been given in the source code .

It means that ComputationException is contained within another class or otherwise not publicly visible.

See http://www.retrologic.com/innerclasses.doc7.html .

How to specify prefixes for package names., In code terms that usually means a single getFoo() or toFoo() method. Note that I haven't covered every last prefix/suffix - there are many more. Thus, this code understands that the class name java.lang.Object is stored in a file with the prefix java/lang/Object.class somewhere in the class path. This code also implements both class path

The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems.

More Java prefixs and suffixes, You can usually contrive that your class names do not conflict with those in the what PI means here and the code is not cluttered up with the class name prefix. In the Java internals, the $ character is considered a valid identifier character just like letters or numbers. However, it's usually used internally by the compiler when generating things like inner classes. From the Java Language Specification:

Looks like a Google (Guice, GSON) convention to discriminate internal types.

Ivor Horton's Beginning Java 2, Read answers for the most popular questions around Java class naming The language specification states that a class name should be a You should reserve verbs for method names as they represent actions executed by things. of this class is the same as interface's name followed by the Impl suffix,  The java.lang.Class.getName() returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String. Declaration Following is the declaration for java.lang.Class.getName() method

Java class naming conventions, rules, and best practice, Below are some naming conventions of java programming language. Should be mnemonic i.e, designed to indicate to the casual observer the intent of its use. The prefix of a unique package name is always written in all-lowercase ASCII  When used in prefix mode, it increments the operand and evaluates to the incremented value of that operand. When used in postfix mode, it increments its operand, but evaluates to the value of that operand before it was incremented. Let's take an example to see the behavior of prefix and postfix form of Java's increment operator.

Java Naming Conventions, The prefix of a unique package name is always written in all-lowercase ASCII The choice of a variable name should be mnemonic- that is, designed to indicate​  1 : Run a loop for 'm' times, inputting 'a' and 'b'. 2 : Add 100 at index 'a' and subtract 100 from index 'b+1'. 3 : After completion of 'm' operations, compute the prefix sum array. 4 : Scan the largest element and we're done. What we did was adding 100 at ‘a’ because this will add 100 to all elements while taking prefix sum array.

Code Conventions for the Java Programming Language: 9. Naming , The syntax is: java:classname[?path=uri-of-classfile] where java: indicates that a user-defined Java function is being called uri-of-classfile is the URI of the is identified in a namespace URI, and the namespace is used to prefix a method call. The 'F' prefix actually stands for "Float" (as in Floating Point.) Tim Sweeney wrote the original "FVector" class along with many of the original math classes, and the 'F' prefix was useful to distinguish from math constructs that would support either integers or doubles, even before such classes were written.

Comments
  • This does not appear to be an inner class, since there is no "outer" class name preceding the $
  • You're asking about internal decisions made by your compiler about synthesized class naming. Outside the decisions made by your compiler, the $ and its position doesn't mean anything.
  • If ComputationException was contained within another class, wouldn't that other class's name be before the $?
  • @emmby Yes. Since this is a google package in an "inject.internal" namespace, I'm going to go ahead and say it was generated through some internal voodoo. I can't tell you what the class' purpose is, only what the $ means... And that's "this is not a human-written public class".