Welcome to Software Ninja blog - your ultimate destination for mastering software development and data manipulation. Explore cutting-edge techniques and expert tips to sharpen your coding skills and become a data virtuoso. Let's embark on a journey of discovery together!
Monday, December 17, 2007
Tuesday, December 11, 2007
Emacs Using 100% CPU
(custom-set-variables
'(semantic-idle-scheduler-idle-time 200))
Emacs Using 100% CPU: "quick fix is to set the Emacs variable semantic-idle-scheduler-idle-time to a large number (by default it is 2 seconds) so that the idle scheduler does not kick in (which is what is using all the CPU)!"
Book Review: Effective Java
Thursday, December 6, 2007
Mylyn User Guide - Eclipsepedia
Developer's Guide - Google Chart API - Google Code
Wednesday, December 5, 2007
You WILL experience the Day of the Ninja -- December 5
Tuesday, December 4, 2007
Springframework Presentations
Friday, October 26, 2007
Free XML editors
Thursday, October 18, 2007
visualvm: Introduction to VisualVM
Tuesday, October 16, 2007
Which class or resource is being lodaed?
System.out.println(this.getClass().getClassLoader().getResource("applicationContext.xml"));
You can also find class files. To find java.lang.Object use
System.out.println(this.getClass().getClassLoader().getResource("java/lang/Object.class"));
The result is something like:
jar:file:/C:/Program%20Files/Java/j2sdk1.4.2_14/jre/lib/rt.jar!/java/lang/Object.class
Notice how the JRE version is in the output.
Retrotranslator
Monday, October 8, 2007
Using Maven to create a one-jar executable jar.
Friday, September 28, 2007
ASP.NET caching based on a cookie
<%@ OutputCache Duration="600" VaryByCustom="StyleSheet" %>
and you have declare the following method in which we access the Cookie and pass the value back
public override string GetVaryByCustomString(System.Web.HttpContext context, string custom) {
if (custom == "StyleSheet"){
return "StyleSheet=" + this.Request.Cookies["StyleSheet"];
}
}
Given this method, you should be able to cache based not only on cookies, but any other string value or anything that can be converted into a string.
Monday, August 20, 2007
What have they done with com/sun/corba/se/connection/ORBSocketFactory?
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/corba/se/connection/ORBSocketFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at weblogic.corba.j2ee.naming.ORBHelper.(ORBHelper.java:113)
at weblogic.corba.client.ClientORBInitializer.initialize(ClientORBInitializer.java:84)
at weblogic.jndi.WLInitialContextFactory.(WLInitialContextFactory.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.(InitialContext.java:197)
at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:105)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:83)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
at com.ihc.phc.monitor.JndiMonitor.getStatus(JndiMonitor.java:29)
at com.ihc.phc.monitor.Monitor.getAllStatus(Monitor.java:21)
at com.ihc.phc.monitor.Main.main(Main.java:12)
Oh how pleasant. This error has been report as bug 6340079 which states:
Reason for compilation errors:
------------------------------
The following packages are not there on jdk1.5.0 but they are in j2sdk1.4.2 1.com.sun.corba.se.connection.* 2.com.sun.corba.se.internal.core.*How was this problem resolved? Remove the offending unit test of course. There is also another thread on the subject stating basically the same thing but without helpful suggestions. The only helpful suggestion seems to have been to try the wlclient jar from a newer version of the WebLogic server (9 or 10). I tried that and now the ClassDefNotFoundError goes away. Now there is a runtime error:
[java.rmi.MarshalException: CORBA MARSHAL 0 Maybe; nested exception is: org.omg.CORBA.MARSHAL: vmcid: 0x0 minor code: 0 completed: Maybe]You know, indecision is bad enough in humans, I do not need it in computers. Maybe it worked? Slight chance I would say. Ok, looks like the newer (9.1) wlclient.jar is not compatible with older (8.1) weblogic instances. Funny thing is, the weblogic.jar with all its bloat works. I wonder ..... Looks like the weblogic.jar has it's own version of the ORBSocketFactory and that is does not use the sun one. Oh bother! Guess it is back to the bloated weblogic.jar for me.
Thursday, August 16, 2007
Watch "Advanced Topics in Programming Languages: Java Puzzlers, Episode VI"
Advanced Topics in Programming Languages: Java Puzzlers, Episode VI 1 hr 13 min 49 sec - Jul 23, 2007 Average rating: (23 ratings) Description: Google Tech Talks July 23, 2007 ABSTRACT Java Puzzlers, Episode VI: The Phantom-Reference Menace/Attack of the Clone/Revenge of the Shift. Josh Bloch and special guest star Bill Pugh present yet another installment in the continuing saga of Java Puzzlers, consisting of eight more programming puzzles for your entertainment and enlightenment. The game show format keeps you on your toes while the puzzles teach you about the subtleties of the Java programming language and its core libraries. Anyone with a working knowledge of the language will be able to understand the puzzles, but even the most seasoned veterans will be challenged. The lessons you take from this session are directly applicable to your programs and designs. Some of the jokes may even be funny. If you loathed Episodes I--V, you'll detest Episode VI. Come early, because overripe fruit will, as usual, be given to the first 50 attendees. This is a repeat of a talk given at Google in May and at JavaOne 2007.
Want to see more cool videos? Go to video.google.com/
Think you have an even cooler video? Add it at video.google.com/videouploadform
If you're having trouble watching the video, try copying the following URL into your browser: http://video.google.com/videoplay?docid=9214177555401838409&pr=goog-sl
Monday, August 13, 2007
LISP Cycles
Monday, June 18, 2007
Felipe Ortiz's Blog: The Last JavaOne 2007 Wrap-up
Tuesday, June 5, 2007
Linux.com | GNU Emacs 22 finally released
Friday, June 1, 2007
Open Source Technical Support by OpenLogic
Thursday, May 24, 2007
JavaOne Online Technical Sessions - Java EE
Wednesday, May 23, 2007
JPC - Computer Virtualization in Java
JavaOne 2007 BOF 9529: Hudson
Slides For JavaOne BOF-2958 Dynamic Scripting BOF — PushToTest - The Open-Source SOA Governance and Test Automation Company
JHat update jar
JavaOne 2007 - BOF-8847: Developing Components for Java Business Integration: Binding Components and Service Engines
JavaONE 2007 - BOF 8034 and BOF 8745
JavaOne 2007 BOF 5000: Glassitrope - Java Desktop Widgets
JavaOne 2007 BOF 3908 Slides: JAVA 3D API
Mandy Chung's Blog: JavaOne 2007 BOFs slides 9123 and 2816
JavaOne 2007 BOF 4108 Slides: Interoperable Web Services Security between Java and .NET with WSIT: Ease of Development and Performance
Thursday, May 17, 2007
Bug ID: 5084229 javax.naming.NamingEnuermation should be closed when parent DirContext is closed
Monday, May 14, 2007
JavaOne 2007 in Review
FindBugs
It was rare that I attended a session that FindBugs was not mentioned. Many of the presenters had good things to say about the project. I only attended one session that dealt with the topic of static code analysis, but it kept getting mentioned in the context of good things everyone should be doing. Take a look if you haven't already. There is support for many IDEs, even Eclipse.Developer Knowledge Base - A Java Developer's Guide to Google Technologies
Tuesday, May 8, 2007
OpenJDK
Wednesday, April 25, 2007
Wicket and Guice
Wicket - Home: "Welcome to Wicket With proper mark-up/logic separation, a POJO data model, and a refreshing lack of XML, Wicket makes developing web-apps in Java simple and enjoyable again. Swap the boilerplate, complex debugging and brittle code for powerful, reusable components written with plain Java and HTML. * Check the feature list * Read some Wicket buzz or some Wicket blogs * Find out why you should use Wicket * Check out some examples and see them in live action * Download Wicket 1.2.6 Wicket is released under the Apache License, Version 2.0 ."
Guice wholly embraces annotations and generics, thereby enabling you to wire together and test objects with less effort than ever before. Annotations finally free you from error-prone, refactoring-adverse string identifiers. In a nutshell: * Guice empowers dependency injection. * Guice cures tight coupling. * Guice enables simpler and faster testing at all levels. * Guice reduces boilerplate code. * Guice is type safe. * Guice externalizes configuration when appropriate. * Guice lets you compose your application of components which are truly independent. * Guice reports error messages as if they will be read by human beings. * Guice is the anti-static. * Guice is small and very fast.
Friday, April 13, 2007
Felipe Gaucho's Blog: The name is One, JavaONE !
Matthew Smith: JDK Community Star
Communciating between JSR-168 portlets and the portal containter
Wednesday, April 11, 2007
Fun with Java Enums
public class Coins {
enum Coin {
PENNY(1),NICKEL(5),DIME(10),QUARTER(25);
int value;
Coin( int v ) { value = v; }
}
public static void main(String[] args) {
System.out.println("A penny is worth: " + Coin.PENNY.value);
}
}
A penny is worth: 1
Coin.PENNY.value = 1000;
System.out.println("A penny is now worth: " + Coin.PENNY.value);
A penny is worth: 1
A penny is now worth: 1000
value
, and any instance variables in an enum, are not magically immutable. The enum type does not do any special checking to ensure that the instances of the type (PENNY, NICKEL, ...) remain constant. Under the covers, the enum type is converted to a static class with static members for each
of the declared possbile values like this:
static final class Coins$Coin extends Enum
{
public static final Coins$Coin[] values()
{
return (Coins$Coin[])$VALUES.clone();
}
public static Coins$Coin valueOf(String s)
{
return (Coins$Coin)Enum.valueOf(Coins$Coin, s);
}
public static final Coins$Coin PENNY;
public static final Coins$Coin NICKEL;
public static final Coins$Coin DIME;
public static final Coins$Coin QUARTER;
int value;
private static final Coins$Coin $VALUES[];
static
{
PENNY = new Coins$Coin("PENNY", 0, 1);
NICKEL = new Coins$Coin("NICKEL", 1, 5);
DIME = new Coins$Coin("DIME", 2, 10);
QUARTER = new Coins$Coin("QUARTER", 3, 25);
$VALUES = (new Coins$Coin[] {
PENNY, NICKEL, DIME, QUARTER
});
}
private Coins$Coin(String s, int i, int j)
{
super(s, i);
value = j;
}
}
value
is given the same access modifiers in the generated class as it was given when we defined the enum. Meaning that the value
is not able to be modified by any member of the same package.
The fix
The fix is fairly simple. Make thevalue
instance variable final:
final int value;
Now when the code that tries to modify the value
is compiled, this error:
Coins.java:28: cannot assign a value to final variable value
Coin.PENNY.value = 1000;
^
1 error
Problem solved. Right? Well, not so fast. For primitive types, yes. But for descendants of Object, maybe not. What if instead of an int
, value
was something like a Map
. You could then do Coin.PENNY.value.put("bad key", "bad value")
and the compiler would be perfectly happy with it.
To fix the problem, ensure that the Map is unmodifiable or immutable
public class Coins
{
enum Coin {
PENNY(1),NICKEL(5),DIME(10),QUARTER(25);
final Map value;
Coin( int v ) {
Map newValue = new HashMap();
newValue.put( "cents", v );
value = Collections.unmodifiableMap( newValue );
}
}
public static void main(String[] args) {
System.out.println("A penny is worth: " +
Coin.PENNY.value.get("cents"));
}
}
Summary
While the compiler will ensure that the enum types are immutable, it is the responsibility of the developer to ensure that any instance variables added to the enum are also immutable. This means the instance variable needs to be final AND the type of the instance variable must itself be immutable.
Friday, April 6, 2007
Thursday, April 5, 2007
Elusive unit test error
- Put the client jar for Performasure in my test classpath. I do not know if the license allows for that.
- Remove it from the server.
java.lang.NoClassDefFoundError: com/sitraka/pas/agent/plugin/instrumentor/method/JdbcDriverInstrumentor$JdbcImplementation at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:502) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:480) at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:182) at java.lang.ClassLoader.loadClass(ClassLoader.java:299) at java.lang.ClassLoader.loadClass(ClassLoader.java:255) at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:224) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:217) at weblogic.j2ee.ApplicationManager.loadFromNetwork(ApplicationManager.java:652) at weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:322) at weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:258) at weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:253) at weblogic.rmi.internal.ClientRuntimeDescriptor.computeInterfaces(ClientRuntimeDescriptor.java:254) at weblogic.rmi.internal.ClientRuntimeDescriptor.intern(ClientRuntimeDescriptor.java:140) at weblogic.rmi.internal.StubInfo.readObject(StubInfo.java:124) at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:824) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1746) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1845) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1769) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1274) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324) at weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:120) at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:120) at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:56) at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:164) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:293) at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:247) at weblogic.jdbc.common.internal.RmiDataSource_814_WLStub.getConnection(Unknown Source) at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:462) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:528) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:561) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:579) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:589) at com.ihc.provider.domain.ProviderImpl.findProviderForId(ProviderImpl.java:401) at com.ihc.provider.domain.ProviderImpl.findProvider(ProviderImpl.java:383) at com.ihc.phc.user.UserServiceImpl.addProviderInfo(UserServiceImpl.java:249) at com.ihc.phc.user.UserServiceImpl.getMessagingDoctors(UserServiceImpl.java:231) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148) at com.ihc.phc.util.CacheInterceptor.invoke(CacheInterceptor.java:37) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176) at $Proxy13.getMessagingDoctors(Unknown Source) at com.ihc.phc.test.user.TestUserServiceImpl.testGetMessagingDoctors(TestUserServiceImpl.java:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)