Important Java Questions For Interview Part – 4
1.What is a Java Bean?
A Java Bean is a software component that has been designed to be reusable in a variety of different environments.
2.What are checked exceptions?
Checked exception are those which the Java compiler forces you to catch.
e.g. IOException are checked Exceptions.
3.What are runtime exceptions?
Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.
4.What is the difference between error and an exception?
An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime.
While exceptions are conditions that occur because of bad input etc.
e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.).
5.What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
For example,closing a opened file,closing a opened database Connection.
6.What is the difference between yielding and sleeping?
When a task invokes its yield() method,it returns to the ready state.
When a task invokes its sleep() method,it returns to the waiting state.
7.What is the difference between preemptive scheduling and time slicing?
Under preemptive scheduling,the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing,a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next,based on priority and other factors.
8.What is mutable object and immutable object?
If a object value is changeable then we can call it as Mutable object.
(Ex.,StringBuffer,…)
If you are not allowed to change the value of an object,it is immutable object.
(Ex.,String,Integer,Float,…)
9.What is the purpose of Void class?
The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
10.What is JIT and its use?
Really,just a very fast compiler… In this incarnation,pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method,rank the expressions according to which ones are re-used the most,and then generate code. In theory terms,it’s an on-line problem.
11.What is nested class?
If all the methods of a inner class is static then it is a nested class.
12.What is HashMap and Map?
Map is Interface and Hashmap is class that implements that.
13.What are different types of access modifiers?
public: Any thing declared as public can be accessed from anywhere.
private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages.
default modifier : Can be accessed only to classes in the same package.
14.What is the difference between Reader/Writer and InputStream/Output Stream?
The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.
15.What is servlet?
Servlets are modules that extend request/response-oriented servers,such as java-enabled web servers. For example,a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.
16.What is Constructor?
A constructor is a special method whose task is to initialize the object of its class.
It is special because its name is the same as the class name. They do not have return types,not even void and therefore they cannot return values.
They cannot be inherited,though a derived class can call the base class constructor.
Constructor is invoked whenever an object of its associated class is created.
17.What is an Iterator ?
The Iterator interface is used to step through the elements of a Collection.
Iterators let you process each element of a Collection.
Iterators are a generic way to go through all the elements of a Collection no matter how it is organized.
Iterator is an Interface implemented a different way for every Collection.
18.What is the List interface?
The List interface provides support for ordered collections of objects.
Lists may contain duplicate elements.
19.What is memory leak?
A memory leak is where an unreferenced object that will never be used again still hangs around in memory and doesn’t get garbage collected.
20.What is the difference between the prefix and postfix forms of the ++ operator?
The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.
21.What is the difference between a constructor and a method?
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself,has no return type,and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name,a return type (which may be void),and is invoked using the dot operator.
22.What will happen to the Exception object after exception handling?
Exception object will be garbage collected.
23.Difference between static and dynamic class loading.
Static class loading:
The process of loading a class using new operator is called static class loading.
Dynamic class loading:
The process of loading a class at runtime is called dynamic class loading.
Dynamic class loading can be done by using
Class.forName(….).newInstance().
24.Explain the Common use of EJB
The EJBs can be used to incorporate business logic in a web-centric application.
The EJBs can be used to integrate business processes in Business-to-business (B2B) e-commerce applications.
In Enterprise Application Integration applications,EJBs can be used to house processing and mapping between different applications.
25.What is JSP?
JSP is a technology that returns dynamic content to the Web client using HTML,XML and JAVA elements. JSP page looks like a HTML page but is a servlet. It contains Presentation logic and business logic of a web application.
26.What is the purpose of apache tomcat?
Apache server is a standalone server that is used to test servlets and create JSP pages. It is free and open source that is integrated in the Apache web server.
It is fast,reliable server to configure the applications but it is hard to install. It is a servlet container that includes tools to configure and manage the server to run the applications. It can also be configured by editing XML configuration files.
27.Where pragma is used?
Pragma is used inside the servlets in the header with a certain value. The value is of no-cache that tells that a servlets is acting as a proxy and it has to forward request.
Pragma directives allow the compiler to use machine and operating system features while keeping the overall functionality with the Java language. These are different for different compilers.
28.Briefly explain daemon thread.
Daemon thread is a low priority thread which runs in the background performs garbage collection operation for the java runtime system.
29.What is a native method?
A native method is a method that is implemented in a language other than Java.
30.Explain different way of using thread
A Java thread could be implemented by using Runnable interface or by extending the Thread class. The Runnable is more advantageous,when you are going for multiple inheritance.
31.What are the two major components of JDBC?
One implementation interface for database manufacturers,the other implementation interface for application and applet writers.
32.What kind of thread is the Garbage collector thread?
It is a daemon thread.
33.What are the different ways to handle exceptions?
There are two ways to handle exceptions,
1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and
2. List the desired exceptions in the throws clause of the method and let the caller of the method handle those exceptions.
34.How many objects are created in the following piece of code? MyClass c1,c2,c3;
c1 = new MyClass ();
c3 = new MyClass ();
Answer: Only 2 objects are created,c1 and c
3. The reference c2 is only declared and not initialized.
35.What is UNICODE?
Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.