If I compile a class
class hussi
{
public static void main(String args[])
{
System.out.println("hello java");
}
}
Will I have any file other than hussi.class file?
Does the javac create any file other than .class file ?
If I compile a class
class hussi
{
public static void main(String args[])
{
System.out.println("hello java");
}
}
Will I have any file other than hussi.class file?
Does the javac create any file other than .class file ?
Java compiler creates .class
for each class. Java file may contain at least 1 class. It can contain more: either top level or inner classes. It can also contain anonymous inner classes. Compiler creates separate file for each such class.
The java compiler produces one file per class, including for inner classes (anonymous or not). They will always be a .class file.
You will get one .class file per class. If you have inner classes you may end up with multiple .class files per .java file.
Java compiler only create one file that is .class file.
But you must have one public class in a java file to compile this otherwise error will occur,and file name must be same as public class name.
If you have more then one class in a java file then more class file will create.
javac
will create one .class
file in this case. However if you have inner classes, along with the class file for the outer class, the class files for inner classes will also be generated
Edit: there is a better answer: https://stackoverflow.com/a/1031966/298455
Even the package-info.java produces a class.
/**
* Javadoc for a package
*
* with an annotation.
*/
@Deprecated
package mypackage;
compiled with
$ javac package-info.java
$ ls -l
total 8
-rw-rw-r-- 1 peter peter 180 2012-03-21 12:08 package-info.class
-rw-rw-r-- 1 peter peter 87 2012-03-21 12:08 package-info.java
$ javap -c -v -classpath .. mypackage.package-info
Classfile /d/peter/untitled/src/main/java/mypackage/package-info.class
Last modified 21-Mar-2012; size 180 bytes
MD5 checksum f152dc2e8a45929ef297f6ac05a4067e
Compiled from "package-info.java"
interface mypackage.package-info
SourceFile: "package-info.java"
RuntimeVisibleAnnotations:
0: #6()
minor version: 0
major version: 51
flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC
Constant pool:
#1 = Class #7 // "mypackage/package-info"
#2 = Class #8 // java/lang/Object
#3 = Utf8 SourceFile
#4 = Utf8 package-info.java
#5 = Utf8 RuntimeVisibleAnnotations
#6 = Utf8 Ljava/lang/Deprecated;
#7 = Utf8 mypackage/package-info
#8 = Utf8 java/lang/Object
{
}