Академический Документы
Профессиональный Документы
Культура Документы
J2EEBrain
LEAVE A COMMENT
interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents
code and data from being arbitrarily accessed by other code de ned
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/2 1/3
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 2
speci c action is determined by the exact nature of the situation. The concept of polymorphism can be
explained as one interface, multiple methods.
Method overloading
Method overriding
the given fully quali ed type name. Thus the getClass() and instanceOf does not perform the same
functionality.
object.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/2 2/3
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 2
Every class inherits the nalize() method from java.lang.Object. The garbage collector uses this method
when it determines that no more references to the object
Related Tutorials :
1. Java Generics
2. Blocks and overloading Java Tutorial
3. Introduction to Exception Handlers Java tutorial
4. Java Enums
5. Abstract Class Java Tutorial
9 0 0 0 1
1
Like
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/2 3/3
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 3
J2EEBrain
LEAVE A COMMENT
If a class contains more than one or more nal methods must the class be de-
clared nal?
No, it not required to make the class nal if it has any nal methods. But if a class is nal it is not neces-
sary that the methods should be declared as nal.
What is a Thread?
Thread is a light weight process. In java thread is the current program in execution. JVM allows an appli-
cation to have multiple threads of execution thus supporting
multithreading.
What are the two approaches for writing code that create a new Thread of
control?
The two approaches are:
1. Extend the Thread class in java.lang package and override the run() method
2. Implement the Runnable interface and implement run() method
What is collection?
A collection is a group of objects which will be treated as a single object.
What is an Iterator?
Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This
interface allows us to walk through a collection of
objects, operating on each object in turn. Generally it is not advisable to modify the collection itself while
traversing an Iterator.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/3 2/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 3
The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits
nulls. (HashMap allows null values as key and value whereas
Hashtable does not allow). HashMap does not guarantee that the order of the map will remain constant
over time. HashMap is unsynchronized and Hashtable is synchronized
What is serialization?
Serialization is a mechanism by which you can save the state of an object by converting it to a byte
stream.
it does not have the native code but built entirely in java programming language. Hence swing works
faster than AWT.
protocol
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/3 3/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 3
Related Tutorials :
1. Java Generics
2. Blocks and overloading Java Tutorial
3. Introduction to Exception Handlers Java tutorial
4. Java Enums
5. Abstract Class Java Tutorial
9 0 0 0 1
1
Like
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/3 4/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 4
J2EEBrain
LEAVE A COMMENT
constants and instance methods, but cannot implement default behavior. An class is abstract if it is de ned with the key-
word abstract or if any
resources. Without synchronization it is possible for one thread to modify a shared variable while another thread is in the
process of using or updating
the same shared variable, which can lead to signi cant errors.
subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be
thrown. Unchecked
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/4 1/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 4
exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses are also unchecked. With an
unchecked exception
the compiler doesnt force client programmers to catch or declare it in a throws clause. Client programmers may not even
know that the exception could
be thrown. Checked exception must be caught at compile time, runtime exceptions do not.
What is Overriding?
When a class de nes a method using the same name, return type and arguments as a method in its superclass, the method
in the
class overrides the method in the superclass. When the method is invoked for an object of the class it is the new de nition of
the method that is
original reference and parameter copy both refer to the same object.
What is serialization?
Serialization is the mechanism used to convert an object to a byte stream.
instance to the Object OutputStream which is connected to a leoutputstream. This will save the object to a le.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/4 2/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 4
referenced objects are serialized along with the target object. Therefore all referenced objects should be serializable. If any
o fthe
What happens to the static elds of a class during serialization?Are these elds serialized as part
of each serialized object?
Yes, the static elds do get serialized. If the static eld is an object then it must have implemented the
Serializable interface. The static elds are serialized as part fo every object, but the commonness of the static elds across
all of the instances is
is garbage collected.
What does the keyword nal mean in front of a class, method and member variable?
Final classes cannot be extended. Final methods cannot be overridden. Final member variables cannot
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/4 3/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 4
What can go wrong if you replace && w/& in the following code?
String a = null;
Related Tutorials :
1. Java Generics
2. Blocks and overloading Java Tutorial
3. Introduction to Exception Handlers Java tutorial
4. Java Enums
5. Abstract Class Java Tutorial
9 0 0 0 1
1
Like
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/4 4/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 5
J2EEBrain
LEAVE A COMMENT
Can a method be overloaded based on different return type but same argument type ?
No, because the methods can be called without using their return type in which case there is ambiquity
for thecompiler.
As many as you want, but the static initializers and class variable initializers are executed in textual or-
der and maynot refer to class variables declared in the class whose declarations appear textually after
the use, even though these class variables are in scope
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/5 1/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 5
What is the difference amongst JVM Spec, JVM Implementation, JVM Runtime ?
The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the
actualimplementation of the spec by a vendor and the JVM.Runtime is the actual running instance of a
JVM implementation.
Whereas Abstract class may have few implemented methods.If some common functionality needs to be
shared.
All those objects not longer being referenced are garbage collected.i.e the memory used by these ob-
jects isreleased.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/5 2/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 5
Common object request broker architecture : platform independent. Uses IIOP to communicate be-
tween objects.
What is JAR le ?
Jar le is an archive of java classes.
jdbc-odbc bridge
Type 4 : pure java driver. no need to have db client installed on client mcs.
What is serialization ?
Process of persisting an object.
What is Downcasting ?
Downcasting is the casting from a general to a more speci c type, i.e. casting down the hierarchy.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/5 3/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 5
Related Tutorials :
1. Java Generics
2. Blocks and overloading Java Tutorial
3. Introduction to Exception Handlers Java tutorial
4. Java Enums
5. Abstract Class Java Tutorial
9 0 0 0 1
1
Like
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/5 4/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 6
J2EEBrain
LEAVE A COMMENT
a particular instance of class and can be called from any method of the class automatic or local variable is
created on entry to a method and has only method
scope
When are static and non static variables of the class initialized ?
The static variables are initialized when the class is loadedNon static variables are initialized just before
the constructor is called.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/6 1/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 6
done in background by a low-priority thread that is referred to as garbage collector. When the gc nds
memory that is no longer accessible from any live thread it
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/6 2/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 6
before the shift, that is if the most signi cant bit before shift is 0 it will introduce 0, else if it is 1, it will in-
troduce 1
features
overridden
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/6 3/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 6
When does the compiler insist that the class must be abstract ?
If one or more methods of the class are abstract.
If class inherits one or more abstract methods from the parent abstract class and no implementation is
provided for that method.
If class implements an interface and provides no implementation for those methods
class
When are the non static variables loaded into the memory ?
They are loaded just before the constructor is called
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/6 4/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 6
Ads by
Related Tutorials :
1. Java Generics
2. Blocks and overloading Java Tutorial
3. Introduction to Exception Handlers Java tutorial
4. Java Enums
5. Abstract Class Java Tutorial
9 0 0 0 1
1
Like
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/6 5/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 7
J2EEBrain
Java Developer
LEAVE A COMMENT
What are the rules for object reference assignment and method call conversion?
An interface type can only be converted to an interface type or to object. If the new type is an interface,
it must be a superinterface of the old
type. A class type can be converted to a class type or to an interface type. If converting to a class type
the new type should be superclass of the old type. If
converting to an interface type new type the old class must implement the interface
An array maybe converted to class object, to the interface cloneable, or to an array. Only an array of ob-
ject references types may be converted to
an array, and the old element type must be convertible to the new element
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/7 1/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 7
that has been thrown, then the exception is considered to be unhandled, in such condition the execution
leaves the method directly as if no try has been executed
Checked exceptions are exceptions that arise in a correct program, typically due to user mistakes like en-
tering wrong data or I/O problems
method
When you extend a class and override a method, can this new method throw ex-
ceptions other than those that were declared by the original method ?
No it cannot throw, except for the subclasses of those exceptions
Is it legal for the extending class which overrides a method which throws an ex-
ception, not o throw in the overridden class ?
Yes it is perfectly legal
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/7 3/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain - Part 7
Ads by
Related Tutorials :
1. Java Generics
2. Blocks and overloading Java Tutorial
3. Introduction to Exception Handlers Java tutorial
4. Java Enums
5. Abstract Class Java Tutorial
9 0 0 0 1
1
Like
PREVIOUS POST
NEXT POST
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html/7 4/4
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain
J2EEBrain
LEAVE A COMMENT
What is the name of the class that is super class for every class?
Object
No. java.lang.String is declared as nal. Class declared as nal cannot be used as a parent class in
inheritance.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html 1/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain
instance.
How many public classes are permitted within a single java class le?
We can de ne only one public class within a single java class le.
What is the command line utility used to compile java source code into bytecode?
javac is the command line utility to compile java source code.
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html 2/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain
A class can have a block of initializer code that is simply surrounded by curly braces and labeled as static
e.g.
public class Demo{
static int =10;
static{
System.out.println(Hello world);
}
}
And this code is executed exactly once at the time of class load
language
When both Oldtypes and Newtypes are classes, one should be subclass of the other
When both Oldtype ad Newtype are arrays, both arrays must contain reference types (not primitive),
and it must be legal to cast an element of Oldtype to an element
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html 3/5
6/21/2017 Java Interview Questions and Answers | Java J2EEBrain
ofNewtype
You can always cast between an interface and a non- nal object
Runtime rules
If Newtype is a class. The class of the expression being converted must be Newtype or must inherit from
Newtype
If NewType is an interface, the class of the expression being converted must implement Newtype
When do you use continue and when do you use break statements ?
When continue statement is applied it prematurely completes the iteration of a loop. When break state-
ment is applied it causes the entire loop to be abandoned.
What is the base class from which all exceptions are subclasses?
All exceptions are subclasses of a class called java.lang.Throwable
You put the code to deal with exceptions that might arise in try block in catch block
Code that must be executed no matter what happens must be place in nally block
Else If one of the operands is oat, the other operand is converted to oat
Else If one of the operands is long, the other operand is converted to long
Related Tutorials :
1. Java Generics
2. Blocks and overloading Java Tutorial
3. Introduction to Exception Handlers Java tutorial
4. Java Enums
5. Abstract Class Java Tutorial
9 0 0 0 1
1
Like
http://www.j2eebrain.com/java-J2ee-java-interview-questions.html 5/5