|
Java Interview Questions and Answers
Name Component subclasses that support painting ?
The Canvas, Frame, Panel, and Applet classes support painting.
What is a native method?
A native method is a method that is implemented in a language other than
Java.
How can you write a loop indefinitely?
for(;;)--for loop; while(true)--always true, etc.
Can an anonymous class be declared as implementing an interface and
extending a class?
An anonymous class may implement an interface or extend a superclass,
but may not be declared to do both.
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.
When should the method invokeLater()be used?
This method is used to ensure that Swing components are updated through
the event-dispatching thread.
How many methods in Object class?
This question is not asked to test your memory. It tests you how well
you know Java. Ten in total.
clone()
equals() & hashcode()
getClass()
finalize()
wait() & notify()
toString()
How does Java handle integer overflows and underflows?
It uses low order bytes of the result that can fit into the size of the
type allowed by the operation.
What is the numeric promotion?
Numeric promotion is used with both unary and binary bitwise operators.
This means that byte, char, and short values are converted to int values
before a bitwise operator is applied.
If a binary bitwise operator has one long operand, the other operand is
converted to a long value.
The type of the result of a bitwise operation is the type to which the
operands have been promoted. For example:
short a = 5;
byte b = 10;
long c = 15;
The type of the result of (a+b) is int, not short or byte. The type of
the result of (a+c) or (b+c) is long.
Is the numeric promotion available in other platform?
Yes. Because Java is implemented using a platform-independent virtual
machine, bitwise operations always yield the same result, even when run
on machines that use radically different CPUs.
What is the difference between the Boolean & operator and the &&
operator?
If an expression involving the Boolean & operator is evaluated, both
operands are evaluated. Then the & operator is applied to the operand.
When an expression involving the && operator is evaluated, the first
operand is evaluated. If the first operand returns a value of true then
the second operand is evaluated. The && operator is then applied to the
first and second operands. If the first operand evaluates to false, the
evaluation of the second operand is skipped.
Operator & has no chance to skip both sides evaluation and && operator
does. If asked why, give details as above.
When is the ArithmeticException throwQuestion: What is the
GregorianCalendar class?
The GregorianCalendar provides support for traditional Western
calendars.
What is the SimpleTimeZone class?
The SimpleTimeZone class provides support for a Gregorian calendar.
How can a subclass call a method or a constructor defined in a superclass?
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.
What is the Properties class?
The properties class is a subclass of Hashtable that can be read from or
written to a stream. It also provides the capability to specify a set of
default values to be used.
What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java
runtime system.
Page Numbers :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
Structs Interview
Questions for more Structs Interview Questions with answers
|