Saturday, January 28, 2012

Java: Improvements to the client and desktop parts of Java SE 6 and Java SE 7 !!!

Client-Side Improvements in Java 6 and Java 7

Learn about the improvements to the client and desktop parts of Java SE 6 and Java SE 7, including the new applet plug-in, the Java Deployment Toolkit, shaped and translucent windows, heavyweight-lightweight mixing, and Java Web Start.

Since the release of Java Platform, Standard Edition 6 (Java SE 6) in December of 2006, a lot of improvements have been made to the client and desktop parts of Java. In this article, we take a tour of Swing, and then we dive into some of the support technologies that let developers make great client apps, such as installation, Java Web Start, applets, and graphics improvements. Then we will take a peek at Java 7.

Wednesday, January 25, 2012

JSR: Part 1- Getting started with JSR 303 (Bean Validation)

Validating objects against different criteria is a requirement in basically every software development project. Examples are countless:
  • A given object might never be allowed to be null
  • A number could be required to be always in the interval [1 ... 100]
  • A String might be expected to match some regular expression or to represent a valid e-mail address, credit card number, license plate etc.
Where Java is concerned, a couple of dedicated validation frameworks have been around for quite a long time. The probably best-known ones are Commons Validator from the Apache Commons project and Hibernate Validator. Other options are iScreen and OVal, and the ubiquitous Spring framework comes with its own validation package, too.

With JSR 303: "Bean Validation" efforts are under-way, to establish a standard validation API. The JSR tries to combine the best features of the different validation frameworks, while making you independent from any concrete implementation.

Tuesday, January 24, 2012

Jailbreak: How to Jailbreak Your iPad 2 & iPhone4S (A5) Using Absinthe [5.0.1]

These are instructions on how to perform an untethered jailbreak of your iPad 2 & iPhone4S (A5) running iOS 5.0.1 using Absinthe for all platforms.
Warning***: Before you continue make sure to do a backup of your device in iTunes as you may lose your Camera Roll during this process.

Note that all above instructions applies to iPhone4S.
Step One
Download the latest version of Absinthe from:

Step Two
Double click to extract the downloaded archive and launch the Absinthe application.

Step Three
As prompted, connect your iPad 2 to the computer via USB. Make sure to remove any passcodes or VPN settings you've previously set.
Step Four
Click the Jailbreak button to begin
Step Five
The application will take you through several steps of the jailbreak: Sending initial data, waiting for reboot, waiting for device to finish booting, Preparing jailbreak data, and Sending payload data.

Step Six
You will be informed that the jailbreak is 'Almost done'.

Step Seven
On you device, locate the Absinthe icon and press it to complete your jailbreak. It could be on any home screen.

If the server is down and you get an Error establishing a database connection message then tap the Settings icon on your springboard and turn on VPN.

You will get a configuration error; however, after about a minute your device will reboot.

Once your device restarts you will be jailbroken with Cydia on the Springboard!

Leave your comments for any clarifications, 

Saturday, January 21, 2012

JEE6: Stress Testing Java EE 6 Applications, how to?

Use stress testing to identify application server configuration problems, potential bottlenecks, synchronization bugs, and memory leaks in Java EE 6 code.

Unit and integration tests are helpful for the identification of business logic bugs, but in the context of Java Platform, Enterprise Edition 6 (Java EE 6), they are meaningless. Both integration and unit tests access your application in a single-threaded way.

After the deployment, however, your code will always be executed concurrently.

Stop Talking, Start Stressing
It is impossible to predict all nontrivial bottlenecks, deadlocks, and potential memory leaks by having theoretical discussions. It is also impossible to find memory leaks with unit and integration tests. Bottlenecks are caused by locks and I/O problems that are hard to identify in a single-threaded scenario. With lots of luck and patience, memory leaks can be identified with an integration test, but they can be far more easily spotted under massive load.

The heavier the load, the greater is the probability of spotting potential concurrency and robustness problems. Cache behavior, the frequency of Java Persistence API (JPA) OptimisticLockException, and the amount of memory needed in production can also be evaluated easily with stress tests.

Architecture: What’s in your architecture toolbox?

It is said that there’s a tool for every job. But when that job is IT architecture, in all its permutations, the definition of tool can be a bit fuzzy.

