aspose file tools*
The moose likes Java in General and the fly likes Please tell me whether this procedure is correct or not. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Please tell me whether this procedure is correct or not." Watch "Please tell me whether this procedure is correct or not." New topic
Author

Please tell me whether this procedure is correct or not.

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi everybody, please tell me whether the following code is right or wrong.

I suppressed the warnings because actually this code is a part of my web application where many requests come to a servlet and there will me a Validator class to validate the data. So I cant make the Pattern and Matcher classes static.

Is this procedure correct. Thank you all in advance.


Love all, trust a few, do wrong to none.
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
chaitanya karthikk wrote:Hi everybody, please tell me whether the following code is right or wrong.


Does it work? Does it do what you'd expect?
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Yes
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
chaitanya karthikk wrote:Yes

Then I would go ahead and say it's correct.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Thank you Kevin.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

chaitanya karthikk wrote:
I suppressed the warnings because actually this code is a part of my web application where many requests come to a servlet and there will me a Validator class to validate the data. So I cant make the Pattern and Matcher classes static.

That's nonsense. pattern.compile(roll) is exactly the same as the static call Pattern.compile(roll).

I'd even change the entire class to make pattern and matcher local variables. Their value only matters during the methods, and they are reset each time.

How I'd implement them:
You can also use two static final Patterns, but I'm not sure how thread safe these will then be.

By the way, I think you want to make "05n61a0564" and "r09" parameters to these methods


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Thank you Rob.
Rob Prime wrote:By the way, I think you want to make "05n61a0564" and "r09" parameters to these methods

Yes I want to make those as parameters to those methods. But this is a web application. Will it work fine, because many requests will be coming. Will this program deliver good performance? I am sorry if you think I am asking an unrelated question in Java forum.

Thank you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

chaitanya karthikk wrote:Will it work fine, because many requests will be coming. Will this program deliver good performance?


But wait a minute. You were asked earlier if it did what you would expect. And you said "Yes". But now it turns out you don't actually know whether it does what you would expect.

However it doesn't really matter because you haven't really described what you would expect anyway. "Good performance"? That really isn't very specific. Are you going to have a web request which does this and nothing else at all? And how long would it have to take before you considered it "not good performance"? You probably don't have an answer for that, because you haven't really thought about it much. But even if you did have a specific performance requirement, nobody could tell by just looking at the code how it would perform. That would depend on the speed of the processor and the size of the memory allocated to the web application server and the number of processors in the machine and the other processes running on the machine and the speed of the network connecting the users to the machine... by now you should get what I'm saying: "It depends. It's more complicated than that."

So the way to go, if this were a real piece of code, would be to decide to use it. Quite likely it wouldn't make any difference if it could be tweaked to run in 1/100 of the time, as it's only going to be a tiny fraction of the whole processing for the request. And remember what my brother Don Knuth said: "Premature optimization is the root of all evil." And that's what you are doing with that question.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi Paul, I am having a requirement in my web application where a user uploads a excel file containing a list of students. I have to validate those and insert it into database, so for validation purpose I wrote this code. You can refer this forum for the actual problem I am facing.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Paul Clapham wrote:
But wait a minute. You were asked earlier if it did what you would expect. And you said "Yes". But now it turns out you don't actually know whether it does what you would expect.
Previously I was not talking about the performance, I was simply talking about whether can I use static content from a non static context.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please tell me whether this procedure is correct or not.