Showing posts with label java. Show all posts

Best example for Javamail  

Posted by Kishore in ,

I have found a wonderful sample of javamail in here http://www.rgagnon.com/javadetails/java-0321.html

Stopping a Java thread  

Posted by Kishore in

I came across a question of how to stop a Java thread. I suddenly felt about the stop and other methods in the Thread class. Then i slowly remembered that they are no longer available and they are deprecated.

Then i started searching in net. Then i found a solution(i was not known that time that it was an ancient technique). It said we have to keep a volatile flag variable and we can check the status in the run(). It sounded good to me.

But when i was reading till end of the document, i came across how to stop a thread in non-running situations (wait or sleep implemented thread, I/O blocked thread i.e. thread reading or writing files). In those situations we can use interrupt method to do it efectively.

Hmmm its been so long since i used threads in my application. I used thread last when i was developing my network file transfer application. The application came very well than i expected. It doesnt even needed any file/directory access permission. I used a special mechanism in it. In that i was using multithreaded server. That was the last time i used effectively. Sounds like i have to brush up core java a bit.

I came across concurrent package when reading about this interrupt method. Hope to write about it soon.

I noted many people getting confused with volatile and transient variables in java.

volatile variable is a kind of static variable which shares its value among the threads. To be precise, the value of a volatile variable can be shared among threads and can be simulataneusly accessed or modified.

transient variable is a used to restrict a field from being serialized.

Frameworks in Java projects  

Posted by Kishore in

When i see some java people and asking about a framework, they say struts, hibernate or spring etc. Noone is keen to create a custom framework of their own.

When i was working in my first project, i underwent a training for ten days to understand the framework they developed. It was such a huge project and they had a solid framework.

Which never failed till the end. It was a portal project but we used the whole project in a single portlet so no much of portlet stuff. But they customized everything that they almost created their own methods and classes to do almost all the things. Since we used JSF, we created a lot of custom components also(Till now i was saying as they, but now its WE. Since i was working in that part and i WAS a specialist in that area)

Enough of the older stories. First lets see what does a framework mean.

Dont need to go for dictionary since the meaning of Framework is evident to all. So for a project, the skeleton is framework. So once the skeleton is framed properly, we can go ahead with filling the skeleton with flesh. Oops, going like a horror movie. So here, if the application has many modules, each module will use almost same(some may need sub framework) the framework. Each module will have its own track in a good framework. So it will make the process of recovery after a damage easy.

For example all projects in java handles with database searching, insertion of new data and updating or deleting data. But they will have different business process or rules.

So here one thing is same, contacting the DB. So the major aim of the framework will be this. Then insertion and updation are same part so they will use a track in the framework(If needed some sub framework may be used for business rules). Searching and deleting(which normally not good to use. Instead we can move to a temp DB and delete contents in intervals) will take their own tracks.

If its a web project then, its good no no must to use a tiered architecture. Majorly 3 tier. Its M..U..S..T.. must to follow this rule. Otherwise its so hard to maintenance and also it will make the whole project rubbish. No intro for 3 tier architecture. Its like teaching a,b,c.. again.

May be these are some of the advatage of using a own framework in JAVA.

The major problems in java are Exception handling and memory management(Though there are strong garbage collection mechanisms, a single coding error will lead to a total mess, which will take days to figure out) and some object pass between classes.

Its good to extend every class from our own custom super class. For example in struts. Instead of extending all action classes from Action. Extend a CustomAction class from Action and the rest can be extended from CustomAction. So it gives a clear control over the Action class. so we can do whatever changes before it finally reaches to the original Action class. For example in the topmost action class, we can have exception catching and handling mechanism so that it will surely make process easy.

Hope i confused u. But i am sure that you should have got an idea about frameworks. Any doubts or scolds, pls do it in comments. lol..