java

八个技巧,提高Web前端性能

微笑、不失礼 提交于 2021-02-18 21:30:38
往期精选 ● 架构师高并发高性能分布式教程 (4000G) ● 39阶段精品云计算大数据实战视频教程 ● 互联网技术干货视频教程大全【菜单为准】 ● 2017年8月最新Intellij IDEA全套视频教程 ● 程序员如何制作高质量的简历【视频+简历】 ● 两套大型电商实战项目 ● 200本经典编程相关书籍下载 更多精彩查看历史记录......... 1. 优化 CSS 性能 CSS,即级联样式表,能从 HTML 描述的内容生成专业而又整洁的文件。很多 CSS 需要通过 HTTP 请求来引入(除非使用内联 CSS),所以你要努力去除累赘的 CSS 文件,但要注意保留其重要特征。 如果你的 Banner、插件和布局样式是使用 CSS 保存在不同的文件内,那么,访问者的浏览器每次访问都会加载很多文件。虽然现在 HTTP/2 的存在,减少了这种问题的发生,但是在外部资源加载的情况下,仍会花费较长时间。要了解如何减少 HTTP 请求以大幅度缩减加载时间,请阅读WordPress 性能。 此外,不少网站管理员在网页中错误的使用 @import 指令 来引入外部样式表。这是一个过时的方法,它会阻止浏览并行下载。link 标签才是最好的选择,它也能提高网站的前端性能。多说一句,通过 link 标签请求加载的外部样式表不会阻止并行下载。 2.减少外部HTTP请求 在很多情况下

Simulate color transparency

十年热恋 提交于 2021-02-18 21:30:32
问题 I have RGB color value and alpha value. How can I get new RGB value assuming that I have white backgound and alpha is applied? 回答1: The formula to be applied to each of the color channels is the following: cr = cf * af + cb * ab * (1 - af) where cr is the resulting color of the pixel, cf is the foreground color, cb the background color, af foreground alpha and ab background alpha. Note that often color values are stored already premultiplied by alpha in which case the formula simplifies to cr

Simulate color transparency

核能气质少年 提交于 2021-02-18 21:30:09
问题 I have RGB color value and alpha value. How can I get new RGB value assuming that I have white backgound and alpha is applied? 回答1: The formula to be applied to each of the color channels is the following: cr = cf * af + cb * ab * (1 - af) where cr is the resulting color of the pixel, cf is the foreground color, cb the background color, af foreground alpha and ab background alpha. Note that often color values are stored already premultiplied by alpha in which case the formula simplifies to cr

Testing WeakReference

帅比萌擦擦* 提交于 2021-02-18 21:29:32
问题 What is the proper approach to testing a weak reference in Java? My initial idea is to do the following: public class WeakReferenceTest { public class Target{ private String value; public Target(String value){ this.value = value; } public String toString(){ return value; } } public class UsesWeakReference{ WeakReference<Target> reference; public UsesWeakReference(Target test){ reference = new WeakReference<Target>(test); } public String call(){ Target test = reference.get(); if(test != null){

Testing WeakReference

隐身守侯 提交于 2021-02-18 21:29:06
问题 What is the proper approach to testing a weak reference in Java? My initial idea is to do the following: public class WeakReferenceTest { public class Target{ private String value; public Target(String value){ this.value = value; } public String toString(){ return value; } } public class UsesWeakReference{ WeakReference<Target> reference; public UsesWeakReference(Target test){ reference = new WeakReference<Target>(test); } public String call(){ Target test = reference.get(); if(test != null){

基于注解的IoC容器

最后都变了- 提交于 2021-02-18 21:21:52
BeanFactory SpringBean的创建是典型的工厂模式,这一系列的Bean工厂,即IoC容器为开发者管理了Bean之间的依赖关系。BeanFactory作为最顶层的一个接口类,定义了IoC容器的基本规范。 在BeanFactory里只对IoC容器的基本行为做了定义,不关心Bean是如何定义及怎样加载的。正如我们只关心能从工厂中获取到什么产品,不关心工厂是怎么生产这些产品的 public interface BeanFactory { //对FactoryBean的转义定义,如果使用Bean的名字检索FactoryBean得到的对象是工厂生成的对象,如果需要得到工厂本身,需要转义 String FACTORY_BEAN_PREFIX = "&"; //根据Bean的名字获取IoC中Bean的实例 Object getBean(String var1) throws BeansException; //根据Bean的名字和Class类型获取Bean的实例,增强了类型安全验证机制 <T> T getBean(String var1, Class<T> var2) throws BeansException; Object getBean(String var1, Object... var2) throws BeansException; <T> T getBean

Ant Junit tests are running much slower via ant than via IDE - what to look at?

岁酱吖の 提交于 2021-02-18 21:17:06
问题 I am running my junit tests via ant and they are running substantially slower than via the IDE. My ant call is: <junit fork="yes" forkmode="once" printsummary="off"> <classpath refid="test.classpath"/> <formatter type="brief" usefile="false"/> <batchtest todir="${test.results.dir}/xml"> <formatter type="xml"/> <fileset dir="src" includes="**/*Test.java" /> </batchtest> </junit> The same test that runs in near instantaneously in my IDE (0.067s) takes 4.632s when run through Ant. In the past, I

Files.move and Files.copy is throwing java.nio.file.FileAlreadyExistsException

妖精的绣舞 提交于 2021-02-18 21:13:10
问题 I want to delete one file and rename another file with the old file but I am not able to move this file as java is throwing java.nio.file.FileAlreadyExistsException Following is the code snippet I am using static void swapData(String origFilePath, String tempFilePath) throws IOException{ Path tempPath = FileSystems.getDefault().getPath(tempFilePath); Path origPath = FileSystems.getDefault().getPath(origFilePath); try{ String origFileName = null; File origFileRef = new File(origFilePath); if

Is the skip() method a short circuiting-operation?

可紊 提交于 2021-02-18 21:12:40
问题 I am reading about Java streams' short-circuiting operations and found in some articles that skip() is a short-circuiting operation. In another article they didn't mention skip() as a short-circuiting operation. Now I am confused; is skip() a short-circuiting operation or not? 回答1: From the java doc under the "Stream operations and pipelines" section : An intermediate operation is short-circuiting if, when presented with infinite input, it may produce a finite stream as a result . A terminal

Affect the order of NetworkInterface.getNetworkInterfaces enumeration in Java 6 on Linux

丶灬走出姿态 提交于 2021-02-18 21:11:44
问题 What is the order in which NetworkInterface.getNetworkInterfaces() returns an enumeration of network interfaces? Is there a way to affect that on JVM level or on Linux OS level? 回答1: According to the source of the OpenJDK (found in src/solaris/native/java/net/NetworkInterface.c, method enumInterfaces ) it will return IPv4 interfaces first (method enumIPv4Interfaces ), followed by IPv6 interfaces (method enumIPv6Interfaces ). The order within those categories seems to be the same that the OS