comp.lang.java.programmer
http://groups-beta.google.com/group/comp.lang.java.programmer
[EMAIL PROTECTED]

Today's topics:

* Need a method for detecting when files are written to a directory - 5 
messages, 3 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d1293173b48ccf65
* Question about EJB's - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2d4a780fe530c2ba
* I got the Herbert Schilt, (Java 2) Package blues. Please help before I shoot the dog 
- 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f29e821306447a70
* Iteration over sets - 2 messages, 2 authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2464f0c85c8b717f
* code hangs when reading from socket - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8990f56bd2a4bba0
* Socket problem -- response slow for host with domain (on SunOS5.8) - 1 messages, 1 
author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bfb84c34caf0c9e9
* Need help w. getOutputStream( ) - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/57fcce963c42a641
* Beginner Advice Sought - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b96a0a430a102e22
* Preventing multiple instance standalone desktop gui applications - 2 messages, 2 
authors
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/afa857e018f3780
* assign JavaScript variable to Java variable problem in JSP - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3491429a868b5a8b
* what sample work to show in job interview? - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f7668b32a1da179
* code optmization - 2 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1b784382e7cbb306
* server application - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4bfd9bcb653fd31c
* Light Servlet Container - 1 messages, 1 author
  
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7a1f451cb3bd91b1
  
==========================================================================
TOPIC: Need a method for detecting when files are written to a directory
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d1293173b48ccf65
==========================================================================

== 1 of 5 ==
Date:   Fri,   Sep 24 2004 10:27 pm
From: Jacob <[EMAIL PROTECTED]> 

Elliott wrote:

> Any help would be greatly appreciated.

Polling is the only portable way (unless you control the
file writing process in some way), and is sufficient in
most cases.

Look at the FileMonitor class at:

   http://geosoft.no/software/index.html#filemonitor

It accepts any File (including a directory) object. Monitoring
a directory will cause an event if a file is created/deleted/
modified within that directory.




== 2 of 5 ==
Date:   Fri,   Sep 24 2004 10:13 pm
From: Sudsy <[EMAIL PROTECTED]> 

Chris Smith wrote:
<snip>
> In any case, I'm getting more and more tired of seeing people who were 
> hired to find the best way to do something default to an EJB solution 
> that is an order of magnitude more complex than needed, just because 
> that's what they are familiar with.  I'm afraid that this reply, taken 
> at face value, encourages this.

You are completely wrong. I prefer to suggest the simpler solutions when
applicable. I recommend an Apache/Tomcat combination over a J2EE server
in most cases, for example.
But I also recognize "appropriate uses of technology". The problem of
how to detect when a file transferred via FTP is ready for processing is
one which arises frequently. Various parties have suggested differing
approaches over the years. A brief perusal of the archives will prove
this out.
Messaging systems which de-couple clients and servers have been around
a lot longer than J2EE; take a look at IBM's MQSeries. They obviously
address a need. Hence my suggestion to at least consider it as an
option.
I didn't say that it was the right or only approach, merely something
which might fit into a complex, heterogeneous architecture.
It's the same with Web Services or XML; they could be considered over-
kill in many scenarios but they DO have their place.
YMMV.




== 3 of 5 ==
Date:   Fri,   Sep 24 2004 10:21 pm
From: "David Hilsee" <[EMAIL PROTECTED]> 

"Sudsy" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> David Hilsee wrote:
> > "Sudsy" <[EMAIL PROTECTED]> wrote in message
> <snip>
> >>Ya know, this is the kind of application for which JMS is ideally
> >>suited. Your client creates the file then sends a notification on
> >>a queue which drives invocation of onMessage on a regular client
> >>or Message Driven Bean which then processes the file.
> >>Just an idea, after all it does address "asynchronous" processing
> >>with loose-coupling.
> >
> > Bonus points if the file can be eliminated altogether by placing its
> > contents in the message.
>
> David,
>     I agree with one proviso: large files shouldn't be queued, IMHO.
> If you're talking in the range of a few to a few tens of kilobytes
> then I'm in complete agreement. I actually almost suggested it my-
> self! ;-)  But when you start talking about MBs...
>     Glad to see that we're both on the same track. It's an elegant
> solution to a recurring problem. Not universal perhaps, but worthy
> of consideration. That's the only reason I suggested it in the first
> place.
>     As I always say, "why reinvent the wheel?".

