Java things-JavaOne 2011, CDI and Google Dart language

Source: Internet
Author: User
Tags http request java se

For the Java community, the most important event of September and October was the annual JavaOne Congress. The theme of JavaOne 2011 is "Driving Java forward (moving Java Forward)". As you can see from this topic, Oracle is trying to lead the Java community as a leader to drive Java development together. The release of the Java SE 7 is an important milestone in this process. Compared to the last JavaOne meeting, JavaOne 2011 was considered a good one in the community and was regarded as a successful meeting. Oracle also attaches greater importance to the Community's role in driving Java development. Unfortunately, due to patent lawsuits between Google and Oracle, developers from Google are once again absent from the JavaOne convention.

On JavaOne 2011, Oracle has released a number of new technologies and projects, as well as the development plans for some important projects.

Java SE 8

According to community feedback, the release time of the Java SE 8 was postponed from the end of 2012 to the summer of 2013, almost exactly 2 years from the release of Java SE 7. What is included in Java SE 8 is:

    • Jigsaw Project: Provides modular system support for Java platform and Java applications.
    • Lambda Project: Adds closure support for the Java language. Provides a batch parallel operation API for the Java Collection API, such as Filter/map/reduce.
    • Integrate some features of the jrockit virtual machine into the hotspot virtual machine, and provide a unified virtual machine implementation.
    • Integrated JavaFX 3.0. JavaFX 2.0 is officially released on JavaOne 2011 and the installation of JavaFX 2.0 is integrated in the JDK 7u2. In Java SE 8, the JAVAFX 3.0 is directly integrated.
    • New JavaScript engines that can be used directly on virtual machines, as well as better JavaScript and Java interoperability. The new JavaScript engine, called Nashorn, is an implementation based on JSR 292.
    • Increase support for multi-touch, camera, location information, compass and gravity accelerator on mobile devices
    • Updates to Java security, date/time, network, internationalization, and accessibility APIs.

Java EE 7

The goal of Java EE 7 is to combine Java EE technology with the current hot cloud computing, turning the Java EE platform itself into a service (Platform as a Service,paas), while providing flexible computing (elastic Computing) and multi-tenant (multi-tenancy) support. The biggest advantage of Java EE 7 in relation to existing cloud computing technologies is standardization and openness. The contents of Java EE 7 include:

    • Provides platform-service support, including service definition and service delivery, and support for multiple tenants in the API.
    • Enhance Web profile capabilities and increase support for Jax RS 2.0.
    • Further simplifying development, including new JMS 2.0, more dependency injection usage, and more service meta data and optimized configuration methods.

Java ME 7

In the Java me aspect, the point of development is to keep the Java se synchronized. When new updates are available in the Java SE, sync to Java me as soon as possible. This includes the release version of synchronization, the Java ME API can run in the Java SE environment, and a consistent tool interface. Another goal is to have the Java Platform support all of the different platforms, regardless of the CPU and memory throttling environment. The final direction is deep integration with content and services, including access to services provided by operators.

Dd.

For the concept of dependency injection, I believe many developers are not unfamiliar. A component relies on the functionality provided by other components while it is running. The traditional approach is for the component itself to find the desired dependent object. This approach can result in tight coupling between components, which is not conducive to maintenance and updating of components. The practice of dependency injection is to indicate its dependencies declaratively, by injecting the Java objects of the required components into the current component at run time by the framework. The concept of dependency injection is more appropriate for Java EE than for Java SE. Many of the resources and services in Java EE are managed by containers. For a single application, it is not easy to find the component that is managed by the container. A better approach is to declare the required resources and services from the application and inject it into the application with the container in charge. In this way, containers are also better able to manage resources and services. In the case of database connectivity, the traditional approach requires that the application itself load the associated driver and create a database connection, and release it at the appropriate time. Using container management and injecting dependencies reduces the workload for application developers.

The limited support for dependency injection is added to Java EE 5. Annotations allow you to inject the corresponding objects of resources into the objects managed by the container. In Java EE 6, the concept of dependency injection is further introduced, namely, the introduction of the JSR 299 (contexts and Dependency injection for the Java EE Platform) specification, referred to as CDI. The CDI specification incorporates best practices from the spring IOC container, JBoss seam, and Google Guice, and is combined with the real needs of Java EE development. Like the literal meaning of CDI, the two core features in CDI are contextual information (context) and dependency injection. The binding point for these two features is the basic component model Bean in Java. In CDI, the Bean defines the state and logic of the application and is managed by the container. Each managed bean has a well-defined scope and lifecycle bound to a specific context. When you need to inject or access a bean, the container is fetched from the context of the scope. When the scope fails, all objects in the corresponding context are deleted. Each bean in CDI can be used as a target for dependency injection.

