Thursday, May 5, 2011

Split a string with "." as a delimiter in Java

Another typical error that most of us make while splitting a string with "." as a delimiter, is not escaping it.


String unsplitString = "abc.def.xyz";
String[] splitStrings = unsplitString.split ("\\.");

Thursday, August 12, 2010

java.lang.UnsupportedClassVersionError

I had my workstation reconfigured.. I installed Java along with a bunch of programs. I tried to run a Hello World program just make sure java was working as expected. I ran into this error

Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld (Unsupported major.minor version 50.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

It was obvious to me that javac version was different than that of java.
To verify, I ran "javac -version" and "java -version. I was right, javac version i had was 1.6 and the jre version showed 1.3..!!! I was surprised..!

I quickly did a "which java" .. It pointed out to a jre that was used by an Oracle installation .. I removed the Oracle installation from Program Files and the Environment Settings too. Alternatively you can just change the Env settings ( PATH variable).

I again ran my Hello World...I was happy to see My Program say Hello To the Whole World again..!! :D

Monday, December 14, 2009

cygwin - clear command not found!

I had installed cygwin and wondering why the 'clear' command is not working(ofcourse clear.exe was missing) . But then as always google looked it up for me.

clear.exe is found in ncurses package. If you dont have it, all you need to have to do is launch the setup file and update the packages installed.

There is another easier way to work around this. If you are using a bash shell, ctrl+ l will work. Try it out.!

Wednesday, December 9, 2009

Open a LIT(.lit) file

I recently downloaded a ebook. It was LIT format, I did not know how to open (read) it, so like every other netizen(almost), I asked Google to bail me out. I found out that the file can be read using a Microsoft Reader, which can be downloaded from here.

Mac users will find this useful and Linux users will find this useful.

Tuesday, June 2, 2009

$'\r': command not found

I was brushing up my shell scripting basics the other day. I had not run any shell scripts on the windows ( via cygwin) . So I thought I would start off with a simple hello world script :

#!/bin/bash
#
# hello.sh
#

echo "Hello World..!!!" # prints Hello World
exit 0

when I executed this script, I got

hello.sh: line 5: $'\r': command not found
Hello World..!!!

so, after a small search on the web I realized the obvious thing I had missed out.
I had to convert the file to UNIX format. I used the UNIX format shell utility dos2unix.
It worked perfectly well.

Sunday, May 3, 2009

Adding applications on facebook

The instructions are pretty simple. I followed what ever was there in this link.
http://blog.togglenetworks.com/category/application-services/php/.

the only difference is that I made use of iFrame instead of FBML.

The below link too is pretty useful.
http://kukuhtw.wordpress.com/2007/12/03/how-to-integrate-your-applications-into-facebook/


I have anyway mentioned the Steps below:


Step 1:

Install the developer application to your facebook account. Login to facebook and proceed to the link: http://www.facebook.com/developers.

Step 2:

Click on the Set up a new application link/button. Give a name to your application, and agree to the terms and conditions.

Step 3:

Once the above step completes, you will be redirected to application edit page. This will contain the application id, the secrete keys and other information that needs to be filled up.

Callback URL is the location of your application that is running on your server. (Typically it will be http://$YOUR_SERVER_NAME/index.php in case of a PHP application.)
If you look at the source code sent yesterday, in the root directory there is a file called index.php, this contains the API keys. Please change them accordingly. Save the changes. You will be sent to My Applications page.

Step 4:

Go to Canvas tab on the edit application page. This contains the canvas URL. You need to choose a URL for your application it can be anything you like, the one constraint is that it should not contain the word "face" anywhere.

In the canvas settings, choose iFrame instead of FBML.
Select Smart Size, and Canvas needs to be full width.

Step 5:

Once you have made these changes, you can save it. You must be able to access your application through, http://apps.facebook.com/ $YOUR_APP_NAME.


There is a wiki - http://wiki.developers.facebook.com/index.php/Creating_your_first_application which gives you detailed step by step information of what needs to be done!

Saturday, April 25, 2009

Development Environment Setup Guide for applications development using Java (JDK 5), Eclipse and JBoss

I successfully set up a development env and have written down the steps I followed. Hope you find them helpful.

1. Download JDK 5 for windows from http://java.sun.com/javase/downloads/index_jdk5.jsp and install the same.

2. Download Eclipse-SDK-3.2.2-win32.zip from www.download.eclipse.org/eclipse/downloads/drops/R-3.2.2-200702121330. This is a zip file, which has to be unzipped, and then you are done with this installation.

3. Download JBoss Application server from www.jboss.com. It will be a simple zip file, which needs to be unzipped.

4. Download latest MySQL version from www.mysql.com. The zip will contain an installation file install it. Usually set the root user name and password to be “root”.

5. Eclipse downloaded will not be configured to start JBoss. A plug in needs to be installed. The following are the steps to do it:

o Start Eclipse.

o Select Help > Software Updates > Find and Install...

o Select Search for new features to install, and press Next >

o Select New Remote Site... from the right menu. In the dialog fill the name with JBoss Eclipse IDE and the URL with http://download.jboss.org/jbosside/updates/stable

o Make sure JBoss Eclipse IDE has a check next to it, and press Finish.

o Expand the JBoss Eclipse IDE tree, and check the release named JBossIDE 1.6.0(or which ever is the latest available). Click Next >, and Eclipse will ask you if you agree to the licensing terms of JBoss Eclipse IDE. If you agree, select I accept the terms in the license agreement, and press Next >

o Eclipse will show you a list of features it is going to install. Press Finish to start installation.

o After all the features have been downloaded, Eclipse will prompt if you want to install each feature. The quickest way to install everything is to press the Install All button.

o At the end of the installation, you will be prompted to restart Eclipse. Click Yes.

6. On the menu bar select Windows -> Open Perspective -> Other -> Debug. Click on OK.

7. Choose the JBoss version you have installed (currently its Jboss-4.0.x). (window -> open perspective -> JBoss AS -> right click on the perspective on the left)

o Right click on the version chosen -> New.

o Give a generic name to your sever.

o In the Home tab, give the location of JBOSS_HOME.

o In the Source tab, choose the current project, along with the default, also add all the jars under JBOSS_HOME/bin and JBOSS_HOME/client

o In the Classpath tab under User Entries, Add External Jars – Add JBOSS_HOME/bin/run.jar

o Click on Apply and then close.

8. Choose New -> Projects -> JBossAOP->JBossAOP Project

o Enter the project name.

o Choose Java1.5

o Click on Finish.

9. Observe on the tool bar the presence of debug tool (green bug).

10. On the drop down select debug. A familiar debug window will appear. Now click on Debug.

11. Observe activity on the console window. The server in now started.

12. In the Browser http://localhost:8080/jmx-console. A jmx console should be displayed.

13. Check the project from the CVS server. The configurations in eclipse

  • WIndow -> Open Perspectives -> Other -> CVS repositories
  • host : [host ip address]
  • location : [ cvs root location ]
  • use extssh
  • type in your server username and password. Click next
  • If every thing goes well you will be asked to type in the project name to be checked out or browser through the repository (Other wise please check the log file for the error message located in YOUR_WORKSPACE/.metadata directory). Choose any one.

    More information can be found at http://www.fsl.cs.sunysb.edu/~dquigley/cse219/index.php?it=eclipse&tt=cvs

14. A Tutorial of building and deploying a J2EE application can be found here.

http://docs.jboss.org/jbosside/tutorial/build/en/html_single

Trouble Shooting:

1. If trouble is encountered while launching the debug probably a launcher ui is missing which can be downloaded from http://www.jira.jboss.com/jira/secure/attachment/12311850/org-jboss-ide-eclipse-launcher-ui.jar.

2. It would be better to download hibernate-tools plugin direct from the hibernate site, because some important might not be downloaded from eclipse. ( I have experienced the same problem). The downloaded zip file will contain two directories namely features and plugins. COPY THE CONTENTS OF THESE DIRECTORIES INTO $ECLIPSE_HOME/features and $ECLIPSE_HOME/plugins
respectively.

Wednesday, April 22, 2009