Large files are a tough call.  When I used the word "if", I was thinking of
possible performance issues that might arise if the message were very large.
Some implementations might handle messages that are on the order of MBs just
fine.  If the JMS provider can handle large messages, and your application
has no problem with dealing with them, then I think it's best to go with it.
I'd probably change the solution only if the implementation could not handle
it.

-- 
David Hilsee





== 4 of 5 ==
Date:   Fri,   Sep 24 2004 10:45 pm
From: Jacob <[EMAIL PROTECTED]> 

Chris Smith wrote:

> In any case, I'm getting more and more tired of seeing people who were 
> hired to find the best way to do something default to an EJB solution 
> that is an order of magnitude more complex than needed, just because 
> that's what they are familiar with.  I'm afraid that this reply, taken 
> at face value, encourages this.

Yes.

Throwing as much technology as possible at problems seems
to be the norm these days. I have been in "enterprise" projects
where young professionals are so focused on technical issues
that they tend to forget the domain problem they are up to.
Include the vast technical overhead in the typical modern
development environments. All this has a huge impact on project
cost, quality, maintainability and longevity (and clutter
programmer CVs with _tools_ rather than _skills_).

I favor the approach of solving problems with as little
technology as possible.




== 5 of 5 ==
Date:   Fri,   Sep 24 2004 10:43 pm
From: "David Hilsee" <[EMAIL PROTECTED]> 

"Chris Smith" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Sudsy wrote:
> > Ya know, this is the kind of application for which JMS is ideally
> > suited.  Your client creates the file then sends a notification on
> > a queue which drives invocation of onMessage on a regular client
> > or Message Driven Bean which then processes the file.
> > Just an idea, after all it does address "asynchronous" processing
> > with loose-coupling.
>
> Maybe... if there are a dozen other things that work out in favor of JMS
> as well.  For example, asking clients to send a message to a JMS bean is
> far more complex than asking them to drop a file into a directory.  One
> can be done by hand by a human being, while the other requires software.
> One can be done by zillions of document-oriented programs including such
> things as Microsoft Word, while the other requires using your own
> proprietary software.  Not to mention that you've just introduced an
> application server to the architecture.
>
> A migration from a simple architecture like the OP proposed to something
> with JMS and message-driven beans ought to be guided by something
> stronger than a distaste for polling.
>
> In any case, I'm getting more and more tired of seeing people who were
> hired to find the best way to do something default to an EJB solution
> that is an order of magnitude more complex than needed, just because
> that's what they are familiar with.  I'm afraid that this reply, taken
> at face value, encourages this.

Your complaints may have merit.  However, there are a lot of things to
consider.  For example, is the application that produces this file
JMS-aware?  Can it understand MOM?  Is it even written in Java?  Can it be
modified?  If it can only copy a file into a directory, then I agree that
JMS may not be appropriate.  If the creator of the file is just an
application that Elllott wrote where he really wanted to use asychronous IPC
and chose to do it by copying a file into a shared directory, then I bet
there are better solutions to his problem than monitoring the filesystem.

-- 
David Hilsee






==========================================================================
TOPIC: Question about EJB's
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2d4a780fe530c2ba
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 10:21 pm
From: Sudsy <[EMAIL PROTECTED]> 

Anonymous wrote:
> Hi
> 
> I recently used websphere to make a few ejb's.
> I have a couple of questions... 
> does one ejb object represent one record? 

Entity EJBs typically do.

> how would you get an existing record in a table, and retreive it into
> the ejb?

It depends on whether you're using BMP or CMP.

> say you want to select name from products where supplierid=1.
> how would you do that with an ejb?

See previous response.

> now that I know how to make ejbs, where would I find stuff on the
> internet that shows how to use them for querys/updates etc?

