Java Program without main () Function

This blog based on Java Program, without main (). Java is class based object oriented programming Language.


  1. class Math  
  2. {  
  3.     Static //main() is not use this program  
  4.    {  
  5.         int a, b, c;  
  6.        a=12;  
  7.        b=5;  
  8.        c=a+b;  
  9.       if(c==a+b)  
  10.      {  
  11.          System.out.println("a+b\t" +c );  
  12.          c=a-b;  
  13.         if(c==a-b)  
  14.        {  
  15.            System.out.println("a-b\t" +c);  
  16.            c=a*b;  
  17.           if(c==a*b)  
  18.          {  
  19.              System.out.println("a*b\t" +c);  
  20.             c=a/b;  
  21.            if(c==a/b)  
  22.           {  
  23.               System.out.println("a/b\t" +c);  
  24.           }  
  25.          else  
  26.          {  
  27.              System.out.println("No result");  
  28.         }  

Create this program in notepad and open CMD and got to location where your program have save as like suppose desktop then type cd desktop then you see CMD

Then my program file save in new folder as like java prog so then I command use cd java prog then seen CMD

Then seen output use command for compile java program.


When compile program then automatically generate class file go to java prog folder or own location where you save program.

It is compile successfully no any error.

After that run the java program use command java and class name …as like this.

Java math

Seen CMD for output.

Finally no any error compiles and run time … only exception at after rum and output but before not any exception…
Ebook Download
View all
View all