Java by Nageswara Rao
Java by Nageswara Rao
Ans)
3) Which part of JVM will allocate the memory for a java program?
Ans). Class loader subsystem of JVM will allocate the necessary memory needed by
the java program.
import statement makes the JVM go to the Java standard library, execute the code
there , and substitute the result into the program. Here, no code is copied and
hence no waste of memory or processors time. so import is an efficient mechanism
than #include.
Ans). In a do..while loop, the statements are executed without testing the condition ,
the first time. From the second time only the condition is observed. This means that
the programmer does not have control right from the beginning of its execution. In a
while loop, the condition is tested first and then only the statements are executed.
This means it provides better control right from the beginning. Hence, while loop is
move efficient than do.. while loop.
difference
between
System.out.exit(0)
and
23) Can you call the main( ) method of a class from another class ?
Ans). Yes , we can call the main( ) method of a class from another class using
Classname.main( ) . At the time of calling the main( ) method, we should pass a
string type array to it.
Ans). String is a class in java.lang package. But in Java, all classes are also
considered as data types. So we can take String as a data type also.
31) Are there any other classes whose objects are immutalbe ?
Ans). Yes, classes like Character, Byte, Integer, Float, Double, Long..called wrapper
classes are created as immutable.Classes like Class, BigInteger, Big Decimal are
also immutable.
between
default
constructor
and
Default constructor
Parameter constructor
Parameterized constructor is
useful to initialize each object
with different data.
Parameterized constructor will
have 1 or more parameters
Methods
Method Overriding
Writing two or more methods with
the same name and same signatures
is called method overriding.
72) What is difference between primitive data types and advanced data
types ?
Ans). Primitive data types represent single values. Advanced data types represent a
group of values. Also methods are not available to handle the primitive data types.
In case of advanced data types, methods are available to perform various
operations.
81) How can you force your programmers to implement only the
features of your class ?
Ans). By writing an abstract class or an interface.
84) Why the methods of interface are public and abstract by default ?
Ans). Interface methods are public since they should be available to third party
vendors to provide implementation. They are abstract because their implementation
is left for third party vendors.
Interface
Runtime.getRuntime( ).gc( );
104). Which of the wrapper classes contains only one constructor ? (or)
Which of the wrapper classes does not contain a constructor with String
as parameter ?
Ans). Character.
Vector
ArrayList
object
is
not
synchronized by default
Incase of a single thread, using
ArrayList is faster than the Vector.
ArrayList increases its size every Vector increases its size every
time by 50 percent (half).
time by doubling it.
Ans).
HashMap
HashMap object is not synchronized
by default.
In case of a single thread, using
HashMap
is
faster
than
the
Hashtable.
HashMap allows null keys and null
values to be stored.
Iterator in the HashMap is fail-fast.
This means Iterator will produce
exeception if concurrent updates are
made to the HashMap.
Hashtable
Hashtable object is synchronized by
default.
In case of multiple threads, using
Hashtable is advisable, with a single
thread, Hashtable becomes slow.
Hashtable does not allow null keys or
values.
Enumeration for the Hashtable is not
fail-fast.
This
means
even
if
concurrent updations are done to
Hashtable, there will not be any
incorrect results produced by the
Enumeration.
List
A List represents ordered collection of
elements.List preserves the order of
elements in which they are entered.
List will allow duplicate values.
Accessing elements
possible in lists.
by
index
is
121). What is the default buffer size used by any buffered class ?
Ans). 512 bytes.
Ans). Executing only one job at a time is called single tasking. Executing several
jobs at a time is called multi tasking. In single tasking, the processor time is wasted,
but in multi tasking, we can utilize the processor time in an optimum way.
reduce
overhead
on
again from init( ) method. This cyclic way of executing the methods is called applet
life cycle.
Ans). Auto boxing refers to creating objects and storing primitive data types
automatically by the compiler.