JavaLanguage Section Index | Page 34
What are the differences between instance and class variables?
Instance variables have separate values for each instance of a class. Class variables maintain a single shared value for all instances of the class, even if no instance object of that class exists...more
What is a method's signature?
The signature of a method is the combination of the method's name along with the number and types of the parameters (and their order).
What is an overloaded method?
Overloaded methods are multiple methods in the same class that share the same name but have different parameter lists. Overloaded methods cannot have the same parameter lists with different return...more
How do I find out all the installed packages?
You cannot find out the installed packages. You can find out the packages with loaded classes with the help of the Package class. The following displays the loaded packages as well as their vendor...more
Where can I get the Java Language Specification (JLS)?
While you can always purchase the book, Sun provides this for free from their web site at http://java.sun.com/docs/books/jls/html/index.html. Be sure to look at the changes for Java 1.1 at http://...more
How can I get the number of days that have elapsed between two Date objects?
That depends on what you mean by "between".
If you want to find out the number of 24-hour periods between two Date objects d1 and d2 (d2 > d1) then you would do this:
double days = (d2.getTim...more
How can I force garbage collection to take place?
Strictly, you can't force it.
You can, however, call System.gc(), which is a "hint" to the runtime engine that now might be a good time to run the GC. Some implementations take that hint to hear...more
How can I implement destructors in Java?
Generally, you won't need to - the most common usage of destructors in C++ is to free memory - and java will do that for you automatically via "garbage collection" (GC). :)
That said, if you have...more
How does garbage collection work?
The best book reference for Garbage Collection is: Garbage Collection - Algorithms for Automatic Dynamic Memory Management by Jones and Lins.
It's available via Amazon and FatBrain.
After readin...more
When should I use an interface instead of an abstract class?
There are two primary axes of "inheritance" in
object-oriented languages like Java. "Implementation"
inheritance is where the sub-class inherits the actual
code implementation from the parent. ...more
How can I store and manipulate unsigned bytes in Java?
The wacky thing about Java is that bytes, shorts, ints, and longs are all signed. Thus, the code:
byte b = 0xAA;
will generate an error (rather than a warning):
possible loss of precision
fo...more
What are the differences between the == operator and the equals() method?
Well, first off, == is a fundamental operator in the
language. The result type of the expression is a boolean. For comparing
boolean types, it compares the operands for the same truth value. F...more
What's the difference between the ">>" and ">>>" operators?
">>" is a signed right shift, while ">>>" is an unsigned right shift. What this means is that if you use a signed shift on a negative number, the result will sti...more
From an inner class, "this" points to the inner object. How do I get a "this" pointer to the enclosing object?
Refer to the outer object by class name: Outer.this, in the following example.
class Outer {
int x = 5;
class Inner {
int x = 10;
public void test() {
System.o...more
How do I change what standard output or standard error goes to so it can go somewhere other than the console?
The System class allows you to reassign where these streams go to with either the static setOut(PrintStream) method or the setErr(PrintStream) method.