Two days ago, a terrible snow storm attacked most of the east coast states. During and after the blizzard, I captured few shots.
Snow
Posted by HillolTwo days ago, a terrible snow storm attacked most of the east coast states. During and after the blizzard, I captured few shots.
How to get rid of the "java.lang.StackOverflowError " during the compilation of your GWT project
Posted by HillolIf you are using GWT 1.6.* (1.6.4 or earlier), have you ever faced "java.lang.StackOverflowError" during the compilation of your project? Perhaps, you may have got this exception. The fact is that, GWT 1.6 uses extensive optimization while compiling java code to javascript code which needs large memory and large stack size.
You can read here about this issue. There is a patch for fixing this problem.
- First, Download the patch from here.
- Then add it to the project run/debug settings.
- In the ".classpath" file (located in your project folder), it should be placed above the GWT core library.
One thing to note here is that, this is a temporary limitation of the GWT build. Hopefully, it'll be solved in the later versions.
Getting Started with GWT 1.6.* and Google App Engine
Posted by HillolThere has been few drastic changes made in GWT 1.6 . The most important one is the new project structure. GWT now uses a "war" directory for most public resource and server configuration files. For the total change list, visit this page.
My previous post "Getting Started With the GWT " was fine for the previous version(1.5.*) of GWT. But, since things are not the same now, I am writing another tutorial for the new version of GWT.
- At first, download the latest build of GWT 1.6 from here.
- Unzip it to any location in your Hard drive.
- Now, add the Google Plugin in your Eclipse IDE. You can follow my another blog.
- Now choose File>New>Web Application Project. Or, you can click the "New Web Application Project" button from the newly added Google Toolbar.
- Give a project name and package structure. Leave other options as default.
- After finishing the "New Web Application" wizard, a default template GWT project would be created according to your given name.
- You'll get a nice starting project after that. Moreover, you'll get an RPC communication mechanism as default in this project. If you look at the project structure, you'll find 3 files GreetingService.java, GreetingServiceAsync.java, GreetingServiceImpl.java in the project. This three files would be used if you need Server-Client communication.
- Now, if you want to develop a web app that will not need any server communication, you have to delete some stuffs from the project.
- Delete those three files. GreetingService.java and GreetingServiceAsync.java are located in your client package. And, GreetingServiceImpl.java is located in the server package.
- Open the "web.xml" file from the "war -> WEB-INF".
- Delete texts starting form "" to "". This portion of xml code is used for the server side servlet mapping.
If you want to deploy your application in the Google App Engine, follow these steps:
- Sign up in Google App engine
- Then sign in with your account.
- Then click on the "Create an application" button.
- Give a application ID and title of your app and click "save".
- Your application is created.
- Now go back to Eclipse. Right click on the project from the "package explorer" tab.
- Select "Deploy to App Engine" from the "Google" sub-menu.
- Choose the "App Engine Project Settings" from the dialog.
- Give the Application ID (It is the app ID you have created earlier) and the version number. Click ok.
- Then give your email (Google id) and password, click Deploy.
- Your project would be compiled and deployed to the Google App Engine.
Using the Union operator in Yahoo Pipes to combine your search results
Posted by HillolIf you have already read my previous blog, then I am assuming you can create a basic pipe. I'll show you now, how to use different search modules and combine their search results into one unified output result.
We'll search in Google and in Yahoo against a keyword and images for the same keyword would be fetched from Flickr. Outputs of these three search would be combined finally.
Follow the procedure:
- Go to Yahoo! Pipes.
- Sign in with your yahoo account.
- Choose “Create a pipe”.
- After the pipe editor has loaded, drag “Google Base ” to the editor panel from the “Sources” category of the left pane.
- Drag "Yahoo Search" to the editor pane.
- Drag "Flickr" to the editor pane.
- Drag "Text input" from the "User inputs" category.
- Edit fields of the “Text input” module as necessery: write “Search For” in the prompt field.
- Write 1 in the position field.
- Write “Einstein” in Default and Debug field.
- Connect this “Text Input” module with
- the text field after the "with keywords" in the Google module
- the text field after the "search for" in the Yahoo module
- the text field “image for” in the Flickr module.
- Now drag “Union ” from the “Operators” category.
- Connect the outputs of Google, Yahoo and Flickr module with 3 input slots of the union module.
- Finally connect the output of the Union module with the "Pipe Output".
- Save the pipe.
Getting started with Yahoo! Pipes.
Posted by HillolI was overlooking any new Yahoo products as their existing other products gave me only a feeling of disgust. I heard about their new product " Yahoo! Pipes". I thought it would be another typical yahoo product. But one day, out of my own curiousity, I logged into pipes. And what I found afterward made me completely astonished. It is an amazing product. According to them:
"Pipes is a powerful composition tool to aggregate, manipulate, and mashup content from around the web."
I am going to show you a step by step introductory view of pipes. I'll give a tutorial of how images can be fetched from Flickr according to your parameters.
- Go to Yahoo! Pipes.
- Sign in with your yahoo account.
- Choose "Create a pipe".
- After the pipe editor has loaded, drag "Flickr " to the editor panel from the "Sources" category of the left pane.
- Drag "Text input" to the editor pane from the "User inputs" category.
- Edit fields of the "Text input" module as necessery: write "Search For" in the prompt field.
- Write 1 in the position field.
- Write "Sunset" in the Default field.
- Connect this "Text Input" module with the text field "image for" in the Flickr module.
- Drag "Location Input" to the editor pane from the "User inputs" category.
- Edit fields of the "Location input" module as necessery: write "Location" in the prompt field.
- Write 2 in the position field.
- Write "Bangladesh" in the Default field.
- Connect this "Location Input" module with the field "near" in the Flickr module.
- Drag "Number Input" to the editor pane from the "User inputs" category.
- Edit fields of the "Number input" module as necessery: write "Number of pics" in the prompt field.
- Write 3 in the position field.
- Write "10" in the Default field.
- Connect this "Number Input" module with the text field after the "Find" in the Flickr module.
- Finally connect the "Pipe Output" with the output connector of the "Flickr" module.
Widget Creation tutorial for Zembly
Posted by Hillol- Go to http://zembly.com
- Sign in to your zembly account or sign up if you are new to zembly.
- After Logging in choose "create" from the top right corner.
- Select Widget from the list.
- Choose "News Feeds" from Categories, then choose "NewsTicker" from the templates.
- Then click on the "Choose this template" button.
- A widget would be created. Choose the rename option. Give a suitable name for your widget.
- Then choose the "Edit this widget" button.
- Choose "RSS url" from the combo box. Write"http://news.google.com/?output=rss" as the rss url.
- Or if you have already created a "yahoo! pipe" which would fetch news feed, then you can choose "Yahoo pipe ID" from the combo box and use the pipe id here.
- Then edit the timeout (how long a news element would be shown on the ticker).
- Click "Save"
- You can preview the widget by clicking the "preview" button.
- A preview window would be popped up.
- Close the window. If you think everything is ok, then choose the "publish button".
- Your widget is ready now. You can share this widget with everyone in your favourite communities directly.
- Or, you can copy the url of your created widget and paste it on your website.
Puzzle with long division
Posted by HillolThis post is all about a simple division of data type “Long”. Just have a look at the following code:
public class LongDivision
{
public static void main(String[] args)
{
final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000;
final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY);
}
}
What would be printed in the console after executing this code?
I am helping you a bit. According toSun, Long has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). So both the two final variable’s value would fit perfectly, there should not be any overflow.
So, we should expect this code to print 1000. But, alas! to the great horror you would see this code to print 5!!!
What the heck with this dumb code?
Wait, here is the twist. The problem is that the computation of the constant MICROS_PER_DAY does overflow. Although the result of the computation fits in a long with room to spare, it doesn’t fit in an int.
Aren’t you thinking this is an absurd stuff? We declared the variable as long, why this poor long data needs to be fit in int?
The fact is that, when you use the int multiplication operation(*), the computation is performed entirely in int arithmetic, and only after the computation completes is the result promoted to a long. By then, it’s too late: The computation has already overflowed, returning a value that is too low by a factor of 200. The promotion from int to long is a widening primitive conversion [JLS 5.1.2].
So why is the computation performed in int arithmetic? Because all the factors that are multiplied together are int values. When you multiply two int values, you get another int value. Java does not have target typing, a language feature wherein the type of the variable in which a result is to be stored influences the type of the computation.
It’s easy to fix the program by using a long literal in place of an int as the first factor in each product. This forces all subsequent computations in the expression to be done with long arithmetic.
So the correct code would be like this:
public class LongDivision
{
public static void main(String[] args)
{
final long MICROS_PER_DAY = 24L * 60 * 60 * 1000 * 1000;
final long MILLIS_PER_DAY = 24L * 60 * 60 * 1000;
System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY);
}
}
NB: Courtesy by “Joshua Bloch”. This puzzle has been taken from his book: “Java™ Puzzlers: Traps, Pitfalls, and Corner Cases“.
Java support in Google-App-Engine
Posted by HillolGoogle has recently added the long awaiting support for java in their Google-App-Engine. Previously, there was support for only python apps. Now you can easily deploy your java web-apps in the App Engine.
These are the main features added for Java (as described by Google):
- A complete Java 6 runtime environment ( in a secure sandbox environment)
- Based on common Java web technology standards, including servlets and WARs, JDO and JPA, java.net, JavaMail and JCache
- Datastore Java API for storing and retrieving data. It provides robust scalable data storage for your web application.
- The Memcache Java API. It is a distributed in-memory data cache in front of robust persistent storage for some tasks.
- The Images Java API. For manipulating images.
- The Google Accounts Java API. App Engine applications can authenticate users with Google Accounts.
- Supports other languages that compile to the JVM or use JVM-based interpreters, such as JRuby, JavaScript (Rhino), and Scala
- A plugin for the Eclipse IDE makes project creation, testing and deployment a snap. This plug-in is a bonus for GWT developers. It has reduced lots of manual works of configuration during deployment and compilation.
The problem with the external update in Database of a Java EE project and how to overcome it.
Posted by HillolSuppose you are developing a java EE project and you need some sort of trigger or procedure to do some back-end works like generating any customized serial number for table entries. You have written that trigger or procedure for the underlying database and then, you have made it to run in the back-end. Ok, you have done the right thing, everything is going right. But oops, are you facing any weired problem when reading back the data in your front-end application? Is there inconsistencies between the actual data and the data in the DB? Yes, you'll face this inconsistency.
The actual problem is that, when you read data through your session beans, all the JPQL queries are made to the EJBs, not to the actual DB. The EJBs themselves cache DB data and they only reflects changes made through the session beans (i.e. through the container). When you write a row in any database table via session beans and after that your trigger changes or inserts any data to that row, EJB can only know about the insert operation done by the session bean, it doesn't know any external change done by your trigger. That's why, when you read back that row by your session bean, you'll get the data excluding the change made by the trigger.
To overcome this issue, you can take either of the following ways:
- You can use native query in your read operation of the session bean. For an example, you can use "entityManager.createNativeQuery("some query");" . Where, entityManger is the instance of the EntityManager class and "some query" means any raw query for your underlying database.
- You can use use the default JPQL queries but after getting the list of data (object list of some entity) from that query, refresh all the entity objects. For an example:
personList = entityManager.createQuery(some JPQL query).getResultset();And now look at the read data again. Is the inconsistency disappeared now? Yes, you have solved the problem successfully. :-)
for (Person person : personList)
{
entityManager.refresh(person);
}
Most Common Elements of GWT module descriptor
Posted by HillolOne of the most important resources generated by the "ApplicationCreator" is the Module.gwt.xml module descriptor for your project. It is created in the top-level directory of the project’s package. It provides a means to define resource locations and structure.
In the default generated file, there are only two elements: