Tuesday, February 28, 2017

What is Heap Memory in Java

In this article we will learn about Heap memory in Java and how to use heap,what is the purpose of heap memory in java.We shall discuss all these questions and this topic is one of the core concept in Java. A Heap is a memory area shared among all threads. The Java Heap is created on Virtual Machine startup. To create objects dynamically in a pool of memory called the heap. The heap is the run time data area from which memory for all class instances,variables and arrays is allocated.

If you need a new object you simply make it on the heap at the point that you need it.

For Example:

String s=new String("lucky");

In this case objects will be created one is on the heap and the second one is SCP(String Constant Pool) and 's' is referring to heap object.

Object creating in SCP is optional. If the object is not available then only new object will be created. Heap storage is reclaimed by the Garbage Collector. Heap may be of fixed size or may be expanded as required.

String s="lucky";

In this case only one object will be created if it is not already available and 's' is referring to that object. If an object already available with this can in SCP then 's' will refer that existing object only instead of creating new object.

In the above case object is not available for garbage collector even though the object does not have any reference variables. All the SCP objects will destroyed at the time of JVM shutdown.

In the case of heap there may be chance of duplicate String Objects 

Example:

String s1 = new String("learn");
1.concat("programming");
String s2 = "learnprogramming";
System.out.println(s1);

System.out.println(s2);

Output:
learn
learnprogramming

At any point of time if we have heap object reference we can find it’s equivalent SCP Object byusing intern() method.If the equivalent SCP Object is not already available then intern() method will create a new object in the SCP.

Example:
class StringTest
{
public static void main(String[] args)
{
String s1 = new String("learn");
String s2 = s1.concat("programming");
String s3 = s2.intern();
String s4 = “learnprogramming”;
System.out.println(s3 == s4);
}

}

If a program need more Heap memory than the automatic memory management system provides then Java Virtual Machine throws OutOfMemoryError. Heap memory does not need to be contiguous. All java objects live on the heap.When object contains another object variable that variable still contains just a pointer to yet another heap object.

Note: Keep in mind that,all java objects are constructed on the heap and that constructor must be combined with new keyword.

Recommended to Read:



Monday, February 27, 2017

spring interview questions

In this post i am sharing fundamental spring framework  interview questions for freshers and experienced candidates.This is one of the leading framework for developing enterprise  applications using Java Environment.Spring is an open source development framework for Enterprise Java. The main purpose of spring is for developing any Java application,but there are extensions for building web applications on top of the JEE platform. The following are some of the fundamental interview questions

1) What is spring?

Ans: Spring is open source development framework for Enterprise Java.By using this framework we can develop any type of Java application. This framework which helps Java programmer for development of code and it provides IOC container,Dependency Injector,MVC flow and many other APIs for the java programmer.Spring framework targets to make JEE development easier to use and promote good programming practice by enabling a POJO-based programming model.

2) What are the advantages of Spring Framework?

Ans: The following are the advantages of Spring Framework: They are

1)  Loose Coupling:
By using Inversion Of Control(IOC) can be achieved loose coupling in spring.
2) Easy to Test:
In spring framework,can be easily Test the code to improve the performance of the applications.
3) Light Weight:
Spring framework is light weight when it comes to size and transaparency.
4) Fast Development
5) Exception Handling:
Spring provides a convienient API to translate technology-specific exceptions into consistent,unchecked exceptions.
6) Transaction Management:
Spring provides a consistent transaction management interface that can scale up to global transactions.
7) MVC Framework:
Spring's web framework is a well designed web MVC framework,which provides a great alternative to web frameworks.

3) Why Spring Framework is needed?

Ans: Spring framework is needed because it is A light weight framework for building java applications. This means any type of java applications such as standalone java,JEE applications,web applications etc.. It also provides Inversion Of Control(IOC),Dependency Injecton(DI) capabilities and it also provides declarative programming with AOP(Aspect Oriented Programming).

4)What are the benefits of Spring Framework?

Ans: The following are the benefits of Spring Framework: They are


  • Reusability
  • Decoupling
  • Reduces coding effort by using pattern implementations such as singleton,factory,service locator etc..
  • Removal of leaking connections 
  • Declarative transaction management
  • Easy to integrate with third party tools and technologies

5) What are the modules used in spring framework?

Ans: The following are the basic spring modules:

  1. Core module
  2. Bean module
  3. Context module
  4. JDBC module
  5. ORM module
  6. Transaction module
  7. web module
  8. JMS module
