Yes, you need at least one class to have a program, but no, you do not need any methods (unlike some other answers).
The reason you need a class is because in Java all the code is inside classes. Therefore, in order to have any code, you need a class. However, the code does not have to be in the method. It can also be in initializers. So here is the complete Java program without methods:
class LookMaNoMethods { static { System.out.println("Hello, world!"); System.exit(0); } }
And it gives ...
$ javac LookMaNoMethods.java $ java LookMaNoMethods Hello, world! $
EDIT: from Java 7, the above code using only a static block and no main method produces any output. The main method is now required. Code without the main method compiles successfully.
rlibby
source share