Sunday, November 16, 2014

25 LATEST TOP ADVANCED JAVA Interview Questions and Answers

Advanced Java Interview Questions and Answers :

What we can not do in jdbc but can do hibernate?
There are many thing we can do in hinernate automaticaly by hibernate tools or seting hibernate properties.some I giving below:

(1) We can migrate database just change database dielect.
(2)we can used caching
(3)if user do not know ant any SQL languge then they can use criteria query.
(4)There is one scnerio where SQL query are failed when want fetch obejct from db but do not know there ID.Hibernate provide this solution using HSQL.

Java is fully object oriented languages or not? Why?
No,java is not fully object oriented language because it does not support "multiple inheritence" and "pointers" which are used in C++.But,by using Interfaces we can implement multiple inheritence.Also,due to presence of Primitive datatypes,which are used in (AutoBoxing)...we can say it is not fully object oriented language.

If i learn Java, what kind of applications can i create that will help Banking, Retail, Hotel, Logistics industry?
When learned the java with the advanced concepts ,the application can be created for all the domain.Using the J2EE will be more friendly and efficiency in the code maintenance, since part of the code will be from the
framework

What is difference between object state and behavior?
If you change the state of an object, you ask it to perform a behavior. An object stores its states in a field e.g.variables, and demonstrates its behavior through methods.

Can we have more than one action servlet?
yes you can have and if you specify different url patter like
*.do for one action servlet
*.abc for other action servlet in your web.xml file

Why use a datasource when you can directly specify a connection details? (in a J2EE application)?
Because, it would be really difficult to specify the connection details in every method that access the database. Instead, if we create a data source, it can be used to connect to the database in every method we want.

If I define a method in JSP scriplet <%..%>, where will it go after translation into a servlet?
It will give compilation error. In order to define a method in JSP, it should be defined in the JSP declarations <%!..% >, and it can be called in the JSP expression.On translation, the method will be added outside all
methods in the servlet class.

How will the struts know which action class to call when you submit a form?
struts-config.xml in this file.
under the tag <type> absolute path of Action class under the tag <name> name of the action form class
Both of this will be called when the desired action mentioned under the <path> tag will be called and
struts-config.xml will call action class mentioned in the <type> tag and also populate the fields of form class
mentioned under <name> tag.

Will it be called overriding if I do not change the parameters or return type, instead throw a different exception in the method signature?
yes, you will be overriding to throw a different exception

Does Java pass arguments by value or reference?
Pass by value.
1. When passing primitives, it passes a copy of the variable to the method. Any change made in the method does not reflect in the calling method.
2. When dealing with objects, a copy of their reference/address is passed. Thus the change made to the
object is reflected in the calling method.

Different between Struts and Spring? or Why use Spring, if you are already using Struts?
Struts:
1.Struts is only for web Applications.We can not develop any type of Java,J2EE applications by using Struts Framework.
2.We can not Integrate other Frameworks with Any other Java Oriented Frameworks.

Spring:
1.Spring is for developing any kind of Java,J2EE applications.
2.It is Layered architecture.We can integrate any no of
Frameworks with Spring.
3.It has So many features like AOP,IOC.

Explain what is synchronization?
When multiple threads working,Synchronization is to lock a method for a particular object.

Write a program to show synchronization?
public someClass{
public synchronised methodA(){
//write your code
}
}

Explain what is orm?
Object Relational Mapping ,its a tool for transaction management that needs to be integrated with Spring,Struts etc.Eg : Hibernate,iBatis,JDO etc

Write a singleton program?
Having single instance through out the application.eg.: Loggers

What is IOC concept & explain it?
Injecting dependencies to object itself instead of depending on container.

Explain spring framework?
Spring is lightweight,Inversion controlled,Aspect oriented ,Container framework.

What are the oops concept?
Inhertitance, Encapsulation, Polymorphism, Data Abstraction

What are the diff types of exception?
Unchecked and Checked exceptions

What is AOP(assepct oriented programing)?
Separating your business logic with other functionalit
y such as services,Loggers etc,Making classess more cohesive.

What is jsp life cycle?
jspinit(),_jspService(),jspdestroy()

Explain servlet life cycle?
init(),service(),destroy()

What is prototype?
Having multiple instances or having clones

