Search Interview Questions | 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. |
|
| ||||
Interview Questions and Answers - Order By Rating | ||||
| ||||
Ans. Arrays are of fixed size and have to reserve memory prior to use. Hence if we don't know size in advance arrays are not recommended to use. Arrays can store only homogeneous elements. Arrays store its values in contentious memory location. Not suitable if the content is too large and needs to be distributed in memory. There is no underlying data structure for arrays and no ready made method support for arrays, for every requriment we need to code explicitly | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   arrays   disadvantages of arrays   arrays memory   arrays vs variables | ||||
| ||||
Ans. No. Global variables are not allowed as it wont fit good with the concept of encapsulation. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   variables   global variables   yes no | ||||
Advanced level question usually asked to senior developers , leads and architects. | ||||
| ||||
Ans. Volatile is an instruction that the variables can be accessed by multiple threads and hence shouldn't be cached. As volatile variables are never cached and hence their retrieval cannot be optimized. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java keywords   volatile   synchronization   compiler optimization   variable caching   architecture Asked in 3 Companies expert | ||||
| ||||
Ans. Variables used in a switch statement can only be a byte, short, int, or char ( and String with Java 7 and above ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   switch   variable   data type basic   rare | ||||
| ||||
Ans. CLASSPATH and PATH are the two variables. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   classpath   path   environment variables   jvm | ||||
Ans. No the static block won't get executed as the referenced variable in the Test class is final. Compiler replaces the content of the final variable within Demo.main method and hence actually no reference to Test class is made. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static block   final variable | ||||
Try 1 Question(s) Test | ||||
Ans. Yes. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   static   static block   final variable   yes no | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. It means that the type of variables are checked at compile time in Java.The main advantage here is that all kinds of checking can be done by the compiler and hence will reduce bugs. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   statically typed language   variable declaration Asked in 7 Companies basic   frequent | ||||
| ||||
Ans. They should be named all in upper case with underscore separating words. Moreover the name should be such that it identifies the value. For example, if we are using constant for employee Id 123, it should be named something like EMPLOYEE_ID_123 and not EMPLOYEE_ID | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  constants   variable names   java conventions | ||||
| ||||
Ans. Final makes sure that the value doesn't change after initialization and static makes sure that there is only one copy that can be shared across objects. Making it non static will unnecessarily create a different copy per object wherein the same value will kept for all copies ( as its final and cannot be changed ). | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   static   final variables   variable constants basic   frequent | ||||
| ||||
Ans. Advantages Can do meta object operations ( like validating something before creating objects , keep count of number of objects ) Can do operations which have nothing to do with objects but still you want them to be tied to Class. Disadvantages Commonly used to static variables sometime leads to problems due to access by different objects. Are not tied to objects so doesn't reflect pure Object Oriented approach. Needs to be synchronized so as to avoid update conflicts by mutiple objects and threads. Some limitation in testing as not all frameworks have facility to mock them. Powermock has but Mockito doesnt | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   static   static variables   static methods | ||||
| ||||
Ans. b,c and d i.e final , public and static | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   interface   interface variables | ||||
Ans. They can be initialized within static method | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   final   final variable   java keywords | ||||
| ||||
Ans. The field of an object | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   oop   instance variable   variables | ||||