Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!

Anand Athinarayanan

Ranch Hand
+ Follow
since May 20, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anand Athinarayanan

Tim : Thank you. By API I mean a library. Regex always has been confusing for me but I understand for text manipulations Regex is powerful. I like it when there is less code.

Campbell : Whoa, that's some good advice. Thank you. I'm checking the link you provided. I have to go back to my notebook now.
2 years ago
I'm working on a problem of stripping NON ASCII data from an input string ,replace it with whitespace  and return the ASCII data. There are probably libraries which do it already but i'm getting back to honing my java skills so i wrote code for that. And then it got me thinking, if i were to expose this as an API what else should i do ? Put it another way do we have a blue print for writing code that makes it API ready.

What are some improvements that i should make when writing code for such problems which are common and what type of tests are run usually ?

2 years ago
It feels great to read through all the replies in this post.

@ Michael D Sims - Using Regex came to my mind after I came out of the interview room.

Update - I didn't get the job but I did learn quite a lot from this thread and I'm happy to realize i have a lot to learn and a long way to go. Thank you everyone for your thoughts !
5 years ago
@Junilu Lacar - Exactly !

@Joe Harry - Thanks. Never Struck me at that moment but again it would have been no use anyway. No body is going to do that in any kind of job.

@ Maneesh -Wish , I could have answered like that
5 years ago
Hello,

I was asked in an interview to write a program which prints the number of Vowels in a String. I started writing the code and used the charAt method of String when the interviewer asked me not to use any of the String API's.
And the String is just a word like "Hello" without any separators.

I couldn't answer the question. So I thought if any of you have an idea on how to do this.

Thanks !
5 years ago
Wong,
I don't find anything wrong with the browser interface, i was looking for ideas for developing a desktop application and thought of something that would be useful to developers. No problem with the java ranch search.

Friedman-Hill,
Thanks for that wonderful insight. Java Ranch has helped me countless times and I would never ever do anything to cause any damage even inadvertently. I'm going to change my requirement a little.
Instead of displaying the results in my application, I'm going to open the user's browser and post the query in Java Ranch's search box and all other interactions will happen through the browser only.
I'm sure its allowed because instead of the user directly launching the browser my application does it for him. If you can think of any problems this may cause to JR, do let me know. I'm not going to have the posting questions/answers feature yet. Even if I do, its going to be the same as the search. Launch the browser with the url and let user do the rest.

Andrew,
Thanks for the tip about StackOverflow. Honestly, I'm just going to restrict myself to searching questions/answers.

7 years ago
Hi There,

I would like to know if there are any API's available for Coderanch or java ranch something that stackoverflow provides to get the questions and the answers.I couldn't find anything in google.
I'm just thinking of developing an application which would enable the users to search java ranch for previously posted questions or may be even post a question or an answer through my application instead of accessing it with the browser. My application would be a desktop app which (if connected to the internet) will allow the user what i just said before.

Does Java ranch provide any API calls for these or do you guys have any other suggestion for me ?

7 years ago
Hi Pai,

I'm very sorry for the late reply. Thank you for your suggestion. Will give it a try.
7 years ago
Hi,

I will be writing a java program which is going to grab the contents of a html webpage and check for a value (inside a div), say the date and then do some processing which is not related to HTML.
What is the easiest way to do it ? Should i be using a full fledged HTML parser considering the fact that I want to check only the value of a div element. I don't need the rest of HTML content.

Are there any alternatives to using open source HTML parsers? If HTML parser is inevitable then which is the most light weight parser among them.

Thanks !

PS: I'm not sure if this is the right sub forum;please move it to the correct one.
7 years ago
Bear and Tim,
Thank you for your replies. Writing thread-safe servlets is more efficient than the alternative to single thread model.

While you can certainly define both member and class variables in a Servlet implementation class, there are J2EE constructs that do that and generally should be used instead



I've never seen a member variable in a Servlet before. What do you mean be J2EE constructs that do that ? Can you give me an example.
7 years ago
Well, our servlets can have instance variables and still be thread safe.
7 years ago
Hi All,
I was reading the Servlet 2.4 spec when I came across thread safety in Servlets. From the spec,

The use of the SingleThreadModel interface guarantees that only one thread at a
time will execute in a given servlet instance’s service method. It is important to
note that this guarantee only applies to each servlet instance, since the container
may choose to pool such objects



I understand that If I implement Single thread model then the container may create more than one instance for each servlet as opposed to only one if i don't implement it.

I was just wondering, why isn't there a combination of both. The container creates multiple instances for each servlet and also take advantage of multi threading. This guarantees thread safety of servlets because each request will have a separate instance of the Servlet class. Why hasn't any container implemented such a model ?

I assume there are potential disadvantages to this model, can any of you list it out ? One disadvantage is creating servlet instances each time a request comes can be costly.
7 years ago
All,

I have a question regarding the forward method of request dispatcher. I know the difference between forward and sendredirect but what i'm not able to understand is why the browser behaves quirky when i click on back button. So here is what I have.

1. A page foo.jsp is displayed to the user which has links and a text box and a submit button. The form action is /foo.do (Yes its struts but my question is not related to struts).Its a post request.
2. If the user clicks on the link (form is submitted thro javascript) or the submit button the request is sent to the server and the controller after processing forwards the request to bar.jsp.

Now bar.jsp is displayed and my address bar is still at /foo.do which is correct since its a server side forward. Now when I click on back button in bar.jsp nothing is happening, the same page (bar.jsp) is displayed again, i can't even say its loaded again because the page is not refreshed, its just like the back button is not working and its not sending any request to the server because I monitor the server after clicking on the back button and there are no activity. I don't have cache prevention headers in my response, so I'm assuming the browser has cached bar.jsp and foo.jsp but why is not going back to foo.jsp when i click on back button ?

Second question -> While in bar.jsp if i press F5 i get a pop up saying the information must be resubmitted, now I'm confused if the page is cached why is it requesting the server again ?

Third question --> Will browsers cache post requests by default if we don't have cache control headers in the response ?

I tested in IE 6 and FF 3.

Thanks !
7 years ago
Hi,
I hope I'm not hijacking the original thread by posting this question but I have a couple of questions regarding the order of records retrieved from DB.
If i insert 5 rows in a table in a particular alphabetical order (A,B,C,D,E) and after some days query it with a select * , wouldn't it return in the same order i Inserted them ?
Atleast thats what I thought it would. But this statement suggests otherwise

The same SELECT query may return results in different order each time it is called.



From this line

I was always told it would be fine, unless the dba had to play with the database in the night, recreating tables, that was why you should never rely on column or row order.

I understand that unless there is some change the rows will be retrieved in the order they were inserted, am i correct ?

The reason I'm surprised is- we have a set of questions displayed to the user and the questions are stored in the DB. In our code we retrieve the questions and just display it directly without any order by and the order of the questions are the same on the screen and DB. Its been like that for all users always.
Hi Paul,
That was just my assumption, I'm glad I got it right atleast for one time I just felt 65 thousand and odd is too small a number in the world of Internet. But as Kumaravadivel pointed out, you cannot go more than that. Thank you guys.
8 years ago