空行会影响 Java 编译吗?

Hypermesh静力学仿真分析与模态分析-02 hypermesh中对较复杂实体进行静力学分析和模态分析,包含材料属性添加,载荷设置等等 阅读详情

简评:往往越简单的问题越容易被人们忽略。

问题

这个月的 Stack Overflow 有篇热门文章是国外有位开发者提出:
当我仅仅对 Java 类增加了一行空行,为什么编译后得到了两个不同的字节码文件?

现在有一个 Java 类

public class HelloWorld {
  public static void main(String []args) {
  }
}

先对这个类编译出来字节码 .class 文件进行 sha256 转译得到

9c8d09e27ea78319ddb85fcf4f8085aa7762b0ab36dc5ba5fd000dccb63960ff  HelloWorld.class

接着在同个 Java 类中增加空行

public class HelloWorld {

  public static void main(String []args) {
  }
}

再次对编译后的字节码文件做 sha256 转译得

11f7ad3ad03eb9e0bb7bfa3b97bbe0f17d31194d8d92cc683cfbd7852e2d189f  HelloWorld.class

天哪,它们竟然不一样,难道空行会影响代码的运行吗。

当然空行不会影响代码的运行,那为什么会编译出不一样的 .class 字节码文件呢。

分析

当我把这个问题抛给身边的程序猿朋友,
大家首先使用 base64 对文件转译同样得出了不一样的数据;
咦,不对,base64 会不会算入了文件的编译时间等文件信息;
好,测试 MD5 加密 .class 文件还是不一样的数据;
大家开始觉得是编译器出错了,按道理应该优化空行的。

看到这建议大家动手试一试,并思考下原因
···
···
···

答案

其实答案很简单,豁然开朗:

你觉得为什么报错时 Java 会抛出具体的报错行数信息,其实 Java 会去记录行数,以便 debug 调试。

往往越简单的问题越容易被人们忽略。

原文链接:Why does a Java class compile differently with a blank line?

