JVM

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……
}

Next, the JVM runs everything between the curly braces {} of your main method. Every Java application has to have at least one Class, and at least one main method (not one main per class; just one main per application).

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

Advertisement

2 Comments »

  1. 1
    Binaryday Says:

    Hi,

    Great blog here. I shall like to discuss certain ideas regarding how to make this blog more popular. Let me know if you are interested.

    Thanks

  2. 2
    Naseer Says:

    hi
    i saw ur blog and looks interesting as u covered vast study area… well i want to suggest to answer the interview question in more professional manner…

    thanks


RSS Feed for this entry

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.