Effective Java 54 Use native methods judiciously
Java Native Interface(JNI) allows Java applications to call native methods, which are special methods written in native programming languages such as C or C++.
Historical usages of native methods
- Access to platform-specific facilities such as registries and file locks.
- Access to libraries of legacy code.
- Access to native methods written for performance-critical part of application.
Disadvantage of native methods
- Native language are not safe (Item 39), native methods are no longer immune to memory corruption errors.
- Since native languages are platform dependent, application use them are far less possible.
- Difficult to debug.
- Fixed cost associated with going into and out of native code.
- It requires "glue code" that is difficult to read and tedious to write.
Summary
Think twice before using native methods. Rarely, if ever, use them for improved performance. If you must use native methods to access low-level resources or legacy libraries, use as little native code as possible and test it thoroughly. A single bug in the native code can corrupt your entire application.
Effective Java 54 Use native methods judiciously的更多相关文章
- Effective Java 27 Favor generic methods
Static utility methods are particularly good candidates for generification. The type parameter list, ...
- Effective Java 76 Write readObject methods defensively
Principle readObject method is effectively another public constructor, and it demands all of the sam ...
- Effective Java 71 Use lazy initialization judiciously
Lazy initialization - It decreases the cost of initializing a class or creating an instance, at the ...
- Effective Java Index
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st langu ...
- 《Effective Java》读书笔记 - 8.通用编程
Chapter 8 General Programming Item 45: Minimize the scope of local variables local variables应该在他们要被用 ...
- Effective Java 目录
<Effective Java>目录摘抄. 我知道这看起来很糟糕.当下,自己缺少实际操作,只能暂时摘抄下目录.随着,实践的增多,慢慢填充更多的示例. Chapter 2 Creating ...
- 【Effective Java】阅读
Java写了很多年,很惭愧,直到最近才读了这本经典之作<Effective Java>,按自己的理解总结下,有些可能还不够深刻 一.Creating and Destroying Obje ...
- [Effective Java]第八章 通用程序设计
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- Effective Java通俗理解(下)
Effective Java通俗理解(上) 第31条:用实例域代替序数 枚举类型有一个ordinal方法,它范围该常量的序数从0开始,不建议使用这个方法,因为这不能很好地对枚举进行维护,正确应该是利用 ...
随机推荐
- Android上的事件流操作数据库
最近在浏览某篇有关事件流的文章时,里面提到了数据的流处理,兴趣来了,就想看看能否在Android端实现一个. 根据文章的介绍,将每次数据的变更事件,像是插入,删除或者更新等,记为一个不可变的事件,让数 ...
- WCF回顾一、基本概念和应用场景
一.WCF描述 wcf是一款基于面向服务的架构的通讯框架平台,在分布式框架中得到了广泛使用. wcf入门非常简单,只要花几分钟就能编写一个完整的wcf程序,而实际上WCF是概念非常多的一门技术,需要花 ...
- tips null和undefined的区别
tips null和undefined的区别 1.undefined类型 undefined类型只有一个值,即特殊的undefined.在使用var声明变量但未对其加以初始化时,这个变量的值就是und ...
- 转载:第二弹!全球首个微信小程序(应用号)开发教程!通宵吐血赶稿!每日更新!
今天一波三折,承受了超出预料的压力和煎熬,最后还是决定继续放出我的更新教程.我想我一没有泄露公司的代码,二没有提供泄露开发工具下载,只是从程序猿角度写了篇开发日志.我已经做好了最坏的准备,就算放弃这份 ...
- SQL实现分组查询取前几条记录
我要实现的功能是统计订单日志表中每一个订单的前三条日志记录,表结构如下: 一个订单在定点杆日志表中有多条记录,要根据时间查询出每一个订单的前三条日志记录,sql如下: select b.OrderNu ...
- ok6410 android driver(4)
Install busybox for goldfish/phone 1. Download busybox source code http://www.busybox.net/ 2. Decomp ...
- .Net 配置文件——继承ConfigurationSection实现自定义处理类处理自定义配置节点
除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...
- js实现向上滚动效果
源码: <style type="text/css"> #up_zzjs{border:1px solid #ccc;width:170px;height:182px; ...
- Windows程序控件升级==>>构建布局良好的Windows程序
01.菜单栏(MenuStrip) 01.看看这就是menuStrip的魅力: 02.除了一些常用的属性(name.text..)外还有: 03.有人会问:上图的快捷键: 方法: 方式一:1.设置菜单 ...
- 简单封装cookie操作
1 //设置cookie 2 function setCookie(name, value, day) { 3 var oDate = new Date(); 4 oDate.setDate(oDat ...