I have created the project using the JDK 1.4. Now I want to use JDK 1.6 version in my project.
for this what steps are required.Means I want to know the what changes is require in code to get a JDK 1.6 feature.Basically I am talking about the features that is added in JDK 1.6. If any one list out that changes it is very helpful.
Thanks in advance..............................
Better to see differences between 1.4 and 1.5 and then between 1.5 and 1.6.
You can check new features in each version on official web site, but below is a little chronology ...
JDK 1.0 (january 23, 1996) oak
Initial release
JDK 1.1 (february 19, 1997)
Retooling of the AWT event model
Inner classes added to the language
JavaBeans
JDBC
RMI
J2SE 1.2 (December 8, 1998) playground
This and subsequent releases through J2SE 5.0 were rebranded retrospectively Java 2 & version name "J2SE"
(Java 2 platform, Standard edition) replaced JDK to distinguish the base platform from
J2EE (java 2 platform, enterprise edition) and J2ME (java 2 platform, micro edition).
Strictfp keyword
Reflection
Swing api integration into the core classes
JVM equipped with a jit compiler
Java plug-in
Java IDL
An IDL implementation for corba interoperability
Collections Framework
J2SE 1.3 (may 8, 2000) kestrel
Hotspot jvm included
JavaSound
JNDI included in core libraries
Java platform debugger architecture (jpda)
RMI was modified to support optional compatibility with corba
J2SE 1.4 (february 6, 2002) merlin
assert keyword
Regular expressions
Exception chaining (allows an exception to encapsulate original lower-level exception)
Internet protocol version 6 (IPV6) support
Non-blocking nio (new input/output)
Logging API
Image i/o api for reading and writing images in formats like jpeg and png
Integrated XML parser and XSLT processor (JAXP)
Integrated security and cryptography extensions (JCE, JSSE, JAAS)
Java web start
J2SE 5.0 (september 30, 2004) tiger [originally numbered 1.5]
Generics: provides compile-time
(static) type safety for collections
and eliminates the need for most
typecasts (type conversion).
Metadata: also called annotations; allows language constructs such as classes and methods to be tagged with additional data, which can then be processed by metadata-aware utilities.
Autoboxing/unboxing: automatic conversions between primitive types (such as int) and primitive wrapper classes (such as integer).
Enumerations: the enum keyword creates a typesafe, ordered list of values (such as day.monday, day.tuesday, etc.). Previously this could only be achieved by non-typesafe constant integers or manually constructed classes (typesafe enum pattern).
Swing: new skinnable look and feel, called synth.
Var args: the last parameter of a method can now be declared using a type name followed by three dots (e.g. Void drawtext(string... Lines)). In the calling code any number of parameters of that type can be used and they are then placed in an array to be passed to the method, or alternatively the calling code can pass an array of that type.
Enhanced for each loop: the for loop syntax is extended with special syntax for iterating over each member of either an array or any iterable, such as the standard collection classesfix the previously broken semantics of the java memory model, which defines how threads interact through memory.
Automatic stub generation for rmi objects.
Static imports concurrency utilities in package java.util.concurrent.
Scanner class for parsing data from various input streams and buffers.
Assertions
StringBuilder class (in java.lang package)
Annotations
Java SE 6 (december 11, 2006) mustang
sun replaced the name "J2SE" with java se and dropped the ".0" from the version number.
Beta versions were released in february and june 2006, leading up to a final release that occurred on december 11, 2006.
The current revision is update 20.
Support for older win9x versions dropped.
Scripting lang support: Generic API for integration with scripting languages, & built-in mozilla javascript rhino integration
Dramatic performance improvements for the core platform, and swing.
Improved web service support through JAX-WS JDBC 4.0 support
Java compiler API: an API allowing a java program to select and invoke a java compiler programmatically.
Upgrade of JAXB to version 2.0: including integration of a stax parser.
Support for pluggable annotations
Many GUI improvements, such as integration of swingworker in the API, table sorting and filtering, and true swing double-buffering (eliminating the gray-area effect).
Java se 6 update 10
A major enhancement in terms of end-user usability.
Java Deployment Toolkit, a set of
javascript functions to ease the
deployment of applets and java web
start applications.
Java Kernel, a small installer including only the most commonly used jre classes. Enhanced updater.
Enhanced versioning and pack200 support: server-side support is no longer required.
Java quick starter, to improve cold start-up time.
Improved performance of java2D graphics primitives on windows, using direct3D and hardware acceleration.
A new Swing look and feel called NIMBUS and based on synth.
Next-generation java plug-in: applets now run in a separate process and support many features of web start applications.
Java se 6 update 12
This release includes the highly anticipated 64-bit java plug-in (for 64-bit browsers only), windows server 2008 support,
and performance improvements of java and JAVAFX applications.
...........
You can check in wikipedia till latest update.
To my opinion, the four most prominent enhancements since Java 1.4.2 are
Generics
enums
enhanced for-loop and
Annotations
There are a lot of additional classes and API enhancements, but if you want to 'upgrade' your code, I'd suggest to start your refactoring with using generics and replacing standard for loops by enhanced for loops. Both can be done without major code changes, clean up the code (you can delete a lot of lines of code) and improve readability. And using generics might reveal some hidden bugs ;)
I have created the project using the JDK 1.4. Now I want to use JDK 1.6 version in my project. For this what steps are required.
Actually, there is (almost) nothing that you need to start to make a JDK 1.4 application run using JDK 1.6. In nearly all cases, you simply need to recompile the code with the JDK 1.6 compiler and run it in a JDK 1.6 JVM. The only problems you are likely to encounter are:
If your code uses "enum" as an identifier, you will need to change it to something else. enum is a keyword starting in Java 1.5.
If your code directly depends on Sun proprietary / internal classes, you may need to deal with unannounced API changes.
You might find the certain official API classes or methods have been marked as deprecated.
There are a small number of changes in API implementations / behaviors with each release that may impact your application. These are typically highlighted in the document on upgrading.
Once you have got your application working on Java 1.6, you can then think about whether and when to start using the Java 1.5 language extensions, and the new / enhanced APIs in the class libraries.
Means I want to know the what changes is require in code to get a JDK 1.6 feature.
Almost no changes are required. But obviously, if you want or need to use a new feature you will need to change your code to do that.
Wikipedia has an summary of the most significant changes made across various Java releases.
UPDATE
As of May 2014, Java 6 has been "end-of-lifed", and Java 8 has been released for a month or so (with no significant early release number dramas). You should now be thinking about moving to at least Java 7, and probably Java 8.
The same principles apply. Recompile and run your regression tests, and you will most likely to be good to go. Then start learning all about the Java 8 language extensions.
What's new in JDK 6?
There are so many changes added in 6.0.
However all your 1.4 code will run smoothly.
For further reference about the version please see the following link
http://en.wikipedia.org/wiki/Java_version_history#Java_SE_6_.28December_11.2C_2006.29
Hope it helps.
The important details on 1.5 extensions are covered in these slides which provides also code examples.
There is a big difference in behaviour for volatile keyword in 1.5 - more along the lines of C# away from C++ behaviour. But it only makes the code safer. So no code changes.
Related
The compiler display warnings if you use Sun's proprietary Java classes. I'm of the opinion that it's generally a bad idea to use these classes. I read this somewhere. However, aside from the warnings are there any fundamental reasons why you should not use them?
Because they are internal APIs: they are subject to change in a undocumented or unsupported way and they are bound to a specific JRE/JDK (Sun in your case), limiting portability of your programs.
Try to avoid uses of such APIs, always prefer a public documented and specified class.
The JDK 6 Documentation includes a link titled Note About sun.* Packages. This is a document from the Java 1.2 docs, so references to sun.* should be treated as if they said com.sun.*
The most important points from it are:
The classes that Sun includes with the
Java 2 SDK, Standard Edition, fall
into package groups java.*, javax.*,
org.* and sun.*. All but the sun.*
packages are a standard part of the
Java platform and will be supported
into the future. In general, packages
such as sun.*, that are outside of the
Java platform, can be different across
OS platforms (Solaris, Windows, Linux,
Macintosh, etc.) and can change at any
time without notice with SDK versions
(1.2, 1.2.1, 1.2.3, etc). Programs
that contain direct calls to the sun.*
packages are not 100% Pure Java.
and
Each company that implements the Java
platform will do so in their own
private way. The classes in sun.* are
present in the SDK to support the Sun
implementation of the Java platform:
the sun.* classes are what make the
Java platform classes work "under the
covers" for the Sun Java 2 SDK. These
classes will not in general be present
on another vendor's Java platform. If
your Java program asks for a class
"sun.package.Foo" by name, it may fail
with ClassNotFoundError, and you will
have lost a major advantage of
developing in Java.
Try running your code with a non-Sun JVM and see what happens...
(Your code will fail with a ClassNotFound exception)
Yes, because nobody guarantees that these classes or API will be the same with the next Java release and I bet it's not guaranteed that those classes are available in Java versions from other vendors.
So you couple your code to special Java version and loose at least portability.
Sun's proprietary Java classes are part of their Java implementation not part of the Java API their use is undocumented and unsupported. Since they are internal they can be changed at any time for any reason that the team working the Sun JVM decides.
Also Sun's Java implementation is not the only one out there! Your code would not be able portable to JVMs from other vendors like Oracle/BEA and IBM.
Here is Oracle's answer: Why Developers Should Not Write Programs That Call 'sun' Packages
I recently had a case that showed a real-world problem you can hit when you use these classes: we had code that would not compile because a method it was using on a sun.* class simply did not exist in OpenJDK on Ubuntu. So I guess when using these classes you can no longer say things like 'this works with Java 5', because it will only work on a certain Java implementation.
Recently, we upgrade the Jdk version from 1.6 to 1.8 in one of my Java project. But there are some compilation or runtime errors, so I have to upgrade some libraries:
gradle: 1.9 to 1.10
spring: 3.x to 4.x
That because they are using some early versions of ASM, but which supports jdk 1.8 only from 5.x
Java said it is backward compatible, but why the original versions of libraries can't work with jdk 1.8 directly?
ASM is a pretty low-level library.
It processes Java byte-code directly (whereas a "normal" application would just let the JVM load its classes). The byte-code format changes from time to time, and newer versions cannot be used by an older JVM.
Messing with JDK or class format internals is not covered by backwards compatibility.
This is really an edge-case, and ASM is pretty much the only "popular" example.
More importantly (and more common) though are slight behavioural changes in system library code. So your application will technically still run, but do things differently. Most of the time, you want that, as it means improvement (for example better performance), but sometimes it can cause bugs for you.
For example:
switching to 64bit JVM can require more memory
changes in garbage collection can lead to unexpected pauses
inclusion of XML parsers into JDK proper requires changes to web application packaging or configuration
memory and runtime characterics of String#substring completely change in "minor" JDK revision
sorting a collection with a custom (incorrectly implemented) comparator suddenly throws exceptions it did not throw before
Calling Thread#stop(Throwable) (which was never a good idea and has been deprecated for a very long time) throws a UnsupportedOperationException since Java 8
Updated Unicode support changing sorting and casing behaviour for some strings
Changes in generics compilation
Inability to extend BitSet and implement Set due to new default methods
Changes in rounding behavior
And many others changes in API and BPI
But all-in-all the legacy app compatibility story is really good with Java. They have to keep it in mind with all their enterprise customers.
Because ASM is a tool that operates on the Java byte-code. And the byte-code format changed to introduce new features. As such, you had to upgrade the tool to support the new byte-code.
Note, that software compiled with an older version of the JDK does not always work with newer versions of Java. For example, enum was not a keyword in early versions of the JDK.
My old projects use Java 6 (1.6), and I don't know when I update (Java 7), they can run fine ?
There is an official list of known incompatibilities between java 6 and java 7 from Oracle (including descriptions of both binary and source-level incompatibilities in public APIs).
Also you can look at the independent analysis of API changes in the Java API Tracker project: http://abi-laboratory.pro/java/tracker/timeline/jre/
The report is generated by the japi-compliance-checker tool.
They should do, yes. Java has a reasonably strong history of backward compatibility. However, if these are in any way important projects you should still perform a thorough test pass before deploying anywhere production-like.
There shouldn't be any compatibility differences as the JVM is basically the same. However it is early days so there may be subtle differences which cause a problem which people are not yet aware of.
e.g. Eclipse looks at the Supplier in the java.exe on Windows and sets the command line arguments differently for different suppliers. It has a problem with Java 6 update 22 because Oracle wanted to change it from "Sun" to "Oracle". I believe this has been changed so it is "Oracle" in Java 7 (but still "Sun" for Java 6)
My point being, that if you write generic Java code, you shouldn't have a problem. However, if you are doing something a bit unusual, you are likely to need to re-test your application.
As was already stated backward compatibility is a very important aspect in new Java releases, so in general there should be no problems in switching to a newer Java version. In this case, however, Java 7 seems to have a few bugs in the new hotspot compiler optimizations. The Apache Software Foundation has issued a warning that their products Lucene and Solr are affected by these bugs.
http://lucene.apache.org/#28+July+2011+-+WARNING%3A+Index+corruption+and+crashes+in+Apache+Lucene+Core+%2F+Apache+Solr+with+Java+7
The affected loop optimizations can be switched off by starting java with -XX:-UseLoopPredicate.
AFAIS here, there's no Java 6 features which get deprecated in Java 7 so yes, your project should run fine.
Have there been incompatibilities between Java releases where Java source code/Java class files targeting Java version X won't compile/run under version Y (where Y > X) ?
By "Java release" I mean versions such as:
JDK 1.0 (January, 1996)
JDK 1.1 (February, 1997)
J2SE 1.2 (December, 1998)
J2SE 1.3 (May, 2000)
J2SE 1.4 (February, 2002)
J2SE 5.0 (September, 2004)
Java SE 6 (December, 2006)
House rules:
Please include references and code examples where possible.
Please try to be very specific/concrete in your answer.
A class that is being marked as #Deprecated does not count as a backwards incompatibility.
Compatibility notes for various versions:
Java 1.4
Java 5
Java 6
Java 7
Java 8
The first major hiccup I remember was the introduction of assert in Java 1.4. It affected a lot of JUnit code.
First of all, Sun actually considers all of the releases you mentioned (other than 1.0 of course) to be minor releases, not major ones.
I am unaware of any examples of binary incompatibility in that time. However, there have been some examples of source incompatibility:
In Java 5, "enum" became a reserved word; it wasn't before. Therefore, there were source files that used enum as an identifier that would compile in java 1.4 that wouldn't compile in java 5.0. However, you could compile with -source 1.4 to get around this.
Adding methods to an interface can break source compatibility as well. If you implement an interface, and then try to compile that implementation with a JDK that adds new methods to the interface, the source file will no longer compile successfully, because it doesn't implement all of the interface's members. This has frequently happened with java.sql.Statement and the other jdbc interfaces. The compiled forms of these "invalid" implementations will still work unless you actually call one of the methods that doesn't exist; if you do that, a MissingMethodException will be thrown.
These are a few examples I can recall off of the top of my head, there may be others.
The interface java.sql.Connection was extended from Java 1.5 to Java 1.6 making compilation of all classes that implemented this interface fail.
Every release of Swing broke something for us, from 1.3 through 1.6.
The JDBC issue has already been mentioned, but existing code worked.
From 1.5 to 1.6 there was a change in the behavior of Socket which broke the Cisco client.
Of course new reserved keywords were introduced.
The big one which I think was truely unforgivable on Sun's part was System.getenv(). It worked in 1.0, and then was deprecated and changed to throw an error on all platforms under the rather dubious justification that the Mac didn't have system environment variables. Then the Mac got system environment variables, so in 1.5 it was undeprecated and works. There is no reasonable justification for doing that. Return an empty set on a Mac (Swing has much bigger cross-platform issues if you want to care about that level of cross platform consistency) or even on all platforms.
I never agreed with them turning off the feature, but to change it to throw an error was just a pure breaking change that if they were going to do, they should have just removed the method entirely.
But, really from 1.0 to 1.1 they were less concerned about backwards compatability. For example, they dropped "private protected" as a modifier.
So the upshot is that every version changes enough to require close evaluation, that is why you still see many 1.4 questions here on SO.
The main one that I can think of is the introduction of new reserved words:
Java 1.3: strictfp
Java 1.4: assert
Java 5.0: enum
Any code that previously used these values as identifiers would not compile under a later version.
One other issue that I remember causing problems on a project that I worked on was that there was a change in the default visibility of JInternalFrames between 1.2 and 1.3. They were visible by default, but when we upgraded to 1.3 they all seemed to have disappeared.
Between 1.3 and 1.4 the interpretation of Long.parseLong(String) handled the empty string differently. 1.3 returns a 0 value, whereas 1.4 throws a NumberFormatException.
Recompiles aren't needed, but working code stopped working if it relied on the 1.3 behaviour.
The semantics of the memory model changed from 1.4 to 1.5. It was changed to allow besides other things double checked locking again. (I think volatile semantics were fixed.) It was broken.
The following will compile under Java 1.4 but not Java 1.5 or later.
(Java 5 introduced 'enum' as a keyword. Note: it will compile in Java 5 if the "-source 1.4" option is provided.)
public class Example {
public static void main(String[] args) {
String enum = "hello";
}
}
Obviously the naming convention of release names is not backwards-compatible.
JDK 1.0 (January 23, 1996)
JDK 1.1 (February 19, 1997)
J2SE 1.2 (December 8, 1998)
J2SE 1.3 (May 8, 2000)
J2SE 1.4 (February 6, 2002)
J2SE 5.0 (September 30, 2004)
Java SE 6 (December 11, 2006)
Java SE 6 Update 10, Update 12, Update 14, Update 16
Java SE 7 ??? JDK7?
(The list is from Wikipedia.)
Yet another example of java.sql breaking compatibility:
In 1.5 a compareTo(Date) method was added to java.sql.Timestamp. This method would throw a ClassCastException if the supplied Date was not an instance of java.sql.Timestamp. Of course, java.sql.Timestamp extends Date, and Date already had a compareTo(Date) method that worked with all Dates, so this meant that code that compared a Timestamp to a (non-Timestamp) Date would break at runtime in 1.5.
It's interesting to note that it appears that 1.6 seems to have fixed this problem. While the documentation for java.sql.Timestamp.compareTo(Date) still says "If the argument is not a Timestamp object, this method throws a ClassCastException object", the actual implementation says otherwise. My guess is that this is a documentation bug.
See report on API changes for the JRE class library here: http://abi-laboratory.pro/java/tracker/timeline/jre/
The report includes backward binary- and source-compatibility analysis of Java classes.
The report is generated by the japi-compliance-checker tool.
...
Another interesting analysis for JDK 1.0-1.6 you can find at Japitools JDK-Results page.
As Sean Reilly said, a new method can break your code. Besides the simple case that you have to implement a new method (this will produce a compiler warning) there is a worst case: a new method in the interface has the same signature as a method you do already have in your class. The only hint from the compiler is a warning that the #Override annotation is missing (Java 5 for classes, the annotation is supported for interfaces in Java 6 but optional).
I have not tried it but in theory this would work in Java 1.1 and break in Java 1.2. (More info here)
public class Test {
float strictfp = 3.1415f;
}
From personal experience, we had some AWT/Swing text fields embedded in a SWT_AWT frame in 1.5, that ceased to be editable after upgrading to 1.6.
We are stuck with Java2SE v1.4 till the end of 2010. That's really nasty, but we can't help it. What options do we have to use some of the new features already now? I can think of several ways like
changing the bytecode, e.g. using Retrotranslator or Retroweaver.
backport of libraries, e.g. Concurrent Backport, but this does not help for generics.
emulation of Java 5 features, e.g. checked Collections, Varargs with helper methods, etc.
changing source code by precompilation, stripping all 1.5 stuff before final compilation, e.g. using Declawer can do this.
I am most interested in very positive experience with it in production environments using Weblogic and "real" stuff.
Thanks for your answers. Here is the summary of all relevant answers and my own research.
Changing the bytecode: The Retros
This is done by the "retro"-tools: Retrotranslator, Retroweaver and JBossRetro. Retrotranslator seems to be the most mature
and active of them tool. These tools scan all classes and change the bytecode to remove Java 5 and 6 features. Many Java5 features are supported, some
by using 3rd party backport libraries. This option is most popular and there is some positive feedback from users. Experiments showed that it's working as
expected. See a short overview on developerworks.
Pro: You can develop entirely in Java 5, build modules and all kind of JARs. In the end you just transform all classes to Java 1.4 and package your EAR.
This is easily done with Retrotranslator's Maven integration (org.codehaus.mojo:retrotranslator-maven-plugin).
Con: Conservative environments do not allow changed bytecode to be deployed. The result of the retro-step is not visible to any coder and can't be approved.
The second problem is fear: There might be some cryptic production problem and the retro-code is another step that might be blamed for that. App-server vendors
might refuse help due to changed bytecode. So nobody wants to take responsibility to use it in production. As this is rather a policital than a technical
problem, so I see no solution. It has happened to us, so I was looking for further options :-(
Compiling Java5 to Java 1.4: jsr14
There is an unsupported option, javac -source 1.5 and -target jsr14 which compiles the Java5 source to valid Java 1.4 bytecode. Most features like
varargs or extended for loop are translated by the compiler anyway. Generics and annotations are stripped. Enums are not supported and I don't know
about autoboxing, as the valueOf methods were mostly introduced in Java5.
Con: Only byte code is translated, library usage is not changed. So you have to be careful not to use Java5 specific APIs (but could use Backports).
Further you have to build all modules at the same time, because for development time you propably want Java5 code with generic and annotation information.
So you have to build the entire project from scratch for Java 1.4 production.
Changing Source back to Java 1.4: Declawer
As answered in a related question, there is Declawer, a compiler extension, that works for generics and varargs, but not for enhanced for loop or
autoboxing. The generated source "is a little funky, but not too bad".
Pro: The generated source is available and can be reviewed. In worst case fixes can be made in this source. There is no "magic", because the source
is valid Java. Some people even use JAD (Java decompiler) to get the Java 1.4 source again. The output of Jad readable is readable if you compile with debug
information and don't use inner classes.
Con: Similar to -target jsr14, you need an extra step in the deployment. Same problems with libraries, too.
Changing Source back to Java 1.4: by hand
Several answers suggested doing it by hand. For an automatic, repeating build process this is of course not useful, but for one-time changes it's
reasonable. Just automate what is possible. Maybe look at Antlr for creating a home-grown conversion tool.
Backported Libraries:
The problem is, that Java5 also ships new libraries, that are not available in older JREs, see related question. Fortunately there are several
backported libraries that give you some functionality of Java5, but can't simulate language features, like generics.
Annotations, discussed at TSS
Concurrent
com.sun.net.httpserver (Java 6 to 5)
Gif writing (Java 6 to 5)
Start your own backport project ;-)
You might copy classes you need from the JDK or other libraries, but most likely they are related to other classes.
Emulating Java5 features in Java 1.4 code:
I was thinking about some things you might do to make your life easier and still staying with Java 1.4. The most important features are typesafe collections,
here are some ideas:
Instead of using generics you can create your own typesafe containers with some template.
Add a typesafe Iterator (which is no Iterator any more).
Add asList methods that allows 1,2,...,n arguments and an array of them (to simulate varargs).
Methods for varargs (converting 1,...,n arguments to arrays) and valueOf can be put in some helper class.
sourcecode precompilation, stripping
all 1.5 stuff before final compilation
and deployment. Are there any tools
which can do this?
Yes. They're called Retrotranslator or Retroweaver. Apart from Generics (which only exist for the compiler's sake anyway), you cannot simply "strip 1.5 stuff". Enums (and maybe also some other features) have to be replaced with functionally equivalent code. Which is exactly what those tools do.
You can code with JDK 1.5 features and target JDK 1.4 at compile time. See available Javac options. However, most libraries are now using JDK 1.5 code, so you'll be stuck with old libs.
It worth noting that while Java 1.4 has been EOL for some time. Java 5.0 will be EOL Oct 8th, 2009. If anyone is promising you Java 5.0 by 2010, I would ask why?!
To simulate annotations in java 1.4 you can use http://xdoclet.sourceforge.net/xdoclet/index.html