When I set out to get a sense of what community members consider the most important tool in their respective architectural toolboxes, I intentionally left the definition of tool open. I was curious to see how those who responded to my questions would interpret the term.
One of those respondents was Farzad Pezeshkpour, head of architecture and engineering for market and credit risk technology at the Royal Bank of Scotland. His personal choice for the most important tool is Enterprise Architect from Sparx Systems.
“In order to do enterprise architecture well,” Pezeshkpour says, “there must be a consistent way to represent it, using a number of different views at different levels of detail, including logical static, logical dynamic, and deployment. There also must be a consistent naming and referencing mechanism to tie together all the architecture views. And finally, there must be an enterprise architecture repository to store and cross-reference these artifacts.
Having these three core elements in our toolset and processes gives an architectural management information view that helps govern our estate more efficiently and intelligently.”
Architecture is deeply connected to the specific business and technological environment in which an organization operates. Pezeshkpour works at one company, in one environment—which is challenging enough. But what happens if your work as an architect takes you into a variety of different environments?
If you find yourself in that situation, Vennster Managing Partner Ronald van Luttikhuizen advises adaptability when it comes to tools. “Especially if you’re a consultant working for various clients, it greatly helps to use the tooling that is available and already in use by clients and stakeholders, instead of rigidly sticking to your own toolset,” says this Oracle ACE Director. 
That can mean dealing with a variety of Unified Modeling Language (UML), Business Process Model and Notation (BPMN), and other modeling and design tools. As for his personal favorite, van Luttikhuizen also lists Sparx Systems’ Enterprise Architect. “A great tool at a great price,” he says.
But van Luttikhuizen’s toolbox also contains some more-basic applications to help him get his message across. “In the end, architecture is about communication,” he says. “So in the beginning of an architecture-oriented project, the most important tools are a whiteboard, Microsoft PowerPoint, and Microsoft Word.”
Karina Ishkhanova, a solution architect and technical lead for payment systems at School-Day Solutions, agrees with van Luttikhuizen about the importance of basic communication tools. “The first stage in defining the future architecture happens in close collaboration with business departments,” she says. “Whiteboards, paper, and markers are indispensable. Sometimes we even cut paper into components to move them around to help visualize the variations on proximity to other system parts.”

For modeling, Ishkhanova uses UMlet, an open source UML tool, which she values for its simplicity. “At more-advanced stages, I move to Oracle JDeveloper,” she says, “to take advantage of its integration and automation features.”

Communication tools are also vital for Lambda Software President Aki Iskandar.
“By far the most important tool in my toolbox is the one that I ask my clients to hand to me before any discussions, let alone architectural work, starts. It’s the set of three blueprint documents that jointly define well-articulated and complete business requirements, the constraints within the environment, and the architectural diagrams for network topologies,” Iskandar says. “Without them, you may overarchitect or underarchitect the system. You can’t architect a system without knowing the constraints before you start.”
Perhaps his last point is the IT architect’s equivalent of the carpentry maxim “Measure twice, cut once.”
While the choice of tools varies among these four architects, that choice is driven by the shared goal of effective communication in order to ensure a good fit between the up-front plan and the completed project. Isn’t that what IT architecture is all about?

JEE6: Interfaces on Demand with EE6 (CDI & ejb3.1)

Interfaces are no longer required with Java EE 6, so you can use them more consciously for the realization of business logic.

Since Java Platform, Enterprise Edition 6 (Java EE 6), interfaces are no longer required by the container in order to realize common use cases. Transactions, security, custom aspects, concurrency, and monitoring are also available for plain classes without any interfaces. Java EE 6 made interfaces meaningful again. Since they are no longer required by the platform, you can use them more consciously for the realization of business logic. An interface becomes a vehicle for encapsulation or abstraction, as it was originally intended to be:
Interfaces are used to encode similarities which the classes of various types share, but do not necessarily constitute a class relationship. For instance, a human and a parrot can both whistle; however, it would not make sense to represent Humans and Parrots as subclasses of a Whistler class. Rather they would most likely be subclasses of an Animal class (likely with intermediate classes), but both would implement the Whistler interface.” []

Unfortunately, interfaces are not used within the context of Java EE as a tool for encoding similarities; they serve as reassurance for possible, but unlikely, future enhancements. Extensive use of interfaces derives from a belief that they might be helpful in the future.

Friday, January 20, 2012

JEE6: Part 3- The Java EE 6 Platform introduction

Part 1 | Part 2 | Part 3

EJB Technology, Even Easier to Use
Enterprise JavaBeans technology is the server-side component architecture for developing and deploying business applications in Java EE. Applications that you write using EJB technology are scalable, transactional, and secure. EJB 3.0, which is part of the Java EE 5 platform, made the technology a lot easier to use. Description:

The latest release of the technology, JSR 318: Enterprise JavaBeans 3.1, which is available in the Java EE 6 platform, further simplifies the technology and makes many improvements that reflect common usage patterns.