6) What is Spring IOC container?

Ans: The Spring IoC container for creating the objects,managing them(dependency injection(DI)),writing them together,configuring them as also meaning their complete life cycle.IOC is also known as Dependency injection(DI). IOC a design pattern by which Loose coupling is achieved in Spring.Since the objects give their dependencies instead of creating or looking for dependent objects.



7) What are the benefits of using IOC?

Ans. It reduces the amount of coding required for the application. This allows the testing of the application to be done quickly and easily as no JNDI lookup mechanism or singletons are required. IoC containers also support lazy loading and eager installation of services.

8) What is the role of IoC container?

Ans: The role of IoC container in spring  is to instantiate,configure and assemble the objects.

9) What is BeanFactory?

Ans: A BeanFactory is an implementation of the factory pattern that applies inversion of control to separate the application's configuration and dependencies from the actual application code. The most commonly used BeanFactory implementation is the XmlBeanFactory class

10) What are the common implementation of the Application Context?

Ans: The FileSystemXmlApplicationContext container loads the definitions of the beans from an XML file. The full path of the XML bean configuration file must be provided to the constructor.

The ClassPathXmlApplicationContext container also loads the definitions of the beans from an XML file. Here,you need to set CLASSPATH properly because this container will look bean configuration XML file in CLASSPATH

The WebXmlApplicationContext container loads the XML file with definitions of all beans from within a web application.

11) Difference between BeanFactory and ApplicationContext?

Ans:  ApplicationContext provides a means for resolving text messages,a generic way to load file resources(such as images),they can publish events to beans that are registered as listeners. In addition,operations on the container or beans in the container,which have to be handled in a programmatic fashion with a bean factory,can be handled declarative in an application context. The application context implements MessageSource,an interface used to obtain localized messages,with the actual implementation being pluggable.

Recommended to READ:
JDBC Interview Questions
JSP Interview Questions
Servlet Interview Questions
Struts Interview Questions
Hibernate Interview Questions
MVC Architecture in Java


Sunday, February 26, 2017

How to use finally block in Java

In this post we will discuss and learn what is finally keyword in java and how it is useful in java,why sun people introduced this concept in java. This is one of the core concept in exception handling. Although try and catch provides terrific mechanism for trapping and handling exceptions.It is not recommended to place the clean up code inside try block because there is no guarantee for execution of all statements inside  the try block.  For example,you allocated a network socket or opened a file somewhere in the guarded region,each exception handler would have to close the file or release the socket. It makes the programmer too easy to forget to clean up the code,and also lead to a lot of redundant code. To overcome this problem java offers finally block.

finally  create a block of code that will be executed after a try/catch block. The finally block will execute whether or not an exception is thrown. Even there is a return statement in the try block, the finally block executes right after the return statement is encountered,and before the return is executes.

Therefore,finally block is the right place to close your files, release the network sockets and perform any other clean up requires. If the try block executes with no exceptions, the finally block executes immediately  after the try block completes. In case there was exception is thrown in try block,then finally block executes immediately after the proper catch block completes.

Syntax:

try{
// you need to write code in this block there is possibility of raised exceptions
}
catch(MyFirstException)

{
//put the code here that handles this exception
}
finally
{
//put the code here to release any resource  we allocated in try block

}

Example:

try{
//open database connection

//read the data
}
catch(MyFirstExcetpion e)

{
}
finally
{
//close the connection
}


Example 1:

try{
System.out.println("try");
}
catch(ArithmeticException ae)
{
System.out.println("catch");
}
finally
{
System.out.println("finally");
}

Output:
try
finally 

In the above program normal termination happens

Example 2:

try
{
System.out.println(10/0);
}
catch(ArithmeticException ae)
{
System.out.println("catch");
}
finally

{
System.out.println("finally");
}

Output:
catch
finally

In the above program also happens normal termination only

Example 3:

try
{
System.out.println(10/0);
}
catch(NullPointerException ne)
{
System.out.println("catch");
}
finally

{
System.out.println("finally");
}

Output:
finally

This program was terminated abnormally

Hence finally block should always execute irrespective of whether the execution is raised or not raised or handled or not handled.
The finally block won’t be executed if the system it self exists(JVM shutdown) i.e in the case of System.exit() finally block won’t be executed.

Recommended to Read More Topics:
MVC Architecture in Java
When to use abstract class and when interface in Java
How cookies works in servlet
IT Basics for Tech Developers


