Interview Type of Questions - 3
Object,
Class, and Methods
- What
is an object?
- What
is a class?
- What
is a method?
- What
is the signature of a method?
- What
is the difference between an instance variable and a class variable?
- What
is the difference between an instance method and a class method?
- How
do I create an instance of a class?
- What
is an abstract method?
- What
is an abstract class?
- What
is an object reference?
Subclassing,
Overloading, and Overriding
- What
is a subclass?
- What
is inheritance?
- What
is an overloaded method?
- What
does it mean to override a method?
- What
is the difference between overloading and overriding?
- Can
I override the equals method or clone method from class Object to take a
parameter or return a value of the type that I specify?
- What
is the super keyword used for?
- Does
the Java language provide virtual methods, like C++?
- What
is a final class?
Interfaces
and Abstract Classes
- What
is an interface?
- How
does a class implement an interface?
- Can
I instantiate an interface?
- Why
does a method in an interface appear to be public even though I didn't declare
it to be public?
- How
is an abstract class different from an interface?
- Does
the Java language allow multiple inheritance?
- What
is the instanceof keyword, and what does it do?
- Why
do I get the error message Can't access protected method clone... when I try to
clone an object?
- How
do I design a class so that it supports cloning?
Packages
and Access Modifiers
- What
are packages, and what are they used for?
- I've
seen both java.applet.Applet and Applet used to refer to the Applet class --
what's the difference?
- Why
can I get some simple class names "for free," without using an import
declaration?
- Is
there a default access modifier for classes and interfaces? For class members
(methods, constructors, and fields)?
- What
does protected access mean?
- What
is the accessibility of a public method or field inside a nonpublic class or
interface?
Constants
and Expressions
- What
is the difference between Integer and int in Java -- why do I get the following
error: Can't convert java.lang.Integer to int?
- How
do I treat all 8 bits of a byte as an unsigned quantity?
- How
do I work around Java's lack of true enums?
- Why
is goto a reserved keyword in Java -- shouldn't it be outlawed?
- What
are some guidelines for using uppercase and lowercase letters in my
identifiers?
- Is
there any limit to the length of an identifier?
- Why
doesn't Java have user-defined operator overloading?
- Why
do I have to put an f after a floating point constant?
- How
and when can I cast from one class to another?
- Can
I use C-like data structures in Java?
Variables
and Methods
- Are
Java objects pointers?
- In
a method invocation, does Java pass arguments by reference or by value?
- If
the Java language lacks pointers, how do I implement classic pointer structures
like linked lists?
- What
does the following error message mean: Can't make a static reference to nonstatic
variable?
- In
a class method, how can I get the name of the class, or create a new instance
of the class?
- Can
I write a method that delivers dynamically (at run time) all public methods of
an object?
- Can
I invoke methods dynamically, from names (String instances) that are determined
at run time?
- How
can I accomplish the equivalent of function pointers in Java, for instance, for
use in an array?
Arrays
- Can
I allocate an array dynamically?
- How
do I initialize an array of objects?
- If
arrays are objects, why can't I use a length method to determine an array's size?
Exceptions
- What
is an exception?
- Why
does the compiler complain about InterruptedException when I try to use
Thread's sleep method?
- Why
do methods have to declare the exceptions they can throw?
- What's
the difference between a runtime exception and a plain exception -- why don't
runtime exceptions have to be declared?
Virtual
Machine
- When,
and by whom, is the main method of a class invoked?
- What
are bytecodes?
- What
is javap?
- What
does it mean to say that Java is interpreted?
- What
kind of garbage collection does the Java Virtual Machine use?
- Is
finalization broken -- why does my finalize method never seem to get invoked?
- I'm
having trouble invoking methods on the objects returned from Class's forName
method -- how should I use Class.forName?
- Why
do I get verifier errors when loading a class file produced by javac?
- How
fast are Java programs compared to equivalent C or C++ programs?
Applets
versus Applications
- What
is an applet?
- How
do applets differ from applications?
- Can
I write Java code that works both as an applet and as a stand-alone application?
Installing
Applets
- How
do I put an applet into a web page?
- Can
I put more than one applet in a web page?
- How
do I use the APPLET tag if I want to show users of non-Java-enabled browsers
what they're missing?
- What
is the complete syntax for using the APPLET tag?
- What
are the different pieces that can make up an applet, and how do I install them?
- Where
can I put my applet's class files, and how do I indicate their location using
the APPLET tag?
- Can
I put my reusable custom classes in a special place so that many different
applets can use them?
Applet
User Interface
- How
do I determine the width and height of my applet?
- How
do I set the background color within the applet area?
- How
can I create a transparent background for my applet?
- Can
I put menus and a menu bar on my applet?
- I
know that cursors can be changed from within frames, but how do I change the
cursor in my applet?
Applet
Program Structure
- Several
applet methods seem special, in that I need to define them even if my own code
doesn't invoke them -- what are the methods, and when (and by whom) are they
invoked?
- Should
applets have constructors?
- How
can my applet tell when a user leaves or returns to the web page containing my
applet?
- How
do I read number information from my applet's parameters, given that Applet's getParameter
method returns a String?
Applet
Communication
- How
can I arrange for different applets on a web page to communicate with each
other?
- How
do I select a URL from my applet and send the browser to that page?
- Can
applets on different pages communicate with each other?
Miscellaneous
- Can
I load an applet dynamically into a Java application, and if so, how does the
applet get the parameter information it would normally get from the APPLET tag?
- Do
I need any special server software or setup to deliver applets?
Components,
Containers, and Peers
- What
are the Component and Container classes?
- How
do I control the positioning of my interface components?
- What
are inset values, and how do I set them?
- Can
I exert complete control over the size and placement of components in my
interface?
- What
do the invalidate and validate methods do?
- Can
I add new AWT components to objects already visible on the screen?
- Can
I add the same component to more than one container?
- How
can I place an outline around a group of components to show explicitly how the
components are grouped?
- What
are AWT peers?
Windows,
Frames, and Dialogs
- How
do I specify where a window is to be placed?
- How
can I draw at the top-left corner of a frame without it being covered by the
frame's border?
- How
do I create a borderless window?
- Several
operations in the AWT, such as setting the cursor (in JDK 1.0.2) or creating a
dialog box, require specifying a Frame instance -- how do I determine the Frame
instance containing the current component?
- How
do I use a FileDialog object in my applet or application?
- Can
I create nonresizable windows?
Miscellaneous
- What
does Component's requestFocus method do?
- Does
the AWT allow you to control the mouse location from within an application?
- Does
the AWT provide a standard way to signal a user error by flashing, beeping, or
some other means?
- What
fonts are available to my AWT program?
- How
can I dynamically change font attributes, for instance, rendering a string in
successively larger font sizes?
Events
-- JDK 1.0.2
- What
information can be carried in the JDK 1.0.2 by an Event object?
- What
information do specific event types in the JDK 1.0.2 carry?
- What
is the general model in the JDK 1.0.2 for distributing and handling events?
- What
methods should I use in the JDK 1.0.2 to handle events?
- What
is an action event?
- How
does the JDK 1.0.2 handle events for function keys, arrow keys, and so on?
- My
frame doesn't close when I click on Quit/Close in the main menu -- how do I fix
this using JDK 1.0.2?
- How
is my program notified when a menu item is selected?
- MenuItemEventExample.html
- How
is my program notified in the JDK 1.0.2 when a list item is selected or
deselected?
- How
do I hook up a scroll bar in the JDK 1.0.2 so that it controls the scrolling of
some other component?
- Does
the AWT in the JDK 1.0.2 distinguish between mouse clicks made with different
buttons on a two- or three-button mouse?
Event
Classes, Listeners, and Methods
- What
information do specific event types in the JDK 1.1 carry?
- How
do I catch events in the JDK 1.1 event model?
- What
are the different kinds of event listeners, and what are their methods?
- When
should I use an event adapter class?
- Do
events propagate in the JDK 1.1 as they did in the older AWT event model?
- Will
my code written for the older JDK 1.0.2 event model still run in the JDK 1.1?
SEMANTIC
EVENTS
- How
do I handle action events in the JDK 1.1?
- How
do I catch menu item events in the 1.1 AWT event model?
- In
the JDK 1.1 AWT event model, how is my program notified when a list item is
selected or deselected?
- How
do I control scrolling in the 1.1 AWT?
LOW-LEVEL
EVENTS
- My
frame doesn't close when I click on Quit/Close in the main menu -- how do I fix
this using the JDK 1.1?
- Is
there an event type that signals when a window is resized?
- How
do I handle events for function keys, arrow keys, and so on in the JDK 1.1
event model?
- How
does the JDK 1.1 distinguish between mouse clicks made with different buttons
on a two- or three-button mouse?
Drawing
AWT Components
- What
is the paint method for, when is it invoked, and by whom?
- What
should I put in my paint method?
- What
is repaint for, when is it invoked, and by whom?
- Why
do my repeated calls to repaint not have any effect?
- What
is update for, when is it invoked, and by whom?
- What
drawing occurs if my applet or other component reappears after being covered by
some other window?
- Can
I implement an invisible or partly transparent component?
- How
does the XOR drawing mode work?
Loading
and Drawing Images
- How
do I load an image from the net into my applet?
- How
do I load an image from a file in a stand-alone Java application, rather than
in an applet?
- When
is an image actually loaded -- why not immediately?
- How
can I make sure that my images are completely loaded before I check for their
data or parameters?
- Why
does my call to Graphics's drawImage method fail to show the image?
- Can
I force Applet's getImage method to make a new connection for each image rather
than reusing a cached version of the image?
- How
do I draw text over a background image?
- How
do I load and display a transparent GIF image over a background image?
- How
can I create an image from a buffer of raw image data (red, green, and blue
values for each pixel)?
- What
is double buffering -- how can I create and draw to an offscreen image?
- How
can I get at the raw data of an image, such as the pixel value at a given
coordinate?
Images
-- JDK 1.0.2
- Using
the JDK 1.0.2, can I clear or reset a clipping rectangle that either I or the
system has created?
- Using
the JDK 1.0.2, can I copy a subarea of one image into another image?
Images
-- JDK 1.1
- How
do I control animation with MemoryImageSource?
- Using
the JDK 1.1, how do I reset a clipping rectangle?
- What's
the best way in JDK 1.1 to draw just a subarea of an image?
Creating
and Controlling Threads
- What
is a thread?
- How
do I create a thread and start it running?
- How
does Thread's stop method work -- can I restart a stopped thread?
- How
should I stop a thread so that I can start a new thread later in its place?
- How
do I specify pause times in my program?
Thread
Interactions
- Why
is thread synchronization important for multithreaded programs?
- What
is a monitor?
- How
does the synchronized keyword work?
- What
objects do static synchronized methods use for locking?
- How
do the wait and notifyAll/notify methods enable cooperation between threads?
- How
do I achieve the effect of condition variables if the Java platform provides me
with only wait and notifyAll/notify methods?
- How
do I make one thread wait for one or more other threads to finish?
- What
do I use the yield method for?
- Does
the Java Virtual Machine protect me against deadlocks?
User
Threads versus System Threads
- Why
does my multithreaded program run fine on Windows NT/95 but block on Solaris?
- Why
do so many applets run a copy of themselves in a separate thread rather than
just running as they are?
- How
can it be that putting an applet thread to sleep in the wrong place can block
other applets from running?
- Can
I have a thread wait on an event from the operating system?
Basic
Input and Output
- How
do I read a line of input at a time?
- Why
doesn't String's replace method have any effect when I apply it to a string?
- How
can I access native operating system calls from my Java program?
- Does
Java provide standard iterator functions for inspecting a collection of
objects?
- The
Math.random method is too limited for my needs -- how can I generate random
numbers more flexibly?
Audio
- How
do I play sounds in an applet?
- How
do I play several audio clips simultaneously?
- Can
I tell when an audio clip has finished playing?
- How
can I play audio in a stand-alone application?
- What
audio formats does the JDK