When the JVM (Java Virtual Machine) starts running, it looks for the class you give it the command line. Then its starts looking for a specially-written method that looks exactly like:
public static void main(String args[])
{
//your code……
}

In Java, everything goes in a class. You’ll type your source code file (with a .java extension), then compile it into a new class file (with a .class extension). When your run your program, you’re really running a class.
Running a program means telling the Java Virtual Machine (JVM) to “Load the 9lessons class, then start executing its main() method. Keep running till all the code in main is finished.
The main() method is where your program starts running.
9lessons.java:
public class 9lessons
{
public static void main(String[] args)
{
System.out.println(“Programming Blog”);
}
}
step 1: javac 9lessons.java
step 2: java 9lessons
The Big Difference Between public class and Default class
9lessons.java:
public class program
{
public static void main(String[] args)
{
System.out.println(“Programming Blog”);
}
}
Above program file name is (9lessons.java) and public class name (program) is different
Error : Class program is public, should be declared in a file named program.java
So public class means file name and class name must be same..
Here Default Class(no public)
9lessons.java:
class program
{
public static void main(String[] args)
{
System.out.println(“Programming Blog”);
}
}
After compiling 9lesson.java creates program.class
In the Default class no need to give file name and class name same..
step 1: javac 9lessons.java
step 2: java program