What kind of EJBs have you made? Stateful or stateless session beans?
You can use JDBC directly or you can use another level of indirection
through the use of DAOs.
Go here:
<http://java.sun.com/j2ee/1.4/docs/tutorial/doc/>
and click on "J2EE 1.4 APIs". It should give you some ideas.





==========================================================================
TOPIC: I got the Herbert Schilt, (Java 2) Package blues. Please help before I shoot 
the dog
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f29e821306447a70
==========================================================================

== 1 of 2 ==
Date:   Fri,   Sep 24 2004 10:31 pm
From: "Gary Labowitz" <[EMAIL PROTECTED]> 

"Rendzina" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all.
> I'm a recent convert to the world of Java and I've hit a problem that
> maybe a few of you learned people could help me with. Please.
>
> I'm reading Herbert Schildt (Java 2, complete reference, 5th edition.)
> and I'm stuck on Chapter 9, Packages and Interfaces.  I did the first
> demo ok but then could not compile anything past  his first program,
>
>  Package p1- Protection.java, Derived. java, SamePackage.java.
> Package p2-Protection.java,OtherPackage.java.
> To test "Demo.java" will not compile.
>
> Is there some simple explanation/rule for getting packages
> working.......classpath?    It's very confusing in Schildt and there
> doesn't seem to be any examples around.
> I'd be grateful for any ideas or help.

Just shoot the Schildt book! This book is an easy read (and I use it in my
classes) but it's (non)explanation of classpath and packages is inadequate.
Try http://jinx.swiki.net/12 (and browse the rest of the wiki) for
information on classpath and packages.
I don't know if the wiki is still being updated (and where is Jon Skeet,
anyway?), but it is still available.
-- 
Gary





== 2 of 2 ==
Date:   Fri,   Sep 24 2004 10:57 pm
From: Andrew Thompson <[EMAIL PROTECTED]> 

On Sat, 25 Sep 2004 01:31:21 -0400, Gary Labowitz wrote:

> I don't know if the wiki is still being updated (and where is Jon Skeet,
> anyway?), ..

Jon is alive and well
<http://google.com/groups?as_uauthors=jon+skeet>

And posting actively, to groups other than those
that most of us are used to reading him on..
<http://google.com/groups?as_uauthors=jon+skeet&group=microsoft.public.dotnet.*>

HTH

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.lensescapes.com/  Images that escape the mundane




==========================================================================
TOPIC: Iteration over sets
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2464f0c85c8b717f
==========================================================================

== 1 of 2 ==
Date:   Fri,   Sep 24 2004 10:49 pm
From: Jacob <[EMAIL PROTECTED]> 

Swarat Chaudhuri wrote:

> I am encountering concurrent modification exceptions while using the
> class "Iterator" to iterate over a Java "HashSet". 

There are two common approaches:

o Loop over a *copy* of the list. Then your iteration and
   insertion will be done on different objects.

o Iterate backwards over the list. If additions are done at
   the end, then this will not interfer with the iteration
   process.




== 2 of 2 ==
Date:   Sat,   Sep 25 2004 12:47 am
From: Babu Kalakrishnan <[EMAIL PROTECTED]> 

Swarat Chaudhuri wrote:
> 
> I have a set S over which I would like to iterate. While iterating, in
> certain cases, I want to add elements to the set. I would like the
> iterator to treat these new elements as if they have not been seen so
> far.  However, doing so seems to guarantee that concurrent modification
> exception will be thrown.
> 
> So the question is, is there a way to achieve what I want to do? Without
> needing to restart the iteration every time an "update" occurs?
> 

The standard HashSet implementation and the Iterator returned by it
cannot do this job (as you already found out). Also since the Iterator
returned by a HashSet does not guarantee any specific order in which it
returns its elements, making the newly added elements appear later in
the iteration order isn't guaranteed either (even assuming that you 
manage to somehow get rid of the ConcurrentModificationException)

The easiest thing to do would be to use the combination of a List and a
HashSet and write your own ListIterator implementation. Check out the 
code sample below. You can use the add/remove methods of the 
ListIterator to add/remove elements.