Some improvements made in EJB 3.1 are as follows:
  •  No-interface view. Allows you to specify an enterprise bean using only a bean class without having to write a separate business interface.
  • Singletons. Let's you easily share state between multiple instances of an enterprise bean component or between multiple enterprise bean components in an application.
  •  Asynchronous session bean invocation. Enables you to invoke session bean methods asynchronously by specifying an annotation.
  •  Simplified Packaging. Removes the restriction that enterprise bean classes must be packaged in an ejb-jar file. You can now place EJB classes directly in a WAR file.
  • EJB Lite. Is a subset of EJB 3.1 for inclusion in a variety of Java EE profiles.

JEE6: Part 2- The Java EE 6 Platform introduction

Part 1 | Part 2 | Part 3

Enhanced Web Tier Capabilities
Some of the most significant enhancements made in Java EE 6 appear in the web tier. As mentioned earlier, one of the goals of Java EE 6 is to make the platform more extensible, and two key improvements in the area of extensibility are web fragments and shared framework pluggability. These two new features are provided in Java EE 6 by Servlet 3.0 technology. Servlet 3.0, JSR 315, the latest version of Servlet technology, offers some other valuable enhancements such as support for asynchronous processing and support for annotations.

Another important Java EE 6 web tier technology is JSF 2.0, the latest version of JSF technology. Among its benefits, JSF 2.0 simplifies page and component authoring through Facelets, and adds support for asynchronous JavaScript and XML (commonly referred to as Ajax), and annotations.

Saturday, January 14, 2012

JEE6: Part 1- The Java EE 6 Platform introduction

Part 1 | Part 2 | Part 3

Java Platform, Enterprise Edition (Java EE) is the industry-standard platform for building enterprise-class applications coded in the Java programming language. Based on the solid foundation of Java Platform, Standard Edition (Java SE), Java EE adds libraries and system services that support the scalability, accessibility, security, integrity, and other requirements of enterprise-class applications.

Since its initial release in 1999, Java EE has matured into a functionally rich, high performance platform. Recent releases of the platform have also stressed simplicity and ease of use. In fact, with the current release of the platform, Java EE 5, development of Java enterprise applications has never been easier or faster.

Java EE 6 adds significant new technologies and extends the usability improvements made in previous Java EE releases.
Progress continues. The next release of the platform, Java EE 6, adds significant new technologies, some of which have been inspired by the vibrant Java EE community. It also further simplifies the platform, extending the usability improvements made in previous Java EE releases.

This article highlights some of the significant enhancements in Java EE 6; it consists of three parts Part 1, 2 and 3.

Friday, January 13, 2012

JPA: Locking mechanisms in JPA 2

JPA 2 supports both optimistic locking and pessimistic locking. Locking is essential to avoid update collisions resulting from simultaneous updates to the same data by two concurrent users.
Optimistic locking is applied on transaction commit. Any database object that has to be updated or deleted is checked. An exception is thrown if it is found out that an update is being performed on an old version of a database object, for which another update has already been committed by another transaction.
Optimistic locking is enabled by default and fully automatic. Optimistic locking should be the first choice for most applications, since compared to pessimistic locking it is easier to use and more efficient.
In the rare cases in which update collision must be revealed earlier (before transaction commit) pessimistic locking can be used. When using pessimistic locking, database objects are locked during the transaction and lock conflicts, if they happen, are detected earlier.
This post covers the following topics:
  1. Optimistic Locking
  2. Pessimistic Locking
  3. Other Explicit Lock Modes
  4.  Locking during Retrieval
1- Optimistic Locking
JPA maintains a version number for every entity object. The initial version of a new entity object (when it is stored in the database for the first time) is 1. In every transaction in which an entity object is modified its version number is automatically increased by one. Version numbers are managed internally but can be exposed by defining a version field.
During commit (and flush), JPA checks every database object that has to be updated or deleted, and compares the version number of that object in the database to the version number of the in-memory object being updated. The transaction fails and an OptimisticLockException is thrown if the version numbers do not match, indicating that the object has been modified by another user (using another EntityManager) since it was retrieved by the current updater.
Optimistic locking is completely automatic and enabled by default in JPA, regardless if a version field (which is required by some ORM JPA providers) is defined in the entity class or not.
2- Pessimistic Locking
The main supported pessimistic lock modes are:

  • PESSIMISTIC_READ - This represents a shared lock.
  •  PESSIMISTIC_WRITE - This represents an exclusive lock.
Setting a Pessimistic Lock
An entity object can be locked explicitly by the lock method:
  em.lock(employee, LockModeType.PESSIMISTIC_WRITE);
