Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What Are The States Of Object In Hibernate?

Answer»

There are 3 states of OBJECT (instance) in hibernate.

  • Transient: The object is in transient state if it is just CREATED but has no primary key (identifier) and not associated with session.
  • PERSISTENT: The object is in persistent state if session is OPEN, and you just saved the instance in the database or retrieved the instance from the database.
  • Detached: The object is in detached state if session is closed. After detached state, object comes to persistent state if you call lock() or update() method.

There are 3 states of object (instance) in hibernate.

2.

How Would You Reattach Detached Objects To A Session When The Same Object Has Already Been Loaded Into The Session?

Answer»

You can USE the session.merge() METHOD CALL.

You can use the session.merge() method call.

3.

What Are The Most Common Methods Of Hibernate Configuration?

Answer»

The most common methods of HIBERNATE CONFIGURATION are:

The most common methods of Hibernate configuration are:

4.

Explain Criteria Api?

Answer»

Criteria is a simplified API for retrieving entities by COMPOSING Criterion objects. This is a very CONVENIENT approach for FUNCTIONALITY like "search" screens where there is a variable number of conditions to be placed upon the RESULT SET.

Example : List employees = session.createCriteria(Employee.class) .add(Restrictions.like("name", "a%") ) .add(Restrictions.like("address", "Boston")) .addOrder(Order.asc("name") ) .list();

Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens where there is a variable number of conditions to be placed upon the result set.

Example : List employees = session.createCriteria(Employee.class) .add(Restrictions.like("name", "a%") ) .add(Restrictions.like("address", "Boston")) .addOrder(Order.asc("name") ) .list();

5.

What Is Session?

Answer»
  • It maintains a connection between hibernate APPLICATION and DATABASE.
  • It provides methods to store, update, DELETE or fetch DATA from the database such as persist(), update(), delete(), load(), get() etc.
  • It is a factory of QUERY, Criteria and Transaction i.e. it provides factory methods to return these instances.

6.

What Is Sessionfactory?

Answer»

SessionFactory provides the INSTANCE of SESSION. It is a factory of Session. It holds the data of second level CACHE that is not enabled by default.

SessionFactory provides the instance of Session. It is a factory of Session. It holds the data of second level cache that is not enabled by default.

7.

What Is Hql (hibernate Query Language)?

Answer»

Hibernate Query Language is KNOWN as an object ORIENTED query language. It is like structured query language (SQL). The main advantage of HQL over SQL is:

  • You don't need to learn SQL
  • Database independent
  • SIMPLE to WRITE query

Hibernate Query Language is known as an object oriented query language. It is like structured query language (SQL). The main advantage of HQL over SQL is:

8.

What Is Lazy Loading In Hibernate?

Answer»

Lazy loading in hibernate IMPROVES the performance. It LOADS the child objects on demand. Since Hibernate 3, lazy loading is enabled by DEFAULT, you don't NEED to do lazy="true". It means not to LOAD the child objects when parent is loaded.

Lazy loading in hibernate improves the performance. It loads the child objects on demand. Since Hibernate 3, lazy loading is enabled by default, you don't need to do lazy="true". It means not to load the child objects when parent is loaded.

9.

Is It Possible To Perform Collection Mapping With One-to-one And Many-to-one?

Answer»

No, COLLECTION MAPPING can only be PERFORMED with One-to-Many and Many-to-Many.

No, collection mapping can only be performed with One-to-Many and Many-to-Many.

10.

How Many Types Of Association Mapping Are Possible In Hibernate?

Answer»

There can be 4 TYPES of ASSOCIATION mapping in HIBERNATE.

  • ONE to One
  • One to Many
  • Many to One
  • Many to Many

There can be 4 types of association mapping in hibernate.

11.

How To Detect The Operating System On The Client Machine?

Answer»

In ORDER to detect the operating system on the client MACHINE, the navigator.appVersion STRING (PROPERTY) should be used.

In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.

12.

Which Viewresolver Class Is Widely Used?

Answer»

The org.springframework.web.servlet.view.InternalResourceViewResolver CLASS is WIDELY USED.

