什么是Java中的.class文件和字节码?

This tutorial will help you to learn about what is .class file and bytecode in java language. You may like to read previous tutorial about How to Write, Compile and Run Your First Java Program?

What is .class File and Bytecode

  • When Java source file is compiled by Java compiler it is converted into Java class file with .class extension.
  • The Java class file contains Java bytecode (highly optimized set of instructions) which is executed by Java Virtual Machine (JVM).

  • .class file contains symbols and each bytecode instruction is stored into one byte exactly.
  • .class file of each class is separately stored. Its name is same as class name in source file. A Java program can have any number of classes. If below program is compiled then two .class file will be created with name A.class and B.class.

class A
{


public static void main(String…s)


{


System.out.println(“A”);


}


}





class B
{


public static void main(String…s)


{


System.out.println(“B”);


}


}

  • A .class file can be executed on any operating system; we just need JVM of that operating system. This makes Java machine independent.

Difference Between .class File in Java and .exe File in C/C++

.class
.exe
It contain bytecode instructions for Java Virtual Machine (JVM).
It contains machine code instructions for Operating System.
Platform independent.
Platform dependent.
It can be converted into source code.
It can’t be converted into source code.
The .class file can’t be executed directly so viruses can’t be attached
to it and hence secure.
The .exe file can be executed directly so viruses can be attached to
it and hence insecure.

翻译自: https://www.thecrazyprogrammer.com/2014/06/what-is-class-file-and-bytecode-in-java.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值