The first argument is an entity object. The second argument is the requested lock mode.
TransactionRequiredException is thrown if there is no active transaction when lock is called because explicit locking requires an active transaction.
LockTimeoutException is thrown if the requested pessimistic lock cannot be granted:

  •  PESSIMISTIC_READ lock request fails if another user (which is represented by another EntityManager instance) currently holds a PESSIMISTIC_WRITE lock on that database object. 
  • PESSIMISTIC_WRITE lock request fails if another user currently holds either a PESSIMISTIC_WRITE lock or a PESSIMISTIC_READ lock on that database object.
- For example, consider the following code fragment:
  em1.lock(e1, lockMode1);
  em2.lock(e2, lockMode2);
em1 and em2 are two EntityManager instances that manage the same Employee database object, which is referenced as e1 by em1 and as e2 by em2 (notice that e1 and e2 are two in-memory entity objects that represent one database object).
If both lockMode1 and lockMode2 are PESSIMISTIC_READ - these lock requests should succeed. Any other combination of pessimistic lock modes, which also includes PESSIMISTIC_WRITE, will cause a LockTimeoutException (on the second lock request).
Pessimistic Lock Timeout
By default, when a pessimistic lock conflict occurs a LockTimeoutException is thrown immediately. The "javax.persistence.lock.timeout" hint can be set to allow waiting for a pessimistic lock for a specified number of milliseconds. The hint can be set in several scopes:
For the entire persistence unit - using a persistence.xml property:
       <property name="javax.persistence.lock.timeout" value="1000"/>
For an EntityManagerFactory - using the createEntityManagerFacotory method:
  Map<String,Object> properties = new HashMap();
  properties.put("javax.persistence.lock.timeout", 2000);
  EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu", properties);
For an EntityManager - using the createEntityManager method:
  Map<String,Object> properties = new HashMap();
  properties.put("javax.persistence.lock.timeout", 3000);
  EntityManager em = emf.createEntityManager(properties);
or using the setProperty method:
  em.setProperty("javax.persistence.lock.timeout", 4000);
In addition, the hint can be set for a specific retrieval operation or query.
Releasing a Pessimistic Lock
Pessimistic locks are automatically released at transaction end (using either commit or rollback).
JPA supports also releasing a lock explicitly while the transaction is active, as so:
  em.lock(employee, LockModeType.NONE);
3- Other Explicit Lock Modes
In addition to the two main pessimistic modes (PESSIMISTIC_WRITE and PESSIMISTIC_READ, which are discussed above), JPA defines additional lock modes that can also be specified as arguments for the lock method to obtain special effects:

  • OPTIMISTIC (formerly READ)
Since optimistic locking is applied automatically by JPA to every entity object, the OPTIMISTIC lock mode has no effect and, if specified, is silently ignored by JPA.
The OPTIMISTIC_FORCE_INCREMENT mode affects only clean (non dirty) entity objects. Explicit lock at that mode marks the clean entity object as modified (dirty) and increases its version number by 1.
The PESSIMISTIC_FORCE_INCREMENT mode is equivalent to the PESSIMISTIC_WRITE mode with the addition that it marks a clean entity object as dirty and increases its version number by one (i.e. it combines PESSIMISTIC_WRITE with OPTIMISTIC_FORCE_INCREMENT).
4- Locking during Retrieval
JPA 2 provides various methods for locking entity objects when they are retrieved from the database. In addition to improving efficiency (relative to a retrieval followed by a separate lock), these methods perform retrieval and locking as one atomic operation.
For example, the find method has a form that accepts a lock mode:
  Employee employee = em.find(Employee.class, 1, LockModeType.PESSIMISTIC_WRITE);
Similarly, the refresh method can also receive a lock mode:
  em.refresh(employee, LockModeType.PESSIMISTIC_WRITE);
A lock mode can also be set for a query in order to lock all the query result objects.
When a retrieval operation includes pessimistic locking, timeout can be specified as a property. For example:
  Map<String,Object> properties = new HashMap();
  properties.put("javax.persistence.lock.timeout", 2000);

  Employee employee = em.find(Employee.class, 1, LockModeType.PESSIMISTIC_WRITE, properties);
  em.refresh(employee, LockModeType.PESSIMISTIC_WRITE, properties);

Setting timeout at the operation level overrides setting in higher scopes.


Sunday, January 8, 2012

JEE6: Observer pattern/Event implementation

Java Enterprise edition jee6 Observer pattern/Event implementation using CDI (JSR-299/JSR-330) and EJB3.1

In few steps you will create the pattern as the following.

1. You will have to define an event class first. It can be any POJO you like:

