Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Saturday, August 2, 2014

Java Featurs


New features in Java SE 8

  • Lambda Expressions
  • Pipelines and Streams
  • Date and Time API
  • Default Methods
  • Type Annotations
  • Nashhorn JavaScript Engine
  • Concurrent Accumulators
  • Parallel operations
  • PermGen Error Removed
  • TLS SNI

New features in Java SE 7

  • Strings in switch Statement
  • Type Inference for Generic Instance Creation
  • Multiple Exception Handling
  • Support for Dynamic Languages
  • Try with Resources
  • Java nio Package
  • Binary Literals, underscore in literals
  • Diamond Syntax
  • Automatic null Handling

New features in Java SE 6

  • Scripting Language Support
  • JDBC 4.0 API
  • Java Compiler API
  • Pluggable Annotations
  • Native PKI, Java GSS, Kerberos and LDAP support.
  • Integrated Web Services.
  • Lot more enhancements.

  • Performance enhancements. Running a Java 5 app on Java 6 even without recompilation will run faster.
  • Java Scripting - it's not just BeanShell anymore. The new package javax.scripting allows access to about 20 different languages from within a running JVM - some are Java based and run in-VM, others spawn external scripting processes. But the access is unified so you don't have to know how it works. Just ask for a "Scripting Engine" and feed it your (or, your users'!) scripts.
  • XML SOAP-based Web Services (JAX-WS) supported directly in Java SE - just add a few annotations and go! Works with JAXB (Java API for XML Binding) which converts between objects and XML. JAX-WS and JAXB are also supported in Java EE 5.
  • JDBC4 (enhancements) and bundled Java Database based on Apache Derby (great for in-JVM testing of database code without deploying a database, similar to HyperSonic or HSQL).
  • Compiler API exposed, for those needing to generate and compile code on the fly.
  • Annotations plug-ins (added runtime support for annotation processing).
  • Many Swing GUI Improvements.
  • A Console class, with readLine (prompting) and readPassword() - reads in "no echo" mode.

New features in J2SE 5.0
  • Generics
  • Enhanced for Loop
  • Autoboxing/Unboxing
  • Typesafe Enums
  • Varargs
  • Static Import
  • Metadata (Annotations)
  • Instrumentation
New features in J2SE 1.4
  • XML Processing
  • Java Print Service
  • Logging API
  • Java Web Start
  • JDBC 3.0 API
  • Assertions
  • Preferences API
  • Chained Exception
  • IPv6 Support
  • Regular Expressions
  • Image I/O API




Wednesday, July 9, 2014

Java 7 Features




#1 Strings in switch

#2 try-with-resources statement

#3 More precise rethrow

#4 Multi-catch

#5 Binary integral literals
With Java 7, you can now create numerical literals using binary notation using the prefix “0b”

int n = 0b100000;
System.out.println("n = " + n);

Output

n = 32

#6 Underscores in numeric literals

#7. Improved type inference for generic instance creation
With Java 5 and 6
Map> retVal = new HashMap>();

Note that the full type is specified twice and is therefore redundant. Unfortunately, this was a limitation of Java 5 and 6.

With Java 7
Java 7 tries to get rid of this redundancy by introducing a left to right type inference. You can now rewrite the same statement by using the <> construct.
Map> retVal = new HashMap<>();


#8 More new I/O APIs for the Java platform (NIO.2)
a) Package
The most important package to look for is java.nio.file. 
b) The java.nio.file.Path interface
Old Way
File file = new File("hello.txt");
System.out.println("File exists() == " + file.exists());

New Way
Path path = FileSystems.getDefault().getPath("hello.txt");
System.out.println("Path exists() == " + Files.exists(path));

c) The java.nio.file.Files class
d) WatchService API



Tuesday, May 6, 2014

10 Unknown Features in Java 8