The org.springframework.web.servlet.view.InternalResourceViewResolver class is widely used.

13.

What Does The Viewresolver Class?

Answer»

The VIEW Resolver CLASS resolves the view component to be invoked for the REQUEST. It DEFINES prefix and suffix properties to resolve the view component.

The View Resolver class resolves the view component to be invoked for the request. It defines prefix and suffix properties to resolve the view component.

14.

What Does @requestmapping Annotation?

Answer»

The @RequestMapping ANNOTATION MAPS the REQUEST with the METHOD. It is APPLIED on the method.

The @RequestMapping annotation maps the request with the method. It is applied on the method.

15.

What Does @controller Annotation?

Answer»

The @CONTROLLER ANNOTATION MARKS the CLASS as controller class. It is APPLIED on the class.

The @Controller annotation marks the class as controller class. It is applied on the class.

16.

What Are The Types Of Advice In Aop?

Answer»

There are 5 TYPES of ADVICES in SPRING AOP.

  • Before Advice
  • After Advice
  • After RETURNING Advice
  • Throws Advice
  • Around Advice

There are 5 types of advices in spring AOP.

17.

What Are The Aop Terminology?

Answer»

AOP terminologies or concepts are as follows:

AOP terminologies or concepts are as follows:

18.

What Is Aop?

Answer»

AOP is an acronym for ASPECT Oriented Programming. It is a methodology that divides the program LOGIC into PIECES or parts or CONCERNS. It increases the MODULARITY and the key unit is Aspect.

AOP is an acronym for Aspect Oriented Programming. It is a methodology that divides the program logic into pieces or parts or concerns. It increases the modularity and the key unit is Aspect.

19.

How Can You Fetch Records By Spring Jdbctemplate?

Answer»

You can FETCH records from the DATABASE by the QUERY method of JDBCTEMPLATE. There are TWO interfaces to do this:

  • ResultSetExtractor
  • RowMapper

You can fetch records from the database by the query method of JdbcTemplate. There are two interfaces to do this:

20.

What Are Classes For Spring Jdbc Api?

Answer»

21.

What Are The Transaction Management Supports Provided By Spring?

Answer»

Spring framework provides two TYPE of TRANSACTION management SUPPORTS:

  • Programmatic Transaction Management: should be used for few transaction operations.
  • Declarative Transaction Management: should be used for MANY transaction operations.

Spring framework provides two type of transaction management supports:

22.

What Is The Difference Between Beanfactory And Applicationcontext?

Answer»

BEANFACTORY is the basic container whereas ApplicationContext is the advanced container. ApplicationContext EXTENDS the BeanFactory INTERFACE. ApplicationContext PROVIDES more FACILITIES than BeanFactory such as integration with spring AOP, message resource handling for i18n etc.

BeanFactory is the basic container whereas ApplicationContext is the advanced container. ApplicationContext extends the BeanFactory interface. ApplicationContext provides more facilities than BeanFactory such as integration with spring AOP, message resource handling for i18n etc.

23.

What Are The Types Of Ioc Container In Spring?

Answer»

There are TWO types of IOC CONTAINERS in spring FRAMEWORK.

  1. BeanFactory
  2. APPLICATIONCONTEXT

There are two types of IOC containers in spring framework.

24.

What Is The Role Of Ioc Container In Spring?

Answer»

IOC CONTAINER is responsible to:

IOC container is responsible to:

25.

Static Synchronization Vs Instance Synchronization?

Answer»

When a static synchronized method is called, the PROGRAM obtains the class lock before CALLING the method. This mechanism is identical to the case in which method is non-static, it is just a different lock, and this lock is solely for static method. Apart from the functional RELATIONSHIP between the two LOCKS, they are not operationally related at all.

When a static synchronized method is called, the program obtains the class lock before calling the method. This mechanism is identical to the case in which method is non-static, it is just a different lock, and this lock is solely for static method. Apart from the functional relationship between the two locks, they are not operationally related at all.

26.

What Is Classloader?

Answer»

