Skip navigation.

exploreopera

| Help

Sign up | Help

BlogtimeException

By Behrang Saeedzadeh (the 3rd incarnation)

Posts tagged with "Programming"

The funniest/scariest programming topic ever submitted to Reddit

,

Reading a File in Java -- Beautifully

,

Till today, I used to read an entire text file like this:

String newLine = System.getProperty("line.separator");

StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
   sb.append(line).append(newLine);
}
return sb.toString();

That's not beautiful. But today I came up with this alternative:

String newLine = System.getProperty("line.separator");

StringBuilder sb = new StringBuilder();
for (String line = br.readLine(); line != null; line = br.readLine()) {
   sb.append(line).append(newLine);
}
return sb.toString();

And I like its beauty. What do you think? Isn't this more beautiful? :sherlock: It would be more convenient if BufferedReader had a readFile() method though. Also it makes sense to make BufferedReader iterable so we could have:

for (String line : buffReader) {
   // do something with line
}

EJB-to-Client Notification

, , , ...

UPDATE: Looks like ICEfaces' approach is not inefficient at all. Actually I didn't want to imply that ICEfaces is inefficient. My point was that JMS is an efficient and reasonable approach for notifying Desktop clients of the events that occur on the server-side.

A few days ago a fella asked me how he can notify (Swing-based) clients of his EJB based application of certain events that occur inside the EJB server (deletes, updates, inserts, etc.)?

My answer was that he has two use JMS for this purpose. He was arguing that JMS is for server-to-server communication, which, of course, is incorrect.

He was asking for something that accomplishes this in a way "as easy as ICEFaces". Well, the problem with ICEFaces' approach is that in ICFaces, your clients periodically send requests to the server to synchronize their states, and this approach, is very inefficient. Actually, it is possible to implement an efficient solution this way, but ICEFaces' approach, is inefficient.

He didn't have a very happy experience with JMS and did not want to go through its complexities once again. But fortunately, there are a few nice POJO based solutions (such as Spring) available today that hides away lots of these complexities and makes using JMS much easier.