1. Default Methods
A new addition to the Java language, you can now add method bodies to interfaces (called default methods). These methods are implicitly added to every class which implements the interface.
This enables you to add functionality to existing libraries without breaking code. That’s definitely a plus. The flip side is that this seriously blurs the line between an interface, which is meant to serve as a contract, and a class which serves as its concrete implementation. In the right hands this can be an elegant way to make interfaces smarter, avoid repetition and extend libraries. In the wrong hands, we'll soon be seeing interface methods querying this and casting it to a concrete type. Shivers….
2. Process Termination Launching an external process is one of those things you do half-knowing you'll come back to debug it when the process crashes, hangs or consumes 100% CPU. The Process class now comes equipped with two new methods to help you take control of unruly processes.
The first one, isAlive(), lets you easily check if the process is still up without having to wait for it. The second and more powerful one is destroyForcibly() which lets you forcibly kill a process which has timed-out or is no longer necessary.
3. StampedLocks
Now here’s something to get excited about. Nobody likes to synchronize code. It's a sure-fire way of reducing your app's throughput (especially under scale), or worse - cause it to hang. Even so, sometime you just don't have a choice.
There are plenty of idioms to synchronize multi-threaded access to a resource. One of the most venerated ones is ReadWriteLock and its associated implementations. This idiom is meant to reduce contention by allowing multiple threads to consume a resource while only blocking for threads that manipulate it. Sounds great in theory, but in reality this lock is sloooow, especially with a high number of writer threads.
This got so bad that Java 8 is introducing a brand new RWLock called StampedLock. Not only is this lock faster, but it also offers a powerful API for optimistic locking, where you can obtain a reader lock at a very low cost, hoping that no write operation occurs during the critical section. At the end of the section you query the lock to see whether a write has occurred during that time, in which case you can decide whether to retry, escalate the lock or give up.
This lock is a powerful tool and deserves a complete post by itself. I'm giddy with excitement about this new toy - well done!
4. Concurrent Adders
This is another little gem for anyone working on multi-threaded apps. A simple and efficient new API for reading and writing to counters from multiple threads, in a way that’s even faster than using AtomicIntegers. Pretty darn cool!
5. Optional Values
Oh, NullPointers, the bane of all Java developers. Maybe the most popular of all exceptions, this has been around since the dawn of time. Or at least 1965.
Borrowing from Scala and Haskell, Java 8 has a new template named Optional for wrapping references that may be null. It’s by no means a silver bullet to end nulls, but more a means for an API designer to signify at the code level (vs. the documentation) that a null value may be returned or passed to a method, and the caller should prepare for it. As such, this will only work for new APIs, assuming callers do not let the reference escape the wrapper where it can be unsafely dereferenced.
I have to say I'm pretty ambivalent about this feature. On one hand, nulls remain a huge problem, so I appreciate anything done on that front. On the other hand I'm fairly skeptical this'll succeed. This is because employing Optional requires continuing company-wide effort, and with little immediate value. Unless enforced vigorously, chances are this will be left at the side of the road.
6. Annotate Anything
Another small improvement to the Java language is that annotations can now be added to almost everything in your code. Previously, annotations could only be added to things like class or method declarations. With Java 8 annotations can be added to variable and parameter declarations, when casting to a value to specific type, or even when allocating a new object. This is part of a concentrated effort (along with improvements to the Java doc tools and APIs) to make the language more friendly towards static analysis and instrumentation tools (e.g FindBugs). It's a nice feature, but much likeinvokeDynamic introduced in Java 7, its real value will depend on what the community does with it.
7. Overflow Operations
Now here’s a set of methods which should have been a part of the core library from day one. A favorite hobby of mine is to debug numeric overflows when ints exceed 2^32, and go on to create the nastiest and most random of bugs (i.e. “how did I get this weird value?”).
Once again, no silver bullet here, but a set of  functions to operate on numbers that throw when overflow in a less forgiving way than your standard +/ * operator which implicitly overflow. If it was up to me I'd have this be the default mode for the JVM, with explicit functions that allow arithmetic overflow.
8. Directory Walking
Iterating the contents of a directory tree has long been one of those go-to google searches (in which case you should probably be using Apache.FileUtils). Java 8 has given the Files class a face-lift, with ten new methods. My favorite one is walk() which creates a lazy stream (important for large file systems) to iterate the contents of a directory structure.
9. Strong Random Generation
There’s no shortage of talk nowadays about password and key vulnerability. Programming security is a tricky business and prone to mistakes. That’s why I like the new SecureRandom.getinstanceStrong()method which automatically picks the strongest random generator available to the JVM. This reduces the chances of you failing to get, or defaulting to a weak generator, which will make keys and encrypted values more susceptible to hacking.
10. Date.toInstant()
Java 8 introduces a complete new date time API. This is fairly understandable, as the existing one isn't very good. Joda has essentially been the go-to Java date time API for years now. Still, even with the new API one big problem remains - there’s a TON of code and libraries using the old API.
And we all know they're here to stay. So what do you do?
For this Java 8 has done something pretty elegant, adding a new method to the Date class called toInstant() which converts it to the new API. This enables you to make a quick jump to the new API, even when working with code that uses the old Date API (and will continue to do so in the foreseeable future).


source:dzone

Tuesday, March 25, 2014

New in Java 8