The classloader is a subsystem of JVM that is used to LOAD CLASSES and interfaces. There are many types of classloaders e.g. BOOTSTRAP classloader, EXTENSION classloader, System classloader, Plugin classloader etc.

The classloader is a subsystem of JVM that is used to load classes and interfaces. There are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc.

27.

How Would You Make A Copy Of An Entire Java Object With Its State?

Answer»

Have this class IMPLEMENT Cloneable INTERFACE and CALL its METHOD CLONE().

Have this class implement Cloneable interface and call its method clone().

28.

What Is The Difference Between Synchronized And Synchronized Block?

Answer»

In case of a SYNCHRONIZED METHOD a thread may need to have the lock for a longer TIME as compared to the synchronized block.

Another difference between synchronized method and block is that we don’t specify the particular OBJECT whose MONITOR is required to be obtained by thread for entering a synchronized method, whereas we can specify the particular object in case of synchronized block.

In case of a Synchronized method a thread may need to have the lock for a longer time as compared to the synchronized block.

Another difference between synchronized method and block is that we don’t specify the particular object whose monitor is required to be obtained by thread for entering a synchronized method, whereas we can specify the particular object in case of synchronized block.

29.

What Gives Java Its 'write Once And Run Anywhere' Nature?

Answer»

The bytecode. JAVA is compiled to be a byte CODE which is the intermediate language between SOURCE code and machine code. This byte code is not platform specific and hence can be fed to any platform.

The bytecode. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform specific and hence can be fed to any platform.

30.

How Can A Subclass Call A Method Or A Constructor Defined In A Superclass?

Answer»

Use the following SYNTAX: SUPER.myMethod(); To CALL a constructor of the superclass, just WRITE super(); in the first line of the SUBCLASS‘s constructor.

Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass‘s constructor.

31.

Which Way A Developer Should Use For Creating Thread, I.e. Sub Classing Thread Or Implementing Runnable.

Answer»

There are TWO ways of creating Thread in java (i.e. sub classing or implementing Runnable). It is very important to understand the implication of using these two approaches. There are two different points about using these two approaches.

By extending the thread class, the derived class itself is a thread object and it gains full control over the thread life cycle. Implementing the Runnable interface does not give developers any control over the thread itself, as it simply defines the unit of work that will be executed in a thread.

Another important point is that when extending the Thread class, the derived class cannot extend any other base classes because Java only allows single inheritance. By implementing the Runnable interface, the class can still extend other base classes if necessary.

To SUMMARIZE, if DEVELOPER NEEDS a full control over the Thread life cycle, sub classing Thread class is a GOOD choice, and if programs need more flexibility by extending other class developer, should go with implementing Runnable interface.

There are two ways of creating Thread in java (i.e. sub classing or implementing Runnable). It is very important to understand the implication of using these two approaches. There are two different points about using these two approaches.

By extending the thread class, the derived class itself is a thread object and it gains full control over the thread life cycle. Implementing the Runnable interface does not give developers any control over the thread itself, as it simply defines the unit of work that will be executed in a thread.

Another important point is that when extending the Thread class, the derived class cannot extend any other base classes because Java only allows single inheritance. By implementing the Runnable interface, the class can still extend other base classes if necessary.

To summarize, if developer needs a full control over the Thread life cycle, sub classing Thread class is a good choice, and if programs need more flexibility by extending other class developer, should go with implementing Runnable interface.

32.

What Would You Use To Compare Two String Variables - The Operator == Or The Method Equals()?

Answer»

I would USE the method EQUALS() to compare the values of the STRINGS and the == to check if two VARIABLES point at the same instance of a STRING object.

I would use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.

33.

Explain Java Thread Life Cycle.

Answer»

The life cycle of threads in Java is very similar to the life cycle of processes running in an operating system. During its life cycle the thread moves from one STATE to another DEPENDING on the operation performed by it or performed on it. A Java thread can be in one of the following states:

  • NEW: A thread that is just INSTANTIATED is in new state. When a start () method is invoked, the thread moves to the ready state from which it is automatically moved to runnable state by the thread scheduler.
  • RUNNABLE (ready_running) A thread executing in the JVM is in running state.
  • BLOCKED A thread that is blocked WAITING for a monitor lock is in this state. This can also occur when a thread performs an I/O operation and moves to next (runnable) state.
  • WAITING A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
  • TIMED_WAITING (sleeping) A thread that is waiting for another thread to perform an action up to a specified waiting time is in this state.
  • TERMINATED (DEAD) A thread that has exited is in this state.