Example:
try
{
System.out.println("How are u?");
System.exit(0);
}
catch (ArithmeticException e)
{
System.out.println("catch");
}
finally
{
System.out.println("finally");

}

Output:
How are u?



Saturday, February 25, 2017

Cloud Computing Interview Questions

In this post i am sharing Cloud Computing Interview Questions. These questions are helpful for freshers and for final year Students. Now a days,Cloud Computing is one one of the important technology. Cloud Computing is the computing which is completely based on the Internet. The main purpose of the cloud computing is that provides the way to deliver the services whenever and wherever the user of the cloud needs.

Companies use the cloud computing to fulfill the needs of their customers,partners and providers. The cloud computing includes vendors,partners,and business leaders as the three major contributors. Now we will see some important questions and answers

1) What is Cloud?

Ans: A cloud is a combination of hardware,software,storage,services and interfaces that helps in delivering computing as a service.It has broadly three users which are end user,business management user,and cloud service provider. The end user is the one who uses the services provided b the cloud. The business management user in the cloud takes the responsibility of the data and services provided by the cloud. Finally the cloud service provider is the one who takes care or is responsible for the maintenance of the IT assets of the cloud. The cloud acts as a common center for its users to fulfill their computing  needs.

2) What is Cloud Computing?

Ans: The Cloud Computing is the computing which is completely based on the internet.It uses the internet and remote servers to maintain data and applications. A simple example for Cloud computing is Gmail and Yahoo etc...

3) Why Cloud Computing is Important?

Ans: There are many applications of Cloud Computing,for both developers and end users. For developers,cloud computing provides increased amount of storage and processing power to run the applications they develop. Cloud computing also enables new ways to access information,process and analyze data,and connect people and resources from any location anywhere in the world.

For end users,cloud computing offers all those benefits and more. A person using a web-based application isn't physically bound to a single PC,location,or network. His applications and documents can be accessed wherever he is,whenever he wants.No fear of losing data if a computer crashes.Documents hosted in the cloud always exist,no matter what happens to the user's machine. It is a whole new world of collaborative computing all enabled by the notion of cloud computing.

Cloud computing does all this at lower costs because the cloud enables more efficient sharing of resources than does traditional network computing.Cloud infrastructure can be located anywhere,including and especially areas with lower real estate and electricity costs.

4) What are the basic characteristics of cloud computing?

Ans: There are four characteristics of cloud computing as follows:

Elasticity and scalability
Self-service provisioning and automatic de-provisioning
Standardized interfaces
Billing self-service based usage model

5) What is Cloud service?

Ans: A cloud service is a service that is used to build cloud applications. This service provides the facility of using the cloud applications.This service provides the facility of using the cloud application without installing it on the computer. It reduces the maintenance and support of the application as compared  to those applications that are not developed of users can use the application from the cloud service which may be public or private application

6) What are the features of Cloud Services?

Ans: The following are the some important features. They are

Accessing and managing the commercial software
Centralizing the activities of management of software in the web environment
Developing applications that are capable of managing several clients
Centralizing the updating feature of software that eliminates the need of downloading the upgrades.

7) What are the advantages of Cloud Service?

Ans: The following are some of the advantages of Cloud service: They are

Helps in the utilization of investment in the corporate sector and therefore,is cost saving.
Helps in the developing scalable and robust applications. Previously, the scaling took months,but now,scaling takes less time
Helps in saving time in terms of deployment and maintenance

8) What are the disadvantage of Cloud Computing?

Ans: The following are the some of the disadvantages of Cloud Computing: They are

Requires a constant internet connection
Doesn't work well with low speed Connections
Can be slow
Features might be limited
Stored data might not be secure
If the cloud loses the data,you are screwed



9) How many types of Cloud Services?

Ans: A cloud Service is any resource that is provided over  the internet. The most common cloud service resources are.

Software as a Service(SaaS)
Platform as a Service(PaaS)
Infrastructure as a Service(IaaS)

10) How many types of deployment models are used in Cloud?

Ans: There are 4 types of deployment models are used in Cloud:

1)public cloud
2)private cloud
3)Community cloud
4)Hybrid Cloud

11) Why does the organization need to manage the workloads?

Ans: The workload can be defined as an independent service or a set of code that can be executed.
The organization manages workloads because of the following reasons:

To know how their applications are running
To know what functions they are performing
To know the charges of the individual department according to  the use of the service

