Java
文章平均质量分 72
caoguanling
Coding for living and fun.
展开
-
深入探讨 Java 类加载器
类加载器(class loader)是 Java™中的一个很重要的概念。类加载器负责加载 Java 类的字节代码到 Java 虚拟机中。本文首先详细介绍了 Java 类加载器的基本概念,包括代理模式、加载类的具体过程和线程上下文类加载器等,接着介绍如何开发自己的类加载器,最后介绍了类加载器在 Web 容器和 OSGi™中的应用。类加载器是 Java 语言的一个创新,也是 Java转载 2013-10-07 19:22:49 · 675 阅读 · 0 评论 -
EJB invocations from a remote client using JNDI
This chapter explains how to invoke EJBs from a remote client by using the JNDI API to first lookup the bean proxy and then invoke on that proxy.After you have read this article, do re转载 2013-10-02 23:02:33 · 1227 阅读 · 0 评论 -
Java heap terminology: young, old and permanent generations
This seems like a common misunderstanding. In Oracle's JVM, the permanent generation is not part of the heap. It's a separate space for class definitions and related data. In Java 6 and earlier, inter转载 2013-10-09 17:57:10 · 1349 阅读 · 0 评论 -
The difference between NoClassDefFoundError and ClassNotFoundException
The difference from the Java API Specifications is as follows.For ClassNotFoundException:Thrown when an application tries to load in a class through its string name using:The forName m转载 2013-10-10 19:01:14 · 708 阅读 · 0 评论 -
EJB 3 Introduction
EJB 3 IntroductionAn EJB platform is for building portable, reusable and scalable business applications using the Java programming language. EJB is a component or framework that lets you build ent转载 2013-10-10 19:41:35 · 732 阅读 · 0 评论 -
ByteBuffer.allocate() vs. ByteBuffer.allocateDirect()
Ron Hitches in his excellent book Java NIO seems to offer what I thought could be a good answer to this question:Operating systems perform I/O operations on memory areas. These memory areas, a转载 2013-10-12 17:29:59 · 871 阅读 · 0 评论 -
Java单例模式在多线程环境中的实现
在Java开发中,如果某个实例的创建需要消耗很多系统资源,那么我们通常会使用惰性加载机制,也就是说只有当使用到这个实例的时候才会创建这个实例,这个好处在单例模式中得到了广泛应用。该机制在single-threaded(单线程)环境下的实现非常简单,然而在multi-threaded(多线程)环境下却存在隐患。本文重点介绍惰性加载机制以及其在多线程环境下的使用方法。(作者numberzero,参考I转载 2013-10-20 16:16:11 · 702 阅读 · 0 评论 -
Java NIO(12-Pipe)
A Java NIO Pipe is a one-way data connection between two threads. A Pipe has a source channel and a sink channel. You write data to the sink channel. This data can then be read from the source channel转载 2013-10-27 19:12:29 · 594 阅读 · 0 评论 -
Java NIO(13-NIO vs. IO)
When studying both the Java NIO and IO API's, a question quickly pops into mind:When should I use IO and when should I use NIO?In this text I will try to shed some light on the differences bet转载 2013-10-27 19:13:35 · 640 阅读 · 0 评论 -
Java NIO(4-Buffer)
Java NIO Buffers are used when interacting with NIO Channels. As you know, data is read from channels into buffers, and written from buffers into channels.A buffer is essentially a block of memory转载 2013-10-27 19:03:04 · 538 阅读 · 0 评论 -
Java NIO(6-Channel to Channel Transfers)
In Java NIO you can transfer data directly from one channel to another, if one of the channels is a FileChannel. TheFileChannel class has a transferTo() and a transferFrom() method which does this f转载 2013-10-27 19:06:13 · 469 阅读 · 0 评论 -
Java NIO(10-ServerSocketChannel)
A Java NIO ServerSocketChannel is a channel that can listen for incoming TCP connections, just like a ServerSocketin standard Java IO. The ServerSocketChannel class is located in the java.nio.channe转载 2013-10-27 19:10:52 · 490 阅读 · 0 评论 -
Java NIO(11-DatagramChannel)
A Java NIO DatagramChannel is a channel that can send and receive UDP packets. Since UDP is a connection-less network protocol, you cannot just by default read and write to a DatagramChannel like you转载 2013-10-27 19:11:39 · 438 阅读 · 0 评论 -
Java NIO(1-Introduction)
Java NIO (New IO) is an alternative IO API for Java (from Java 1.4), meaning alternative to the standard Java IO API's. Java NIO offers a different way of working with IO than the standard IO API's.转载 2013-10-27 18:57:27 · 612 阅读 · 0 评论 -
Java NIO(2-Overview)
Java NIO consist of the following core components:ChannelsBuffersSelectorsJava NIO has more classes and components than these, but the Channel, Buffer and Selector forms the core of the API,转载 2013-10-27 18:59:46 · 517 阅读 · 0 评论 -
Java NIO(5-Scatter / Gather)
Java NIO comes with built-in scatter / gather support. Scatter / gather are concepts used in reading from, and writing to channels.A scattering read from a channel is a read operation that reads d转载 2013-10-27 19:04:58 · 513 阅读 · 0 评论 -
Java NIO(8-FileChannel)
A Java NIO FileChannel is a channel that is connected to a file. Using a file channel you can read data from a file, and write data to a file.A FileChannel cannot be set into non-blocking mode. It转载 2013-10-27 19:09:03 · 494 阅读 · 0 评论 -
Java NIO(3-Channel)
Java NIO Channels are similar to streams with a few differences:You can both read and write to a Channels. Streams are typically one-way (read or write).Channels can be read and written asynchrono转载 2013-10-27 19:00:56 · 485 阅读 · 0 评论 -
Java NIO(7-Selector)
A Selector is a Java NIO component which can examine one or more NIO Channel's, and determine which channels are ready for e.g. reading or writing. This way a single thread can manage multiple channel转载 2013-10-27 19:08:01 · 499 阅读 · 0 评论 -
Java NIO(9-Socket Channel)
A Java NIO SocketChannel is a channel that is connected to a TCP network socket. There are two ways aSocketChannel can be created:You open a SocketChannel and connect to a server somewhere on the转载 2013-10-27 19:10:01 · 517 阅读 · 0 评论 -
Package java.util.concurrent
Package java.util.concurrentUtility classes commonly useful in concurrent programming.See: DescriptionInterface Summary InterfaceDescriptionBlockingDeque转载 2013-11-21 17:03:18 · 887 阅读 · 0 评论 -
面向对象的5个基本设计原则
面向对象的3个基本要素:封装、继承、多态面向对象的5个基本设计原则:单一职责原则(Single-Resposibility Principle) 其核心思想为:一个类,最好只做一件事,只有一个引起它的变化。单一职责原则可以看做是低耦合、高内聚在面向对象原则上的引申,将职责定义为引起变化的原因,以提高内聚性来减少引起变化的原因。职责过多,可能引起它变化的原因就越多,这将转载 2013-11-22 17:57:51 · 438 阅读 · 0 评论 -
HTTP Session工作原理的简单介绍
HTTP协议(http://www.w3.org/Protocols/)是“一次性单向”协议。 服务端不能主动连接客户端,只能被动等待并答复客户端请求。客户端连接服务端,发出一个HTTP Request,服务端处理请求,并且返回一个HTTP Response给客户端,本次HTTP Request-Response Cycle结束。 我们看到,HTTP协议本身并不能支持服务端保存客户端的状态转载 2013-11-13 21:56:37 · 872 阅读 · 0 评论 -
深入Java内存区域与OOM
概述:对于从事C、C++程序开发的开发人员来说,在内存管理领域,他们即是拥有最高权力的皇帝又是执行最基础工作的劳动人民——拥有每一个对象的“所有权”,又担负着每一个对象生命开始到终结的维护责任。 对于Java程序员来说,不需要在为每一个new操作去写配对的delete/free,不容易出现内容泄漏和内存溢出错误,看起来由JVM管理内存一切都很美好。不过,也正是因为Java程转载 2013-12-04 12:49:41 · 486 阅读 · 0 评论 -
关于Java 对象序列化您不知道的 5 件事
序列化的数据是安全的?不见得吧。Java 对象序列化(Java Object Serialization)在 Java 编程中是如此基本,以致很容易让人想当然。但是,和 Java 平台的很多方面一样,只要肯深入挖掘,序列化总能给予回报。在这个新系列的第一篇文章中,Ted Neward 给出 5 个需重新审视 Java 对象序列化的理由,并提供重构、加密和验证序列化数据的技巧(和转载 2013-12-04 15:46:49 · 606 阅读 · 0 评论 -
Java序列化的高级认识
如果你只知道实现 Serializable 接口的对象,可以序列化为本地文件。那你最好再阅读该篇文章,文章对序列化进行了更深一步的讨论,用实际的例子代码讲述了序列化的高级认识,包括父类序列化的问题、静态变量问题、transient 关键字的影响、序列化 ID 问题。在笔者实际开发过程中,就多次遇到序列化的问题,在该文章中也会与读者分享。 评论:杨 硕, 研究生, 东北大转载 2013-12-04 12:43:52 · 542 阅读 · 0 评论 -
A good example of equals()
@Override public boolean equals(Object object) { if (!(object instanceof ToDo)) { return false; } ToDo other = (ToDo) object; if ((this.id == n转载 2014-03-01 15:57:00 · 409 阅读 · 0 评论 -
深入理解OutOfMemoryError
当堆栈跟踪信息里面出现OutOfMemoryError的时候,你应该很清楚发生了什么。应用程序由于没有足够的内存空间所以挂了。一般知道这个就也够了,但是对于构建和维护应用程序的人来说,要想弄清楚具体为什么报错的话,这里倒可以再多分享一点经验。在这篇文章里面,我们主要介绍一下不同的OutOfMemoryError具体是什么含义。我们先从最简单的例子开始,后面会有一些更有意思的话题。转载 2014-03-13 18:25:58 · 511 阅读 · 0 评论 -
JPA 2 | Dynamic Queries Vs Named Queries
JPA has its own Query language called JPQL. JPQL is very similar to SQL, with one major difference being that JPQL works with entities as defined in the application whereas SQL works with table and转载 2014-03-13 17:24:05 · 656 阅读 · 0 评论 -
Understanding Java Garbage Collection
What are the benefits of knowing how garbage collection (GC) works in Java? Satisfying the intellectual curiosity as a software engineer would be a valid cause, but also, understanding how GC works转载 2014-03-27 20:33:50 · 595 阅读 · 0 评论 -
volatile关键字介绍
Java同步机制可以有以下实现方式① ThreadLocal ② synchronized( ) ③ wait() 与 notify() ④ volatile 目的:都是为了解决多线程中的对同一变量的访问冲突 ThreadLocal ThreadLocal 保证不同线程拥有不同实例,相同线程一定拥有相同的实例,即为每一个使用该变量的线程提供一个该变量值转载 2014-03-30 11:31:09 · 442 阅读 · 0 评论 -
关于 Java Database Connectivity 您不知道的 5 件事
目前,许多开发人员把 Java Database Connectivity (JDBC) API 当作一种数据访问平台,比如 Hibernate 或 SpringMany。然而 JDBC 在数据库连接中不仅仅充当后台角色。对于 JDBC,您了解的越多,您的 RDBMS 交互效率就越高。在本期 5 件事 系列 中,我将向您介绍几种 JDBC 2.0 到 JDBC 4.0 中新引入的功能。转载 2014-03-18 18:13:34 · 525 阅读 · 0 评论 -
关于java.util.concurrent 您不知道的 5 件事 第 1 部分
Concurrent Collections 是 Java™ 5 的巨大附加产品,但是在关于注释和泛型的争执中很多 Java 开发人员忽视了它们。此外(或者更老实地说),许多开发人员避免使用这个数据包,因为他们认为它一定很复杂,就像它所要解决的问题一样。事实上,java.util.concurrent 包含许多类,能够有效解决普通的并发问题,无需复杂工序。阅读本文,了解 java.util转载 2014-03-19 15:17:02 · 483 阅读 · 0 评论 -
关于多线程编程您不知道的 5 件事
虽然很少有 Java™ 开发人员能够忽视多线程编程和支持它的 Java 平台库,更少有人有时间深入研究线程。相反地,我们临时学习线程,在需要时向我们的工具箱添加新的技巧和技术。以这种方式构建和运行适当的应用程序是可行的,但是您可以做的不止这些。理解 Java 编译器的线程处理特性和 JVM 将有助于您编写更高效、性能更好的 Java 代码。在这期的 5 件事 系列 中,我将通过同步方法转载 2014-03-18 17:30:50 · 382 阅读 · 0 评论 -
关于 Java Scripting API 您不知道的 5 件事
现在,许多 Java 开发人员都喜欢在 Java 平台中使用脚本语言,但是使用编译到 Java 字节码中的动态语言有时是不可行的。在某些情况中,直接编写一个 Java 应用程序的脚本 部分 或者在一个脚本中调用特定的 Java 对象是更快捷、更高效的方法。这就是 javax.script 产生的原因了。Java Scripting API 是从 Java 6 开始引入的,它填补了便捷的转载 2014-03-19 11:23:31 · 778 阅读 · 0 评论 -
关于 JVM 命令行标志您不知道的 5 件事
VM 是多数开发人员视为理所当然的 Java 功能和性能背后的重负荷机器。然而,我们很少有人能理解 JVM 是如何进行工作的 — 像任务分配和垃圾收集、转动线程、打开和关闭文件、中断和/或 JIT 编译 Java 字节码,等等。不熟悉 JVM 将不仅会影响应用程序性能,而且当 JVM 出问题时,尝试修复也会很困难。本期 5 件事 系列 将介绍一些命令行标志,您可以使用它们来诊断转载 2014-03-18 17:53:07 · 473 阅读 · 0 评论 -
关于 Java 性能监控您不知道的 5 件事
全功能内置分析器,如 JConsole 和 VisualVM 的成本有时比它们的性能费用还要高 — 尤其是在生产软件上运行的系统中。因此,在聚焦 Java 性能监控的第 2 篇文章中,我将介绍 5 个命令行分析工具,使开发人员仅关注运行的 Java 进程的一个方面。JDK 包括很多命令行实用程序,可以用于监控和管理 Java 应用程序性能。虽然大多数这类应用程序都被标注为 “实验型”,在技转载 2014-03-19 14:06:30 · 739 阅读 · 0 评论 -
关于 java.util.concurrent 您不知道的 5 件事,第 2 部分
并发 Collections 提供了线程安全、经过良好调优的数据结构,简化了并发编程。然而,在一些情形下,开发人员需要更进一步,思考如何调节和/或限制线程执行。由于 java.util.concurrent 的总体目标是简化多线程编程,您可能希望该包包含同步实用程序,而它确实包含。本文是 第 1 部分 的延续,将介绍几个比核心语言原语(监视器)更高级的同步结构,但它们还未包含在 Col转载 2014-03-19 17:38:21 · 347 阅读 · 0 评论 -
关于 Java Collections API 您不知道的 5 件事,第 1 部分
对于很多 Java 开发人员来说,Java Collections API 是标准 Java 数组及其所有缺点的一个非常需要的替代品。将 Collections 主要与 ArrayList 联系到一起本身没有错,但是对于那些有探索精神的人来说,这只是 Collections 的冰山一角。关于本系列您觉得自己懂 Java 编程?事实上,大多数程序员对于 Java 平台都是浅尝转载 2014-03-19 18:17:09 · 623 阅读 · 0 评论 -
The Principles of Java Application Performance Tuning
This is the fifth article in the series of "Become a Java GC Expert". In the first issue Understanding Java Garbage Collection we have learned about the processes for different GC algorithms, about转载 2014-03-31 17:33:48 · 634 阅读 · 0 评论