YOLOv11改进 | 损失函数改进篇 | MPDIoU、InnerMPDIoU助力细节涨点(二次创新 + 代码解析) 本文为读者详细介绍了YOLOv11模型的最新改进,带来的改进机制是最新的损失函数MPDIoU和融合了最新的Inner思想的InnerMPDIoU(效果打爆之前的所有的损失函数提升检测精度和处理细节方面的作用。通过深入探讨MPDIoU和InnerMPDIoU(全网首发)的工作原理和实际代码实现,本文旨在指导读者如何将这些先进的损失函数技术应用到YOLOv11模型中,以提高其性能和准确性。文章内容涵盖从理论基础、代码实现,到实际教你如何添加本文的机制到你的模型中。 阅读详情

相关推荐

Android Geckoview实战:5分钟搞定JS与原生交互(附完整Demo代码)

本文详细介绍了在Android应用中使用GeckoView替代系统WebView,构建稳定高效的JavaScript与原生代码交互桥梁的实战方法。通过WebExtension架构,文章提供了从环境配置、扩展开发到Android端集成的完整步骤,并附有可运行的Demo代码,帮助开发者快速解决混合应用中的兼容性问题。

u5v6w7的博客 936

Java 中的空行和注释

在编写代码时,使用注释是一个好习惯,因为它们可以帮助其他开发者(或未来的你)理解代码的目的和功能。此外,一些自动化工具(如代码格式化器)可以根据预设的规则自动插入或删除空行,以确保代码符合特定的编码规范。它们通常用于解释一段较长的代码或暂时移除多行代码(尽管更好的做法是使用版本控制系统来管理代码的变更)。需要注意的是,虽然注释对于代码的可读性和可维护性非常重要,但过度使用注释也可能导致代码变得冗长和难以阅读。在Java编程中,注释是一种重要的工具,用于为代码添加说明、解释或临时性地移除某些代码行。

ad5889的博客 2524

GPU核心性能指标

内存科普 CPU缓存分为三类,一级缓存(L1)、二级缓存(L2)和三级缓存(L3)。CPU在实际数据读取中重要的却是一级缓存,因为一级缓存速度最快,二级缓存其次,三级缓存最慢,只是三级缓存的容量最大。 DDR1,DDR2,DDR3内存条(DDR是Double Data Rate双倍速率同步动态随机存储器的英文缩写)就是俗称的一二三代内存条。这三种内存条工艺不同,接口不同,性能不同,互不兼容。要区分它们,也不难。内存条可以用在CPU内存或者GPU显存中。比如 the NVIDIA Tesla M2050 GP

Charles Ren's Tech Blog 2万+

代码空行太多会影响jvm_Twitter将更多代码转移到JVM,并将性能和封装作为主要驱动力...

代码空行太多会影响jvm 尽管它几乎可以肯定仍然是世界上最大的基于Ruby on Rails的网站,但Twitter逐渐将越来越多的堆栈转移到JVM。 更改的部分原因是JVM经常提到的优点(例如性能和可伸缩性),但也受到对更好地封装单个服务的需求以及其他体系结构问题的驱动。 去年,该公司宣布已在Scala中重写了其后端消息队列和Tweet存储,并且在2010年Spring,Twitter的搜...

cunfu6353的博客 301

Qoder Quest 模式实战:从需求到代码的自动化开发

本文深入探讨Qoder Quest模式如何实现从需求到代码的自动化开发。通过编写清晰的Spec规格说明,Qoder能智能分解任务并在后台执行,生成高质量代码,大幅提升开发效率,让开发者专注于架构设计等创造性工作。

herb5的博客 1152

交叉编译Qt6.5.3(RK3568开发板)

注意,如果使用其它版本的交叉编译器的话,请确保你的交叉编译器能够支持 C++17标准。为确保后续交叉编译没问题,需要确保开发板使用的GLIBC版本不小于2.34版本。到 linaro 网站上下载交叉编译工具,我下载的是 gcc-linaro-11.3.1-2022.06-x86_64_aarch64-linux-gnu.tar.xz。安装 CMake ,最低要求3.16版本,如果要静态编译,需要3.21及以上版本。我使用的3.27版本。:指定为最后交叉编译后的Qt6.5.3库的安装目录。

m0_46309425的博客 5104

java 代码规范 空行_JAVA总结--代码规范

一、命名规范1、标识符:统一、达意、简洁统一:一个词有多种表达方式,不求最好,但求统一;例:供应商,既可以用supplier,也可以用provider,选择一种统一使用;达意:明确表达其意义,正确而且丰富;例:newSupplier与supplier1, service2的区别;简洁:在统一与达意的前提下,进行简洁;若不能达意,请放弃简洁;骆驼法则:不使用特殊符号分割,而是通过首字母大写来分割;例...

weixin_34355337的博客 2273

RK3568/RK3588 + YT 9215交换机芯片,MAC TO MAC 调试记录

原来的方案是rk3568 gmac 直接接phy,phy 接 switch 芯片,只是把交换芯片当交换用,驱动方面基本不用开发,但是要做vlan 那么必须涉及交换芯片的开发。选择裕太微有两个方面的原因:1.国产化替代2.可获得原厂技术支持3.目前已经完成 两个gmac 口交换芯片的配置,实现vlan,内部交换,两个光口可正常通信。

Nyiragongo的博客 1万+

java空行代码转义,代码千行bug率统计

最近测试项目bug比较多,领导要求做一个代码千行bug率统计,目前没想到好的自动化方法,只想到了在编译机器上用linux命令获取研发的代码行数进行统计:1.连文件的空行都进行统计的linux命令:find . -name ‘*.java‘|xargs wc -l|grep ‘total‘|awk ‘{print $1}‘find . -name ‘*.java‘|xargs cat|wc -l2....

weixin_39823676的博客 318

Uni-App 使用极光推送完整指南

Uni-App集成极光推送的完整指南:从注册极光账号到代码实现。包含前期准备(获取AppKey、注册厂商账号)、Uni-App配置(插件导入、初始化代码)、高级功能(角标设置、Java后台接口)及常见问题排查。详细说明了推送监听、registrationID获取、消息接收处理等核心功能实现步骤,并提供两种推送接口示例(按平台推送和统一推送)。适合需要在Uni-App项目中实现推送功能的开发者参考。

cyj0919的博客 428

CesiumJS【Basic】- #002 加载在线瓦片地图数据

cesiumjs 加载各类在线地图数据

AlanL的专栏 952

java空行会不会被编译器忽略_空行会影响 Java 编译吗?

简评:往往越简单的问题越容易被人们忽略。问题这个月的 Stack Overflow 有篇热门文章是国外有位开发者提出:当我仅仅对 Java 类增加了一行空行,为什么编译后得到了两个不同的字节码文件?现在有一个 Java 类public class HelloWorld {public static void main(String []args) {}}先对这个类编译出来字节码 .class 文件...

weixin_35034831的博客 116

DFIG风电场经LCC-HVDC外送系统SIMULINK建模与仿真

本文基于MATLAB/Simulink平台构建了DFIG风电场经LCC-HVDC外送系统的仿真模型。系统采用1000MW聚合DFIG模型与双极12脉动LCC-HVDC连接,详细阐述了参数设计、控制策略及接口协调方法。重点解决了风电场无功能力不足、功率波动影响换相等关键技术问题,为大规模风电基地外送提供了仿真研究框架。模型整合了官方DFIG和HVDC详细模块,通过参数缩放和控制系统优化,实现了完整系统的动态仿真分析。

huanghm88的专栏 120

java 判断空行_空行会影响 Java 编译吗?

简评:往往越简单的问题越容易被人们忽略。问题这个月的 Stack Overflow 有篇热门文章是国外有位开发者提出:当我仅仅对 Java 类增加了一行空行,为什么编译后得到了两个不同的字节码文件?现在有一个 Java 类public class HelloWorld {public static void main(String []args) {}}先对这个类编译出来字节码 .class 文件...

weixin_39725873的博客 303

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java中什么时候使用空行_空行会影响 Java 编译吗?

简评:往往越简单的问题越容易被人们忽略。问题这个月的 Stack Overflow 有篇热门文章是国外有位开发者提出:当我仅仅对 Java 类增加了一行空行,为什么编译后得到了两个不同的字节码文件?现在有一个 Java 类public class HelloWorld {public static void main(String []args) {}}先对这个类编译出来字节码 .class 文件...

weixin_42497299的博客 1080

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

java空行会不会被编译器忽略,空行会影响 Java 编译吗?

简评:往往越简单的问题越容易被人们忽略。问题这个月的 Stack Overflow 有篇热门文章是国外有位开发者提出: 当我仅仅对 Java 类增加了一行空行,为什么编译后得到了两个不同的字节码文件?现在有一个 Java 类public class HelloWorld {public static void main(String []args) {}}先对这个类编译出来字节码 .class 文...

weixin_32512261的博客 240

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

java里class有什么用_为什么给Java代码加个空行,class文件就翻脸不认人了?

原创:小姐姐味道(微信公众号ID:xjjdog),欢迎分享,转载请保留出处。public class HelloWorld { public static void main(String[] args) {System.out.println("love xjjdog");}}为了写出这几行优美的代码,主要是为了让它输出优美动听的乐符,我下了一番功夫。你不...

weixin_39860919的博客 118
上一篇: 如何在Cordova Android 7.0.0 以下版本集成最新插件 极光插件为例
下一篇: AWS 推出长期支持的 OpenJDK 免费分发版本 —— Amazon Corretto
极光推送
博客等级 码龄14年 109粉丝 108原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值