10 Things to Do After Installing Ubuntu 12.04

June 10, 2012 1 comment

1/ Install cinnanmon 1.4

Open terminal ( Ctrl + Alt + t )

$ sudo add-apt-repository ppa:gwendal-lebihan-dev/cinnamon-stable
$ sudo apt-get update
$ sudo apt-get install cinnamon

- restart

2/ Install ibus-unikey for type vietnamese

$ sudo apt-get install ibus-unikey
$ im-switch -s ibus

- Logout then login.

- Applications / System Tools / System Settings / Language Support /Keyboard input method system: Ibus

- Application / System Tools / Preferences / Keyboard Input Method

++ General: checked all checkbox

++ Input method: Add Vietnamese – Unikey.

Use Ctrl + space for active / deactive

3/ Install Meld Diff Viewer from Ubuntu Software Centre

Compare and Meld your files.

4/ Install Synaptic Package Manager from Ubuntu Software Centre

5/ Install ant, maven end jdk 1.6.23


$ sudo apt-get install ant1.7

$ sudo apt-get install maven2

Categories: Ubuntu Tags:

EJB – Enterprise Java Bean

Benefits of Enterprise Beans

For several reasons, enterprise beans simplify the development of large, distributed applications. First, because the EJB container provides system-level services to enterprise beans, the bean developer can concentrate on solving business problems. The EJB container–and not the bean developer–is responsible for system-level services such as transaction management and security authorization.

Second, because the beans–and not the clients–contain the application’s business logic, the client developer can focus on the presentation of the client. The client developer does not have to code the routines that implement business rules or access databases. As a result, the clients are thinner, a benefit that is particularly important for clients that run on small devices.

Third, because enterprise beans are portable components, the application assembler can build new applications from existing beans. These applications can run on any compliant J2EE server provided that they use the standard APIs.

 Types of Enterprise Beans

+ Session Bean ( Stateless, Stateful): Performs a task for a client; implements a web service

+ Entity Bean: Represents a business entity object that exists in persistent storage

+ Message-Driven Bean: Acts as a listener for the Java Message Service API, processing messages asynchronously

What Is an Entity Bean?

An entity bean represents a business object in a persistent storage mechanism

+ Persistence

+ Shared Access

+ Primary Key

+ Relationships

Categories: EJB Tags:

review JSP/Servlet

March 29, 2012 Leave a comment

<%@ page language=”java” import=”java.util.*”  %>

<%

out.println(“Hello World.”);

String username = (String)session.getAttribute(“username”);

session.setAttribute(“username”, Object);

session.removeAttribute(“username”);

String user = (String)application.getAttribute(“username”);

ServletContext application = getServletContext();

application.setAtribute(“username”, Object);

application.removeAttribute(“username”);

String value = request.getParameter(“value”);

String[] value = request.getParameterValue(“names”);

//GET, POST

request.getMethod();

%>

<%@include file=”common.jsp” %>

<jsp:include page=”header.jsp” flush=”true” />

<jsp:include page=”testParam,jsp” flush=”true”>

<jsp:param name=”greeting” value=”Hello World” />

<jsp:include>

<jsp:forward page=”pageThree.jsp” />

<% response.sendRedirect(“hello.jsp?username=abc”); %>

// trong file Servlet

HttpSession session = request.getSession(false);     // không yêu cầu tạo mớ

Categories: serlvet Tags: ,

Java Object Ordering

January 12, 2012 Leave a comment
Categories: Java Tags:

Java Comparator

January 12, 2012 Leave a comment

class Employee{
private int age;
private String name;

// get, set age, name
}


class AgeComparator implements Comparator {
public int compare(Object emp1, Object emp2){

/*
* parameter are of type Object, so we have to downcast it
* to Employee objects
*/

int emp1Age = ((Employee)emp1).getAge();
int emp2Age = ((Employee)emp2).getAge();

if(emp1Age > emp2Age)
return 1;
else if(emp1Age < emp2Age)
return -1;
else
return 0;
}
}


class NameComparator implements Comparator {

public int compare(Object emp1, Object emp2){
//parameter are of type Object, so we have to downcast it to Employee objects

String emp1Name = ((Employee)emp1).getName();
String emp2Name = ((Employee)emp2).getName();

//uses compareTo method of String class to compare names of the employee
return emp1Name.compareTo(emp2Name);
}
}


public class JavaComparatorExample {

public static void main(String args[]){

//Employee array which will hold employees
Employee employee[] = new Employee[2];

//set different attributes of the individual employee.
employee[0] = new Employee();
employee[0].setAge(40);
employee[0].setName("Joe");

employee[1] = new Employee();
employee[1].setAge(20);
employee[1].setName("Mark");

System.out.println("Order of employee before sorting is");

for(int i=0; i < employee.length; i++){
System.out.println( "Employee " + (i+1) + " name :: " + employee[i].getName() + ", Age :: " + employee[i].getAge());
}

/*
Sort method of the Arrays class sorts the given array.
Signature of the sort method is,
static void sort(Object[] object, Comparator comparator)

IMPORTANT: All methods defined by Arrays class are static. Arrays class
serves as a utility class.
*/

//Sorting array on the basis of employee age by passing AgeComparator
Arrays.sort(employee, new AgeComparator());
System.out.println("\n\nOrder of employee after sorting by employee age is");

for(int i=0; i < employee.length; i++){
System.out.println( "Employee " + (i+1) + " name :: " + employee[i].getName() + ", Age :: " + employee[i].getAge());
}

//Sorting array on the basis of employee Name by passing NameComparator
Arrays.sort(employee, new NameComparator());

System.out.println("\n\nOrder of employee after sorting by employee name is");
for(int i=0; i < employee.length; i++){
System.out.println( "Employee " + (i+1) + " name :: " + employee[i].getName() + ", Age :: " + employee[i].getAge());
}

}

}

