Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming at compile time or at runtime

I have been reading many answers about the different between the compile time and the runtime in Java. But I am still not clear. Some answers said: the compile time is the period when you, the developer, are compiling your program or code. My question is when do I compile my program or code? For example: I open my IDE, eclipse or netbeans, write code in different classes and click on Run button and my application opens. Can someone explain me when did I compile my program/code in this sample process? or when was I in the compile time stage in this sample process?

like image 774
O Connor Avatar asked Oct 21 '22 12:10

O Connor


1 Answers

When you write any java class,extension of file must be .java. Let take simple java class to print Hello World :

public class Simple {

    public static void main(String[] args) {
        System.out.println("Hello World !!");
    }

}

So save this file as Simple.java.

Now open the cmd,lets say file saved in d:\test directory

d:\test>javac Simple.java // When you run this the .java is converted into byte code and it is saved in .class file.

d:\test>java Simple // JVM will execute the byte code file i.e. Simple.class

Note : All this process is done by IDE internally

like image 135
Kick Avatar answered Oct 23 '22 01:10

Kick