Java

Cayenne in a Minute

Java DZone - Fri, 10/09/2010 - 11:21

Cayenne is a powerful Java Object Relational Mapping framework. It’s open source and completely free. One of the main Cayenne distinctions is that it comes with cross-platform modeling GUI tools. This places Cayenne in the league of its own, making it a very attractive choice over both closed source commerical products and traditional “edit your own XML” open source solutions.

Categories: Java

JSF Basics

Java DZone - Fri, 10/09/2010 - 09:59

This is a brief tutorial that takes a quick look at some of the very basics of JSF, how we define pages and hook them up to server side objects. Rather than cover the fundamentals of starting a new JSF application, I’m going to start from one of the Knappsack archetypes which can provide you with a JEE 6 application ready to roll. In this case, we are going to start with a servlet based example so you can run it using the embedded servlet containers.

Categories: Java

Further Delays in JDK7: Which Plan Would You Choose?

Java DZone - Fri, 10/09/2010 - 09:57

In his latest blog entry , Mark Reinhold, Chief Architect of the Java Platform Group, explains how the current schedule for JDK7 is unrealistic. Following the Oracle acquisition, there were some delays in integration that slowed things down. Mark explains that there are two plans at the moment:

Categories: Java

Open Source Android Apps for Developers: Android-bluetooth

Java DZone - Fri, 10/09/2010 - 09:39

Android-bluetooth(Experimental unofficial Bluetooth API for Android) is an open source Android project which aims to provide a simple API to access Android’s Bluetooth stack. This library does not to require a rooted device: it is intended to work with standard firmware provided by phone manufacturers.

Categories: Java

Show ProgressBar in Notification Area

Java DZone - Fri, 10/09/2010 - 08:57

When you download from the Market you get informed about the progress in the download area. That's a really nice feature, which you may want for your own download or processing progress. I will show you the basics of generating such a Notification. All you need to do is add it to your code.

Categories: Java

Your Cross-Cutting Concerns are Someone Else's Core Domain

Java DZone - Fri, 10/09/2010 - 03:36

Consider a domain, for example an online bookshop project that we call BuyCheapBooks. The Ubiquitous Language for this domain would talk about Book, Category, Popularity, ShoppingCart etc.

Categories: Java

Java EE 6 Update 1 with JDK 6 U21 - and Using the Update Tool

Java DZone - Fri, 10/09/2010 - 01:16

A description of the new JavaEE 6 SDK w/ JDK bundles, and, probably more useful, how the update process looks in the new world of GlassFish 3 IPS packages.

Categories: Java

Project Coin possibilities under JDK 7 plan A and plan B

Java DZone - Fri, 10/09/2010 - 00:56

Mark Reinhold has announced in various venues that Oracle is rethinking the plan for JDK 7.

Categories: Java

New schedule for JDK 7?

Java DZone - Thu, 09/09/2010 - 22:35

JDK 7 delayed to mid 2012

Categories: Java

Thinking, Speaking & Dreaming about Technology: An Interview with Michael Hüttermann

Java DZone - Thu, 09/09/2010 - 22:07

First in a series of interviews dedicated to learning more about JetBrains Development Academy Experts. In this interview we have a conversation with Academy Board Member Michael Hüttermann. Michael is Cologne JUG leader, author, senior coach, consultant, and freelancer for Java/JEE, SCM/ALM and agile software development.

Categories: Java

Java Concurrency – Part 6 : Atomic Variables

Java DZone - Thu, 09/09/2010 - 20:20

Learn how to use atomic variables, especially AtomicInteger to solve concurrency problems in Java.

Categories: Java

A Simple Transactional File JCA 1.5 Connector (4 Classes / 2 Reusable)

Adam Bien Java Blog - Thu, 09/09/2010 - 19:42

There is a common prejudice that JCA connectors have to be too complicated for day to day use. "Custom & lightweight" solutions are built instead, which are usually orders of magnitudes more complex, than a pragmatic JCA implementation. So, how to built one:

  • JCA connectors are deployed as .rar archives with internal structure similar to ejb-jar archives. You can reuse your existing packaging and just change the ending from .jar to .rar
  • Start with the ra.xml deployment descriptor. You "only" have to implement the elements listed in this deployment descriptor:
<connector xmlns="http://java.sun.com/xml/ns/j2ee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                   http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
                     version="1.5">
                <display-name>Generic JCA</display-name>
                  <vendor-name>adam-bien.com</vendor-name>
                    <eis-type>Generic JCA</eis-type>
                      <resourceadapter-version>1.0</resourceadapter-version>
                        <resourceadapter>
                              <outbound-resourceadapter>
                                    <connection-definition>
                                          <managedconnectionfactory-class>...genericjca.GenericManagedConnectionFactory</managedconnectionfactory-class>
                                            <connectionfactory-interface>...genericjca.DataSource</connectionfactory-interface>
                                              <connectionfactory-impl-class>...genericjca.FileDataSource</connectionfactory-impl-class>
                                                <connection-interface>...genericjca.Connection</connection-interface>
                                                  <connection-impl-class>...genericjca.FileConnection</connection-impl-class>
                                                </connection-definition>
                                                  <transaction-support>LocalTransaction</transaction-support>
                                                    <authentication-mechanism>
                                                          <authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
                                                            <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
                                                          </authentication-mechanism>
                                                            <reauthentication-support>false</reauthentication-support>
                                                          </outbound-resourceadapter>
                                                        </resourceadapter>

                                                      </connector>

                                                       

                                                      •  GenericManagedConnectionFactory and GenericManagedConnection are mostly reusable. These classes care about connection management. You will be able to manage a connector through e.g. the Glassfish admin console. The code is surprisingly simple - its mainly book keeping and logging. See  http://kenai.com/projects/javaee-patterns/, project GenericJCA.
                                                      • The "core" business logic resides in the FileConnection:
                                                      public class FileConnection implements Connection, LocalTransaction{

                                                              private String buffer;
                                                                private FileOutputStream fileOutputStream;
                                                                  private ConnectionRequestInfo connectionRequestInfo;
                                                                    public final static String FILE_NAME = "/temp/jcafile.txt";
                                                                      private GenericManagedConnection genericManagedConnection;
                                                                        private PrintWriter out;

                                                                            public FileConnection(PrintWriter out,GenericManagedConnection genericManagedConnection,ConnectionRequestInfo connectionRequestInfo) {
                                                                                  this.out = out;
                                                                                    this.genericManagedConnection = genericManagedConnection;
                                                                                      this.connectionRequestInfo = connectionRequestInfo;
                                                                                        this.initialize();
                                                                                      }

                                                                                          private void initialize(){
                                                                                                try {
                                                                                                      this.buffer = null;
                                                                                                        this.fileOutputStream = new FileOutputStream(FILE_NAME,true);
                                                                                                      } catch (FileNotFoundException ex) {
                                                                                                            Logger.getLogger(FileConnection.class.getName()).log(Level.SEVERE, null, ex);
                                                                                                              throw new IllegalStateException("Cannot initialize OutputStream: " + FILE_NAME);
                                                                                                            }

                                                                                                            }

                                                                                                                public void write(String content) {
                                                                                                                      this.buffer = content;
                                                                                                                    }

                                                                                                                        public void close() {
                                                                                                                                  this.genericManagedConnection.close();
                                                                                                                            }

                                                                                                                                public void destroy(){
                                                                                                                                      try {
                                                                                                                                            if(this.fileOutputStream != null)
                                                                                                                                                  this.fileOutputStream.close();
                                                                                                                                              this.fileOutputStream = null;
                                                                                                                                                this.buffer = null;
                                                                                                                                                 } catch (IOException ex) {
                                                                                                                                                      Logger.getLogger(FileConnection.class.getName()).log(Level.SEVERE, null, ex);
                                                                                                                                                        throw new IllegalStateException("Cannot close stream: " +ex,ex);
                                                                                                                                                      }
                                                                                                                                                    }

                                                                                                                                                        public void begin() throws ResourceException {
                                                                                                                                                              this.initialize();
                                                                                                                                                            }

                                                                                                                                                                public void commit() throws ResourceException {
                                                                                                                                                                      out.println("#FileConnection.commit "  +toString());
                                                                                                                                                                        try {
                                                                                                                                                                           this.fileOutputStream.write(this.buffer.getBytes());
                                                                                                                                                                             this.fileOutputStream.flush();
                                                                                                                                                                               this.fileOutputStream.close();
                                                                                                                                                                                } catch (IOException ex) {
                                                                                                                                                                                      Logger.getLogger(FileConnection.class.getName()).log(Level.SEVERE, null, ex);
                                                                                                                                                                                        throw new ResourceException(ex);
                                                                                                                                                                                      }
                                                                                                                                                                                    }

                                                                                                                                                                                        public void rollback() throws ResourceException {
                                                                                                                                                                                              out.println("#FileConnection.rollback  " +toString());
                                                                                                                                                                                                this.buffer = null;
                                                                                                                                                                                                  try {
                                                                                                                                                                                                        this.fileOutputStream.close();
                                                                                                                                                                                                      } catch (IOException ex) {
                                                                                                                                                                                                            Logger.getLogger(FileConnection.class.getName()).log(Level.SEVERE, null, ex);
                                                                                                                                                                                                              throw new ResourceException(ex);
                                                                                                                                                                                                            }


                                                                                                                                                                                                      The nice thing are transaction callbacks. You will be notified about the transaction progress by the container. At commit time, you just write the buffer to the file - in case of a rollback you have to clear the buffer. This sample is not fully transactional - because in general you will have to deal with corrupted files etc. - but it should be clear how it works.

                                                                                                                                                                                                      After installation, you will be able to inject the interface (and so the FileConnection) to your business logic.

                                                                                                                                                                                                      @Stateless

                                                                                                                                                                                                      public class JCAClientBean implements JCAClientRemote {

                                                                                                                                                                                                          @Resource(mappedName="jca/FileFactory")

                                                                                                                                                                                                          private DataSource dataSource;

                                                                                                                                                                                                       ...and the transactions will be propagated transparently for you.

                                                                                                                                                                                                      JCA connectors are not as lean as simple as EJB 3.1 or CDI,  but orders of magnitude more robust and more maintainable, than solutions and workarounds which are usually built instead.

                                                                                                                                                                                                      You will find a working example (tested with Glassfish v2) in http://kenai.com/projects/javaee-patterns/. See GenericJCA, GenericJCAAPI and JCAClient projects. I described this solution in dedicated chapter "Generic JCA", page 181 in Real World Java EE Patterns - Rethinking Best Practices".

                                                                                                                                                                                                      The example presented here is based on the ancient Java EE 5 technology. JCA 1.6 connectors are lot simpler and more elegant - stay tuned. 

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      Cloud Computing with Scala and GridGain

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 15:32

                                                                                                                                                                                                      The presentation is devoted to live coding demonstration of writing basic MapReduce application in Scala using GridGain middleware.

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      My first steps with Gradle: creating a multi module java web project and running it with jetty.

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 15:29

                                                                                                                                                                                                      I am a experienced maven user. Sometime I love it, sometimes I hate it. I like it a lot better than ant, but in some situation you would like maven to be easier and more descriptive. The past year there was a lot of fuzz about Gradle. This would give you the best of ant as well as the best of maven, and even more. My first encounter was not very positive, but I kept it in my mind to try it later with a more serious project. This blogpost is about that second more serious try. It will not teach the gradle experts anything, but it will be an easy introduction in to what gradle has to bring for people that are just interested in gradle.

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      Ext GWT or SmartGWT or Vaadin

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 14:25

                                                                                                                                                                                                      My journey continues. Deciding on a RIA framework is harder than i thought because of the existance of many quite good approaches. First i checked ExtJS but as mentioned in my previous post, we wont want to write 80% of our app in javascript. So i came to Ext GWT which was the more viable option. Then someone pointed me to vaadin, which works by handling events on the server by widget network communication. But after seeing some limitations on the widget part of vaadin, i also checked SmartGWT, which is definitely the widget monster. You simply get everything you can imagine.

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      Workaround to Multi Threaded Testing

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 08:32

                                                                                                                                                                                                      Since it has been introduced in JDK 1.5, I have loved the Executor abstraction over multi threaded execution. Basically you define tasks, implementing Runnable or Callable interfaces, and you submit those tasks to an Executor implementation. It's the Executor who knows how the tasks must be processed: scheduled at a certain time, enqueued in a separate single thread or using a thread pool. Different instances of Executor can be obtained through the Executors class.

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      Oracle "Leaning Heavily" Towards JDK 7/JDK 8 Feature Split

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 08:15

                                                                                                                                                                                                      We've all known for some time that the JDK 7 development schedule was a bit too ambitious given the sudden addition of closures and the re-structuring after the Oracle acquisition. Having been written 'pre-acquisition', the initial JDK 7 roadmap looked unrealistic even in late 2009. So what does this mean? More delays? Not necessarily, says Mark Rienhold.

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      JPA Compound Primary Keys Explained

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 08:10

                                                                                                                                                                                                      JPA Compound Primary Keys Explained with code snippet

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      Beans Should Be Deprecated - The Future of Object Architecture With Properties

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 07:45

                                                                                                                                                                                                      In my previous post I discussed the case for Properties and the basics of how they work. In this post I will dive into the specific workings of Properties in Sgine and how to use the various features it provides. This post is all about Properties in Sgine for use primarily with Scala but the concepts and ideas are applicable to Java as well. Properties provide the future of object architecture and beans should have been deprecated long ago.

                                                                                                                                                                                                      Categories: Java

                                                                                                                                                                                                      Re-thinking JDK 7

                                                                                                                                                                                                      Java DZone - Thu, 09/09/2010 - 07:30

                                                                                                                                                                                                      "It’s been clear for some time that the most recent JDK 7 development schedule is, to put it mildly, unrealistic." So: "Plan A: JDK 7 (as currently defined) Mid 2012 Plan B: JDK 7 (minus Lambda, Jigsaw, and part of Coin) Mid 2011 JDK 8 (Lambda, Jigsaw, the rest of Coin, ++) Late 2012"

                                                                                                                                                                                                      Categories: Java
                                                                                                                                                                                                      Syndicate content