OUTPUT of the above given Java Comparable Example would be :
Order of employee before sorting is
Employee 1 name :: Joe, Age :: 40
Employee 2 name :: Mark, Age :: 20
Order of employee after sorting by employee age is
Employee 1 name :: Mark, Age :: 20
Employee 2 name :: Joe, Age :: 40
Order of employee after sorting by employee name is
Employee 1 name :: Joe, Age :: 40
Employee 2 name :: Mark, Age :: 20

 

Categories: Java Tags:

Generic Persistent Layer Hibernate and spring 3.1

December 26, 2011 Leave a comment

Ở Spring 3.1 thì không cần dùng HibernateTemplate nữa

Bắt đầu từ Spring 3.0 và Hibernate 3.0.1, quản lý Hibernate Session với Springs HibernateTemplate là không còn cần thiết nữa. Bây giờ có thể dùng contextual sessions – sessions được quản lý trực tiếp bởi Hibernate và được giữ sống xuyên suốt trong tầm vực của một transaction.

Kết quả là, bây giờ cách thực hành tốt nhất là sử dụng trực tiếp API Hibernate thay vì HibernateTemplate, sẽ hiệu quả để  decouple the DAO layer hiện thực từ Spring entirely.

Exception Translation without the template

One of the responsibilities of HibernateTemplate is exception translation – translating the low level Hibernate exceptions – which tie the API to Hibernate as the single possible ORM – into higher level, generic Spring exceptions.

Without the template to do that, exception translation can still be enabled by annotating the DAOs with the @Repository annotation. That, coupled with a Spring bean postprocessor will advice all @Repository beans with all the implementations of PersistenceExceptionTranslator found in the Spring context – to provide exception translation without using the template.

Exception translation is done through proxies; in order for Spring to be able to create proxies around the DAO classes, these must not be declared final.

NOTE: As of Hibernate 3.0.1, transactional Hibernate access code can also be coded in plain Hibernate style. Hence, for newly started projects, consider adopting the standard Hibernate3 style of coding data access objects instead, based on {@link org.hibernate.SessionFactory#getCurrentSession()}.

Spring configuration thì có 2 cách: java configuration và xml configuration, nhưng mình vẫn thích dùng cách truyền thống hơn đó là xml configuration. Tùy thói quen của mỗi người miễn sao thấy tiện cho mình là được.

Mục đích của bài viết này không nhằm hướng dẫn configuration mà generic persistence layer, nên chỉ một số lưu ý khi configuration.

Potential for Exceptions

The Transaction Factory

The Hibernate contract for creating transactions is specified by the TransactionFactory interface. In order for Spring to fully manage transactions, the default implementation of this contract – JDBCTransactionFactory – is replaced by default with it’s Spring-aware counterpart – SpringTransactionFactory.

This can also be done manually, in the Hibernate properties (it is however redundant):

transaction.factory_class=org.springframework.orm.hibernate3.SpringTransactionFactory

The Current Session Context

When the Hibernate SessionFactory is created in the Spring context by it’s factory bean, it will create the CurrentSessionContext. This is the contract for supporting the current session concept and its implementation is decided by analyzing the “hibernate.current_session_context_class” Hibernate property.

Setting this property to “managed” means using the managed implementation for contextual sessions – ManagedSessionContext – which assumes that the current session is managed by an external entity. In our Spring context, that would fail with:

org.springframework.orm.hibernate3.HibernateSystemException: No session currently bound to execution context

Setting the property to “thread” would enable the thread-bound strategy in the Hibernate configuration; this would also conflict with Spring Transaction management and would result in:

org.springframework.orm.hibernate3.HibernateSystemException: persist is not valid without active transaction

To let Spring manage transactions, this property needs to be “org.springframework.orm.hibernate3.SpringSessionContext”; because this is also the default, the explicit definition of the property can be removed.

to be continue…

Categories: Hibernate Tags:

Những mẹo khi dùng BlackBerry

December 18, 2011 Leave a comment

Mình dùng con Storm để hướng dẫn nhé.

1/ Khắc phục âm thanh nhỏ khi đàm thoại

Options / Phone Options / General Options / Default Call Volume: 100%

2/ Hiển thị thông tin trên màn hình khi khóa phím

Bạn vào Options / chọn Owner Sau đó đánh vào những gì mình thích

3/

Categories: BB Storm 9530 Tags:
Follow

Get every new post delivered to your Inbox.