运行时和编译时的区别是什么?
当前回答
我们可以将其分为两大类静态绑定和动态绑定。它取决于何时与相应值绑定。如果引用是在编译时解析的,那么它是静态绑定;如果引用是在运行时解析的,那么它是动态绑定。静态绑定和动态绑定又称早期绑定和后期绑定。有时也称为静态多态和动态多态。
约瑟夫Kulandai。
其他回答
这里是对“运行时和编译时的区别?”这个问题的回答的扩展。运行时和编译时开销的差异?
产品的运行时性能通过更快地交付结果来提高其质量。产品的编译时性能通过缩短编辑-编译-调试周期来提高其时效性。然而,运行时性能和编译时性能都是实现及时性质量的次要因素。因此,只有当整体产品质量和时效性得到改善时,才应该考虑运行时和编译时性能的改进。
这里有一个很好的进一步阅读的来源:
将源代码转换为“屏幕|磁盘|网络”可以(大致)以两种方式发生;称之为编译和解释。
在编译程序中(例如c和fortran):
源代码被输入到另一个程序(通常称为编译器),该程序生成一个可执行程序(或一个错误)。 运行可执行文件(通过双击它,或在命令行上键入它的名称)
在第一步发生的事情被称为在“编译时”发生,在第二步发生的事情被称为在“运行时”发生。
在解释程序中(例如MicroSoft basic(在dos上)和python(我想)):
源代码被输入到另一个程序(通常称为解释器),该程序直接“运行”它。在这里,解释器充当程序和操作系统(或非常简单的计算机中的硬件)之间的中间层。
在这种情况下,编译时和运行时之间的差异很难确定,而且与程序员或用户的关系也小得多。
Java是一种混合,代码被编译成字节码,然后在虚拟机上运行,虚拟机通常是字节码的解释器。
还有一种中间情况,即程序被编译为字节码并立即运行(如在awk或perl中)。
Imagine that you are a boss and you have an assistant and a maid, and you give them a list of tasks to do, the assistant (compile time) will grab this list and make a checkup to see if the tasks are understandable and that you didn't write in any awkward language or syntax, so he understands that you want to assign someone for a Job so he assign him for you and he understand that you want some coffee, so his role is over and the maid (run time)starts to run those tasks so she goes to make you some coffee but in sudden she doesn’t find any coffee to make so she stops making it or she acts differently and make you some tea (when the program acts differently because he found an error).
例如:在强类型语言中,类型可以在编译时或运行时检查。在编译时,这意味着如果类型不兼容,编译器将报错。在运行时,意味着你可以很好地编译你的程序,但在运行时,它会抛出一个异常。
嗯,好吧,运行时是用来描述程序运行时发生的事情。
编译时间用来描述在构建程序(通常由编译器)时发生的事情。