-1

I have compiles one java file, suppose test.java using javac test.java

after compilation,it generates two class files test.class and test$.class.

any one help me about that $ class files.The code is working fine.I need to understand $ class files.

is it a temp file ?

below is my code package test.myfolder;

public class test{

public String Login;
public String Name;
public String Num;
public String AccNum;

public test()
{
    this.Login = Abc.getMissChar();
    this.Name = Abc.getMissChar();
    this.Num = Abc.getMissChar();
    this.AccNum = Abc.getMissChar();
}

public test(String pLogin, String pName, String pNum, String pAccNum)
{
    this.Login = pLogin;
    this.Name = pName;
    this.Num = pNum;
    this.AccNum = pNum;
}

public String getLogin() {
    return Login;
}

public String getName() {
    return Name;
}

public String getNum() {
    return Num;
}

public String getAccNum() {
    return AccNum;
}
Rahul
  • 76
  • 1
  • 2
  • 9
  • This is due to anonymous-inner class. – Himanshu Bhardwaj Apr 01 '13 at 05:46
  • 2
    The $classfile indicated that you have used inner classes in your code. stackoverflow.com/questions/380406/java-inner-class-class-file-names may give you some idea – ATR Apr 01 '13 at 05:47
  • The $classfile indicated that you have used inner classes in your code. stackoverflow.com/questions/380406/java-inner-class-class-file-names may give you some idea – ATR Apr 01 '13 at 05:48
  • Read this http://stackoverflow.com/questions/399546/synthetic-class-in-java – prasanth Apr 01 '13 at 05:52
  • Read this post in StackOverflow. http://stackoverflow.com/questions/399546/synthetic-class-in-java – prasanth Apr 01 '13 at 05:55

2 Answers2

1

If you have anonymous classes (or maybe just a switch statement), Java creates these extra class files with the $ in them.

Those are not temporary files. Java will need them to load your class.

Community
  • 1
  • 1
Thilo
  • 257,207
  • 101
  • 511
  • 656
  • is there is any issue with this $ class files.I have tried to delete that one,but it shows file not found. – Rahul Apr 01 '13 at 05:54
  • Don't delete it. It is not a temporary file. Java will need that file to load your class. – Thilo Apr 01 '13 at 05:57
  • But in my code no inner classes are there.It is used only for set and get method for values only..I am bit confused about this $class files.... – Rahul Apr 01 '13 at 06:02
  • I have added the my java code also. – Rahul Apr 01 '13 at 06:24
  • Are you sure the compiler really creates that file? Can you delete it and compile again? – Thilo Apr 01 '13 at 07:33
1

If a source file has more than one class, each class is compiled into a separate class file and I think there is another inner or anonymous classes inside your class.

Biswajit
  • 2,434
  • 2
  • 28
  • 35
  • test.java file is an existing file.I have updated that file and compiled.In the previous case only test.class file is there.After updating the java file and compiled again with target 1.5 command(As our javac version upgraded to 1.6,I need in 1.5 ).it generates test.class and test$1.class.... – Rahul Apr 01 '13 at 06:07