What is a platform?
Answer:
A platform is the hardware or software environment in which a
program runs. Most
platforms can be described as a combination of the operating system and
hardware, like Windows
2000 and XP, Linux, Solaris, and MacOS.
What is the main difference between Java platform and other platforms?
Answer:
The Java platform differs from most other platforms in that it's a
software-only platform that
runs on top of other hardware-based platforms. The Java platform has
two components: 1. The Java
Virtual Machine (Java VM) 2. The Java Application Programming Interface
(Java API)
What is the Java Virtual Machine?
Answer:
The Java Virtual Machine is a software that can be ported onto various
hardware-based platforms.
What is the Java API?
Answer:
The Java API is a large collection of ready-made software components
that provide many useful
capabilities, such as graphical user interface (GUI) widgets
What is the package?
Answer:
The package is a Java namespace or part of Java libraries. The Java API
is grouped into
libraries of related classes and interfaces; these libraries are known
as packages.
What is native code?
Answer:
The native code is code that after you compile it, the compiled code
runs on a specific
hardware platform.
Is Java code slower than native code? Can main() method be
overloaded?
Answer:
Yes. the main() method is a special method for a program entry. You can
overload main()
method in any ways. But if you change the signature of the main method,
the entry point for
the program will be gone.
What is the serialization?
Answer:
The serialization is a kind of mechanism that makes a class or a bean
persistence by having
its properties or fields and state information saved and restored to
and from storage.
What is a transient variable?
Answer:
A transient variable is a variable that may not be serialized. If you
don\'t want some field
to be serialized, you can mark that field transient or static.
Which containers use a border layout as their default layout?
Answer:
The Window, Frame and Dialog classes use a border layout as their
default layout.
Answer:
Not really. As a platform-independent environment, the Java platform
can be a bit slower
than native code. However, smart compilers, well-tuned interpreters,
and just-in-time bytecode
compilers can bring performance close to that of native code without
threatening portability.
What are three ways in which a thread can enter the waiting state?
Answer:
A thread can enter the waiting state by invoking its sleep() method, by
blocking on IO, by
unsuccessfully attempting to acquire an object's lock, or by invoking
an object's wait() method.
It can also enter the
waiting state by invoking its (deprecated) suspend() method.
Can a lock be acquired on a class?
Answer:
Yes, a lock can be acquired on a class. This lock is acquired on the
class's Class object.
What method is used to specify a container's layout?
Answer:
The setLayout() method is used to specify a container's layout.
Which containers use a FlowLayout as their default layout?
Answer:
The Panel and Applet classes use the FlowLayout as their default
layout.
Can Java object be locked down for exclusive use by a given thread?
Answer:
Yes. You can lock an object by putting it in a "synchronized" block.
The locked object is
inaccessible to any thread other than the one that explicitly claimed
it.
What state does a thread enter when it terminates its processing?
Answer:
When a thread terminates its processing, it enters the dead state.
What is the difference between Process and Thread?(donated in April
2005)
Answer:
A process can contain multiple threads. In most multithreading
operating systems, a process
gets its own memory address space; a thread doesn't. Threads typically
share the heap belonging
to their parent process. For instance, a JVM runs in a single process
in the host O/S.
Threads in the JVM share the heap belonging to that process; that's why
several threads
may access the same object.Typically, even though they share a common
heap, threads have
their own stack space. This is how one thread's invocation of a method
is kept separate
from another's.This is all a gross oversimplification, but it's
accurate enough at a high level.
Lots of details differ between operating systems.Process vs. Thread A
program Similar to a
sequential program vs. Can run on its own Cannot run on its own Unit
of allocation Unit of
execution vs. Have its own memory space Share with others Each
process has one or more
threads vs. Each thread belongs to one process Expensive, need
to context switch
vs. Cheap, can use process memory and may not need to context switch
More secure. One process
cannot corrupt another process Less secure.vs. A thread can write the
memory used by another
thread
If a method is declared as protected, where may the method be accessed?
Answer:
A protected method may only be accessed by classes or interfaces of the
same package or by
subclasses of the class in which it is declared.
What is the purpose of finalization?
Answer:
The purpose of finalization is to give an unreachable object the
opportunity to perform any
cleanup processing before the object is garbage collected.
Which class is the superclass for every class.
Answer:
Object.
What is the purpose of the finally clause of a try-catch-finally
statement?
Answer:
The finally clause is used to provide the capability to execute code no
matter whether or
not an exception is thrown or caught.
What is a static method?
Answer:
A static method is a method that belongs to the class rather than any
object of the class
and doesn't apply to an object or even require that any objects of the
class have been
instantiated.
What is the difference between a Window and a Frame?
Answer:
The Frame class extends Window to define a main application window that
can have a menu bar.
What do heavy weight components mean?
Answer:
Heavy weight components like Abstract Window Toolkit (AWT), depend on
the local windowing
toolkit. For example, java.awt.Button is a heavy weight component, when
it is running on the
Java platform for Unix platform, it maps to a real Motif button. In
this relationship, the
Motif button is called the peer to the java.awt.Button. If you create
two Buttons, two peers
and hence two Motif Buttons are also created. The Java platform
communicates with the Motif
Buttons using the Java Native Interface. For each and every component
added to the application,
there is an additional overhead tied to the local windowing system,
which is why these
components are called heavy weight.
Which package has light weight components?
Answer:
javax.Swing package. All components in Swing, except JApplet, JDialog,
JFrame and JWindow are
lightweight components.
Does a class inherit the constructors of its superclass?
Answer:
A class does not inherit constructors from any of its superclasses.
Name primitive Java types.
Answer:
The primitive types are byte, char, short, int, long, float, double,
and boolean.
What restrictions are placed on method overloading?
Answer:
Two methods may not have the same name and argument list but different
return types.
What restrictions are placed on method overriding?
Answer:
Overridden methods must have the same name, argument list, and return
type. The overriding
method may not limit the access of the method it overrides. The
overriding method may not
throw any exceptions that may not be thrown by the overridden method.
What is casting?
Answer:
There are two types of casting, casting between primitive numeric types
and casting between
object references. Casting between numeric types is used to convert
larger values, such as
double values, to smaller values, such as byte values. Casting between
object references is
used to refer to an object by a compatible class, interface, or array
type reference.
What is the difference between a Scrollbar and a ScrollPane?
Answer:
A Scrollbar is a Component, but not a Container. A ScrollPane is a
Container. A ScrollPane
handles its own events and performs its own scrolling.
What is tunnelling?
Answer:
Tunnelling is a route to somewhere. For example, RMI tunnelling is a
way to make RMI
application get through firewall. In CS world, tunnelling means a way
to transfer data.
Java Language
Question:
Does the code in finally block get executed if there is an exception
and a return statement
in a catch block?
Answer:
If an exception occurs and there is a return statement in catch block,
the finally block is
still executed. The finally block will not be executed when the
System.exit(1) statement is
executed earlier or the system shut down earlier or the memory is used
up earlier before the
thread goes to finally block.
What are use cases?
Answer:
A use case describes a situation that a program might encounter and
what behavior the program
should exhibit in that circumstance. It is part of the analysis of a
program. The collection of
use cases should, ideally, anticipate all the standard circumstances
and many of the
extraordinary circumstances possible so that the program will be
robust.
What is scalability and performance?
Answer:
Performance is a measure of "how fast can you perform this task." and
scalability describes how
an application behaves as its workload and available computing
resources increase.
Java Language
Question:
What is the benefit of subclass?
Answer:
Generally:
The sub class inherits all the public methods and the implementation.
The sub class inherits all the protected methods and their
implementation.
The sub class inherits all the default(non-access modifier) methods and
their implementation.
The sub class also inherits all the public, protected and default
member variables from the
super class.
The constructors are not part of this inheritance model.
In System.out.println(),what is System,out and println,pls explain?
Answer:
System is a predefined final class,out is a PrintStream object acting
as a field member and
println is a built-in overloaded method in the out object.
What is meant by "Abstract Interface"?
Answer:
First, an interface is abstract. That means you cannot have any
implementation in an interface.
All the methods declared in an interface are abstract methods or
signatures of the methods.
Why Java does not support pointers?
Answer:
Because pointers are unsafe. Java uses reference types to hide pointers
and programmers feel
easier to deal with reference types without pointers. This is why Java
and C-sharp shine.
Can you declare a class as private? (donated in April, 2005)
Answer:
Yes, we can declare a private class as an inner class. For example,
class MyPrivate {
private static class MyKey {
String key = "12345";
}
public static void main(String[] args) {
System.out.println(new MyKey().key);//prints 12345
}
}
Can Java code be compiled to machine dependent executable file?
Answer:
Yes. There are many tools out there. If you did so, the generated exe
file would be run in the
specific platform, not cross-platform.
What are the drawbacks of inheritance? (donated by RS in Mar. 2005)
Answer:
Since inheritance inherits everything from the super class and
interface, it may make the
subclass too clustering and sometimes error-prone when dynamic
overriding or dynamic overloading
in some situation. In addition, the inheritance may make peers hardly
understand your code if
they don't know how your super-class acts.
Usually, when you want to use a functionality of a class, you may use
subclass to inherit such
function or use an instance of this class in your class. Which is
better, depends on your
specification.