Skip to main content

Posts

Showing posts from July, 2013

Can 'transient' variables be declared as 'final' or 'static'?

Java's serialization provides an elegant, and easy to use mechanism for making an object's state persistent. While controlling object serialization, we might have a particular object data member that we do not want the serialization mechanism to save. The modifier transient can be applied to field members of a class to turn off serialization on these field members. Every field marked as transient will not be serialized. You use the transient keyword to indicate to the Java virtual machine that the transient variable is not part of the persistent state of an object. The transient modifier applies to variables only. Like other variable modifiers in the Java system, you use transient in a class or instance variable declaration like this: class TransientExample { transient int hobo; . . . } This statement declares an integer variable named hobo that is not part of the persistent state of the TransientExample class.

When To Use Abstract Class and Interface?

What is the difference between interface and an abstract class?  This is the first question most of the java interviewers start in interviews. Ofcourse it seems a silly question and can answer. But if interview goes depth of the concept of abstract class and interface, most of the candidates not able to answer. To overcome that ignorance just read the points that I have highlighted below. 1. Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods. A Java Interface can contain only method declarations and public static final constants and doesn't contain their implementation. The classes which implement the Interface must provide the method definition for all the methods present. 2. Abstract class definition begins with the keyword "abstract" keyword followed by Class definition. An Interface definition be

How To Use Lazy Loading for Efficient Java Logging

It is always a good Java programming practice to prefix log statements with a check for "loggability" by testing Logger.isLoggable(Level) prior to logging. However, this practice presents Java developers with a dilemma: Failing to do so results in slower performance, but following it contributes to more total lines of code. Often, developers opt to just bypass it. In this intermediate Java tip, Jason Weinstein offers a solution: lazy loading. By wrapping Java logging in your own class (as shown below), you can ensure the isLoggable() test is always made, while at the same time lazily binding the message creation so that it occurs only when the message is going to be logged.

javax.resource.spi.LocalTransactionException: No more data to read from socket

j avax.ejb.EJBException: Unable to complete container-managed transaction.                 at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5147)                 at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901) com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)                 at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)                 at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)                 at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) 21T16:28:33.064+0200|WARNING|glassfish3.1.2|javax.enterprise.system.core.transaction.com.sun.jts.jtsxa|_ThreadID=111;_ThreadName=Thread-2;|JTS5067: Unexpected error occurred in commit oracle.jdbc.xa.OracleXAException                 at oracle.