博文

目前显示的是标签为“java”的博文

Spring bean config XML, Java config and more

1. XML-based metadata This is typical bean definition written in XML:     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">         <property name="dataSource" ref="dataSource"/>     </bean>    <jee:jndi-lookup id="dataSource" jndi-name="java:databaseName"/> Or     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">         <property name="dataSource" ref="dataSource"/>     </bean>     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">         <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>         <property name="url" value="jdbc:jtds:sqlserver://host_name/database_name;schema=dbo"/>         <property name="username" value="dummy"/...

Install Oracle Java 7 on Ubuntu 12.04

This tested to be working: http://www.liberiangeek.net/2012/04/install-oracle-java-jdk-7-in-ubuntu-12-04-precise-pangolin/

常用 JVM parameters

Read more:  http://javarevisited.blogspot.dk/2011/11/hotspot-jvm-options-java-examples.html

Image processing with IM4java

记得以前做图片相关需求的时候,使用的是Jmagick+ImageMagick,一直有一个难以解决的问题,就是使用Jmagick之后,往往运行数天后就会导致jboss的jvm崩溃掉。 这几天发现了一个新东西,或能解决这个老问题,记录一下,留备后用,那就是ImageMagick的另外一种java接口:IM4java。 IM4Java和Jmagick不同之处,在于前者不是通过JNI的方式来调用ImageMagick,而是生成命令来调用,据官网上说的,这样做有几个好处, Advantages of im4java: the interface of the IM commandline is quite stable, so your java program (and the im4java-library) will work across many versions of IM. im4java also provides a better OO interface (the "language" of the IM-commandline with it's postfix-operation notation translates very easily into OO-notation). And most important: you can use im4java everywhere JMagick can't be used because of the JNI hazard (e.g. java application servers). im4java的优点:im命令行接口相当稳定,可以适应多种版本的IM,它还提供了友好的OO接口,最重要的是,它不存在“JNI风险” about  JNI hazard Running native code using JNI from within java always imposes additional risks. The JVM is no longer sandboxed, so there might be some security issues. In addition, there could be errors like mem...

Java中的Dynamic Proxy 动态代理

图片
Dynamic Proxy是这样一种class:它是在运行时生成的class,在生成它时你必须提供一组interface给它,然后该class就宣称它实现了这些 interface。你当然可以把该class的实例当作这些interface中的任何一个来用。当然啦,这个Dynamic Proxy其实就是一个Proxy,它不会替你作实质性的工作,在生成它的实例时你必须提供一个handler,由它接管实际的工作     。  动态代理的定义: 一个动态代理类在运行期implements一组interface,使得interface实现类的方法调用被分派至其他的类(另外的interface实现类或者任意的类)的方法 。 讲得更通俗一些,要了解动态代理,我们就要知道什么东西动态了,代理了什么?首先,一个Proxy代理了一组interface的方法。注意, 代理的是interface ,而不是Class,也不是abstract Class;其次, Proxy具有的型别由绑定的interface所决定的 ,动态就体现在此。 public   interface  Resource  {      public   void  operationA();      public   void  operationB(); }                                                  public   class  Concret...

Accessing Jython from Java Without Using jythonc

You may or may not know that it is possible to access Jython code from Java without compiling it using the jythonc utility. This technique is possible using a mixture of Java interfaces and usage of the  PythonInterpreter . As a matter of fact, I believe that using this technique correctly is more effective than using jythonc. To put it simply, to use this technique you must create a "factory" method which uses the  PythonInterpreter  class to interpret a .py module for use within Java code. Any Java code that uses the Jython code should be coded against an interface which is implemented by the Jython code. In order to provide a fully functional example, I've created a simple application with hard-coded data. This application shows the potential for using this technique within your Java applications to have the ability for use of dynamic Jython objects. The application is simply called "jyinterface" and it contains four pieces of code: -Main.java - Jyt...

Stateful Session Bean Example

In this part of Enterprise Session Beans, you will learn how to develop, deploy, and run a simple Java EE application named account using stateful session bean. The purpose of account is to performs two transaction operations (deposit and withdraw) for the customer. The account application consists of an enterprise bean, which performs the transactions, and two types of clients: an application client and a web client . here are following steps that you have to follow to develop a account JEE application . Create the enterprise bean: AccountBean Create the application client: AccountCustomer Deploy account onto the server. Run the application client. I. Creating the enterprise bean: The enterprise bean in our example is a statelful session bean called AccountBean. The account session bean represents an account information in an online customer account. The bean’s customer can deposit to or withdraw the amount from his account. To manage account, you...

Stateless Session Bean Example

图片
In this part of Enterprise Session Beans, you will learn how to develop, deploy, and run a simple Java EE application named example using stateless session bean. The purpose of example is to performs the mathematical operations such as Addition, Subtraction, Multiplication, and Division. The example application consists of an enterprise bean, which performs the calculations, and two types of clients: an application client and a web client . There are following steps that you have to follow to develop a example JEE application Create the enterprise bean: CalculatorBean Create the web client: WebClient Deploy example onto the server. Using a browser, run the web client. I. Creating the enterprise bean: The enterprise bean in our example is a stateless session bean called CalculatorBean . The source code for CalculatorBean is in “net/roseindia/ejb3/stateless” directory. Creating CalculatorBean requires these steps: (i) Coding the bean’s...

EJB - Intro to Session beans

图片
What is a Session bean A session bean is the enterprise bean that directly interact with the user and contains the business logic of the enterprise application . A session bean represents a single client accessing the enterprise application deployed on the server by invoking its method. An application may contain multiple sessions depending upon the number of users accessing to the application. A session bean makes an interactive session only for a single client and shields that client from complexities just by executing the business task on server side. For example, whenever a client wants to perform any of these actions such as making a reservation or validating a credit card, a session bean should be used. The session bean decides what data is to be modified. Typically, the session bean uses an entity bean to access or modify data. They implement business logic, business rules, algorithms, and work flows. Session beans are relatively short-lived components. The EJB container may...