what happened to sun.* packages - java

I don't find any references in JDK 7 documentation regarding sun.* packages.
Is it deprecated. But then what are the substitutes?
For eg: sun.reflect.*; is deprecated, so what are the options now?
It would be great if someone could post the deprecated packages and the new options available.
Note: I succeded in using them by setting access rules to all available.
What does this mean?

You have to use the java.lang.reflect package for reflection purposes.
See: http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/package-summary.html

The sun.reflect packages are not deprecated. They are for internal use by the JDK only. Oracle (formerly Sun) does not document the internal packages and does not guarantee that they will exist on all Java platform implementations (any vendor can make a Java platform implementation) nor that they will be the same in all versions of the standard Oracle Java platform implementation.
Oracle explains this on their website:
The sun.* packages are not part of the supported, public interface.
A Java program that directly calls into sun.* packages is not
guaranteed to work on all Java-compatible platforms. In fact, such a
program is not guaranteed to work even in future versions on the same
platform.

Related

Why are there differences between openJDK and oracleJDK

I have problems with the following method:
sun.security.x509.AuthorityKeyIdentifierExtension.getEncodedKeyIdentifier()
It exists in openJDK but it does not exist in oracleJDK. I always thought that except for some special cases regarding licensing those JDKs should be the same ...
While I can work around that issue, I fear there are other incompatibilities I might not be aware of.
Classes that are not part of the standard packages and classes that are deprecated can be not part of a jdk.
In your case you can try to solve the problem using the classes of the package javax.security.cert. Searching for it on google you can find some tutorials like this one.
Just to complete the answer is true that "generally" both compiled code comes from the same source code in the open jdk and in the oracle jdk. But oracle jdk and open jdk have different licences so there are also few little differences. Generally the differences are not related to the source of common classes, but to the presence or absence of classes or entire packages. As an example see the font library.
This is not the only difference. As you noted in your code also the security packages are different, because the open jdk added also the old sun version of x509 certificate classes and the oracle jdk not. There is no guarantee on what classes are included or not if they are not part of the standard packages. So if you have problems running your code on different jdk environments use only standard packages or explicitly import libraries as you need.
That class is not part of the public Java API and is therefore not guaranteed (or even likely) to exist in every JRE implementation, nor every release of the same provider's implementation.
If it's not part of the standard APIs, then you can't count on it.
Java Standard Edition 8 - all JDKs should provide these
Java Enterprise Edition 7 - some environments and libraries will provide these
While the OpenJDK and OracleJDK implementations happen to be very similar as they share a common history, they could diverge (or converge) in any private APIs or implementation details at any time, simply because they are separately-run projects.
Instead you should be using the appropriate implementation-agnostic APIs in java.security and javax.security for dealing with certificates.
Oracle JDK was previously called SUN JDK and that was before the takeover by Oracle. Earlier, it was the official proprietary implementation of the Java language. After the takeover it was named as Oracle JDK and Oracle’s team maintains the JDK.
OpenJDK is an open source implementation of the Java Standard Edition platform with contribution from Oracle and open Java community.
Actually, Oracle JDK’s build process builds from OpenJDK source code. So there is no major technical difference between Oracle JDK and OpenJDK.
Apart from the base code, Oracle JDK includes, Oracle’s implementation of Java Plugin and Java WebStart. Also includes third party closed source and open source components like graphics rasterizer and Rhino respectively.
How Oracle JDK and OpenJDK is kept in Sync:
All of the development and bug fixes happens in OpenJDK and then they are propagated to the Oracle JDK. Security fixes happens in private forest without public code reviews unlike general fixes, then they are pushed to Oracle JDK and then to OpenJDK.
more on http://javapapers.com/java/oracle-jdk-vs-openjdk-and-java-jdk-development-process/

java 8 doesn't support sun.awt? [duplicate]

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.

JavaFX package change betwwen jre 1.7 and 1.8

I am a bit confused. In Oracle jre 1.7, we have the package com.sun.webpane.webkit and in oracle JRE 1.8, we have com.sun.webkit (no webpane)
How are we supposed to handle such change so that an application works on both environment, any best practises ?
Thanks
You should not use com.sun classes in your code. Such classes are not part of the public API which is supported by Oracle or the OpenJDK for the JDK and JavaFX. Oracle makes no guarantees that com.sun classes will be backwards compatible between releases.
Oracle do guarantee that the public APIs, e.g., java.* and javafx.* will be backwards compatible between releases. So stick to using only supported public APIs in your code and your code should work much better across different Java releases.
For the particular control you are trying to utilize (the webkit implementation embedded in JavaFX), the public API for that is the javafx.scene.web.WebView API.