The life cycle of threads in Java is very similar to the life cycle of processes running in an operating system. During its life cycle the thread moves from one state to another depending on the operation performed by it or performed on it. A Java thread can be in one of the following states:

34.

What Is Platform?

Answer»

A PLATFORM is basically the hardware or software ENVIRONMENT in which a program runs. There are TWO TYPES of PLATFORMS software-based and hardware-based. Java provides software-based platform.

A platform is basically the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides software-based platform.

35.

What's The Difference Between J2sdk 1.5 And J2sdk 5.0?

Answer»

There's no DIFFERENCE, SUN Microsystems just re-branded this VERSION.

There's no difference, Sun Microsystems just re-branded this version.

36.

What Are Four Steps For The Execution Of Query:

Answer»
  • QUERY is parsed
  • Query is compiled.
  • Query is optimized.
  • Query is executed.

In CASE of statement, the above FOUR steps are performed every time. And in case of prepared statement the above three steps are performed once.

In case of statement, the above four steps are performed every time. And in case of prepared statement the above three steps are performed once.

37.

What Is Jit Compiler?

Answer»

Just-In-TIME(JIT) compiler:It is used to improve the performance. JIT compiles parts of the BYTE code that have similar functionality at the same time, and hence reduces the amount of time NEEDED for compilation.Here the term “compiler” refers to a TRANSLATOR from the instruction set of a Java VIRTUAL machine (JVM) to the instruction set of a specific CPU.

Just-In-Time(JIT) compiler:It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.

38.

What Is The Difference Between Constructors And Other Methods In Core Java?

Answer»
  • Constructor will be AUTOMATICALLY invoked when an object is created whereas method has to be called explicitly.
  • Constructor needs to have the same name as that of the class whereas functions need not be the same.
  • There is no return type given in a constructor signature (header). The value is this object itself so there is no need to INDICATE a return value.
  • There is no return statement in the body of the constructor.
  • The first line of a constructor must EITHER be a call on another constructor in the same class (USING this), or a call on the superclass constructor (using super). If the first line is neither of these, the COMPILER automatically inserts a call to the parameterless super class constructor.

39.

What Is The Difference Between Prepared Statement And Statement In Java?

Answer»

A STATEMENT is parsed and executed each time its call SENT to database. A prepared statement MAY be parsed once and executed repeatedly with different PARAMETERS.

A statement is parsed and executed each time its call sent to database. A prepared statement may be parsed once and executed repeatedly with different parameters.

40.

How Many Types Of Memory Areas Are Allocated By Jvm?

Answer»

Many types:

Many types:

41.

What Are The Differences Between The Methods Sleep() And Wait()?

Answer»

The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could STOP WAITING EARLIER if it RECEIVES the notify() or notifyAll() call. The METHOD wait() is defined in the class Object and the method sleep() is defined in the class Thread.

The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

42.

What Is Annotation In Java?

Answer»

An annotation, in the JAVA programming language is a special form of syntactic metadata that can be added to Java Source Code. Classes, methods, variables parameters and packages may be annotated. Unlike Java doc TAGS, Java annotation are reflective, in that they are embedded in class files generated by the compiler and may be RETAINED by the java VM to make retrievable at run-time.

Annotation is basically to ATTACH metadata to method, class or package. Metadata is used by the compiler to perform some basic compile-time CHECKING

An annotation, in the java programming language is a special form of syntactic metadata that can be added to Java Source Code. Classes, methods, variables parameters and packages may be annotated. Unlike Java doc tags, Java annotation are reflective, in that they are embedded in class files generated by the compiler and may be retained by the java VM to make retrievable at run-time.

Annotation is basically to attach metadata to method, class or package. Metadata is used by the compiler to perform some basic compile-time checking