These changes include:
    • Lambda Expressions, a new language feature, has been introduced in this release. They enable you to treat functionality as a method argument, or code as data. Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.
    • Method references provide easy-to-read lambda expressions for methods that already have a name.
    • Default methods enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces.
    • Repeating Annotations provide the ability to apply the same annotation type more than once to the same declaration or type use.
    • Type Annotations provide the ability to apply an annotation anywhere a type is used, not just on a declaration. Used with a pluggable type system, this feature enables improved type checking of your code.
    • Improved type inference.
    • Method parameter reflection.
    • Classes in the new java.util.stream package provide a Stream API to support functional-style operations on streams of elements. The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations.
    • Performance Improvement for HashMaps with Key Collisions
  • Compact Profiles contain predefined subsets of the Java SE platform and enable applications that do not require the entire Platform to be deployed and run on small devices.
    • Client-side TLS 1.2 enabled by default
    • New variant of AccessController.doPrivileged that enables code to assert a subset of its privileges, without preventing the full traversal of the stack to check for other permissions
    • Stronger algorithms for password-based encryption
    • SSL/TLS Server Name Indication (SNI) Extension support in JSSE Server
    • Support for AEAD algorithms: The SunJCE provider is enhanced to support AES/GCM/NoPadding cipher implementation as well as GCM algorithm parameters. And the SunJSSE provider is enhanced to support AEAD mode based cipher suites. See Oracle Providers Documentation, JEP 115.
    • KeyStore enhancements, including the new Domain KeyStore typejava.security.DomainLoadStoreParameter, and the new command option -importpassword for the keytool utility
    • SHA-224 Message Digests
    • Enhanced Support for NSA Suite B Cryptography
    • Better Support for High Entropy Random Number Generation
    • New java.security.cert.PKIXRevocationChecker class for configuring revocation checking of X.509 certificates
    • 64-bit PKCS11 for Windows
    • New rcache Types in Kerberos 5 Replay Caching
    • Support for Kerberos 5 Protocol Transition and Constrained Delegation
    • Kerberos 5 weak encryption types disabled by default
    • Unbound SASL for the GSS-API/Kerberos 5 mechanism
    • SASL service for multiple host names
    • JNI bridge to native JGSS on Mac OS X
    • Support for stronger strength ephemeral DH keys in the SunJSSE provider
    • Support for server-side cipher suites preference customization in JSSE
    • The new Modena theme has been implemented in this release. For more information, see the blog at fxexperience.com.
    • The new SwingNode class enables developers to embed Swing content into JavaFX applications. See the SwingNode javadoc and Embedding Swing Content in JavaFX Applications.
    • The new UI Controls include the DatePicker and the TreeTableView controls.
    • The javafx.print package provides the public classes for the JavaFX Printing API. See the javadoc for more information.
    • The 3D Graphics features now include 3D shapes, camera, lights, subscene, material, picking, and antialiasing. The new Shape3D (BoxCylinderMeshView, and Spheresubclasses), SubSceneMaterialPickResultLightBase (AmbientLight andPointLight subclasses) , and SceneAntialiasing API classes have been added to the JavaFX 3D Graphics library. The Camera API class has also been updated in this release. See the corresponding class javadoc for javafx.scene.shape.Shape3D,javafx.scene.SubScenejavafx.scene.paint.Material,javafx.scene.input.PickResultjavafx.scene.SceneAntialiasing, and theGetting Started with JavaFX 3D Graphics document.
    • The WebView class provides new features and improvements. Review Supported Features of HTML5 for more information about additional HTML5 features including Web Sockets, Web Workers, and Web Fonts.
    • Enhanced text support including bi-directional text and complex text scripts such as Thai and Hindi in controls, and multi-line, multi-style text in text nodes.
    • Support for Hi-DPI displays has been added in this release.
    • The CSS Styleable* classes became public API. See the javafx.css javadoc for more information.
    • The new ScheduledService class allows to automatically restart the service.
    • JavaFX is now available for ARM platforms. JDK for ARM includes the base, graphics and controls components of JavaFX.
    • The jjs command is provided to invoke the Nashorn engine.
    • The java command launches JavaFX applications.
    • The java man page has been reworked.
    • The jdeps command-line tool is provided for analyzing class files.
    • Java Management Extensions (JMX) provide remote access to diagnostic commands.
    • The jarsigner tool has an option for requesting a signed time stamp from a Time Stamping Authority (TSA).
      • The -parameters option of the javac command can be used to store formal parameter names and enable the Reflection API to retrieve formal parameter names.
      • The type rules for equality operators in the Java Language Specification (JLS) Section 15.21 are now correctly enforced by the javac command.
      • The javac tool now has support for checking the content of javadoc comments for issues that could lead to various problems, such as invalid HTML or accessibility issues, in the files that are generated when javadoc is run. The feature is enabled by the new -Xdoclint option. For more details, see the output from running "javac -X". This feature is also available in the javadoc tool, and is enabled there by default.
      • The javac tool now provides the ability to generate native headers, as needed. This removes the need to run the javah tool as a separate step in the build pipeline. The feature is enabled in javac by using the new -h option, which is used to specify a directory in which the header files should be written. Header files will be generated for any class which has either native methods, or constant fields annotated with a new annotation of type java.lang.annotation.Native.
      • The javadoc tool supports the new DocTree API that enables you to traverse Javadoc comments as abstract syntax trees.
      • The javadoc tool supports the new Javadoc Access API that enables you to invoke the Javadoc tool directly from a Java application, without executing a new process. See the javadoc what's new page for more information.
      • The javadoc tool now has support for checking the content of javadoc comments for issues that could lead to various problems, such as invalid HTML or accessibility issues, in the files that are generated when javadoc is run. The feature is enabled by default, and can also be controlled by the new -Xdoclint option. For more details, see the output from running "javadoc -X". This feature is also available in the javac tool, although it is not enabled by default there.
    • Unicode Enhancements, including support for Unicode 6.2.0
    • Adoption of Unicode CLDR Data and the java.locale.providers System Property
    • New Calendar and Locale APIs
    • Ability to Install a Custom Resource Bundle as an Extension
    • For sandbox applets and Java Web Start applications, URLPermission is now used to allow connections back to the server from which they were started. SocketPermissionis no longer granted.
    • The Permissions attribute is required in the JAR file manifest of the main JAR file at all security levels.
  • Date-Time Package - a new set of packages that provide a comprehensive date-time model.
    • Pack200 Support for Constant Pool Entries and New Bytecodes Introduced by JSR 292
    • JDK8 support for class files changes specified by JSR-292, JSR-308 and JSR-335
    • New SelectorProvider implementation for Solaris based on the Solaris event port mechanism. To use, run with the system property java.nio.channels.spi.Selectorset to the value sun.nio.ch.EventPortSelectorProvider.
    • Decrease in the size of the /jre/lib/charsets.jar file
    • Performance improvement for the java.lang.String(byte[], *) constructor and thejava.lang.String.getBytes() method.
    • Parallel Array Sorting
    • Standard Encoding and Decoding Base64
    • Unsigned Arithmetic Support
    • The JDBC-ODBC Bridge has been removed.
    • JDBC 4.2 introduces new features.
  • Java DB
    • JDK 8 includes Java DB 10.10.
    • The class java.net.URLPermission has been added.
    • In the class java.net.HttpURLConnection, if a security manager is installed, calls that request to open a connection require permission.
    • Classes and interfaces have been added to the java.util.concurrent package.
    • Methods have been added to the java.util.concurrent.ConcurrentHashMap class to support aggregate operations based on the newly added streams facility and lambda expressions.
    • Classes have been added to the java.util.concurrent.atomic package to support scalable updatable variables.
    • Methods have been added to the java.util.concurrent.ForkJoinPool class to support a common pool.
    • The java.util.concurrent.locks.StampedLock class has been added to provide a capability-based lock with three modes for controlling read/write access.
  • Java XML - JAXP
    • Hardware intrinsics were added to use Advanced Encryption Standard (AES). TheUseAES and UseAESIntrinsics flags are available to enable the hardware-based AES intrinsics for Intel hardware. The hardware must be 2010 or newer Westmere hardware. For example, to enable hardware AES, use the following flags:
      -XX:+UseAES -XX:+UseAESIntrinsics
      
      To disable hardware AES use the following flags:
      -XX:-UseAES -XX:-UseAESIntrinsics
      
    • Removal of PermGen.
    • Default Methods in the Java Programming Language are supported by the byte code instructions for method invocation.




Summary:
  • Lambda expressions: a new language feature  that enables you to treat functionality as a method argument, or code as data.
  • Other significant enhancements and changes to the Java language and standard libraries including default methods, the new java.util.stream package, and the Date-Time API.
  • Compact Profiles contain predefined subsets of the Java SE platform and enable applications that do not require the entire Platform to be deployed and run on small devices.
  • Security enhancements include updates to the Java Cryptography Architecture; limited doPrivileged, a mechanism that enables code to assert a subset of its privileges; SSL/TLS Server Name Indication (SNI) Extension; and keystore enhancements.
  • JavaFX documentation has been updated for this release.
  • A new JavaScript engine, Nashorn, is included in JDK 8.
  • Java Mission Control 5.3 is included in JDK 8.
  • Decommission of the JVM Permanent Generation space and replaced by the Metaspace.