More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Likewise classes, methods also provide a way for code reuse and abstraction. Code is reused, clean and easy to understand if classified properly within classes and methods.
Help us improve. Please let us know the company, where you were asked this question :
We need methods to access variables in a polymorphic way as overriding only happens with methods and not with variables. Moreover getter provides a way to minimally open the access window for the object and hence provides better encapsulation. To add to those, we can have validation in the getter method before returning elements.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Frankly saying I dont see much use of method overloading as its just little design convenience as you can use the same name but still have binding to different methods depending on the need.
Method overriding is really important and is much more useful than method overloading. Along with other programming concepts like interfaces and dependency injection , it facilitates the development of software as libraries and plug-gable components.
Help us improve. Please let us know the company, where you were asked this question :
Q463. How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ?
Ans. Eclipse Vert.x is a tool kit for building reactive applications on the JVM. Vert.x is event driven and non blocking. This means the application can handle lot of concurrency using a small number of kernel threads. Vert.x lets the application scale with minimal hardware.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, doesn't provide exclusive access as we cannot allocate and deallocate memory exclusively as Java internally manages it. The advantage of this is that it relieves the coder for such tasks and helps protect from many bugs that may get introduced with imperfect coding. Moreover as java garbage collector collects all unclaimed memory or objects, it helps the application from memory leaks.
On the flip side , as coder doesn't have extensive excess to memory , it is upto java to decide on the state for programming construct and data storage and hence may introduce some security risks. For example - Java keeps string literals in string pool and there is no exclusive way to remove it and hence may stay and sensitive data in string pool may introduce security issues. Moreover when we overwrite a value or object for a variable / reference, it is upto java to purge those values and hence it may stay in memory for a while till java decide that it is no longer referenced and hence should be removed and hence makes it vulnerable for inappropriate access.
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  disadvantages of garbage collection  advantages and disadvantages of java memory management  java for security applications  java with sensitive data  memory management
Q467. Is it ok to use optional everywhere just to get over nullpointerexception ?
Ans. Optional is to be used for arguments / atrributes which are indeed optional i.e the request should continue even if they aren't provided. It should not be used for mandatory attributes or arguments as we would like application to shout out ( with error message / exception trace ) to signify a problem.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Though var args are used rarely but they are pretty useful if a method is expected to receive variable number of arguments. For example - it's pretty useful for the main method as the caller has the flexibility to provide arguments in infinite ways.It provides a convenience and flexibility to the caller.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It means that only 1 thread can access have access to Vector at a time and no parallel access is allowed whereas Array List allows parallel access by multiple threads.
Help us improve. Please let us know the company, where you were asked this question :
Ans. pop method pulls the top element from the stack and then move the top to the next element whereas peek only get the top element but doesn't move the top.
Help us improve. Please let us know the company, where you were asked this question :