Programming at compile time or at run time

I read a lot of answers about the differences between compilation time and runtime in Java. But I still do not understand. Some answers said: compilation time is the period when you, the developer, compile your program or code. My question is when do I compile my program or code? For example: I open an IDE, eclipse or netbeans, write code in different classes and click the Run button, and my application opens. Can someone explain to me when I compiled my program / code in this example? or when I was at the compilation stage in this sample process?

+4
source share
3 answers

When you write any java class, the file extension must be .java . Take a 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 cmd, say the file saved in the d: \ test directory

d: \ test> javac Simple.java // When you run this, .java is converted to byte code and stored in a file .class.

d: \ test> java Simple // The JVM will execute the bytecode file, i.e. Simple.class

Note: this whole process is done using the internal IDE

+1
source

Do it. Open the notebook. Enter:

  class Sampl{
        public static void main(String []args){
              System.out.println("hi from run time");
        }
  }

Save it as Sampl.java

- c:\j\ ~/j/, linux

, JDK

cd c:\j\

Sampl.java

javac Sampl.java

2 : Sampl.java Sampl.class

Sampl.java Sampl.class ,

java -cp. SAMPL

, .java - .

javac - java-

java.exe - ,

[ jboss java jboss ]

google java tutorial command propmpt

+1

, , , , , , , Java, , - Java - Java JVM .

Java, - Java, Java-. , , , - ( , Java).

( IDE) , Java, javac Java. IDE , - , , , - , .

(. IDE i.e. Eclipse, .)

0

Source: https://habr.com/ru/post/1530759/


All Articles