Reputation: 59650
I have few questions regarding Java constructors
Edit
The answers for 1 & 3 are very clear. I'm still not sure about 2 & 4 since I'm getting different answers for them.
Upvotes: 3
Views: 3195
Reputation: 11
Upvotes: 0
Reputation: 1
The default access modifier of a constructor is CLASS ACCESS MODIFIER, If a class is public , then access modifier of a constructor is public. If the class is default , then constructor is also default.
Upvotes: 0
Reputation: 35598
new
operator returns the object and in the process of creating the object, calls the constructor. Another way to think about it (although this is only a way to think about it, it isn't technically correct) is simply that the return type is implied by convention. A good place to read more about this is to read about new
in the context of C++. The constructor's role is not to create the object but rather to initialize the memory contained within the object.Upvotes: 2
Reputation: 81429
Thoughts on Tomcat performance and scalability: This is a highly variable situation based on your server hardware and types of requests and of course the quality, efficiency and memory footprint of the code serving each request.
Your lower bound on concurrent requests was 500. Consider that you probably want to create a thread for each request and given a 1MB stack per thread you're looking .5 GB just for thread stack space. And this is before heap memory and the performance overhead of allocating that many threads. I think that if need to handle that many requests at a time you might want to consider a more heavy duty server like JBoss.
Upvotes: 1
Reputation: 262464
Can a constructor be private? If yes then in which condition?
Yes. There are no conditions. Of course, no one except the class itself can call it then.
This is actually a frequent pattern: Have a static getInstance()
and keep the constructor private.
There can also be private constructors that the public constructors internally call.
Constructor is a method or not?
Hmm. I say "no". At the very least, it is a "very special kind of" method. In what context exactly? The terminology is less important than what you are trying to do.
If constructor does not return anything then why we are getting a new Object every time we call it.
The new
operator returns something (the new instance).
Whats the default access modifier of a constructor.
Same as for methods. Package-private.
If you do not specify any constructor, the class gets a default constructor, which takes no arguments, does nothing except calling the parent constructor and is public.
Upvotes: 3
Reputation: 112346
new
. What returns the object is the new
, the constructor simply sets up the internal state.Upvotes: -1
Reputation: 5059
With regards to your Tomcat question, it depends on which version of Tomcat, which IO model it's using (e.g., NIO versus historical network IO modules), and your configuration. Single Tomcat's can process hundreds of requests at a time, although the concurrency is tune-able (each request will be handled by a distinct thread or thread from a pool).
Upvotes: 0
Reputation: 38511
Upvotes: 0