Wednesday, March 12, 2014
Monday, March 10, 2014
Getting started with RESTful webservice using Jersey
Jersey helps developing RESTful webservices seamlessly and makes your life easy. This article gives you a quick start on how to create your first RESTful web service using Jersey & Maven. I assume you have a decent understanding of maven and J2EE.
Make sure you have
Make sure you have
- Eclipse Kepler
- M2Eclipse plugin
- Java 1.7
- Tomcat 7
Step 1 - Maven Project
Create a new maven project from your eclipse. Select maven-archetype-webapp archetype, provide group id, artifact id, package in the following dialog. (See screenshot below)
Note: By default installed facets will not be Java 1.7, Dynamic web module 2.4. You can edit this in org.eclipse.wst.common.project.facet.core.xml under .settings folder. Also make sure to change the JRE from 1.5 to 1.7 in your project build path.
Step 2 - Maven Dependencies
Add the following jersey server and jersey servlet dependencies to your pom.xml
Step 3 - Deployment Descriptor
Add the Jersey servlet container to your web.xml.
Step 4 - REST Resource
Create your package and SampleRestResource class. Add the path "/sample" at the class level, and add 2 GET resources. One with path "/hello" and the other with "/hello/{message}".
Step 5 - Run your application
Right click on your project --> Run As --> Run on Server --> Select tomcat. Now your first resource can be accessed from http://localhost:8080/jersey-rest-helloworld/jersey/sample/hello and the other resource from http://localhost:8080/jersey-rest-helloworld/jersey/sample/hello/your%20message
You can download the complete source here.
Monday, January 20, 2014
Why Singleton design pattern is still a good interview question to Java developers
Why every interviewer asks about singleton design pattern?
Well the answer could be either,
Well the answer could be either,
- That's what the interviewer knows to ask for.
- Or its a good way to start and branch into several other discussions.
- Or its one of the simplest design pattern and a controversial one in terms of usage.
What ever the reason may be, we better know it.
What is Singleton
Singleton is categorized under "Creational design pattern" and part of Gang of Four design pattern. Singleton is a design pattern which suggests only one instance of a class for the entire application at any condition. There are several ways to achieve this, and be assured that most of answers you say may not convince the interviewer and he can over rule the solution.
Ways to do it
Before getting into the details are there any examples of Singleton to be used in real scenarios? Yes, java Runtime, Logger, Service locators of JEE pattern follows singleton. Now, we shall look into the most common ways to implement Singleton.
Singleton - Eager Initialization Example
As the name states in this approach the instance is "eagerly" created before it is expected/asked for. It means the class will be initialized during the application startup.
In this example the interviewer would be interested in asking, What if the instance of this class is not required at all.
Yes it is a drawback that the instance is created even if it is not required. And that would be an issue only if this object is large, or else it is the best to leave it as is. Lets say the interviewer says, it is a large object and I do not want it to be eager loaded. Well the next section describes you how you could write Singleton with lazy initialization.
Singleton - Lazy Initialization Example
Lazy loading is an interesting topic in programming, it means creating the object in a delayed(lazy) way. Generally any expensive process could adapt lazy style. To make our singleton lazy we have initialize the instance variable only when it is expected.
You could see the instance variable is assigned with the object when it is null and then on the same variable is reused. Take a closer look into line 10, it ensures thread safety. If you are just writing just the pseudo code, there could be a question what would you synchronize as you haven't initialized the object yet. We synchronize the block with the class here.
Next is the volatile keyword for the instance variable, do we need that? If so why.
Yes it is absolutely required or you may run in into out of order write error scenario. ie. The reference is returned even before the object is constructed (in other words the memory is allocated but the constructor code isn't finished execution). Also volatile keyword helps as the concurrency control tool in a multi-threaded application.
Singleton - Enum way Example
Easiest of the ways, by default Enums are thread safe and ensures single instance.
For an interview I would not suggest this approach, since it would finish up the question pretty quick. You don't want to do that, better hold the interviewer on the topic you know well. In terms of implementation I would suggestion the Enum way or the one that is discussed in the next section.
Singleton - Bill pugh way Example
William Pugh co-author of findbugs static code analyzing tool, on his research suggested the following way while implementing singleton.
You could witness SingletonHolder, SingletonBillPughExample will not be initialized until getInstance() is invoked.
Ways to do it
Before getting into the details are there any examples of Singleton to be used in real scenarios? Yes, java Runtime, Logger, Service locators of JEE pattern follows singleton. Now, we shall look into the most common ways to implement Singleton.
Singleton - Eager Initialization Example
As the name states in this approach the instance is "eagerly" created before it is expected/asked for. It means the class will be initialized during the application startup.
In this example the interviewer would be interested in asking, What if the instance of this class is not required at all.
Yes it is a drawback that the instance is created even if it is not required. And that would be an issue only if this object is large, or else it is the best to leave it as is. Lets say the interviewer says, it is a large object and I do not want it to be eager loaded. Well the next section describes you how you could write Singleton with lazy initialization.
Singleton - Lazy Initialization Example
Lazy loading is an interesting topic in programming, it means creating the object in a delayed(lazy) way. Generally any expensive process could adapt lazy style. To make our singleton lazy we have initialize the instance variable only when it is expected.
You could see the instance variable is assigned with the object when it is null and then on the same variable is reused. Take a closer look into line 10, it ensures thread safety. If you are just writing just the pseudo code, there could be a question what would you synchronize as you haven't initialized the object yet. We synchronize the block with the class here.
Next is the volatile keyword for the instance variable, do we need that? If so why.
Yes it is absolutely required or you may run in into out of order write error scenario. ie. The reference is returned even before the object is constructed (in other words the memory is allocated but the constructor code isn't finished execution). Also volatile keyword helps as the concurrency control tool in a multi-threaded application.
Singleton - Enum way Example
Easiest of the ways, by default Enums are thread safe and ensures single instance.
For an interview I would not suggest this approach, since it would finish up the question pretty quick. You don't want to do that, better hold the interviewer on the topic you know well. In terms of implementation I would suggestion the Enum way or the one that is discussed in the next section.
Singleton - Bill pugh way Example
William Pugh co-author of findbugs static code analyzing tool, on his research suggested the following way while implementing singleton.
You could witness SingletonHolder, SingletonBillPughExample will not be initialized until getInstance() is invoked.
Friday, December 20, 2013
Spring MVC 3 + Spring Security + Hibernate 4 tutorial
This tutorial helps you to create a spring mvc application integrated with hibernate 4 and Spring security. Before continuing read through my previous article on Spring MVC 3 - Hello world example
The tutorial uses MySQL as database and source code enhanced from the previous Hello world example.
Add the following to the dependencies section
Now we are set to use hibernate and spring security in your application.
Create file application-security.xml inside your webapp >> WEB-INF >> spring folder and paste this content.
Replace the following to your servlet-context.xml. The changes include adding necessary namespaces and made beans as default namespace for convenience.
The tutorial uses MySQL as database and source code enhanced from the previous Hello world example.
Changes to your pom
Add/modify the following to the properties section of your pom.xml. The spring version is increased to 3.2.3 to support transactions.Add the following to the dependencies section
Create file application-security.xml inside your webapp >> WEB-INF >> spring folder and paste this content.
Replace the following to your servlet-context.xml. The changes include adding necessary namespaces and made beans as default namespace for convenience.
Create User.java with the following content, make sure your test database has an user table with fields that matches the properties in the below
Create UserController.java with the following content
Create UserDAO.java with the following content
Download the complete code in github
Friday, November 15, 2013
Spring MVC 3 - hello world example - Quick start
This tutorial helps you to quickly create and run a spring-mvc hello world application. Spring version used for this example is 3.2.3-RELEASE.
Prerequisites
Prerequisites
- JDK 1.6+
- Eclipse Juno+
- Spring IDE 3.4+ for eclipse
- Maven 3
- Maven Integration plugin for eclipse
- Tomcat 7+
Initial Steps
Right click and create New --> Spring project. In the next dialog, fill in the project name as "spring-mvc-spring-sample" and select "Spring MVC Project". Please specify package name "com.ananth.spring" and click Finish.
Run your application
Right click on your eclipse project --> Run As --> Run on server --> Finish.
The source can be download from github. Next chapter Spring MVC with Spring security & Hibernate.
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed - Axis2
I was recently working on writing some client code which makes multiple webservices calls. The stubs for both my client were generated using Axis2. I had to make requests to 2 different services, where one of the service was serving a dummy SSL certificate and the other one was serving a valid SSL certificate.
I landed up getting the following exception,
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
Here are the steps I took to overcome this error,
Bypass SSL security check
I googled and got several links on how to bypass the SSL security check in Java. Most of them were suggesting to use XTrustProvider.install() to turn off SSL check. After implementing this solution the error went away if I invoked only the service which was serving a dummy SSL certificate. When I tried using both the services I again got caught with the same exception, though I tried ignoring the SSL check in the 2nd service. Axis2 actually for some reason "reuses" or caches the security certificate and the SSL socket factory is singleton. So use this class only if you are using a single service.XTrustProvider.java
Use the following InstallCert.java to generate your certificate and tell your SSL socket factory to use this trust store like this. Note: Add this line before the call to your first service, else you will end up in the same exception.
InstallCert.java
Thursday, October 10, 2013
How to make Eclipse autocomplete to suggest as you type
Recently some one was asking if Eclipse content assist/autocomplete can be made to suggest as I type my class name? Immediately I could remember XCode for mac doing something like that and I felt there should be a way in Eclipse.
By default eclipse autosuggest would trigger once you type "." the goal is to make it suggest me the "Type/Class" names too. How to make it do?
Steps:
Go to Eclipse(Windows for windows users) --> Preferences --> Java --> Editor --> Content Assist
Under subsection "Auto Activation" the default value for Auto activation triggers for Java will be "." change this to
.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Optionally you can increase/reduce the Auto activation delay to a lesser value.

You are all set! Now Eclipse will start suggesting as you type.
By default eclipse autosuggest would trigger once you type "." the goal is to make it suggest me the "Type/Class" names too. How to make it do?
Steps:
Go to Eclipse(Windows for windows users) --> Preferences --> Java --> Editor --> Content Assist
Under subsection "Auto Activation" the default value for Auto activation triggers for Java will be "." change this to
.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
Optionally you can increase/reduce the Auto activation delay to a lesser value.

You are all set! Now Eclipse will start suggesting as you type.
Thursday, August 1, 2013
How to open multiple eclipse instances on Mac
Multiple instances of eclipse in mac can not be opened by default. While windows users have the privilege to run several eclipses at the same time. I was wondering if there is a way to the same in Mac.
Though there are other solutions like editing the eclipse.app etc, the best solution is to use "OSX Eclipse Launcher utility plugin".
Follow these simple instructions
Though there are other solutions like editing the eclipse.app etc, the best solution is to use "OSX Eclipse Launcher utility plugin".
Follow these simple instructions
- Go to help --> Eclipse Marketplace...
- Search for "OS X Eclipse laucher utility"
- Cick Install, Next, Finish and restart your eclipse.
Once the plugin is installed, click on File --> Open Workspace. Here you go, a new instance of eclipse is opened with a new workspace.
Monday, July 29, 2013
How to right click on a mac mouse
Initially I was puzzled on how do I right click on my new mac mouse. :-) If you have searched for this article, you also would have had the same question.
Navigate to System Preferences --> Mouse --> "Check" Seconday click --> Click on right side.
Once you are done with that you can right click on the mac mouse.
Navigate to System Preferences --> Mouse --> "Check" Seconday click --> Click on right side.
Once you are done with that you can right click on the mac mouse.
Thursday, July 25, 2013
How to convert XML to Java object and vice versa in runtime?
Well the obvious choice would be to use JaxB, due to its familiarity. Let us see it with a simple example. JAXB is governed by the same team as Glassfish. JAXB comes by default with JDK1.6+. JAXB stands for Java Architecture for XML Binding.
XML has become a common form of data storage in many applications and for webservices. There are two common operations that are required while dealing with XML from Java. Read an xml file and convert it to a Java object, and write a Java object to an xml file.
JAXB does both the above said operations and those operations are called as
Marshalling: Converting Java object to XML
Its a simple process, lets see this with a sample program
Output
While running the above example you will run into the following exception,
Exception in thread "main" javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.ananth.samples.Employee" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at com.ananth.samples.Java2XMLExample.main(Java2XMLExample.java:20)
Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "com.ananth.samples.Employee" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:216)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
... 3 more
To fix the above exception you have to add an @XmlRootElement annotation to your Employee Pojo.
Instead of System.out you can point to the File to which you want to write the output during jaxbMarshaller.marshal(employee, file);. Once make the change while rerunning the sample will give your the following output.
UnMarshalling: Converting XML to Java object
Its a simple process, lets see this with a sample program
Now, I had a question why do I should I have a @XmlRootElement annotation in my pojo. Cant I do I deal with my existing POJOs of my application?
The answer is you cant do it with JAXB but there are other options like XStream. I have referred their two minutes tutorial and it really look me only 2 minutes to try it out.
Add the XStream maven dependency and after that it is as easy as calling toXML and fromXML methods of XStream object.
XML has become a common form of data storage in many applications and for webservices. There are two common operations that are required while dealing with XML from Java. Read an xml file and convert it to a Java object, and write a Java object to an xml file.
JAXB does both the above said operations and those operations are called as
- Marshalling – Convert a Java object into a XML.
- Unmarshalling – Convert a XML into a Java Object.
Let us see this with an example,
Its a simple process, lets see this with a sample program
Output
While running the above example you will run into the following exception,
Exception in thread "main" javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.ananth.samples.Employee" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:317)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:243)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at com.ananth.samples.Java2XMLExample.main(Java2XMLExample.java:20)
Caused by: com.sun.istack.internal.SAXException2: unable to marshal type "com.ananth.samples.Employee" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:216)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:286)
at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
... 3 more
To fix the above exception you have to add an @XmlRootElement annotation to your Employee Pojo.
Instead of System.out you can point to the File to which you want to write the output during jaxbMarshaller.marshal(employee, file);. Once make the change while rerunning the sample will give your the following output.
Its a simple process, lets see this with a sample program
Now, I had a question why do I should I have a @XmlRootElement annotation in my pojo. Cant I do I deal with my existing POJOs of my application?
The answer is you cant do it with JAXB but there are other options like XStream. I have referred their two minutes tutorial and it really look me only 2 minutes to try it out.
Add the XStream maven dependency and after that it is as easy as calling toXML and fromXML methods of XStream object.
Friday, July 19, 2013
XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]
100/100 times I know that this exception happens while there is a parse error in your xml and there is something wrong at the specified row and column.
Knowing the following exception is due to an XML parse error, recently I was puzzled for a while trying to look into the actual content of the file. I couldn't see any closing tag error at the row and column mentioned.
After looking closer, I figured out my xml is used by multiple threads where a few threads were trying to write the XML and the other was trying to read the same file. And the exception was due to thread safety and the file was not fully written before the read. :-)
Message: XML document structures must start and end within the same entity.
com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8829,4]
Message: XML document structures must start and end within the same entity.
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:256)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.skipTags(XMLStreamReaderUtil.java:146)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.skipElement(XMLStreamReaderUtil.java:119)
at com.sun.xml.internal.ws.wsdl.parser.WSDLParserExtensionFacade.definitionsElements(WSDLParserExtensionFacade.java:129)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parseWSDL(RuntimeWSDLParser.java:314)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:135)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
Knowing the following exception is due to an XML parse error, recently I was puzzled for a while trying to look into the actual content of the file. I couldn't see any closing tag error at the row and column mentioned.
After looking closer, I figured out my xml is used by multiple threads where a few threads were trying to write the XML and the other was trying to read the same file. And the exception was due to thread safety and the file was not fully written before the read. :-)
Message: XML document structures must start and end within the same entity.
com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8829,4]
Message: XML document structures must start and end within the same entity.
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:256)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.skipTags(XMLStreamReaderUtil.java:146)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.skipElement(XMLStreamReaderUtil.java:119)
at com.sun.xml.internal.ws.wsdl.parser.WSDLParserExtensionFacade.definitionsElements(WSDLParserExtensionFacade.java:129)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parseWSDL(RuntimeWSDLParser.java:314)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:135)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.
at com.sun.xml.internal.ws.client.WSServiceDelegate.
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
Monday, June 17, 2013
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
I got this exception while I was trying to execute an open source application that I found from the web. I was trying to run the application from my eclipse managed tomcat 7 server. I noticed that my project's maven dependencies were not having the right jars.
This problem can be fixed by adding maven dependencies in the project's web deployment assembly.
This problem can be fixed by adding maven dependencies in the project's web deployment assembly.
- Open the project's properties (e.g., right-click on the project's name in the project explorer and select "Properties")
- Select "Deployment Assembly"
- Click the "Add..." button on the right margin
- Select "Java Build Path Entries" from the menu of Directive Type and click "Next"
- Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish".
Friday, June 14, 2013
Wikipedia, RHEL ditches MySQL and moves to MariaDB
Prior to this Wikipedia has moved to MariaDB from MySQL recently.
According to news from the Red Hat summit which concludes in Boston on Friday, RHEL 7 will also include MongoDB.
The switch was expected to happen after Red Hat's community distribution Fedora announced earlier this year that it would be moving to MariaDB. But it will come as a major jolt to Oracle, the owner of MySQL. (openSUSE, the community distribution of SUSE, announced a switch to MariaDB at the same time as Fedora.)
Many changes in Fedora foreshadow changes in the enterprise distribution.
Once RHEL makes the switch, it will flow on to CentOS, a distribution that provides RHEL without the trademarks, hence making it free in terms of cost. CentOS is widely used by small businesses.
MySQL became Oracle's property after the company bought Sun Microsystems in 2010. There have been many complaints about its stewardship of what was once the last word in open-source database software.
MariaDB is a fork of MySQL that was begun by Ulf Michael Widenius under his new company, Monty Program. Widenius is one of the three co-founders of the original MySQL. The company was sold to Sun in 2008.
Earlier this year, Monty Program merged with SkySQL, a company set up in October 2010 by former employees of the original MySQL. Notable among SkySQL's ranks are former MySQL senior vice-president of global services, Ulf Sandberg, and adviser David Axmark, another of the three co-founders of MySQL.
Widenius and several others raised objections to Oracle's acquisition of MySQL but failed to stop the sale going through.
MySQL's first employee in Australia, Arjen Lentz, said Fedora and OpenSuSE were community driven, whereas RHEL's switch to MariaDB was a corporate decision with far-reaching implications.
"I presume there is not much love lost between Red Hat and Oracle (particularly since the "Oracle Linux" stuff started) but I'm pretty sure this move won't make Oracle any happier," said Lentz, who now runs his own consultancy, Open Query, from Queensland. "Thus it's a serious move in political terms."
He said that in practical terms, MariaDB should now get much more of a public footprint with people (people knowing about MariaDB and it being a/the replacement for MySQL), and direct acceptance both by individual users and corporates.
"Monty Program actually merged (aka was bought) by SkySQL a few months ago. SkySQL does not have significant activity in Australia and New Zealand, Open Query has. SkySQL is currently mainly active in Europe.
"So in terms of significance for AU/NZ, Open Query is definitely happy with this move, and is set to gain business for it. Which is nice in economic terms for Australia, it's not a foreign company with Australian clients."
According to news from the Red Hat summit which concludes in Boston on Friday, RHEL 7 will also include MongoDB.
The switch was expected to happen after Red Hat's community distribution Fedora announced earlier this year that it would be moving to MariaDB. But it will come as a major jolt to Oracle, the owner of MySQL. (openSUSE, the community distribution of SUSE, announced a switch to MariaDB at the same time as Fedora.)
Many changes in Fedora foreshadow changes in the enterprise distribution.
Once RHEL makes the switch, it will flow on to CentOS, a distribution that provides RHEL without the trademarks, hence making it free in terms of cost. CentOS is widely used by small businesses.
MySQL became Oracle's property after the company bought Sun Microsystems in 2010. There have been many complaints about its stewardship of what was once the last word in open-source database software.
MariaDB is a fork of MySQL that was begun by Ulf Michael Widenius under his new company, Monty Program. Widenius is one of the three co-founders of the original MySQL. The company was sold to Sun in 2008.
Earlier this year, Monty Program merged with SkySQL, a company set up in October 2010 by former employees of the original MySQL. Notable among SkySQL's ranks are former MySQL senior vice-president of global services, Ulf Sandberg, and adviser David Axmark, another of the three co-founders of MySQL.
Widenius and several others raised objections to Oracle's acquisition of MySQL but failed to stop the sale going through.
MySQL's first employee in Australia, Arjen Lentz, said Fedora and OpenSuSE were community driven, whereas RHEL's switch to MariaDB was a corporate decision with far-reaching implications.
"I presume there is not much love lost between Red Hat and Oracle (particularly since the "Oracle Linux" stuff started) but I'm pretty sure this move won't make Oracle any happier," said Lentz, who now runs his own consultancy, Open Query, from Queensland. "Thus it's a serious move in political terms."
He said that in practical terms, MariaDB should now get much more of a public footprint with people (people knowing about MariaDB and it being a/the replacement for MySQL), and direct acceptance both by individual users and corporates.
"Monty Program actually merged (aka was bought) by SkySQL a few months ago. SkySQL does not have significant activity in Australia and New Zealand, Open Query has. SkySQL is currently mainly active in Europe.
"So in terms of significance for AU/NZ, Open Query is definitely happy with this move, and is set to gain business for it. Which is nice in economic terms for Australia, it's not a foreign company with Australian clients."
Thursday, June 13, 2013
Type mismatch: cannot convert from null to double
Today while I was doing a code review with my team mates, I noticed some code like this
When I asked them why do you type cast "null to double", the answer they gave was I got "Type mismatch: cannot convert from null to double". There are 2 possible solutions for this,
- Use Double instead of double, then you may use null.
- Use "not a number" (NaN) like this
How to remove a plugin from eclipse
Go to Help > About Eclipse > Installation Details, select the software you no longer want and click Uninstall. (On Mac it is Eclipse > About Eclipse > Installation Details.) In older versions, you might need to Run Help > Software Updates > Manage Configuration..., select the feature of interest, and disable it with the task shown in the right window.
When a feature is disabled, all its plug-ins will be disabled also. They are still available on disk, and they can be enabled at any time in the future.
To physically remove the feature and its plug-ins, you will have to manually remove the feature from the eclipse/features directory and its plug-ins from the eclipse/plugins directory. I advise extreme caution here. Remove the wrong ones, and you may spend quite some trouble restoring your Eclipse to a stable state.
When a feature is disabled, all its plug-ins will be disabled also. They are still available on disk, and they can be enabled at any time in the future.
To physically remove the feature and its plug-ins, you will have to manually remove the feature from the eclipse/features directory and its plug-ins from the eclipse/plugins directory. I advise extreme caution here. Remove the wrong ones, and you may spend quite some trouble restoring your Eclipse to a stable state.
Thursday, June 6, 2013
How to use VIM editor
VIM Editor Commands
Vim is an editor to create or edit a text file. There are two modes in vim. One is the command mode and another is the insert mode.
From command mode to insert mode type a/A/i/I/o/O (see details below)
From insert mode to command mode type Esc (escape key)
Some useful commands for VIM
Text Entry Commands (Used to start text entry)
Cursor Movement Commands
Most commands can be repeated n times by typing a number, n, before the command. For example 10dd means delete 10 lines.
Examples:
Opening a New File
Vim is an editor to create or edit a text file. There are two modes in vim. One is the command mode and another is the insert mode.
- In the command mode, user can move around the file, delete text, etc.
- In the insert mode, user can insert text.
From command mode to insert mode type a/A/i/I/o/O (see details below)
From insert mode to command mode type Esc (escape key)
Some useful commands for VIM
Text Entry Commands (Used to start text entry)
- a Append text following current cursor position
- A Append text to the end of current line
- i Insert text before the current cursor position
- I Insert text at the beginning of the cursor line
- o Open up a new line following the current line and add text there
- O Open up a new line in front of the current line and add text there
Cursor Movement Commands
- h Moves the cursor one character to the left
- l Moves the cursor one character to the right
- k Moves the cursor up one line
- j Moves the cursor down one line
- nG or :n Cursor goes to the specified (n) line (ex. 10G goes to line 10)
- ^F (CTRl F) Forward screenful
- ^B Backward screenful
- ^f One page forward
- ^b One page backward
- ^U Up half screenful
- ^D Down half screenful
- $ Move cursor to the end of current line
- 0 (zero) Move cursor to the beginning of current line
- w Forward one word
- b Backward one word
- :wq Write file to disk and quit the editor
- :q! Quit (no warning)
- :q Quit (a warning is printed if a modified file has not been saved)
- ZZ Save workspace and quit the editor (same as :wq)
- x Delete character
- dw Delete word from cursor on
- db Delete word backward
- dd Delete line
- d$ Delete to end of line
- d^ (d caret, not CTRL d) Delete to beginning of line
- Yank (has most of the options of delete)-- VI's copy commmand
- yy yank current line
- y$ yank to end of current line from cursor
- yw yank from cursor to end of current word
- 5yy yank, for example, 5 lines
- Paste (used after delete or yank to recover lines.)
- p paste below cursor
- P paste above cursor
- "2p paste from buffer 2 (there are 9)
- u Undo last change
- U Restore line
- J Join next line down to the end of the current line
- :w Write workspace to original file
- :w file Write workspace to named file
- :e file Start editing a new file
- :r file Read contents of a file to the workspace
- To create a page break, while in the insert mode, press the CTRL key and l. ^L will appear in your text and will cause the printer to start A new page.
Most commands can be repeated n times by typing a number, n, before the command. For example 10dd means delete 10 lines.
- . Repeat last command
- cw Change current word to a new word
- r Replace one character at the cursor position
- R Begin overstrike or replace mode – use ESC key to exit
- :/ pattern Search forward for the pattern
- :? pattern Search backward for the pattern
Examples:
Opening a New File
- type vim filename (create a file named filename)
- type i ( switch to insert mode)
- enter text (enter your Ada program)
- hit Esc key (switch back to command mode)
- type :wq (write file and exit vim)
- type vim filename (edit the existing file named filename)
- move around the file using h/j/k/l key or any appropriate command
- edit required text (replace or delete or insert)
- hit Esc key (exit from insert mode if you insert or replace text)
- type :wq
Wednesday, June 5, 2013
How to exit from an unix manual page
Though the answer is simple, I have struggled a bit to get out of the man page. Thought this could help for unix beginners like me.
"man" command is very useful to read the manual of any commands that you use from terminal on a linux/mac machines.
From your terminal "man command-name" takes you to the manual page.
In order to navigate in the pan page use "up" or "down" arrow keys for navigation. In certain cases you may have to use enter key.
To get out of the man page simply type "q", this will take you to the command prompt from open terminal.
Ex: man ssh, man chmod, man ls
"man" command is very useful to read the manual of any commands that you use from terminal on a linux/mac machines.
From your terminal "man command-name" takes you to the manual page.
In order to navigate in the pan page use "up" or "down" arrow keys for navigation. In certain cases you may have to use enter key.
To get out of the man page simply type "q", this will take you to the command prompt from open terminal.
Ex: man ssh, man chmod, man ls
How to create a new git local branch and push to repository (remote/origin)
From your terminal using commands
Check your git version with the following command,git --version
git checkout -b newbranch
git push -u origin newbranch
The "-u" option is available only from git 1.7.0. It refers to "upstream" to where you want to push to or pull from.
From eclipse
Right click on your eclipse project Team -> Switch to -> New branch.

