Interview Questions and Answers - Order By Newest Q781. What are the the methods to clear cache in Hibernate ? Hibernate
Ans. Evict() and clear(). Evist is used to clear a particular object from the cache whereas clear clears the complete local cache. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   orm   hibernate cache Q782. What are different types of second level cache ? Hibernate
Ans. 1. EHCache ( Easy Hibernate )
2. OSCache ( Open Symphony )
3. Swarm Cache ( JBoss )
4. Tree Cache ( JBoss ) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   orm   hibernate cache   technical lead Asked in 7 Companies Q783. Can we disable first level cache ? What should one do if we don't want an object to be cached ? Hibernate
Ans. No.We can either call evict after the object retrieval or can use separate sessions. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   orm   hibernate cache   architectureAns. Hibernate is a Java ORM Framework. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   orm   frameworks   architecture Q785. What are the different types of inheritance in Hibernate ? Hibernate
Ans. Table Per Class , Table per Sub Class , Table per Concrete Class Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   orm   inheritance hibernate Asked in 1 Companies Basic   frequent Q786. What is lazy fetching in Hibernate ? Hibernate
Ans. Lazy fetching is the technique of not loading the child objects when parent objects are loaded. By default Hibernate does not load child objects. One can specify whether to load them or not while doing the association. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   lazy fetching   architecture Asked in 11 Companies   frequent Try 2 Question(s) Test Q787. Different types of Hibernate Instance States ? Hibernate
Ans. Transient - In this state, an instance is not associated with any persistence context Persistent - In this state, an instance is associated with a persistence context Detached - This is a state for an instance which was previously associated with a persistence context an has been currently closed dissociated Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate Q788. Is It Good to use Reflection in an application ? Why ? Core Java
Ans. no, It's like challenging the design of application. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   reflection api   yes-no   architecture Asked in 1 Companies intermediate Q789. Why is Reflection slower ?
Ans. Because it has to inspect the metadata in the bytecode instead of just using precompiled addresses and constants. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   reflection   reflection api   architecture Q790. When should we use prototype scope and singleton scope for beans ? Spring
Ans. We should use singleton scope for beans when they are stateless and prototype when they are stateful. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  spring   bean scope   general electric   ge  singleton Q791. Difference between Assert and Verify ? Testing
Ans. Assert works only if assertions ( -ea ) are enabled which is not required for Verify.Assert throws an exception and hence doesn't continue with the test if assert evaluates to false whereas it's not so with Verify. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  assert   junit   mockito   verify   testing   unit testing Asked in 5 Companies Q792. Which class elements are not persisted ? Hibernate
Ans. Static and Transient. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   orm Q793. What entries we make in the hibernate config file if we are not using hbm files but Annotations ? Hibernate
Ans. We configure Entity classes having annotated mappings. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   hibernate annotations Q794. How many SessionFactory and Session objects are created ? Java EE
Ans. Single SessionFactory object and multiple session objects for opening different session. Hibernate creates new Session object per thread. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   sessionfactory hibernate   session hibernate Q795. What is the use of hbm2ddl Configuration in Hibernate ? Hibernate
Ans. This configuration specifies if hibernate should creates the Schema / Table on its own if the respective table is not found. "update" doesn't create the table if it's not found whereas configuration set as "create" creates the schema automatically. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   hibernate configuration   hibernate.cfg.xml   hbm2ddl Q796. What is the difference between these 2 annotations ?
@Entity
@Entity ( name="EMPLOYEES" ) Hibernate
Ans. The first annotation will try to map the Class with the Table as of same name as Class whereas the second annotation will specify the Entity name as "EMPLOYEES" and hence will try to map with Table Name "EMPLOYEES". Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   hibernate annotations   entity annotations Q797. What is the difference between these 2 annotations ?
@Entity ( name ="EMPLOYEES")
@Entity @Table ( name=""EMPLOYEES"" )
@Entity ( name="EMP")
@Table ( name="EMPLPYEES" ) Hibernate
Ans. First Annotation will set the Entity name as EMPLOYEES and hence will try to map with the same Table name. The second annotation will make the Entity mapped to table EMPLOYEES irrespective of the Entity Name ( which is class name in this case ). Third Annotations will set the different names for Enitity and Table and will explicitly map them. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   hibernate annotations   entity annotation   table annotation Q798. What are the different ID generating strategies using @GeneratedValue annotation ? Hibernate
Ans. Auto , Identity , Sequence and Table. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   generatedvalue annotations   architecture Q799. How to do Eager loading in Hibernate ? Hibernate
Ans. Using lazy = false in hibernate config file or @Basic(fetch=FetchType.EAGER) at the mapping Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   lazy loading hibernate   basic annotation hibernate   architectureAns. Instead of Saving Parent as well as Child Entities individually , Hibernate provides the option to persist / delete the related entities when the Parent is persisted. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   cascade   hibernate relationship   hibernate associations Q801. What are the different Cascade types ? Hibernate
Ans. Detach, Merge , Persist , Remove , Refresh Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   cascade   cascade type Q802. Which type of associated Entities are Eagerly loaded by Default ? Hibernate
Ans. OneToOne Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   hibernate associations   hibernate relationship Q803. After which Hibernate version , related Entities are initialized lazily ? Hibernate
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 Q804. Can we declare Entity class as final ? Hibernate
Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hibernate   proxy objects   proxy classes   entity hibernate Q805. What is the difference between int[] x; and int x[]; ? Core Java
Ans. No Difference. Both are the acceptable ways to declare an array. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   array   arrays   array declaration   difference between Asked in 3 Companies basic Q806. What are the annotations used in Junit with Junit4 ?
Ans. @Test The Test annotation indicates that the public void method to which it is attached can be run as a test case. @Before The Before annotation indicates that this method must be executed before each test in the class, so as to execute some preconditions necessary for the test. @BeforeClass The BeforeClass annotation indicates that the static method to which is attached must be executed once and before all tests in the class. @After The After annotation indicates that this method gets executed after execution of each test. @AfterClass The AfterClass annotation can be used when a method needs to be executed after executing all the tests in a JUnit Test Case class so as to clean-up the set-up. @Ignores The Ignore annotation can be used when you want temporarily disable the execution of a specific test. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   junit   jnuit4   junit annotations Q807. What is asynchronous I/O ?
Ans. It is a form of Input Output processing that permits other processing to continue before the I/O transmission has finished. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   io   file   fileio   java7   architecture Q808. If there is a conflict between Base Class Method definition and Interface Default method definition, Which definition is Picked ?
Ans. Base Class Definition. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java8   default methodsFrequently asked these days as there are major changes in Java 8. Q809. What are new features introduced with Java 8 ? Core Java
Ans. Lambda Expressions , Interface Default and Static Methods , Method Reference , Parameters Name , Optional , Streams, Concurrency. Sample Code for Lambda Sample Code for interface default Sample Code for Optional Sample Code for Streams Sample Code for java.time Sample Code for Predicate Sample Code for Consumer Sample Code for MapMerge Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java8   technical lead   technical architect Asked in 14 Companies expert   frequent Rarely asked as default methods have been introduced with Java 8. Q810. Can we have a default method without a Body ? Core Java
Ans. No. Compiler will give error. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java8   default method   yes-no   rare