Some common scopes are predefined in CDI. The default scope is dependent, which means that only the injected object is in effect. The scope applicationscoped represents the global scope of the application, which is used to create globally unique objects. Requestscoped and sessionscoped are related to HTTP, representing HTTP requests and HTTP sessions, respectively. Conversationscoped is a scope that applies the length of a custom lifecycle and can be used to implement workflows across multiple pages. The Orderprocessor class in the following code only survives in the HTTP request and relies on the implementation of the Orderdao interface. The container finds the implementation object of the Orderdao interface at run time and injects it into the object of the Orderprocessor class.

@Named
@RequestScoped Public
class Orderprocessor {
 @Inject
 private Orderdao Orderdao
}

The usual way to rely on injection is to rely on interfaces only in code, and to inject them by selecting the object of the appropriate implementation class at run time. If the interface has only one implementation class, no additional declarations are required. If the interface has a different implementation, you need to use a qualifier (qualifier) to declare the implementation of the specific use, or the container will not be able to make the right choice. One feature of CDI is that qualifiers are not ordinary strings, but type-safe annotations.

A new qualifier annotation can be created by using the qualifier meta annotation. As the following code creates a new qualifier annotation inmemory.

@Qualifier
@Retention (RUNTIME)
@Target ({TYPE}) public
@interface InMemory {}

This annotation can be added to the implementation of the Orderdao interface.

@InMemory public
    class Inmemoryorderdao implements Orderdao {
}

If you want to use a simple, memory-based storage implementation when testing, you can use the inmemory annotation to declare it. This allows the container to use the object of the Inmemoryorderdao class when injected.

@Named
@RequestScoped Public
class Orderprocessor {
 @Inject @InMemory
 private Orderdao Orderdao;
}

Use type-safe annotation types to avoid problems that can occur when strings are used. When using strings to differentiate, it is possible to create problems that are difficult to discover due to subtle errors in string content.

Google Dart Language

Google's developers seem keen to develop new programming languages, and every new language has a big impact. Not long ago, Google's developers released a new programming language, dart. The goal of the DART language is to create structured Web applications. Similar node.js and GWT are used in the same way, that is, the same programming language is used on the server side and the client. In Node.js, JavaScript is used, Java is the main in GWT, and Dart is more like an upgraded version of GWT, just a better design language instead of Java. On the server side, Dart runs on top of the virtual machine (DARTVM), while on the browser side, it is converted to JavaScript for execution.

In syntax, Dart is like a combination of Scala and JavaScript. Dart has concepts of classes and interfaces, while type declarations are optional. In Dart, the type declaration of a variable is optional. The starting point for this design is to allow developers to choose the right type declaration strategy based on the different stages of development and the type of application. Using dynamic types is a good option in the initial prototyping phase or in the development of small applications, and static typing is a better approach for complex, modular, large-scale applications. Dart does not limit the choice of type declarations.

The following Dart code example shows the basic usage of optional types and class inheritance.

Class Animal {
 var legs;
 Animal (This.legs); Simplified construction Method
 Tellmylegs () {print (this.legs);}
}
Class Dog extends Animal {
 Dog (): Super (4); 
}
Main () {
 var dog = new Dog ();
 Dog.tellmylegs (); Output 4

}

It is worth mentioning the DART's concurrent programming model. The DART program is always single-threaded at run time, which is similar to JavaScript. Concurrency is accomplished through a similar actor isolation (isolate). Each spacer is a unit that runs concurrently, with its own memory and execution logic. The isolation body communicates through message passing. The isolation in Dart is very similar to web worker in HTML5.

Dart's goal is not to replace JavaScript or Java, but to move the platform. In Dart, in addition to the core library, there is a library of Dom APIs that can operate on the DOM.

Dart language as soon as it was released, a lot of things are at a relatively early stage. However, the related resources are open source code. Interested people can focus on the following links: Dart Language official website, dart source code and Dartforce website on Google code. The easiest way to do this is to download the dart virtual machine on Linux and the Windows platform (which does not support Windows XP) and write some dart code to experiment.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.