vishnu priyag

Ranch Hand
+ Follow
since Aug 29, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
1
Total given
8
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by vishnu priyag

Thanks for the resources, but my question is, does java io streams uses TCP/IP to interact with resources like files that are present in the system where the application is running?
1 week ago
Got it, what is the relation between java io streams and file handles when I use io streams to make connection to files or resources like socket ?
1 week ago
Thanks for the reply.

Consider, the java code,
1. Open a file, and reads the content from the file using IO Streams
2. Send the content to network.

Please correct me if i am wrong,
here while reading the content from file, File handles being used and
for sending data through network, TCP/IP is being used.

If i don't close the TCP/IP connection, all the TCP/IP connections will be used.
What happens when i don't close the file? does all the file handles get consumed?
What about the streams?, does streams also use TCP/IP?

Thank you.
1 week ago
Hi,

Can anyone please explain what is meant by resource leak in general?
what are the causes for it?
How to resolve it?

Thank you.
1 week ago

Bear Bibeault wrote:Implementing them is as simple as adding the appropriate doXXX methods to the servlet. What goes in the method depends on what you want to do with them.

HEAD is used to return body-less information regarding a resource, OPTIONS is most often used for CORS. TRACE is generally used for debugging.



I understand about the functionality, but want to know how to write logic for those in servlet methods.
2 weeks ago

Bear Bibeault wrote:It's actually rare for those to be implemented in most servlets -- what usage are you envisioning using these HTTP methods for? CORS?



No, i don't have any specific requirements for implementing, but just want to know how to implement it and test the same to see the response.
2 weeks ago
Hi,

I have gone through many sites understanding HEAD, OPTIONS, TRACE, but none of them shown the code implementation of these methods in servlet.
Can someone please share the code implementation part for these methods.

Thank you.
2 weeks ago
Thank you for all your suggestions😊
3 weeks ago

Stephan van Hulst wrote:Let's say you have two different test methods that run concurrently. Both tests instantiate SomeServlet with a different implementation of SomeService. One of the tests will win, and their version of SomeService will overwrite the version that was injected by the other unit test, which will inevitably cause one of the unit tests to fail.

This kind of highlights the problem with static fields in general: You never know when another (potentially malicious) piece of code is going to mess with variables that were not meant to be accessed out-of-order.


Thank you i got it.

Stephan van Hulst wrote:Let me turn the question around on you. You chose Java to write your application in. Java is an Object Oriented language. That means that you encapsulate data in objects and you attach behavior to objects with which they can manipulate their encapsulated fields. So then, why are you choosing to ignore object oriented programming and return to the old dark days of global variables? What good reason do you have to use a static field, while instance fields are the way the language is supposed to be used?


Cause working with objects occupy space in heap, i feel it's better to use static when there is no states associated with class, i may be wrong here.
3 weeks ago
Thanks for the awesome explanation. It cleared most of my doubts. But there is still one more doubt.


Injecting test mocks for the above service still works fine right?
Why i am interested in static variable is, in servlets only one instance is created and i.e being shared by all threads. So as the instance variable always shared by all the threads, what's the big deal of using static variable here, this still be used by all the threads right.
3 weeks ago
Hi,

I know, there will be some limit to any application server or web container in handling the number of concurrency requests.
So, what happens when more requests reach to tomcat than the number it can process by creating threads? They are lost or tomcat holds them in a queue until the resources get freed to process the extra requests?


Thank you.
3 weeks ago

Tim Holloway wrote:JEE has a standard Authentication and Authorization mechanism built into every JEE container from jetty and Tomcat all the way up to IBM's WebSphere and WildFly and Oracles's WebLogic.

The built-in (container-based) A&A services are FAR more secure than almost every user-designed security system. They don't require writing and debugging code and support for them is built into the JEE APIs.



What is the JEE Api that offers the built in Authentication and Authorization in tomcat and how can i use it for my application?
3 weeks ago

Stephan van Hulst wrote:
use container managed authentication or add a specialized security framework to your application.


I know there are some security frameworks present, but what is meant by container managed authentication?

Stephan van Hulst wrote:

I noticed in many projects, methods in service and dao are instance, why not make them static?


Because many services implement service contracts. It's a bad idea for services to consist of static methods, because that means you can't easily swap out implementations.



for eg:

Service


ServiceImpl





Are you mentioning that the polymorphism can't be used as above example with static methods as we are doing with instance methods ?

Stephan van Hulst wrote:

As single instance is only be created, why not make dependencies as static like making service as static dependency in controller and dao as static dependency in service.


Static fields are the downfall of any well-written application. If you ever find yourself adding a static field to your class that is not a constant, smack yourself in the head first, and then think again if you can't do it in a more object oriented way instead.

The reasons are many.


I didn't understand what is the issue with static variables as dependency.


3 weeks ago
Hi,

This is the login functionality part of my sample servlet web application using MVC pattern.

Controller



Service



Dao



Model


I know, in servlets and most of the frameworks only one instance of class is created and all threads run on the same object, so,
1.  is it recommendable to use dependencies in the class as instance variable(as i mentioned in my code), but not as local (As instance variables are not thread safe and local are thread safe)?
2.  I noticed in many projects, methods in service and dao are instance, why not make them static? as they are not running on the object states
3. As single instance is only be created, why not make dependencies as static like making service as static dependency in controller and dao as static dependency in service.

Can someone please suggest me the correct way to do these.

Thank you.
3 weeks ago
Hi,

I am confused about when to use join and select. Can you please help me to understand
1. what's the difference between the following two queries and
2. When to use them

select c.name, s.address from customer c, shipping s where c.customer_id = s.customer_id;

select c.name, s.address from customer c join shipping s on c.customer_id = s.customer_id;


Thank you.