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. |
|
| |||||||||||
Core Java - Interview Questions and Answers for 'Initialization' - 19 question(s) found - Order By Newest | |||||||||||
| |||||||||||
Ans. Declaration is intimation to the compiler about the nature of Data a reference is going to hold. For example - List myList; Instantiation is reservation of memory. For example myList = new ArrayList(); Initialization or construction is setting the default values for member elements. For example myList = new ArrayList(mySet); ** Example 2nd is both for instantiation as well as initialization. The only difference is that 2nd will initialized the member elements to their default values whereas 3rd will initialized it with the elements from set. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  declaration   instantiation   initialization   construction   declaration vs instantiation   instantiation vs initialization   declaration vs initialization Asked in 1 Companies basic   frequent | |||||||||||
Frequently asked question in companies using Hibernate. | |||||||||||
| |||||||||||
Ans. It's a feature to lazily initialize dependencies , relationship and associations from the Database. Any related references marked as @OneToMany or @ManyToMany are loaded lazily i.e when they are accessed and not when the parent is loaded. | |||||||||||
Sample Code for Lazy Initialization | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  hibernate   lazy loading hibernate   lazy initialization hibernate   architecture Asked in 77 Companies Basic   frequent | |||||||||||
Try 2 Question(s) Test | |||||||||||
| |||||||||||
Ans. 1. Set lazy=false in the hibernate config file. 2. Set @Basic(fetch=FetchType.EAGER) at the mapping. 3. Make sure that we are accessing the dependent objects before closing the session. 4. Force initialization using Hibernate.initialize 5. Using Fetch Join in HQL. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  hibernate   lazy loading hibernate   lazy initialization hibernate   lazyinitializationexception   architecture Asked in 2 Companies | |||||||||||
Try 2 Question(s) Test | |||||||||||
| |||||||||||
Ans. We are not resizing the first array here but assigning the reference strArray to a new Array with size 5. So after line 2, We have 2 arrays in memory, one with size 2 and other with size 5 with strArray referring to second array with size 5. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays  array initialization | |||||||||||
| |||||||||||
Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc. We cannot access methods defined in String class or in any class in hierarchy between String and Object. For example - we cannot do obj.append("abc") as it will now give compile time error. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  object initialization  object declaration   runtime polymorphism  object oriented programming (oops)  oops concepts | |||||||||||
| |||||||||||
Ans. No, It will throw compile time error saying "must provide either dimension expressions or an array initializer" Alternatively we can provide array initializer like String[] strArray = new String[]{"Buggy","Bread"}; which will initialize it to size 2 with values as "Buggy" and "Bread" | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays  array initialization | |||||||||||
| |||||||||||
Ans. The default value of the boolean type is false. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   data type   boolean   initialization   default object construction   default constructor   default value | |||||||||||
| |||||||||||
Ans. After Hibernate 3.0 | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  hibernate   lazy loading hibernate   lazy initialization hibernate | |||||||||||
| |||||||||||
Ans. Constructor has the same name as class name whereas instance initialization block just have a body without any name or visibility type. instance initialization blocks are useful if we want to have some code run regardless of which constructor is used or if we want to do some instance initialization for anonymous classes. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  instance initialization blocks  constructor  constructor vs instance initialization blocks Asked in 2 Companies | |||||||||||
Try 1 Question(s) Test | |||||||||||
| |||||||||||
Ans. Yes, It's an instance initialization block. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  code  instance initialization block | |||||||||||
Try 1 Question(s) Test | |||||||||||
| |||||||||||
Ans. Make sure that the properties of dependent Hibernate entities are not accessed and if yes, better wrap the whole code within single transaction. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  lazy loading  lazy initialization | |||||||||||
| |||||||||||
Ans. Lazy Initialization means , Load Dependencies when required. Which means less load on application resources as only required data is loaded upfront. It's not only good for better performance but for better resource utilization too. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  lazy loading  lazy initialization   frequent | |||||||||||
| |||||||||||
Ans. The error states that Hibernate is not able to initialize proxy / dependent entity objects as there is no session or transaction present. Very likely we are trying to load the dependent entities lazily but the call to dependent object property is not wrapped within the session or transaction. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  Lazy Loading  Lazy Initialization  org.hibernate.LazyInitializationException | |||||||||||
| |||||||||||
Ans. First resolution is a big No as it conveys no lazy loading in complete app. even second is advocating the same but for a particular mapping. third one is most appropriate if loading and dependent entity property access is closer to each other in code and can be accomplished. I don't mind using 4th too. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  lazy loading  lazy initialization  LazyInitializationException | |||||||||||
| |||||||||||
Ans. No. It's a resource and performance overhead. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  LazyInitializationException  Lazy Loading | |||||||||||
| |||||||||||
Ans. No, We haven't specified the size of array to be initialized. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays  array initialization | |||||||||||
| |||||||||||
Ans. Yes, size of the array will be 2. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays  array initialization | |||||||||||
| |||||||||||
Ans. No. It will result in error saying "Cannot define dimension expressions when an array initializer is provided" | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays  array initialization | |||||||||||
| |||||||||||
Ans. It will give compile time error saying "The final field array.length cannot be assigned" Arrays once initialized cannot be resized. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  arrays  array initialization | |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||