Saturday Nov 17, 2007

NetBeans 6.0 (Beta 2) Java Editor ... you need to take look

I installed NetBeans 6.0 (Beta 2) on my Mac about a month ago. I didn't do much with it until last week. One of my TODO's has been: "work on Javadocs" for Project OpenPTK. I know ... I know ... we should have been writing the Javadocs as we wrote code, just like every good developer does :-).

I decided to use NetBeans 6.0 (Beta 2), instead of my NetBeans 5.5 install. I'm really happy I did ... the new editor ROCKS. There's a ton of new features, I'm sure i'll get to use them all eventually. Did I say the new editor "JUST ROCKS".

As I was adding Javadoc comments "/\*\*", the NetBeans Editor started a nice template for me with @param, @throws, @return elements as necessary. This made it easier for me to "Fill-In-The-Blanks" with notations. As I went through all the Java files in Project OpenPTK's public api code, I noticed that the Editor was flagging different things in the code. It highlighted methods that should have @Override, include lines not being used, local variable that were conflicting with global fields and few other things. I decided to open every Java source file in the project and see what the editor found. I removed a lot of include lines that were not need being used.

There's a lot of other cool features in this new Editor. Here's a just few things that I played with:

  • I really like the new diff features, especially when you delete lines and the icon lets you see what was removed, compared to what's in SVN.
  • The default colorizing is a lot nicer.
  • The highlighting is very useful, double-click on a variable and it's highlighted everywhere, the right-side margin shows a little "tick" mark where that variable is used thoughout your source file.
  • I needed to use the Instant Renaming feature a couple of times (when a local variable name was the same as a global field ... oops). Just start changing the local variable where it's defined and it will dynamically change everywhere in the method.

There's many more new features. Take a look at this NetBeans wiki site, it's a good summary of the Editor's features.

Wednesday Jun 14, 2006

I discovered the Future (and FutureTask)

I'm working on updating a Java program that has to call a Web Service. The application is a Corporate phonebook (white pages) that uses the Sun LDAP Directory server. One option in the program calls a Web Service to get external (non-LDAP) data about a person. The application would wait if the Web Service was either slow or not available, eventually timing out. The timeout was too long for the end-user.

The requirement was to have the application call the Web Service with the option of setting a specific timeout.

I reviewed my Java books on threading, searched the web and tried to write a test Java app that would create a Thread, have the new Thread call the Web Service and stop if the Thread took too long. I tried using various combinations of

wait(millseconds)

and

notify()

to make something happen. No luck. I asked a friend "What am I doing wrong"?

His anwser was

java.util.concurrent.FutureTask

Thanks again to Brian Doherty for the advise.

The java.util.concurrent.\* package is new in the Java SE 5.0 release. I found a great example of using FutureTask in Core Java 2 Volume II - Advanced Features, Seventh Edition Chapter 1. Multithreading. The get(timeout_value,timeout_unit) method was exactly what I needed. It was soooooo much easier to implement a test program with the java.util.concurrrent package then by manually trying to make wait()/notify() work. Here's my test program which has a timeout value set to expire before the work (sleeping) is complete:

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class testFutureTask
{
   Perform perform = null;
   FutureTask task = null;
   Thread thd = null;
   
   public testFutureTask()
   {
   }
   
   public static void main(String[] args)
   {
      testFutureTask test = new testFutureTask();
      test.begin();
   }
   
   private void begin()
   {
      String answer = null;
      perform = new Perform("what is the question");
      task = new FutureTask(perform);
      thd = new Thread(task);
      thd.start();
      System.out.println("\\nPerforming the Task, (please wait) ... \\n");
      try
      {
//         answer = task.get();  // run until complete
         answer = task.get(5000,TimeUnit.MILLISECONDS); // timeout in 5 seconds
      }
      catch (ExecutionException e)
      {
         e.printStackTrace();
      }
      catch (InterruptedException e)
      {
         answer = "got interrupted.";
      }
      catch (TimeoutException e)
      {
         answer = "tired of waiting, timed-out.";
      }
      System.out.println(answer);
      return;
   }
}

class Perform implements Callable
{
   private String input = null;
   private String output = null;
   
   public Perform(String input)
   {
      this.input = input;
   }
   
   public String call() throws Exception
   {
      output = "The response to '" + input + "' is 42";
      try
      {
         Thread.sleep(10000);
      }
      catch (InterruptedException e)
      {
         System.out.println("Perform::call(), sleep interrupted.");
      }
      return output;
   }
}

Tuesday Jul 12, 2005

JavaOne children grow up fast

JavaOne Y.A.T.R. (Yet Another Trip Report)

I just got back (to the office) from the 4th of July holiday and vacation. Prior to this time-off, I attended the JavaOne conference. I eventually made it back to ORD from SFO (Note to self, don't travel the Friday before a long holiday weekend).

Java is ten ... Happy Birthday. While sitting in one of the General Sessions (someone was talking about Java's beginning) I realized that my oldest son had his first birthday when Java was released. Children grow up fast. You probably don't notice all their changes over the years when you're with them every day. You might not notice the advances they've made over the years until you take a look back. Hearing people talk about Java, relative to where it came from, is a lot like looking at the photo album of your children or noticing the growth marks you've put on the door-way each birthday ... you realize they've come a long way.

I remember evangelizing Java back in its beginning. I was giving Java presentations all the time. We talked to people that accepted Java full-force and saw the value in adopting the technology. We also talked to people that said NO. I remember very clearly one customer that said (I quote) "Java ... it doesn't have thick of the market" ... "we'll stay with our PowerBuilder strategy" (is PowerBuilder still around). The evolution of Java seems to have followed the technology adoption theories discussed in the book Crossing The Chasm by Geoffrey A. Moore. I'd say that Java has definitely crossed the chasm and is in the "Early Majority" and "Late Majority" phases. I can't remember the last time I give a presentation where I had to "sell" Java. Well, there was a little bit when .Net first made an appearance. There were some people that tried to compare Java to .Net.

At the end of the week I looked back at the sessions I attended. I thought about the how this years conference was different then the ones I attended before, especially the early ones. The first JavaOne conference I attended was the second one. Back then, the General Sessions and break-out sessions had an overall theme around "what could be done" with Java and "what features are still needed". This years conference, from my perspective, highlighted three key topics:

  • Java is solving real business problems today.
  • Tools are here (or soon to be here) to solve complexity.
  • Interoperability is the focus moving forward, can you say SOA.

JavaOne Information
Sessions

About

Scott Fehrman

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
News

No bookmarks in folder

Projects

No bookmarks in folder

Ref. Material

No bookmarks in folder