// Warning - untested : provided only as sample

// ListIterator implementation does not check for concurrent
// modification. Code for this should be added . (See the
// API docs for "modCount" field in the AbstractList class)


import java.util.ArrayList;
import java.util.HashSet;
import java.util.ListIterator;

public class MyHashSet extends HashSet
{

     private ArrayList list = new ArrayList();

     public boolean add(Object o)
     {
         if (super.add(o))
         {
             list.add(o);
             return true;
         } else
             return false;
     }

     public boolean remove(Object o)
     {
         if (super.remove(o))
         {
             list.remove(o);
             return true;
         } else
             return false;
     }

     // Do similar stuff with other HashSet methods if necessary
     // ensuring that the contents of "list" matches that of the set

     public ListIterator listIterator()
     {
         return new MyListIterator();
     }

     public class MyListIterator implements ListIterator
     {
         private int nextIndex;
         private Object lastReturned;

         public int nextIndex()
         {
             return nextIndex;
         }

         public boolean hasNext()
         {
             return nextIndex < size();
         }

         public Object next()
         {
             return lastReturned = list.get(nextIndex++);
         }

         public int previousIndex()
         {
             return nextIndex - 1;
         }

         public boolean hasPrevious()
         {
             return nextIndex > 0;
         }

         public Object previous()
         {
             return lastReturned = list.get(--nextIndex);
         }

         public void add(Object o)
         {
             MyHashSet.this.add(o);
         }

         public void remove()
         {
             if (lastReturned == null)
                 throw new IllegalStateException(
                         "Cannot remove before a next or previous call");
             MyHashSet.this.remove(lastReturned);
         }

         public void set(Object o)
         {
             throw new UnsupportedOperationException("Unsupported");
         }
     }
}

BK




==========================================================================
TOPIC: code hangs when reading from socket
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8990f56bd2a4bba0
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 10:35 pm
From: [EMAIL PROTECTED] (Jani Yusef) 

I am attempting to send data to a client socket and then turn around
and read the response back from the client. The data is sent but when
I attempt to read the data sent back it hangs. I have checked and the
client is receiving the data just fine and seemingly sending back a
perfectly correct reponse. Is there an error in the code below which
is preventing me from reading the data sent back to me correctly?
Any advice would be much appreciated.

//servo is an instance of ServerSocket and socko is an instance of
Socket


//send the message to attached clients
Socket s=servo.accept();
PrintStream ps=new PrintStream(s.getOutputStream());
ps.println(response);
                        
//Now read the response from the clients
s=servo.accept();//read input from clients
br=new BufferedReader(new InputStreamReader(s.getInputStream()));
response=br.readLine();//STUCK HERE, THE NEXT LINE IS NOT REACHED




==========================================================================
TOPIC: Socket problem -- response slow for host with domain (on SunOS5.8)
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bfb84c34caf0c9e9
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 10:33 pm
From: Babu Kalakrishnan <[EMAIL PROTECTED]> 

Sudsy wrote:
> Nishi Bhonsle wrote:
> <snip>
> 
>> I think, even though the sysadmin does not open the connections to 
>> port 25, they should
> 
>  > be dropping packets instead of rejecting them .ie. If I run the same 
> telnet command on
>  > my windows box, I get the following returned pretty quickly
> 
>> C:\>telnet yahoo.com 25
>> Connecting To yahoo.com...Could not open a connection to host on port 
>> 25 : Connect failed
>>
>> If I get such a response from the solaris box, that would help too.
>>
>> What do you think?
> 
> 
> I think you haven't been around long enough! The port is operating in
> "stealth" mode. Incoming SYN packets which don't pass the filters are
> simply "dropped on the floor" as opposed to being rejected. That way,
> a port scanner can't tell whether or not there's actually service on
> the port.
> If there weren't so many yahoos trying to find open relays...  :-(
> Seriously, this is completely acceptable behaviour.
> 

I think the DROP policy is being implemented on the firewall in front of 
the Solaris server (or on that server itself), not on the yahoo.com 
server. (If you look at my previous message, I was able to connect 
succesfully to the server)

