Oracle lays out long-range Java intentions

Cool:

  • Supports GPU (which now will have a complete platform for games?)
  • Support for FPGA;
  • Elimination of primitives types (long are the same types as objects);
  • Improved support for 64-bit (more data types, arrays indexed long, …);
  • Support for true Generics.

 

Oracle’s wish list for Java beyond next year’s planned Java SE (Standard Edition) 8 release includes object capabilities, as well as enhancements for ease-of-use, cloud computing, and advanced optimizations.

JDK (Java Development Kit) 10 and releases beyond it are intended to have a unified type system, in which everything would be made into objects, with no more primitives, according to an Oracle slide presentation entitled “To Java SE 8 and Beyond!” posted on the QCon conference website. Oracle cites an ambitious list of goals for Java in the presentation, which was apparently delivered by Oracle Technology Evangelist Simon Ritter last week. A slide entitled “Java SE 9 (and Beyond)” reveals goals for interoperability, including having a multilanguage JVM and improved Java/native integration.

[ Discover 9 killer programming languages for the JVM. | See Oracle's two-year road map for Java, which covers this year and 2013. | Oracle already has revised one detail of its road map, briefly extending the support period for JDK 6. | For more news on Java, subscribe to InfoWorld's Enterprise Java newsletter. ]

Other languages besides Java, such as JRuby, Scala, and Groovy, already have become popular on the JVM in recent years. A timeline provided in the presentation has JDK 9 arriving in 2015, JDK 10 in 2017, JDK 11 in 2019, and JDK 12 in 2021. The presentation declares, “Java is not the new Cobol.”

Ease-of-use goals for Java include a self-tuning JVM and language enhancements. Advanced optimizations eyed include the unified type system and data structure optimizations. Under the subheading, “Works Everywhere and With Everything,” Oracle lists goals like scaling down to embedded systems and up to massive servers, as well as support for heterogeneous compute models.

For cloud environments, a hypervisor-aware JVM is noted as an intention for JDK 9 and above, including cooperative memory page sharing. Multitenancy goals for JDK 8 and beyond include improved sharing between JVMs in the same OS and per-thread/threadgroup resource tracking and management. The vision for language features in JDK 9 includes large data support, with 64-bit and large-array backing. JDK 10 and above would feature true generics, function types, and data structure optimizations, including multidimensional arrays.

Heterogeneous compute models planned for JKD 9 and beyond include Java language support for GPU (graphics processing unit), FPGA (field programmable gate array), off-load engines, and remote PL/SQL. Also called for in the Oracle presentation is “open development,” in which prototyping and research and development would be done in OpenJDK, which is the open source process for Java. Plans also call for greater community and cooperation with partners and academia.

See: http://www.javaworld.com/javaworld/jw-03-2012/120315-oracle-s-java-roadmap.html

Comparing exams for JavaEE 6 with the Sun Certified Business Component Developer (SCBCD 5)

Now, the $Oracle$ don’t call anymore “SCBCD 5″, the new name is, “Java Enterprise Edition 5 Business Component Developer Certified“. Then, bye bye for our precious names SCBCD, SCJP…

The   exame  content of the Java Enterprise Edition 5 Business Component Developer Certified, countinus the same as the SCBCD:

  • EJB 3.0 Overview
  • General EJB 3.0 Enterprise Bean Knowledge
  • EJB 3.0 Session Bean Component Contract & Lifecycle
  • EJB 3.0 Message-Driven Bean Component Contract
  • Java Persistence API Entities
  • Java Persistence Entity Operations
  • Persistence Units and Persistence Contexts
  • Java Persistence Query Language
  • Transactions
  • Exceptions
  • Security Management

In other words, verify our knowledgement in EJBs: Session Beans, Message Driven Beans e Entities Beans.

But with the version 6 of the JavaEE, the $Oracle$  left the SCBCD5 in 2 exams , one to Session Beans/Message Driven Beans and other to Entities Beans (JPA), whereupon:

Java EE 6 Enterprise JavaBeans Developer Certified Expert Exam

  • Introduction to Java EE
  • Implementing Session Beans
  • Accessing Session Beans
  • Advanced Session Bean Concepts
  • Singleton Session Bean
  • Developing Java EE Applications Using Messaging
  • Developing Message-Driven Beans
  • Using Timer ServicesObjectives
  • Implementing Interceptor Classes and Methods
  • Implementing Transactions
  • Implementing Security
  • Using EJB Technology Best Practices

 

Java EE 6 Java Persistence API Developer Certified Expert Exam

  • Overview of the Java Persistence API
  • Introducing the Auction Application
  • Java Persistence API Entities
  • Understanding the Entity Manager
  • Modeling Entity Relationships
  • Entity Inheritance and Object-Relational Mapping
  • Persisting Enums and Collections
  • Introduction to Querying
  • Using the Java Persistence API Query Language
  • Using the Java Persistence API Criteria API
  • Using the Java Persistence API in a Container
  • Implementing Transactions and Locking
  • Advanced Java Persistence API Concepts

So, to have a  equivalent level of the SCBCD 5,  we have $pay$ 2 exams!

There are people who say that is better, because they are more specific tests to check knowledge of technology. For others, it’s just another reason for the $Oracle$  earn more cash!

 

Books to SCBCD 5:

 

Books to JavaEE 6:

 

 

Serialization :: Using ObjectOutputStream and ObjectInputStream

Serialization is the process of creating a copy in binary data of an object. When the data of an object is serialized, we can store the binary content in a file or even database for later use. When the serialization happens, we say that data was persisted.

The magic of serialization happens in two ways:

1. To WRITE it in a stream (serialize);
2. To READ it in a stream (deserialize);

As example, was used the package java.io:

To serialize:

java.io.FileOutputStream
java.io.ObjectOutputStream

To deserialize:

java.io.FileInputStream
java.io.ObjectInputStream

Below, we will persist the object “book” in the file “book.obj”. For that happens, the Class Book must implement Serializable.

POJO – Book.java:

public class Book implements Serializable {

	private static final long serialVersionUID = 916284536305404828L;

	private String name;

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
}

JUnit – SerializationTest.java:

public class SerializationTest {

	private static final String BOOK_NAME = "Clean Code";

	Book book;

	@Before
	public void init() {
		book = new Book();
		book.setName( BOOK_NAME );
	}

	@Test
	public void serializationTest() throws FileNotFoundException, IOException, ClassNotFoundException {

		serializeBook();

		deserializeBook();
	}

	private void serializeBook() throws FileNotFoundException, IOException {

		ObjectOutputStream objectOutputStream = new ObjectOutputStream( new FileOutputStream("book.obj") );

		objectOutputStream.writeObject(book);
		objectOutputStream.close();
	}

	private void deserializeBook() throws FileNotFoundException, IOException, ClassNotFoundException {

		ObjectInputStream objectInputStream = new ObjectInputStream( new FileInputStream("book.obj") );

		Object object = objectInputStream.readObject(); 

		if( object instanceof Book )
			book = (Book) object;

		objectInputStream.close();

		Assert.assertFalse( book == null );
		Assert.assertEquals( book.getName(), BOOK_NAME );
	}
}

The Serializable interface serves as a “markup” for the our classes, because there are no methods to implement.

As a “good programming practice”, we can set the attribute static final serialVersionUID which is the serialization version identifier of a class that implements the Serializable interface.

To deserialize the object “book”, we use the method objectInputStream.readObject() of the class java.io.ObjectInputStream. That method returns the object that was persisted in the file “book.obj”.

Eclipse Metrics plugin

Provide metrics calculation and dependency analyzer plugin for the Eclipse platform. Measure various metrics with average and standard deviation and detect cycles in package and type dependencies and graph them.