java smart card api support on IBM JRE

I know Oracle JRE has Java Smart API implementation. However, if I try to use IBM JRE, it doesn't even ship with javax.smartcardio package.
Who know whether IBM JRE provide javax.smartcardio package and implementation or not? If so, where to get it?
Who know whether IBM JRE provide javax.smartcardio package and implementation or not? If so, where to get it?
IBM knows if they provide that particular package. If they provide it, they will know where you can get it. I presume IBM. IBM used to ship with their own (badly designed, but working) smart card library however.
Note that JSR 268 specifies a package in the javax namespace. This means that implementation of the JSR is optional. You may be able to download and use a reference implementation from Oracle from their page. It states that the "RI" is available for free (although the testing kit costs about 50K$).

javax vs java package

What's the rationale behind the javax package? What goes into java and what into javax?
I know a lot of enterprise-y packages are in javax, but so is Swing, the new date and time api (JSR-310) and other J2SE packages.
Originally javax was intended to be for extensions, and sometimes things would be promoted out of javax into java.
One issue was Netscape (and probably IE) limiting classes that could be in the java package.
When Swing was set to "graduate" to java from javax there was sort of a mini-blow up because people realized that they would have to modify all of their imports. Given that backwards compatibility is one of the primary goals of Java they changed their mind.
At that point in time, at least for the community (maybe not for Sun) the whole point of javax was lost. So now we have some things in javax that probably should be in java... but aside from the people that chose the package names I don't know if anyone can figure out what the rationale is on a case-by-case basis.
I think it's a historical thing - if a package is introduced as an addition to an existing JRE, it comes in as javax. If it's first introduced as part of a JRE (like NIO was, I believe) then it comes in as java. Not sure why the new date and time API will end up as javax following this logic though... unless it will also be available separately as a library to work with earlier versions (which would be useful). Note from many years later: it (date and time API) actually ended up being in java after all.
I believe there are restrictions on the java package - I think classloaders are set up to only allow classes within java.* to be loaded from rt.jar or something similar. (There's certainly a check in ClassLoader.preDefineClass.)
EDIT: While an official explanation (the search orbfish suggested didn't yield one in the first page or so) is no doubt about "core" vs "extension", I still suspect that in many cases the decision for any particular package has an historical reason behind it too. Is java.beans really that "core" to Java, for example?
java packages are base, and javax packages are extensions.
Swing was an extension because AWT was the original UI API. Swing came afterwards, in version 1.1.
The javax namespace is usually (that's a loaded word) used for standard extensions, currently known as optional packages. The standard extensions are a subset of the non-core APIs; the other segment of the non-core APIs obviously called the non-standard extensions, occupying the namespaces like com.sun.* or com.ibm.. The core APIs take up the java. namespace.
Not everything in the Java API world starts off in core, which is why extensions are usually born out of JSR requests. They are eventually promoted to core based on 'wise counsel'.
The interest in this nomenclature, came out of a faux pas on Sun's part - extensions could have been promoted to core, i.e. moved from javax.* to java.* breaking the backward compatibility promise. Programmers cried hoarse, and better sense prevailed. This is why, the Swing API although part of the core, continues to remain in the javax.* namespace. And that is also how packages get promoted from extensions to core - they are simply made available for download as part of the JDK and JRE.
Javax used to be only for extensions. Yet later sun added it to the java libary forgetting to remove the x. Developers started making code with javax. Yet later on in time suns decided to change it to java. Developers didn't like the idea because they're code would be ruined... so javax was kept.
java.* packages are the core Java language packages, meaning that programmers using the Java language had to use them in order to make any worthwhile use of the java language.
javax.* packages are optional packages, which provides a standard, scalable way to make custom APIs available to all applications running on the Java platform.
Some packages like javax.swing were not included in java standard library at first. Sun company decided to consider them official and included them into the early versions of java as standard libraries or standard extensions.
By convention, all the standard extensions start with an X while they can get promoted to first-class over time like what happened for javax.swing.
All the javax packages were aimed to be experimental packages. By the time Swing was stable enough and ready to be moved to the java package there was too much code out there that they decided to leave it as it is to keep their commitment with backwards compatibility. This is explained in the book Learn Java in 21 days from the Sams editorial, written by Laura Lemay and Rogers Candedhead.

Categories