12) Which services are provided by window Azure operating System?

Ans: Windows Azure provides three core services which are given as follows:

Compute
storage
Management

13) Explain Public and private cloud?

Ans: The public cloud(or external cloud) is freely available for access. You can use a public cloud to collect data of the purchasing of items from a web site on the internet. You can also use public cloud for the reasons which are given as follows:

Helps when an application is to be used by a large number of people,such as an e-mail application on the internet.
Helps when you want to test the application and also needs to develop the application code
Helps when you want to implement the security for the application
Helps when you want to increase the computing capacity
Helps when you are developing the project on an ad-hoc basis by using PaaS

The Private cloud allows the usage of services by a single client on a private network. The benefits of this model are data security,corporate governance,and reliability concerns. It offers a well managed environment. It provides capability to internal users allows provision of services.

Watch Video: Top Cloud Computing Interview Questions

Recommended to Read:

MVC Architecture in Java
Life cycle of Servlet
IT Basics for Tech Developers
JSP Interview Questions
JDBC Interview Questions
TOP 20 HR Interview Questions For Experienced

Friday, February 24, 2017

Interthread Communication in Java

In this article i am sharing interthread communication in Java. This is one of the core concept in Core Java,there is possibility many interview questions raised from this topic and at the same time this topic is also helpful for written Test. Java includes elegant inter process communication mechanism via wait(),notify() and notifyAll() methods. These methods are implemented as final methods in Object class.You must notice one thing is you have to these three methods within the synchronized context only otherwise we will get runtime exception saying IllegalMonitorStateException.All these three methods are available in Object class only but not Thread class. Because threads are calling these methods on any object.

The following are the rules to use these methods:

wait(): This methods tells calling the thread to give up the monitor and go to sleep until some other thread enters same the same monitor and calls notify() and notifyAll().

notify(): This method wake up a thread that called wait() method on the same object

notifyAll(): This method wakes up all threads that  called wait() method on the same object.

These methods are declared within the object as shown below:

final void wait() throws InterrruptedException
final void notify()
final void notifyAll()


Example:

class ThreadA
{
public static void main(String arg[])throws InterruptedException
{
ThreadB b = new ThreadB();
b.start();
synchronized(b)
{
System.out.println("Main Method calling wait method ");
b.wait();
System.out.println("Main Got Notification");
System.out.println(b.total);
}
}
}
class ThreadB extends Thread
{
int total = 0;
public void run()
{
synchronized(this)
{
System.out.println("Child Starting calculation");
for(int i = 1; i<=100; i++)
{
total = total + i;
}
System.out.println("Child giving notification");
this.notify();
}
}

}

Output:








Recommended to Read:

Synchronization Interview Questions
Java Multithreading Examples
Java Multithreading Interview Questions
Life cycle of Thread in Java

SCJP Written Test Questions

In this post i am sharing SCJP/OCJP(Oracle Certified Java Programming) Written Test Questions and Answers. These questions are very helpful who want become OJCP Certified candidate. Then he/she must give Written Test. Now we will see some of the important Questions and answers

1) What is the appropriate definition of the hashCode method in class Person?
public class Person{
private String name,comment;

private int age;
public Person(String n,int a,String c)
{
name=n;
age=a;
comment=c;
}
public boolean equals(Object o){
if(!o (instanceof Person))return false;
Person p=(Person)o;
return age==p.age&&name.equals(p.name);
}
}

A. return super.hashCode();
B. return name.hashCode()+age * 7;
C. return name.hashCode()+comment.hashCode()/2;
D.return name.hashCode()+comment.hashCode()/2-age * 3;

Answer:  B

2) Given this method in a class:

public String toString()
{
StringBuffer sb=new StringBuffer();
sb.append('<');
sb.append(this.name);
sb.append('>');
return sb.toString();
}

Which Statement is True?

A. This Code is NOT thread-safe
B. The programmer can replace StringBuffer with StringBuilder with no other changes.
C. This code will perform poorly. For better performance,the code should be rewritten like follows: return "<" + this.name + ">";
D. This code will perform well and converting the code to use StringBuilder will not enhance the performance.

Answer : B