public class HelloEvent {
    private String message;
    public HelloEvent(String message) {
        this.message = message;
    public String getMessage() {
        return message;
2. An event has to be fired by an injected javax.enterprise.event.Event class. It can be injected into an EJB 3.1:
public class HelloMessenger {
    @Inject Event<HelloEvent> events;
    public void hello(){ HelloEvent("from bean " + System.currentTimeMillis()));
3. The event can be consumed by another Session Bean / managed bean. You only have to use the @Observes annotation:

public class HelloListener {
    public void listenToHello(@Observes HelloEvent helloEvent){
        System.out.println("HelloEvent: " + helloEvent);
4. You can access the EJB 3.1 directly - without any backing beans. You only have to use the name (messenger) from the @Named annotation in the JSF 2.0 page and bind the action to the method (hello()) name:
            <h:commandButton value="Fire!" action="#{messenger.hello}"/>

The project (Jee6ObsorverEvents) was implemented in few minutes with NetBeans 7.1, tested with Glassfish v3.1.1

JEE6: Is war package is the new ear ?

The pragmatic way of modularization and packaging...

It is not only possible to put EJBs and JSR-299 Beans together directly into a WAR - EJBs can be also packaged separately into a JAR. After copying the “ejb-jar” into the [WAR]/WEB-INF/lib folder, the included beans become automatically available to the web app.

No additional configuration or tweaking is required. In the contrary to the the old EAR packaging, all the classes are loaded with the same classloader. There is no difference between packaging the beans in a standalone JAR, or putting the byte code directly into the WEB-INF/classes folder.

You could even sprinkle the beans in as many JARs as you like - the Dependency Injection between them will just work. Because all the JARs inside the WEB-INF/lib are loaded by exactly the same classloader - it just behaves like a single JAR.

The new Java EE 6 WAR-packaging is interesting for the majority of the “business” projects with “weak” requirements regarding the modularization. You can partition your software into dependent pieces, without paying the costs of true JAR-isolation.

The EAR packaging is still interesting for projects with higher modularization requirements - here the EJB-JARs will be loaded with an isolated classloader separately. In the majority of all cases it is just an overhead: it is unlikely, that someone will replace a single EJB-JAR without rebuilding and testing the whole EAR...

from Adam Bien's blog

Saturday, January 7, 2012

IDE: NetBeans 7.1 released

The NetBeans community is proud to announce the release of NetBeans IDE 7.1.
This release introduces support for JavaFX 2.0 by enabling the full compile/debug/profile development cycle for JavaFX 2.0 applications. NetBeans IDE 7.1 also provides significant Swing GUI Builder enhancements, CSS3 support, and tools for visual debugging of Swing and JavaFX user interfaces. Additional highlights include Git support integrated into the IDE, new PHP debugging features, various JavaEE and Maven improvements, and more.
"The latest NetBeans IDE release provides the Java developer community with many new features to help them create leading-edge Web, mobile and enterprise applications,” said Ted Farrell, chief architect and senior vice president, Tools and Middleware, Oracle. “As the first IDE to support JavaFX 2.0, NetBeans IDE 7.1 not only gives developers rich support for developing JavaFX 2.0 applications, but also ensures they have access to all of the advances delivered in the latest Java platform releases.”
NetBeans IDE 7.1 is a free, open source IDE available for Windows, Mac, Solaris, and Linux that enables developers to rapidly create Web, enterprise, desktop, and mobile applications for the Java platform. 

For NetBeans 7.1 features you can watch the following screen cast NetBeans IDE 7.1 Overview.

Thursday, January 5, 2012

IDE: Oracle JDeveloper Versions vs. Oracle Weblogic Server Versions

The last ADF projects when I am trying to run ADF applications build with JDeveloper of version X on a Weblogic Server with a different ADF Runtime version Y installed, I get a very big problems especially when they got tested with QA team.

You need to make sure that the ADF Runtime versions of JDeveloper and Weblogic Server matched.

Next issue is that you can’t install the ADF Runtime on any Weblogic Server you like.

The ADF Runtime will only work with a specific Weblogic Server. As each JDeveloper version comes with its own ADF Runtime version, there is a direct connection between JDeveloper and Weblogic Server.

To help you to use the right combination use the below table:
JDeveloper (ADF Runtime)Weblogic Server + Sherman patch + Sherman patch UPDATE1

There is no backward or forward compatibility!

You don’t need to try, I’ve tested most but not all combinations and run into trouble whenever I mixed versions starting from version

For my tests I used the production code.

The application was build on JDeveloper under Window 7, the resulting ear file was deployed (using the WLS admin page) on the Weblogic Server on a HP Linux box.

The ADF Runtime installed on the WLS was downloaded from here.

Credits goes to original author Timo Hahn at his post.