This in my opinion is bad practice. The policy for outgoing connections 
from the firewall which are to be denied should always be REJECT rather 
than DROP so that the connection fails immediately. A DROP policy is 
fine for ingress filtering when you don't want a port scanner from 
outside to even see that the machine is up (and also slow it down in its 
task).

I still wonder why the difference in connection failure time between the 
Solaris machine and Windows one though (since the OP mentioned that both 
are behind the same firewall). May be an additional filter on the 
Solaris machine ? Or different policies based on different hosts ?

BK




==========================================================================
TOPIC: Need help w. getOutputStream( )
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/57fcce963c42a641
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 10:41 pm
From: Steve Burrus <[EMAIL PROTECTED]> 

I need some pretty immediate help w. using the getOutputStream() servlet 
method to be able to see an image in my web browser!! Can anyone 
possibly help me with this please???




==========================================================================
TOPIC: Beginner Advice Sought
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b96a0a430a102e22
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 10:48 pm
From: Scott Ellsworth <[EMAIL PROTECTED]> 

In article <[EMAIL PROTECTED]>, "jbeck" <[EMAIL PROTECTED]> 
wrote:

> Is it me, or does it seem like some of the free stuff is as good, if not 
> better than commercial stuff. I used Dev-C++ for learning C++, and I think 
> it worked as well as anything else (and I tried about 3 or 4 different 
> ones...including two seperate versions of the same product from Microsoft).

It really varies.  I find Eclipse good in most ways, but because the 
project file format is binary and closed, I have to manually generate 
projects when my clients change them.

IDEA, on the other hand, uses plain old xml.  One XSLT later, and i have 
the hundred or so modules made, and the requisite projects generated.  
Darn cool.

I understand this should be an easy Eclipse plugin, but I am not up to 
creating such a beast right now.

> For Java, I plan on using the command line based compiler for a bit 
> longer...at least until I *think* I know what I am doing! :-) 

You learn a lot that way.  I find IDEs useful, but it really depends on 
what you need.

Scott




==========================================================================
TOPIC: Preventing multiple instance standalone desktop gui applications
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/afa857e018f3780
==========================================================================

== 1 of 2 ==
Date:   Fri,   Sep 24 2004 11:09 pm
From: Jacob <[EMAIL PROTECTED]> 

Paul Lutus wrote:

> There can be excellent reasons to do this. It is not necessarily a sign of
> prorgammer laziness. If the program reads and writes to its own
> configuration file, it is very confusing to a user to have multiple
> instances running, and it seems inconsistent to spend time reconfiguring an
> application, only to have the changes wiped out because of a minimized
> extra instance that is closed automatically when the system is shut down.

All programs (of a certain size and complexity) access persistent
session information. That a program has this feature is no excuse
to make it a "singelton" application.

Technically, session information is no different from _data_ (as
stored in a database). If concurrent modification is an issue
then your session storage strategy is to simple.

But of course, the user runs a certain *risk* when launching
several instances of a program that stores configuration. This
is a risk that he is aware of and must take the consequences of.
The user should understand that when changing color in app A, exiting
app A (=> store settings), and then exiting app B (=> store settings),
then the color setting will be lost for the next session. This
will be the user responsibility. The programmer is responsible for
ensuring that the session info is never corrupted it any way.
It takes some effort.

I have many standard programs running that  solves this problem
just fine, and I have written quite a few as well.





== 2 of 2 ==
Date:   Fri,   Sep 24 2004 11:31 pm
From: Paul Lutus <[EMAIL PROTECTED]> 

Jacob wrote:

> Paul Lutus wrote:
> 
>> There can be excellent reasons to do this. It is not necessarily a sign
>> of prorgammer laziness. If the program reads and writes to its own
>> configuration file, it is very confusing to a user to have multiple
>> instances running, and it seems inconsistent to spend time reconfiguring
>> an application, only to have the changes wiped out because of a minimized
>> extra instance that is closed automatically when the system is shut down.
> 
> All programs (of a certain size and complexity) access persistent
> session information. That a program has this feature is no excuse
> to make it a "singelton" application.