Give your new branch name in the following dialog and then click Finish. This will create a new branch from your current working branch.
Make all your changes to the new branch, to push the newly created branch right click Team -> Commit & Push (EGit2.x versions).
From github
The simplest way to create a new branch is from Github. If you have push access to the repository, start typing the new branch name in the search box of switch branches/tags. This box will appear once you click on the down arrow near branch. Once you complete typing the branch name, you will see an option to create new branch with the name provided. Click on it, you are done.

Thursday, May 30, 2013
Why should you have your code "neat"
It is a painful truth that most of my fellow developers don't care about code readability and maintainability. Sometimes its frustrating to make changes on an unformatted, in other words poorly written code.
Code that we write represents our brain and I consider my code as how an artist considers his painting.
After reading an article on Style matters, I thought of writing this post on few important readability factors and how important it is to have your source code neat.
Top 5 readability & maintainability factors
Code that we write represents our brain and I consider my code as how an artist considers his painting.
After reading an article on Style matters, I thought of writing this post on few important readability factors and how important it is to have your source code neat.
Top 5 readability & maintainability factors
- Documentation with proper comments
- Formatted code with proper indentations
- Organized file folders
- Proper naming conventions
- Never use deprecated code
Comments & Documentation
A good developer learns a project just from the code; javadoc plays a significant role in the learning process. Imagine that all open source projects and JDK code with no comments and documentation. I am sure that it would at least take 10 times more effort to figure how to use them. A good javadoc in your application saves enormous amount of time for fellow developers.
All IDEs shows help texts for a method or class on mouse over for quick assistance, remember they all come from the javadoc of that method or class. When you leave your code with no comments, then you are letting some fellow developer to be handicapped in some way.
Formatted code with proper indentations
When my sister write Java classes in notepad for her college project, it is acceptable to have a code which doesn't have a decent formatting. Considering the modern IDEs that we use, formatting takes a few seconds. It has to be a habit to write formatted code and not for the sake of your manager or your lead wants it.
To the least there are options to do a format at your project level which formats all your classes in the project. For example using eclipse, "Right click on your project -> Source -> Format". Boom all your code is formatted decently with the basic code formatting settings, however you can go and edit the settings as you want and also you can share it across your team as an xml file.
All IDEs shows help texts for a method or class on mouse over for quick assistance, remember they all come from the javadoc of that method or class. When you leave your code with no comments, then you are letting some fellow developer to be handicapped in some way.
Formatted code with proper indentations
When my sister write Java classes in notepad for her college project, it is acceptable to have a code which doesn't have a decent formatting. Considering the modern IDEs that we use, formatting takes a few seconds. It has to be a habit to write formatted code and not for the sake of your manager or your lead wants it.
To the least there are options to do a format at your project level which formats all your classes in the project. For example using eclipse, "Right click on your project -> Source -> Format". Boom all your code is formatted decently with the basic code formatting settings, however you can go and edit the settings as you want and also you can share it across your team as an xml file.
Organized file folders
During several code reviews that I have witnessed project documents kept under "src". One common answer I heard from developers was its easy to access. I was shocked to see project documents going inside your deployable files. A good java project should have well organized packages which very well represents OO design being followed. Writing everything in the same folder makes it unmaintainable as the project grows.
Proper naming conventions
In most cases the people who maintain the code is not same as the author. They may not be knowing the project as good as the original author, or may be less skilled programmers compared to the author. Having very good class, method and variable names makes it very much easy for the person who maintains it. Reading java code should more or less be similar to reading english. Following descriptive naming convention helps to understand the code much faster. Using i, j, k, abc, xyz as your method or variable names through out your project makes it almost an unsolvable puzzle for people who follow. Sometimes it makes it tougher to debug for even the author who wrote it.
During several code reviews that I have witnessed project documents kept under "src". One common answer I heard from developers was its easy to access. I was shocked to see project documents going inside your deployable files. A good java project should have well organized packages which very well represents OO design being followed. Writing everything in the same folder makes it unmaintainable as the project grows.
Proper naming conventions
In most cases the people who maintain the code is not same as the author. They may not be knowing the project as good as the original author, or may be less skilled programmers compared to the author. Having very good class, method and variable names makes it very much easy for the person who maintains it. Reading java code should more or less be similar to reading english. Following descriptive naming convention helps to understand the code much faster. Using i, j, k, abc, xyz as your method or variable names through out your project makes it almost an unsolvable puzzle for people who follow. Sometimes it makes it tougher to debug for even the author who wrote it.
Never use deprecated code
A method or class is deprecated when a code is "buggy" or "inefficient" or for a "bad coding practice". And it is represented with @deprecated annotation. A good API would always give an alternative better option before deprecating the existing one. Look for the alternative option and never use deprecated code.
Note: All the points discussed here are for code written Java and may be applicable for other programming languages too.Wednesday, May 22, 2013
Collection of very interesting unix commands
How to get your top 100 unix commands
history | sed "s/^[0-9 ]*//" | sed "s/ *| */\n/g" | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 100 > commands.txt
How to copy a file to all subfolders of a directory using unix command
find . -type d -exec cp pathtofile {}/ \;
How to delete all .svn folders from current directory using unix command
find . -type d -name '.svn' -print -exec rm -rf {} \;
How to list all network connections (including which app they belong to)
lsof -i -nP
How to run the last command as root
sudo !!
How to execute the previous command until it is successful
until !!; do :; done
How to display summary of git commit ids and messages for a given branch
git log --pretty='format:%Cgreen%H %Cred%ai %Creset- %s'
How to list all file extensions present in the current directory
ls | perl -lne '++$x{lc $1} if /[.](.+)$/ }{ print for keys %x'
How to get your top 10 commands with number of times you have used it
cat .bash_history | cut -f 1 -d\ | sort | uniq -c | sort -r | head
To generate list of usernames from an svn logs (Run from top level of the svn project)
svn log | grep -E "r[0-9]+ \| .+ \|" | awk -F"|" '{print $2}' | sort | uniq > ~/authors.txt
How to get process details from its pid
ps -p $pid
How to open firefox profile manager
/Applications/Firefox.app/Contents/MacOS/firefox-bin -p
https://docs.google.com/forms/d/1XNMoSdfYFe_WkPfU--M88oL00PDLIOAo1HxjhZvZYJ4/viewform
Mr. Robg
My previous post
http://stackoverflow.com/questions/1102986/most-powerful-examples-of-unix-commands-or-scripts-every-programmer-should-know
http://www.commandlinefu.com/commands/browse/sort-by-votes
Subscribe to:
Posts (Atom)