3) Given
1.public void testIfA()
2.{
3.if(testIfB("TRUE"))
4.{
5.System.out.println("True");

6.}
7.else
8.{
9.System.out.prinltn("Not True");

10.}
11.public Boolean testIfB(String str){
12.return Boolean.valueOf(str);
13.}

What is the result when method testIfA is invoked?

A. True
B. Not True
C. An exception is thrown at runtime
D. Compilation fails because of an error at line number 3
E: Compilation fails because of an error at line number 12

Answer: A 


4. Given
public static void test(String str)
{
int check=4;

if(check=str.length())
{
System.out.println(str.charAt(check=1)+",");
}
else
{
System.out.println(str.charAt(0)+",");
}
}
and the invocation:
test("four");
test("tee");
test("to");
What is the result?

A. r,t,t
B. r,e,o
C. Compilation fails
D. An Exception is thrown at runtime

Answer: C

5)
public class person
{
private String name;
public Person(String name)
{
this.name=name;

}
public boolean equals(Object o)
{
if(!o instanceof Person)
return false;
Person p=new (Person)o;
return p.name.equals(this.name);
}
}
Which statement is true?

A. compilation fails because the hashCode method is not overridden
B. A HashSet could contain multiple Person Objects with the same name
C. All Person objects will have the same hash code because the hashCode method is not overridden
D. If a HashSet contains more than one person Object with name ="Fred",then removing another Person,also with name ="Fred" will remove them all

Answer: B

6) Given

class Polish
{
public static void main(String[] args)
{
int x=4;
StringBuffer sb=new StringBuffer("..fedcba");
sb.delete(3,6);
sb.insert(3,"az");
if(sb.length()>6)x=sb.indexOf("b"));
sb.delete((x-3),(x-2));
System.out.println(sb);
}
}
What is the result?

A. .faza
B. .fzba
C. ..azba
D. .fazba
E. ..fezba
F. Compailation fails
G. Exception thrown at run time

Answer:

C is correct because StringBuffer methods use zero-based indexes,and that ending indexes are typically exclusive

Recommended to Read:

SCJP Java written Test Part 1
SCJP Java written Test Part 2
IT Basics for Tech Developers 
When to use abstract class and when interface in Java




Monday, February 20, 2017

Hibernate Interview Questions

In this post I am sharing frequently asking Hibernate Interview Questions and answers.Hibernate is a pure Object Relational Mapping(ORM) and persistence framework. It allows you to map plain old java objects to relational database tables using XML configuration files. Hibernate is ambitious project that aims to be a complete solution to the problem of managing persistent data in Java. Hibernate integrates smoothly with most new and existing applications and does not require disruptive changes to the rest of the application.Let us see some of the frequently asking interview questions in Hibernate.


1) What is Hibernate?

Ans:  Hibernate is a popular framework of  java that aims to be a complete solution to the problem of managing persistent data. It allows you to map plain old java objects to relational database tables using XML configuration files. After java objects mapping to database tables,database is used and handled using java objects without writing complex database queries.

2) Why Hibernate?

Ans: All most all applications require persistent data. When we talk about persistence in java,we are normally talking about storing  data in relational database using SQL. In java data is stored in the form of object. Hibernate is also one of the Object relational mapping framework.After java objects mapping to database tables,database is used and handled using java objects without writing complex database queries.

ORM provides the following benefits:

Improved productivity: High-level object-oriented API,less java code to write,No SQL to write
improved performance:  Lazy loading,sophisticated caching,eager loading
improved maintainability: A lot less code to write
improved portability: ORM generates database specific  SQL for you

3) What is ORM?

Ans: ORM stands for Object Relational Mapping. It is the fundamental concept of Hibernate framework which maps database between tables with java objects and then provides various API's to perform different types of operations on the tables.

4) What does ORM consists of?

Ans:  The following are the ORM solutions:
  • API for performing basic CURD operations
  • API to express queries referring to classes 
  • Facilities to specify metadata
  • Optimization facilities,dirty checking,lazy associations fetching



5) What are the benefits of Hibernate over JDBC?

Ans: The following are some of the benefits of Hibernate over JDBC:


  • Using Hibernate Developer doesn't need to be expert of writing complex queries. HQL simplifies query writing process while in case of JDBC, developer has to write and tune queries.
  • In case of Hibernate, there is no need to create Connection pools as hibernate does all connection handling automatically. In case of JDBC,developer manually need to create connection pool.
6) What are the Core interfaces of Hibernate?

Ans: The following are the Core interfaces of Hibernate:


  1. Configuration
  2. SessionFactory
  3. Session
  4. Query
  5. Criteria
  6. Transaction
7) What is the most comman methods of hibernate configuration?

Ans:  The most common methods of hibernate configuration are:

1) XML configuration(hibernate.cfg.xml)
2) Programmatic Configuration

8) What is the use of configuration interface in Hibernate?

Ans: Configuration interface of hibernate framework is used to configure hibernate. It's also used to bootstrap hibernate. Mapping documents of hibernate are located using this interface.

9) What is pojo?

Ans: POJO stands for Plain Old Java Objects. These are java beans with proper getter() and setter() methods for each and every properties. Use of POJO instead  of simple java classes results in an efficient and well constructed code.

10) What is HQL?

Ans: HQL is a query language used in Hibernate which is an extension of SQL. It is every efficient,simple and flexible query language to do various type of operations on relational database without writing complex queries.

11) How do you map java objects with Database tables?

Ans: The following steps you must follow to map java objects with Database tables:

1) First we need to write a java domain objects that means setter() and getter() methods
2) Now write hbm.xml, where we map java class to table and database columns to java class variables.




12) What is the general flow of Hibernate Communication with RDBMS?

Ans:  The following steps the flow of hibernate communicate with RDBMS:

1) First Load the Hibernate Configuration file and create Configuration object. It will automatically load all hbm mapping files.
2)Create a Session Factory from Configuration object
3)Now get one session from this Session Factory
4)Create  HQL Query
5)Execute query to get list containing java objects.

13) What are the states of object in hibernate?

Ans: There are 3 states in hibernate. They are:

Transient: The object is in transient state if if is just created but has no primary key 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 is session is closed. After detached state, object comes to persistent state,object comes to persistent state if you call lock() or update() method.

14) How do we create Session Factory in Hibernate?

Ans:  To create a Session Factory in Hibernate,an object of Configuration is created first which refers to the path of configuration file and then for that configuration,session factory is created as given below:

Configuration cfg=new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory factory=cfg.buildSessionFactory();
Session session=factory.openSession();

15)What is the difference between session.save() and session.saveOrUpdate() methods in hibernate?

Ans: Hibernate executes SQL Statements asynchronously. An insert statement is not usually executed when the application calls Session.save()

Session.save(): This method saves a record only if it is unique with respect to its primary key and will fail to insert if primary key already exists in the table.

Session.saveOrUpdate():  This method inserts a new record if primary key is unique and will update an existing record if primary key exists in the tables already.

16) What is transaction management in Hibernate?

Ans: Transaction Management is the process of managing a set of statements or commands. In hibernate,transaction management is done by transaction interface as shown in below code:

Session s=null;
Transaction tran=null;
try{
s=SessionFactory.openSession();
tran=s.beginTransaction();
doTheActions(s);
tran.commit();
}
catch(RuntimeException exe)
{
tr.Rollback();
}
finally
{
s.close();
}

17) What is the use of session.lock() in Hibernate?

Ans: This method is used to reattach an object which has been detached earlier.

18) Does Hibernate supports polymorpism?

Ans: YES. Hibernate supports polymorphism. It's queries and associations are supported in all mapping strategies of hibernate.

19) What is difference between merge and update?

Ans: if you are sure that the session does not contain an already persistent instance with the same identifier then use update() method.

If you want to merge your modifications at any time without consideration of the state of the session then use merge() method.

20) difference between get() and load()?

Ans:
  •  get() method returns null if object is not found whereas load() method  throws ObjectNotFoundException if object is not found
  • get() method always hit the database whereas load() method does not hit the database
  • get() method returns real objects not proxy whereas load() method returns proxy object
21) How to make a immutable class in hibernate?

Ans: If you make a class as mutable="flase",class will be treated as an immutable class. By default,it is mutable="true".

22)How many types of association mapping are possible in hibernate?

Ans: There are 4 types of association mapping in hibernate. They are

1) One to Many
2)Many to One
3)Many to Many

23)Is it possible to perform collection mapping with One-to-One and Many-to-One?

Ans: No, collection mapping can only be performed with one-to-many and many-to-many

24) What is Lazy Loading?

Ans: It improves the perfromance. It loads the child objects on demand. The 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.

25)Difference between first level cache and second level cache?

Ans: First Level Cache is associated with Session and it is enabled by default whereas Second level cache is associated with SessionFactory and it is not enabled by default.

Watch the Video for More details: Hibernate Interview Questions

Recommended to Read:

Struts Interview Questions
JDBC Interview Questions
Servlets Interview Questions
JSP Interview Questions
MVC Architecture in Java


High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...