In spring bean class uses singleton or prototype?
By Default spring uses singleton or mention singleton="true" for singleton else false for prototype inside bean tag.

20 LATEST TOP CORE JAVA Interview Questions and Answers

CORE JAVA Interview Questions and Answers :

Explain about Core Java?
Java is increasingly used for middleware applications to communicate between Server and clients. Java has features such as multithreading, portability and networking capabilities. Changes in the java library made java as a favorite programming language for developers it added functionality to their scripts.

State some advantages of Java?
Platform independence is the key feature of Java during runtime. Syntax of java is similar to the popular object oriented languages such as C and C++. Java program can eliminate most of the bugs present in the program. Manual memory allocation and de allocation feature present in Java is automated.

State the main difference between C++ and Java?
The main difference between C++ and Java lies in multiple inheritances. Java Meta class model has a better solution than C++. Persistent objects can be implemented by features such as object serialization and reflection mechanism. GUI can be implemented easily.

Explain about the security aspect of Java?
Java has some bugs in its applets. Java team stated that they have zero tolerance over security features and subsequent editions of Java are improving Bug free environment. Some of the features are overriding the runtime stack, disallowing the corruption of memory outside its own process, reading or writing on local files where it is actually forbidden to do these processes, etc.

Explain about the interpreter in Java?
Machines should have Java interpreter for the Java byte code to get executed. Linking is a very easy process and this feature helps while developing applications. Java compiler which is available with software development kit is a bit slower in execution of scripts.

Explain about the performance aspects of Core Java?
Performance of interpreted byte codes is enough but it can be improved much more than that. Byte codes are translated into machine language within no time, this speed of execution can be achieved during application compiling time. JIT compilers are also present which compile the byte codes into native code.

Explain about the dynamic behavior of core java?
This language was designed to adapt the changing environment and behavior. New methods and instance variables can be added to the client side without any major changes happening at the client end. This function is very important for GUI builders, pluggable components, debuggers and object database.

Explain about Java SDK?
Java SDK is not so comfortable with people used to command line interpreter. IDEs include compilers, editors, debugging facilities, drag and drop techniques, etc. This compiler strives to generate hundreds of lines in code UI. This platform may become a universal platform.

What are the three best choices for development environment?
The three best choices for development environment include.
1) Java SDK and text editor can be a perfect choice.
2) Java SDK and a text editor which is built within the SDK.
3) Using IDE such as free Forte community edition.

Explain about Class in Java?
In Java every thing exists within a class. It defines the behavior of the class and its characteristics. Java applications and applets are built in the class. Rules present for class name are generous and some of the basic rules are names should start with a letter after that letter they can have any combination of letters and digits. It can contain names to any length.

Explain about Java data types?
Variables declared should have a declared type. Out of the eight data types four data types are integer, two are floating type integers, one is character type out of which one is Boolean and the other Unicode. Core Java is known to be a strong typed language.

Explain about Java assignment statement?
After declaring a variable, it should be initialized explicitly. Uninitialized variable can never be used. To a declared variable you must assign a variable name on the left, equal sign and a java expression should have a appropriate value to the right.

Give the difference between the println method and sqrt method?
Println method operates on the object system.out and has the value which should be printed namely y. sqrt method is a static method. It does not operate on any object. It has the number stored in x for which the square toot should be found out.

Explain about strings in Java?
Strings represent nothing but a string of characters. Java does not have any built in string type. It contains predefined class which can be called enough as a String. Instance of a string is called as a string. Much similar to many object oriented languages a + sign is used.

Explain the reason behind ending a program with a System.exit (0)?
The reason behind ending a program with System.exit (0) involves technicalities. When main method exits the new thread automatically does not end. The appearance of this thread is because of dialog box functionality. System.exit ends all the methods.

Explain about inheritance hierarchies?
An inheritance hierarchy has a collection of all classes which fall under the main class. Inheritance chain defines the path from where all the sub classes originated and their relation ship. Controller normally handles user input. Inheritance hierarchy is very important in software modeling.

Explain about the select method with an example?
Select part is useful in selecting text or part of the text. Arguments specified for the select command are the same as applicable to substring. First index is usually represents the start of the index. End of line makers are counted as one character. Example t.select (10,15)