J2SE 5: New wine in new bottle with old corkMarch 15th, 2005 J2SE stands for Java 2 Standard Edition. The 2 stands for version 2 of the platform.
Java Quiz: Why StringBuilder Should be Used Instead of StringBuffer?August 23rd, 2008 First tell me what is the best way to concatenate large number of String objects? Is it a + b?
Most Java developers know not to use a + b (+ operator) because of huge performance problems, they use StringBuffer instead. In fact I did some tests in the past which confirms this folklore.
Java SE Goes Beta (Feature Complete). Download Now.February 17th, 2006 Java SE 6 Beta offers the first feature complete version of next major release of the Java SE platform. Sun expects to ship the final release of Java SE 6 in the fall of 2006.
Three Free Notable Java Software / APISeptember 8th, 2005 GMail API for Java
GMailer API for Java (g4j) is set of API that allows Java programmer to communicate to GMail. With G4J programmers can made Java based application that based on huge storage of GMail.
How To Pass Command Line Arguments To Ant Task / ScriptAugust 17th, 2008 Ant is a popular, high quality Java based build and deployment tool from Apache Foundation. You can invoke Java programs in ant using the java task.
Java EE 6 HighlightsMay 6th, 2008 The key features of Java EE 6 (Java Enterprise Edition version 6) are:
Modular Platform - Java EE 6 introduces profiles targeted for particular segment of users like web developers or mobile developers. Java Profiles allows you to select Java EE 6 features to be included in a profile.
Java Popularity Statistics (from JavaOne 2008)May 7th, 2008 Sun revealed the following statistics about Java at JavaOne 2008:
1. 90% of Personal Computers on Internet have Java
2.
Gripe: Java blog aggregator: javablogs.comFebruary 16th, 2004 Few Gripes on Java.blogs:
After few days with java.blogs I realized I don't want a few things. For example I am not interested in knowing anything about IDEA releases.
Java Blogger's in IndiaDecember 11th, 2005 I want to create a list of Java blogger's in India or of Indian origin. If you are one please state so with your url in the comment below.
How to install / enable Java Plugin / Applets in Firefox on CentOS 5September 28th, 2009 CentOS comes with OpenJava JRE installed. However that doesn't provide the required libraries to run Java from browsers (read: applets).
Top 10 Java LiesMarch 6th, 2006 Here are the top ten Java lies I have heard over the years. Feel free to add yours in the comments.
Java Framework To Create Java FrameworksJanuary 26th, 2006 I have seen way too many java frameworks, way beyond my limits of tolerance. And I have found a perfect solution.
How To Solve Apache Ant java Task Execution ErrorsJuly 26th, 2006 I have seen myriad errors when executing java task. For example I have seen: javax.xml.parsers.FactoryConfigurationError?: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl? not found when executing the java task in jdk1.5.0
The problems with debugging the errors is that the commandline used by java task is not visible, even in verbose mode.
Ruby on Java = JRuby - Project to WatchDecember 18th, 2005 JRuby is a project to watch for. It implements Ruby on Java virtual machine.
Back To Java...July 29th, 2008 I am on to create a cool (really really cool) application with Java back-end, distributed processing and all. Expect to see lots of Java tech tips and articles in the coming days.
March 15th, 2005 at 6:31 pm
Hi,
Thank you very much for this information.
Mind if I extend my question here itself? Actually, I load my classes through URLClassLoader. And generally I am loading JAR files through URLClassLoader. Now I want this JAR file to be unloaded. Can I extend your logic to URLClassLoader for JAR files too?
March 15th, 2005 at 6:33 pm
Thank you.
March 15th, 2005 at 6:41 pm
Actually, the JSP first-load time is not ONLY due to the class being reloaded, (loading a class from the bytecode doesn’t take that long, if it did Java would be a lot slower than it is ;-). A more significant amount of time is spent generating the bytecode, as a change to the JSP source has to be converted first into Java source, and then in to byte-code, which can then be loaded by the ClassLoader. So, add two parse/generate cycles to one byte load…
March 16th, 2005 at 4:28 pm
If you are interested in seeing an interesting twist on dynamic reloading of classes, check out the source in our plugin engine at http://www.platonos.org. We not only load plugins, each with their own classloader, but we are now adding the ability to dynamically unload portions of a plugin that are dependent on another.
As it turns out, when plugin A provides an interface that plugin B provides an implementation for, the plugin B ClassLoader (through delegation to A’s classloader) holds a lock on the implementation Class itself. Even after we null out the classloader in plugin A (if we are trying to unload A), B’s classloader keeps a lock on A because of the interface Class that B’s implementation class keeps a lock on. Basically you have this:
interface pluginAInterface{}
class pluginBImpl implements pluginAInterface{}
each is loaded by a different classloader. When used, plugin B’s classloader sees that pluginBImpl implements pluginAInterface. It starts in plugin B’s classloader looking for it. It can’t find it there (because the pluginAInterface Class is in plugin A’s classloader classpath). The plugin engine delegates the lookup to plugin A’s classloader to find the byte code for this pluginAInterface Class. It’s found there, so plugin A’s classloader “loads” the bytecode, but plugin B’s classloader “sees” the bytecode by initially delegating to A to find it. Once found, a classloader’s built in cache stores the classloader:class pointer (meaning, the classloader AND the class make up a sort of “key” as a pointer to the actual bytecode in memory) so it no longer needs to delegate to A. BUT, the big problem is that the pluginBImpl Class maintains it’s own list of interfaces it implements, primarily their Class reference. The bad thing about this is there is no way to set this to null at runtime!
So our trick is to use a second classloader within a plugin to allow each interface implemented by another plugin to have it’s own classloader so we can discard that one to get reloading/unloading to work.
It’s a bit tricky, but it does the trick. Probably still more hidden issues we haven’t come across yet.
March 18th, 2005 at 3:00 am
@Goldy Lukka Yes. You should be able to. However I haven’t used URLClassLoader in this fashion, so I am not sure if it has any hard-to-remove references. I guess a spike solution is in order
BTW: I enjoy your site.
@Kevin Thanks for the very informative comment.
March 19th, 2005 at 2:54 am
Goldy Lukka,
The trick to using URLClassLoader to reload or unload .jar files is making sure that NO other code is referencing any of the classes within the .jar file. Dependencies are difficult to manage. We have gone to great pains to try to resolve unload/reload with the issue of plugins depending on one another. We still have problems in many cases making it happen. In some cases, developers of plugins just have to be aware that if they want to make their plugin as dynamic as possible, they really have to develop it in such a way that they properly clean up any references they have on other plugin classes.
If your .jar file is just adding implementations to say, a core applications interface API, you should be able to easily remove it. As we discovered, an implemting class keeps a reference (lock) on the interface it implements. So the class in your .jar file would keep the ref to the interface, which is ok, you simply null it out and/or null the classloader that loaded the .jar and you are fine. If however the .jar file provides interfaces that other classes (maybe from other .jar files) make use of, that becomes more difficult. Any class outside of the classloader that loaded the .jar file making use of any class from inside the loaded .jar has to also be unloaded. Again, referring to our engine, it starts a chain reaction of unloading events that can be difficult to manage. We solved the problem by having two classloader instances per plugin. One that handles the interfaces that are implemented by other plugin classes, and one for the rest of the classes. It’s not pretty, but thus far it works. We are still experimenting to make this a better process.
March 22nd, 2005 at 7:35 pm
Kevin,
It’s true that you can’t null the reference to the interface class ( Class#getInterfaces() ), if this was possible it would mean that you remove the interface in the byte code at runtime, from:
public class MyTestImpl implements TestImpl
{
}
to
public class MyTestImpl
{
}
The same is true for superclasses.
March 23rd, 2005 at 6:23 pm
it’s great information that how plugins are works. Can i have the simplest possible code of custom class loader. Ultimately the custom class loader is nees to be loaded by the default classloader or not? If so then will i be able to see to classloader in the callgraph of such kind of program?
April 1st, 2005 at 6:02 am
@Sandip Why not use the URLClassLoader? Also there is a sample ClassLoader code provided in Java Tutorials.
September 11th, 2006 at 11:39 am
Thanks for the information.
I read something on the internet which I think is important for some people here:
Two classes are not of the same package if they are loaded by different ClassLoader objects!
Let’s say you have a package with two classes, one is public and the other package-private. These should be loaded by the same ClassLoader(or subclass) object. If you don’t you get a runtime error when the public class tries to access the package-private class.
So if you planned to make a new ClassLoader object for every class, consider using one ClassLoader object for each package. The other option is to make all classes public.