This is not an excuse, this is a necessity. One program instance can store
state information, end of story.

-- 
Paul Lutus
http://www.arachnoid.com





==========================================================================
TOPIC: assign JavaScript variable to Java variable problem in JSP
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3491429a868b5a8b
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 10:52 pm
From: [EMAIL PROTECTED] (Matt) 

If I assign Java variable a to javascript variable x, it is
fine.
 <%
  int a = 10;
 %>
 var x = <%= a %>;
 alert(x);

But if I do the other way around, then it has 500 error. any ideas??

<% 
  int b; 
%>
 <% b %> = x;


thanks!




==========================================================================
TOPIC: what sample work to show in job interview?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f7668b32a1da179
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 11:00 pm
From: [EMAIL PROTECTED] (Matt) 

For a job interview, what sample work we should show? We cannot show
the source code we did in previous jobs, or documentations in previous
jobs, because of company's propreitary, correct?

please advise. thanks!!




==========================================================================
TOPIC: code optmization
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1b784382e7cbb306
==========================================================================

== 1 of 2 ==
Date:   Fri,   Sep 24 2004 11:17 pm
From: Babu Kalakrishnan <[EMAIL PROTECTED]> 

[Moving top posted response down]

 > Chris Smith <[EMAIL PROTECTED]> wrote in message 
news:<[EMAIL PROTECTED]>...
 >
 >> Maybe it's time you gave more information.


mank wrote:
> 1. public static String getData(String var,float mFactor) {
> if (var == null || var.trim().length() == 0) {
> return null;
> }
> try {
> Pattern pattern = PatternManager.getDollarAmountPattern();
> if (pattern==null) return var;
> PatternMatcher matcher = new Perl5Matcher();
> if (matcher.contains(var, pattern)) {
> MatchResult result = matcher.getMatch();
> var = result.group(2);
> if (result.group(2) == null || result.group(2).trim().length() < 1)
>   return var;
> else {
>  copay=String.valueOf(Math.round(Float.parseFloat(var)*mFactor));
> }
> if (result.group(1) != null && result.group(1).trim().length() > 0) {
>   return result.group(1) + var;
> }
> else if (result.group(3) != null && result.group(3).trim().length() >
> 0) {
>   return result.group(2) + result.group(3);
> }
> else {
>   return "$" + result.group(2);
> }}}
> catch (NumberFormatException ex) {}
> return copay;
> }
> 2. result.group(1/2/3)  is a method used to extract the part of the
> input pattern. It is a standard method of jakarta ORO (pattern
> matching)..
> 3.My question was which is a better coding style if I have to call a
> method thrice then should I use a temporary variable as is done in
> your solution?
>   

Please do not top-post. It is difficult to follow the thread.

The code you have posted this time adds something to the previous 
version, but isn't still clear enough. The variable "var" is now known 
to be local, but you've introduced a new one called "copay" which isn't 
declared locally. So we have to assume that it is an instance variable - 
Is this correct ?

There is only one suggestion I can provide - though that has more to do 
with improving the readability of the code rather than optimization 
(Though I suspect it might improve performance as well) :

When you use the same complex expression a multiple number of times in 
any section of code, it is worthwhile to move it into a separate method. 
In your code, the expression "someString != null && 
someString.trim().length() > 0" (and the negation of the same 
expression) occurs in 4 places, so it is well worth it to move it into a 
method.

Since you're using jakarta libraries anyway, you'll find that the same 
function is available as "isNonBlank()" and the negated function as 
"isBlank()" in the org.jakarta.commons.lang.StringUtils class. Also that 
library implements it slightly more efficiently (checks for strings that 
are all whitespace without producing an intermediate String object using 
trim()).

And the answer to your point no. (3) : In my opinion it is always better 
to use a temporary variable than calling a function more than once on 
the fly. Introducing a variable only adds an additional reference slot 
in your stack frame - whereas calling the method multiple number of 
times will most probably create additional Objects as well - more work 
for the garbage collector, as well as use up extra execution time (which 
may matter if the method in question is complex).

