Steps to compile a java program

  1. Create your .java source file

    • Name of the file should be same as class name (just a norm, works otherwise).

  2. Compile your .java source file to generate a .class file

    	javac -d <destination of .class files> sourcefile.java
    • .class file will have same name as class.

    • javac here is java compiler.

  3. Go to destination folder which contains .class file and run following command.

    	java filename
    • Actually filename will be filename.class but we write without .class

    • java here is application launcher

  • Note that jvm looks for public static void main(String[] variable) and not the compiler.

  • Hence, when you do not mention this main function and compile program, it does not give you compile-time error. But when you run it without main run-time error is obtained.

Last updated