Page 1 of 1

Assertion error is JVM or Programmer Exception?

Posted: Sun Aug 27, 2017 5:34 am
by RRRRRR
Firstly ->I wanted to ask that whether Assertion error is JVM or Programmer Exception?

Secondly -> When we don't write main method in our program and execute code then it gives like->

Error: Main method not found in class a.TestClass, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

So above is Error or Exception???

Re: Assertion error is JVM or Programmer Exception?

Posted: Sun Aug 27, 2017 8:46 am
by admin
1. Thrown by the JVM when an assertion fails. Please read ExceptionClassSummary document given with our question bank.
2. The error message itself is quite clear. It is an Error.

Re: Assertion error is JVM or Programmer Exception?

Posted: Sun Aug 27, 2017 1:55 pm
by RRRRRR
Thank you very much. Ok next time i take care about it :)

Re: Assertion error is JVM or Programmer Exception?

Posted: Tue Nov 23, 2021 12:50 am
by jokovkilg
In Java, each application must have the main method. The main method is the entry point of every java program. The java program searches for the main method while running. This error occurred when the main method is not available. The reason that the compiler don't complain about the public is because it doesn't care about the main method. It doesn't take difference for it if a main exists or not. It's the JVM which need a start point public and static to launch your application.

So you should make your main method as public:

public static void main(String[] args)

The JVM is programmed to look for a specific signature for the main method before executing the program. It finds this signature by looking for a specific series of bytes in the bytecode. That signature only results from compiling a method that is - public static void main. If any of the three modifiers (public, static and void) are omitted the bytecode code will look different and the JVM will not be able to find your main method.