Of course the above will apply only for method calls that will yield the 
same result when called multiple number of times. Not for methods such 
as iterator.next() :-)

BK


BK



== 2 of 2 ==
Date:   Fri,   Sep 24 2004 11:23 pm
From: Babu Kalakrishnan <[EMAIL PROTECTED]> 

Babu Kalakrishnan wrote:
> 
> The code you have posted this time adds something to the previous 
> version, but isn't still clear enough. The variable "var" is now known 
> to be local, but you've introduced a new one called "copay" which isn't 
> declared locally. So we have to assume that it is an instance variable - 
> Is this correct ?
> 

Just noticed that the method you've defined is declared static. So copay 
needs to be static as well if not a local. Do you think this is correct ??

If it is local, then you might want to defer the String->float / 
float->string conversions to the point where it is actually needed.

BK




==========================================================================
TOPIC: server application
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4bfd9bcb653fd31c
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 11:25 pm
From: [EMAIL PROTECTED] (Luke) 

Paul Lutus <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Luke wrote:
> 
> / ...
> 
> >> In that case, create the server on your own computer. You are very
> >> unlikely to find a free hosting service that will allow the use of a
> >> student-designed Java server.
> > 
> > ok, I could do that, but a couple problems, first of all I access the
> > web via the school network, as a result, I've tryed hosting web-sites
> > before, but it won't work because the router or whatever it is that
> > routs the traffic on the network, doesn't direct incoming http
> > connections to my comp.
> 
> No, you missed my point. Your goal is to test your code locally. Do this by
> setting up a Web server on your own machine, not one accessible to the
> outside world. You most certainly do not want to expose your prototype code
> to the entire Net anyway.
> 
> > Second problem, I don't have a computer that 
> > I could devote solely to web hosting.
> 
> What? All you want to do is set up a test Web server. This is not a great
> difficulty, nor is it a big system load, because you are not going to open
> it up to the world.
> 
> > so ok, if noone knows of any free webhosts that will alow for server
> > applications, does anyone know of any cheap ones that a poor student
> > could afford?
> 
> It is on your system now. Both Windows and Linux systems readily start up
> Web servers for you. You do not need, nor do you want, to expose your
> experimental code to the entire world. And this arrangement is free.
> 
> Please ask your professor for advice on this issue.

ok, this was my fault, I should have given more information from the
start.
I'm doing this on my own for the... (fun?) of it.  another thing that
makes your suggestion not possible is that the client server project I
want to work on is a multiple user type situation.  think along the
lines of:
me trying to make a chat room and wanting to test it with other people
so I know it will work with more than just one or two people, it's not
a chat room program, but that analogy should do just fine.  echoing my
first point, I'm doing this on my own apart from the school, I think
they might host student web-page/sites, thats another possibility that
I'm looking into, but I'm also seeing if anyone from this community
would have any suggestions.  sorry for having not been more specific
to begin with.  Thanks for your replys' so far and more reply's would
be equally appreceated




==========================================================================
TOPIC: Light Servlet Container
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7a1f451cb3bd91b1
==========================================================================

== 1 of 1 ==
Date:   Fri,   Sep 24 2004 11:28 pm
From: [EMAIL PROTECTED] (Genawa) 

Hello Everybody,

I have been looking around for a very light weight servlet container.
Both Jetty and Tomcat are 8MB-10MB distributions before install and
takes almost 15MB of RAM. I found winstone
(http://winstone.sourceforge.net/) which is only a 139K download, very
light weight and what I am looking for but only an ALPHA release.

Is there anything else out there that's similar?



Genawa



=======================================================================

You received this message because you are subscribed to the
Google Groups "comp.lang.java.programmer".  

comp.lang.java.programmer
[EMAIL PROTECTED]

Change your subscription type & other preferences:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

Report abuse:
* send email explaining the problem to [EMAIL PROTECTED]

Unsubscribe:
* click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe


=======================================================================
Google Groups: http://groups-beta.google.com 

Reply via email to