Friday, December 18, 2015

Features of Java Version

Features of Java 5

For-each loop
Varargs
Static Import
Autoboxing and Unboxing
Enum
Covariant Return Type
Annotation
Generics



Features of Java 6

Pluggable Annotation Processing API
Common Annotations
Java API for XML Based Web Services – 2.0
JAXB 2.0
Web Services Metadata
Streaming API for XML
XML Digital Signature
Java Class File Specification Update
Java Compiler API
JDBC 4.0
Scripting in the Java Platform


Features of Java 7 (55 New Features)

String in switch statement
Binary Literals
The try-with-resources
Caching Multiple Exceptions by single catch
Underscores in Numeric Literals
Diamond Operator
Fork and Join
New File System API (NIO 2.0)
Concurrency Utilities


Features of Java 8


  • Lambda expression − Adds functional processing capability to Java.

List primeNumbers = ReferenceToStaticMethod.testPredicate(numbers, a -> ReferenceToStaticMethod.isPrime(a));


  • Method references − Referencing functions by their names instead of invoking them directly. Using functions as parameter.

List primeNumbers = ReferenceToStaticMethod.testPredicate(numbers, ReferenceToStaticMethod::isPrime);


  • Default method − Interface to have default method implementation.
  • New tools − New compiler tools and utilities are added like ‘jdeps’ to figure out dependencies.
  • Stream API − New stream API to facilitate pipeline processing.
  • Date Time API − Improved date time API.
  • Optional − Emphasis on best practices to handle null values properly.
  • Nashorn, JavaScript Engine − A Java-based engine to execute JavaScript code.

Pessimistic and Optimistic concurrency control



There are 2 different concurrency control mechanisms
1. Pessimistic concurrency control
2. Optimistic concurrency control

What is the difference between optimistic and pessimistic concurrency control


Pessimistic concurrency involves locking rows to prevent other users from modifying the same data at the same time. Until the lock is released by the lock owner, no other users will be able to access that data. Pessimistic locking can very easily lead to performance bottle necks in an application.

Pessimistic Locking is when you lock the record for your exclusive use until you have finished with it. It has much better integrity than optimistic locking but requires you to be careful with your application design to avoid Deadlocks. To use pessimistic locking you need either a direct connection to the database (as would typically be the case in a two tier client server application) or an externally available transaction ID that can be used independently of the connection.




Optimistic concurrency does NOT involve locking rows when reading. Instead, this model checks if two users tried to update the same record at the same time. If that happens one user's changes are committed and the other user's changes are discarded and an exception will be thrown to notify the user.

Optimistic Locking is a strategy where you read a record, take note of a version number and check that the version hasn't changed before you write the record back.

If the record is dirty (i.e. different version to yours) you abort the transaction and the user can re-start it.

This strategy is most applicable to high-volume systems and three-tier architectures where you do not necessarily maintain a connection to the database for your session. In this situation the client cannot actually maintain database locks as the connections are taken from a pool and you may not be using the same connection from one access to the next.