tushar attar

Ranch Hand
+ Follow
since Mar 12, 2016
tushar likes ...
Notepad Chrome Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tushar attar

Hi Everyone

What is the most correct way to write Database query code with try-with-resource?

I was using it everytime like

Then i realised i was doing it all wrong and it require syntax mentioned here https://stackoverflow.com/questions/8066501/how-should-i-use-try-with-resources-with-jdbc .

But the way mentioned in the above page is even bigger than the code if we use simple try catch, so using try-with-resources overkill for sql queries or is there a good way?
2 years ago

I used okhttp library to call API Calls on a website of mine based on WordPress. In that call, I forgot to close connection in the end and called various endpoints on the loop. Next morning I saw that the CPU and RAM usage was still high even after 6 hours of performing calls, which led me to infer that the possibility is that I forgot to close the connections and when I checked I saw I forgot to call response.body().close()

Now here is am thinking,  doesn't the server close the connection automatically and release resources after a certain time if I don't  close connection manually?
2 years ago
Anonymous inner class can only access final or effectively final, hence the reference 'result' cannot be updated. The above code would not compile.
I am facing a dilemma here. Earlier I used to use Core Java Library HttpUrlConnection to get JSON data over the web and use to parse it with GSON. Earlier these days my university teacher told me to use Retrofit library instead. Thinking of it a better and optimized way to code, I started working with it.

I loved its simplicity and rich feature but here I am struggling a lot due to of Callback anonymous inner class. Due to of it I am unable to pass the objects to other methods of mail application files, which I used to handle easily when I worked with HttpUrlConnection. Now here is my question, am I going any wrong, or is it really not a wise decision to use Retrofit with my java applications and I should stick to HttpUrlConnection.

Please let me know!

I am pasting a code below just to explain my point here:
2 years ago
HI ,

I am using JavaMail to send email using SMTP server. I am successfully able to send mail as well as emails are getting save in sent folder, only the issue is, when I try to sync Microsoft outlook with mail server, it doesn't show the mail I sent through java mail despite the emails are getting added to sent box whereas The mail I sent from outlook client or using Roundcube are getting sync. Can you please assist me with this? Below is the source code.

3 years ago
Iam developing an cliet side app and using REST API to post data on one website. But instead of connecting I am getting this error "javax.net.ssl.SSLProtocolException: handshake alert:  unrecognized_name" . StackTrace is as below:

Please asist me
Hi Community

I am wondering what are the applications of java EE. I know we can make a website with help of servlets and JSP but that can be accomplished with PHP as well, then what is the benefit of coding a website in java when it can be done in  a much simpler way in PHP. Also thinking as a client, one would ask the programmer to code in PHP than java as JAVA web hosting are way too expensive than simple shared hosting plans on which PHP website can run. Then what is the real benefit of JAVA?

I have started learning java EE a few days ago and I am wondering if I had made a correct decision. Please let me know what are the benefits of a website/web-app over other languages maybe PHP or .net. Also I there any other purpose of java other than the website building. Are there any popular applications which are built solely on java?

I am very confused if I has chosen the right path. Thanks in advance.

3 years ago
Hi have just started to learn cookie tracking mechanism but for some reason getCookie() method is returning junk data. Here is my code:




Output of showdata should be something like, student name: xyz    student address: address  but i am getting this output  

Please let me know where i am going wrong
3 years ago
Thanks, I just corrected one more error , i created in later stage and it resolved the problem. Thanks Rob your solution did help.
3 years ago
Thanks for pointing out error, I corrected it still no success
3 years ago
Thanks for a reply, i am currently following a tutorial and in that they didn't used a package.
3 years ago
I am learning servlet and following a tutorial. Here we create two servlet which communicates with each other. One servlet take post request from html form and forward the result to other servlet using requestdispatcher applies some more logic and display the result. But when i click on submit button on html fom i get  "HTTP Status 405 - HTTP method POST is not supported by this URL" error. My codes are





Same code run in tutorial but i am getting error, please tell me where i am wrong.

3 years ago

2) javax.GenericServlets is not a class, nor does the "javax" package actually have any classes in it. Or was that just a copy/paste error?

I am sorry that was typo error
import line is aactually import javax.servlet.*

PATH has nothing to do with the classpath. CLASSPATH does, though, although I don't recommend using it.

Then what is the solution?
3 years ago
Hi , I am using tomcat and have setup the classpath in PATH enviroment variable to the servlet-api.jar file. Whenever i compile my java servlet code i get import javax.GenericServlets not found . Though if I compile code using -classpath "path to servlet api" while compiling code it compiles successfully.

What i am doing wrong while setting up the PATH variable?
3 years ago
Thanks, it worked
3 years ago