Posts

Showing posts from 2009

Remote access with Spring HttpInvoker

Image
Introduction I can remember the early days of Java where I used RMI to create distributed system. But it is very difficult to use RMI these days because distributed communication is restricted due to the security concerns under the organizational policies. Enterprise applications are evolved to adapt to current environment but for small scale distributed systems are not possible. This fact mainly forced me to explore the new technologies which is best suit for my requirements which are listed below Enterprise applications are mainly depends on HTTP protocols. Therefore, my choice also  HTTP. The RMI communication protocol is JRMP, but over the network, there are lot of problems communicating via JRMP. The best use is pure HTTP protocol without any tunneling because which can cause to firewall problems. The Framework should support to send and receive Java serialized objects  over the chosen protocols (which is HTTP according to the above point). The development e

Java 6 Collections: Why need HashSet

Image
If the ordering of the elements is not important, then the Hash set allows you to find the element much faster. But anyway, if you access these elements in the iterative manner, you may get random ordering each time. The well known data structure for finding objects quickly is the hash table. Java HashSet and HashTable are based on the hash table data structure. Specially, if the universe U is larger, it is impractical to storing objects in the Table T which is size of U . Instead Key can represent the actual object because K is relatively smaller compared to associated object. The storage requirement is Θ( K ) and to search a element in the hash table required only Ο(1) time. In the direct addressing such as ArrayList, an element is stored is referenced in the k slot of the table, instead hashing, this element is stored in slot h(k) for the hash function h . In other words, k 3 an k 10 can be in the same slot. If two keys are fallen to a same slot which is called hash

Java 6 Collections: Why use LinkedList

Image
Java collections framework avoid the idiosyncratic programming. Therefore, collection framework is more manageable and usability is unified across the applications, and best practices are enforced. Anyway, it is very important to understand the generics based new collection framework. I love to do programming with Eclipse. As shown in the above figure, the instance variable ‘d’ can be initialized with with the ‘ArrayList’ whose parameterized type is ‘Dog’. The type of the instance variable d is ‘List’ which is also based on ‘Dog’ generic type. To this array you can add only instances which are type of ‘Dog’. If the generic type is changed to ‘Integer,’ everything will change from ‘Dog’ to ‘Integer’. If you are comfortable with Java Generics, this is the time to consider that how they have implemented Collection to cater for any Object. Linked List Array and her counterpart ArrayList has direct access which cost Ο(1) time . Comparably, this is the cheapest. However, arra

Java Thread Interaction: use of wait and notify

In this blog, my main intention to introduce the thread interaction based on the java.lang.wait() and java.lang.notify()/notifyAll() methods. Anyway, I would keen to keep the things simple. It is not difficult to visualize one of the playground trainings you had participated. There is one trainer and number of players. All the players are waiting for the ball which has been thrown by the instructor. One person can acquire ball at once and he will re-throws the ball back to the trainer. To make the things simple, suppose a player, who acquired the ball, has been pulled out from the field. For the design, we have two factors to model The behavior between Trainer and the players The ownership of the ball In the first case players are waiting for the trainer’s notification to acquire the ball, anyway in this competition thread scheduler decide who should get the ball, mean no special priority (all the Player threads are in the same priority level). To win the competition at

Example for boolean java.lang.Thread.isAlive()

Image
This blog intended to check the aliveness of a thread. We have used the method boolean isAlive()  define in the class java.lang.Thread, which is not a static method. Aliveness of the thread can be noted in the Thread lifecycle diagram as follows.   I wrote a simple example to demonstrate the status of the aliveness of the Thread. In that program, aliveness tested before start, that is where the thread is in the New state, before end (Runnable, Running, or Blocked) and after end which is Dead status. The AliveExample thread is blocked while main thread is running, although it is alive. package com.ojitha.thread; enum Alive { YES(" thread is alive"), NO(" thread is not alive"); private String msg; private Alive(String msg){ this.msg = msg; } public String getMessage(){ return this.msg; } } public class TestAlive { /** * @param args */ public static void main(String[] args) { AliveExample a = new AliveExample(); Thread t = new Th

Java Constructor Loading Tips

This is very interesting topic to discuses Java constructor loading. As a Java programmer, unfortunately, I haven't had a chance to go through in my experience because most of the time standard programming doesn't use this. However, it is very important to know that how the JVM load static/instance blocks and variables with the constructor in the initiation of new objects. I've wrote very simple program to illustrate this scenario. public class Constructors { public static int count=0; public static void main(String[] args){ System.out.println("["+ ++Constructors.count +"]"+"Instantiate"); ChildClass c = new ChildClass(); } } //super class class SuperClass { //super class instance variable int varS =++Constructors.count; SuperClass(){ System.out.println("["+ ++Constructors.count +"]"+"

2009 Top 10s

With the start of 2009, lots of good reviews of previous year as well as predictions for this year have been released. This blog amass the top 10s I found from different locations. 10 Java Technology Resolution for 2009 InformIT most popular 2008 list Interview with Donald Knuth How to Network Vista and XP Computers Together C++ Reference Guide The Top 10 iPhone Applications .NET Reference Guide SQL Server Reference Guide Java Reference Guide The Top 10 Problems with IT Certification in 2008 Looking Inside Microsoft System Center Operations Manager 2007 Microsoft Office Reference Guide " What’s Hot for 2009? " from IEEE Computer Society 10 predictions for Linux and open source in 2009 IBM Developerworks top 10 contents

Best 10 Windows programs

I've used Linux as well as Windows. There are thousand of free software utilities for Linux platform which always make my life easier. I was wonder whether there is comprehensive enough tools which can support Windows in some difficult occasions. Recently, I found very good blog " My 10 favorite Windows programs of all time ". These tools are very interesting.