Save the Software Craftsmanship!

For Eclipse 3.1 +: http://metrics.sourceforge.net/update

Vagrant?

Vagrant is a tool for building and distributing virtualized development environments.

Although Vagrant is written in Ruby, web developers from many different languages come to use it (Python, Java, Clojure, etc.)

 

Why Vagrant?

Web developers use virtual environments every day with their web applications. From EC2 and Rackspace Cloud to specialized solutions such as EngineYard and Heroku, virtualization is the tool of choice for easy deployment and infrastructure management. Vagrant aims to take those very same principles and put them to work in the heart of the application lifecycle. By providing easy to configure, lightweight, reproducible, and portable virtual machines targeted at development environments, Vagrant helps maximize your productivity and flexibility.

Vagrant is a development tool which stands on the shoulders of giants, using tried and proven technologies to achieve its magic. Vagrant uses Oracle’s VirtualBox to create its virtual machines and then uses Chef or Puppet to provision them.

Benefits of Vagrant

For Solo Developers

Maintaining consistent development environments over multiple projects is simply an unfeasible task for a modern web developer. Each project depends on its own libraries, message queue systems, databases, framework, and more, each with their own versions. In addition to the dependencies, running all these on a single home machine and remembering to turn it all off at the end of the day or when working on other projects is also unfeasible. Vagrant gives you the tools to build unique development environments for each project once and then easily tear them down and rebuild them only when they’re needed so you can save time and frustration.

For Teams

Each member of a team ideally has identical development environments: same dependencies, same versions, same configurations, same everything. But this is simply not true today. With database agnostic ORMs, multiple web server options, and fast-moving libraries, one team member may be using MySQL with one version of a library while another team member may be using PostgreSQL with another version of the same library. Or perhaps one team member’s configuration for their server is slightly different. These are all real cases which are bound to cause real issues at some point down the road. Vagrant gives teams the ability to enforce a consistent and portable virtual development environment that is easy to create and quick to setup.

For Companies

If you’ve ever maintained a large web application, one of the hardest parts is onboarding new resources. Message queues, caching, database servers and other infrastructure pieces mean a lot of installation and a lot more configuration (see case-in-point: insanity). Vagrant gives you the tools to build a development environment once and then easily distribute it to new members of your development team so you can get them to work and saving time, money and frustration.

From: http://vagrantup.com/docs/getting-started/why.html

Getting Started with Vagrant

Vagrant uses Oracle’s VirtualBox to build configurable, lightweight, and portable virtual machines dynamically. The first couple pages serve to introduce you to Vagrant and what it has to offer while the rest of the guide is a technical walkthrough for building a fully functional Ruby on Rails development environment.

 

Get VirtualBox

Vagrant depends on Oracle’s VirtualBox to create all of it’s virtual environments. VirtualBox is a general-purpose full virtualizer for x86 hardware. Targeted at server, desktop and embedded use, it is now the only professional-quality virtualization solution that is also Open Source Software. VirtualBox runs on WindowsMac OS XLinux, and Solaris.

Here is a link directly to the download page.

Vagrant currently supports VirtualBox 4.0.x and 4.1.x.

 

1. Install Ruby 1.9.x

  • Download Ruby 1.9.3 here.

2. Install  RubyInstaller Development Kit (DevKit)

  • Download DevKit  here.
  • Extract the downloaded DevKit.
$ cd <DEV_KIT_DIR>
$ ruby dk.rb init
$ ruby dk.rb install

3. Install Vagrant

$ gem install vagrant

4. Your First Vagrant Virtual Environment

$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box
$ vagrant init lucid32
$ vagrant up

5. Halting the Environment

This will attempt a graceful shutdown of your VM (such as issuing a halt in a linux machine) and wait for it to shut down.

vagrant halt

 

Destroying the Environment!

Completely destroy the virtual environment. :-P

$ vagrant destroy

Refactoring :: Send Mail with Attachment

Hi, in that example, I do a refactoring on Email class of the post Send Mail with Attachment.

Mail.java

package com.christianborges.mail;

import java.io.IOException;
import java.util.Properties;

import javax.activation.DataHandler;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import com.christianborges.mail.attachment.InputStreamDataSource;

public class Mail {

	private static final String TRUE = "true";
	private static final String MAIL_TRANSPORT_PROTOCOL = "smtp";
	private static final int THREAD_INTERVAL_SEND_MAIL = 10;

	private InputStreamDataSource attachmentStream;
	private MimeBodyPart attachFilePart;

	public void send(final MailMessage mailMessage) throws Exception {

		if (mailMessage == null)
			throw new NullPointerException();

		final Message mimeMesssage = new MimeMessage( this.createMailSession(mailMessage) );
		final MimeBodyPart mimeBodyPart = new MimeBodyPart();

		mimeMesssage.setFrom(mailMessage.getFromAddress());
		mimeMesssage.setSubject(mailMessage.getSubject());

		mimeBodyPart.setContent(mailMessage.getBody(), mailMessage.getContentType().getBaseType());

		this.setAttachment(mailMessage, mimeMesssage, mimeBodyPart);

		for (InternetAddress toAddress : mailMessage.getToAddressess()) {
			mimeMesssage.setRecipient(Message.RecipientType.TO, toAddress);
			Transport.send(mimeMesssage);
			Thread.sleep(THREAD_INTERVAL_SEND_MAIL);
		}

		this.attachFilePart = null;
		this.attachmentStream = null;
	}

	private Session createMailSession(final MailMessage mailMessage) {

		final Properties sessionProperties = new Properties();

		sessionProperties.setProperty("mail.transport.protocol", MAIL_TRANSPORT_PROTOCOL);
		sessionProperties.put("mail.smtp.host", mailMessage.getMailSecurity().getSmtpServer());
		sessionProperties.put("mail.smtp.auth", TRUE);
		sessionProperties.put("mail.smtp.port", mailMessage.getMailSecurity().getSmtpPort());

		if (mailMessage.getMailSecurity().isSSL()) {
			sessionProperties.put("mail.smtp.starttls.enable", TRUE);
		}

		final Authenticator auth = new Authenticator() {

			@Override
			public PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(mailMessage.getMailSecurity().getUser(), mailMessage.getMailSecurity().getPasswd());
			}
		};

		return Session.getInstance(sessionProperties, auth);
	}

	private void setAttachment(final MailMessage mailMessage, final Message mimeMesssage, final MimeBodyPart mimeBodyPart)
			throws IOException, MessagingException {

		if (mailMessage.hasAttachment()) {
			attachmentStream = new InputStreamDataSource(mailMessage.getMailAttachment());
			attachFilePart = new MimeBodyPart();

			attachFilePart.setDataHandler(new DataHandler(attachmentStream));
			attachFilePart.setFileName(attachmentStream.getName());

			final Multipart mimeMultipart = new MimeMultipart();
			mimeMultipart.addBodyPart(mimeBodyPart);

			if (attachFilePart != null) {
				mimeMultipart.addBodyPart(attachFilePart);
			}

			mimeMesssage.setContent(mimeMultipart);
		}
	}
}

Continue reading Refactoring :: Send Mail with Attachment →

Scrum Master

It is not the strongest of species that survive, nor the most intelligent, but the one most responsive to change.

“Não é o mais forte da espécie que sobrevive, nem o mais inteligente. É aquele que melhor se adapta as mudanças.”

Charles Darwin

Hibernate 4 – Maven Dependency


  org.hibernate
  hibernate-core
  4.0.1.Final



  org.hibernate
  hibernate-entitymanager
  4.0.1.Final



  org.hibernate
  hibernate-annotations
  3.5.6-Final

Software Craftsmanship

“Don’t comment bad code – rewrite it”

– Brian W. Kernighan and P J Plauger