-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java #35
Comments
Could you send a pull request for this? |
Personally, I don't think this should be included in this project.
That is because
$ ls
A.java
$ cat A.java
class A{}
$ javac A.java
$ ls
A.class A.java
$ java A
Exception in thread "main" java.lang.NoSuchMethodError: main |
Yes, that is true and it is supposed to compile. The purpose of compiler is to compile the code and generate bytecode that can then be executed by the JVM In the two cases you point. An empty .java file : here in this case javac compiles the file, checks for syntax errors (which there are none) and then finishes compilation. No .class file is generated as the javac generates .class file for each class and anonymous classes. Since there is no class hence no .class file. An A.java file with class A{} : here the javac compile the file, checks syntax errors (which are none) and generates an A.class file. in either of the case, its not the compilers job to check if the .java file makes sense or not or it will give an runtime error or not. Compiler checks for syntax and compile time issues and generates bytecode if successful. |
As of Java 21, this is a valid program:
Reference: https://openjdk.org/jeps/445 |
an empty
.java
is compilable byjavac
, or evenclass A{} in A.java
is compilable.The text was updated successfully, but these errors were encountered: