in a variable name in Java

0 votes

I am a beginner in Java. While looking at the naming conventions for variables it was mentioned that we can use "$" symbol in the variable name. Along with it, there was this line which said 

"Java does allow the dollar sign symbol $ to appear in an identifier, but these identifiers have a special meaning, so you should not use the $ symbol in your identifiers."

So can someone explain what is the special meaning behind $ symbol?

Oct 10, 2018 in Java by 93.lynn
• 1,600 points
5,599 views

1 answer to this question.

0 votes

Java compiler uses "$" symbol internally to decorate certain names.

For Example:

public class demo {
    class test {
        public int x;
    }

    public void myTrial () {
        Object obj = new Object () {
            public String toString() {
                return "hello world!";
            }
        };
    }
}

Compiling this program will produce three .class files:

  • demo.class, containing the main (outer) class demo
  • demo$test.class, containing the named inner class demo.test
  • demo$1.class, containing the anonymous inner class (local to method demo.myTrial)

The javac uses $ in some automatically-generated variable names for the implicitly referencing from the inner classes to their outer classes.​

answered Oct 10, 2018 by code.reaper12
• 3,500 points

Related Questions In Java

0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,230 points
1,888 views
0 votes
2 answers

How to create a 2-D array in java?

int[][] multi = new int[5][]; multi[0] = new ...READ MORE

answered Jul 16, 2018 in Java by Daisy
• 8,120 points
942 views
0 votes
3 answers

How to read a Text File in Java?

You can use readAllLines and the join method to ...READ MORE

answered Jul 28, 2018 in Java by samarth295
• 2,220 points
2,098 views
0 votes
3 answers

Check if a String is numeric in Java

Java 8 Lambda Expression is used: String someString ...READ MORE

answered Sep 3, 2018 in Java by Daisy
• 8,120 points
3,357 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 79,308 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
7,921 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
16,941 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,356 views
0 votes
1 answer

Deep copying a 2d array in Java

I guess, for deep copying you will ...READ MORE

answered Nov 13, 2018 in Java by code.reaper12
• 3,500 points
8,403 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,500 points
4,248 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP